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



54
55
56
57
58
59
# File 'lib/neo4j-server/cypher_transaction.rb', line 54

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

  expect_response_code(response,200)
  response
end

#_create_cypher_response(response) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/neo4j-server/cypher_transaction.rb', line 35

def _create_cypher_response(response)
  first_result = response.body['results'][0]

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

#_delete_txObject



48
49
50
51
52
# File 'lib/neo4j-server/cypher_transaction.rb', line 48

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
# File 'lib/neo4j-server/cypher_transaction.rb', line 28

def _query(cypher_query, params=nil)
  statement = { statement: cypher_query, parameters: params, resultDataContents: ['row', 'REST'] }
  body = { statements: [statement] }
  response = @connection.post(@exec_url, body)
  _create_cypher_response(response)
end