Class: Neo4j::Server::CypherTransaction
- Inherits:
-
Object
- Object
- Neo4j::Server::CypherTransaction
- Includes:
- Core::CypherTranslator, Resource, Transaction::Instance
- Defined in:
- lib/neo4j-server/cypher_transaction.rb
Overview
The CypherTransaction object lifecycle is as follows:
-
It is initialized with the transactional endpoint URL and the connection object to use for communication. It does not communicate with the server to create this.
-
The first query within the transaction sets the commit and execution addresses, :commit_url and :exec_url.
-
At any time, ‘failure` can be called to mark a transaction failed and trigger a rollback upon closure.
-
‘close` is called to end the transaction. It calls `_commit_tx` or `_delete_tx`.
If a transaction is created and then closed without performing any queries, an OpenStruct is returned that behaves like a successfully closed query.
Constant Summary collapse
- ROW_REST =
%w(row REST)
Constants included from Core::CypherTranslator
Core::CypherTranslator::EMPTY_PROPS, Core::CypherTranslator::SANITIZE_ESCAPED_REGEXP
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#commit_url ⇒ Object
readonly
Returns the value of attribute commit_url.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#exec_url ⇒ Object
readonly
Returns the value of attribute exec_url.
Attributes included from Resource
Instance Method Summary collapse
- #_commit_tx ⇒ Object
- #_delete_tx ⇒ Object
- #_query(cypher_query, params = nil) ⇒ Object
-
#initialize(url, session_connection) ⇒ CypherTransaction
constructor
A new instance of CypherTransaction.
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
#create_escape_value, #cypher_prop_list, #cypher_string, #escape_quotes, #escape_value, #label_string, #prop_identifier, #sanitize_escape_sequences, sanitized_column_names, translate_response
Methods included from Transaction::Instance
#acquire_read_lock, #acquire_write_lock, #close, #expired?, #failed?, #mark_expired, #mark_failed, #pop_nested!, #push_nested!, #register_instance
Constructor Details
#initialize(url, session_connection) ⇒ CypherTransaction
Returns a new instance of CypherTransaction.
17 18 19 20 21 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 17 def initialize(url, session_connection) @base_url = url @connection = session_connection register_instance end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
15 16 17 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 15 def base_url @base_url end |
#commit_url ⇒ Object (readonly)
Returns the value of attribute commit_url.
15 16 17 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 15 def commit_url @commit_url end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
15 16 17 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 15 def connection @connection end |
#exec_url ⇒ Object (readonly)
Returns the value of attribute exec_url.
15 16 17 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 15 def exec_url @exec_url end |
Instance Method Details
#_commit_tx ⇒ Object
37 38 39 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 37 def _commit_tx _tx_query(:post, commit_url, nil) end |
#_delete_tx ⇒ Object
33 34 35 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 33 def _delete_tx _tx_query(:delete, exec_url, headers: resource_headers) end |
#_query(cypher_query, params = nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/neo4j-server/cypher_transaction.rb', line 24 def _query(cypher_query, params = nil) fail 'Transaction expired, unable to perform query' if expired? statement = {statement: cypher_query, parameters: params, resultDataContents: ROW_REST} body = {statements: [statement]} response = exec_url && commit_url ? connection.post(exec_url, body) : register_urls(body) _create_cypher_response(response) end |