Class: Neo4j::Transaction
- Inherits:
-
Object
- Object
- Neo4j::Transaction
- Defined in:
- lib/neo4j/transaction.rb
Overview
All modifying operations that work with the node space must be wrapped in a transaction. Transactions are thread confined. Neo4j does not implement true nested transaction, instead it uses flat nested transactions
Class Method Summary collapse
-
.new(instance = Neo4j.started_db) ⇒ Java::OrgNeo4jGraphdb::Transaction
Starts a new Neo4j Transaction.
-
.run {|| ... } ⇒ Object
Runs a block in a Neo4j transaction.
Instance Method Summary collapse
-
#acquire_read_lock(java_entity) ⇒ Java::OrgNeo4jGraphdb::Lock
Acquires a read lock for entity for this transaction.
-
#acquire_write_lock(java_entity) ⇒ Java::OrgNeo4jGraphdb::Lock
Acquires a write lock for entity for this transaction.
Class Method Details
.new(instance = Neo4j.started_db) ⇒ Java::OrgNeo4jGraphdb::Transaction
Starts a new Neo4j Transaction
37 38 39 |
# File 'lib/neo4j/transaction.rb', line 37 def self.new(instance = Neo4j.started_db) instance.begin_tx end |
.run {|| ... } ⇒ Object
Runs a block in a Neo4j transaction
Many operations on neo requires an transaction. You will get much better performance if one transaction is wrapped around several neo operation instead of running one transaction per neo operation. If one transaction is already running then a ‘placebo’ transaction will be created. Performing a finish on a placebo transaction will not finish the ‘real’ transaction.
If an exception occurs inside the block the transaction will rollback automatically.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/neo4j/transaction.rb', line 66 def self.run raise ArgumentError.new("Expected a block to run in Transaction.run") unless block_given? begin tx = Neo4j::Transaction.new ret = yield tx tx.success rescue Exception => e if Neo4j::Config[:debug_java] && e.respond_to?(:cause) puts "Java Exception in a transaction, cause: #{e.cause}" e.cause.print_stack_trace end tx.failure unless tx.nil? raise ensure tx.finish unless tx.nil? end ret end |
Instance Method Details
#acquire_read_lock(java_entity) ⇒ Java::OrgNeo4jGraphdb::Lock
Acquires a read lock for entity for this transaction. The lock (returned from this method) can be released manually, but if not it’s released automatically when the transaction finishes. There is no implementation for this here because it’s an java method
25 26 |
# File 'lib/neo4j/transaction.rb', line 25 def acquire_read_lock(java_entity) end |
#acquire_write_lock(java_entity) ⇒ Java::OrgNeo4jGraphdb::Lock
Acquires a write lock for entity for this transaction. The lock (returned from this method) can be released manually, but if not it’s released automatically when the transaction finishes. There is no implementation for this here because it’s an java method
16 17 |
# File 'lib/neo4j/transaction.rb', line 16 def acquire_write_lock(java_entity) end |