Class: Neo4j::Server::CypherTransaction

Inherits:
Object
  • Object
show all
Includes:
Core::CypherTranslator, Resource, Transaction::Instance
Defined in:
lib/neo4j-server/cypher_transaction.rb

Defined Under Namespace

Classes: CypherError

Constant Summary

Constants included from Core::CypherTranslator

Core::CypherTranslator::SANITIZE_ESCAPED_REGEXP

Instance Attribute Summary collapse

Attributes included from Resource

#resource_data, #resource_url

Instance Method Summary collapse

Methods included from Resource

#convert_from_json_value, #expect_response_code, #handle_response_error, #init_resource_data, #resource_headers, #resource_url_id, #response_exception, #wrap_resource

Methods included from Core::CypherTranslator

#cypher_prop_list, #escape_quotes, #escape_value, #sanitize_escape_sequences, sanitized_column_names, translate_response

Methods included from Transaction::Instance

#acquire_read_lock, #acquire_write_lock, #close, #failure, #failure?, #pop_nested!, #push_nested!, #register_instance

Constructor Details

#initialize(db, response, url, connection) ⇒ CypherTransaction

Returns a new instance of CypherTransaction.



18
19
20
21
22
23
24
25
26
# File 'lib/neo4j-server/cypher_transaction.rb', line 18

def initialize(db, response, url, connection)
  @connection = connection
  @commit_url = response.body['commit']
  @exec_url = response.headers['Location']
  raise "NO ENDPOINT URL #{@connection} : HEAD: #{response.headers.inspect}" if !@exec_url || @exec_url.empty?
  init_resource_data(response.body, url)
  expect_response_code(response,201)
  register_instance
end

Instance Attribute Details

#commit_urlObject (readonly)

Returns the value of attribute commit_url.



7
8
9
# File 'lib/neo4j-server/cypher_transaction.rb', line 7

def commit_url
  @commit_url
end

#exec_urlObject (readonly)

Returns the value of attribute exec_url.



7
8
9
# File 'lib/neo4j-server/cypher_transaction.rb', line 7

def exec_url
  @exec_url
end

Instance Method Details

#_commit_txObject



70
71
72
73
74
75
# File 'lib/neo4j-server/cypher_transaction.rb', line 70

def _commit_tx
  response = @connection.post(@commit_url)

  expect_response_code(response,200)
  response
end

#_create_cypher_response(response) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/neo4j-server/cypher_transaction.rb', line 49

def _create_cypher_response(response)
  first_result = response.body['results'][0]
  cr = CypherResponse.new(response, true)

  if (response.body['errors'].empty?)
    cr.set_data(first_result['data'], first_result['columns'])
  else
    first_error = response.body['errors'].first
    cr.set_error(first_error['message'], first_error['code'], first_error['code'])
  end
  cr
end

#_delete_txObject



64
65
66
67
68
# File 'lib/neo4j-server/cypher_transaction.rb', line 64

def _delete_tx
  response = @connection.delete(@exec_url, headers: resource_headers)
  expect_response_code(response,200)
  response
end

#_query(cypher_query, params = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/neo4j-server/cypher_transaction.rb', line 28

def _query(cypher_query, params=nil)
  statement = {statement: cypher_query}
  body = {statements: [statement]}

  if params
    # TODO can't get this working for some reason using parameters
    #props = params.keys.inject({}) do|ack, k|
    #  ack[k] = {name: params[k]}
    #  ack
    #end
    #statement[:parameters] = props

    # So we have to do this workaround
    params.each_pair do |k,v|
      statement[:statement].gsub!("{ #{k} }", "#{escape_value(v)}")
    end
  end
  response = @connection.post(@exec_url, body)
  _create_cypher_response(response)
end