Module: Neo4j::Transaction
Defined Under Namespace
Modules: Instance
Instance Method Summary collapse
- #current ⇒ Neo4j::Transaction
- #new(current = Session.current!) ⇒ Neo4j::Transaction::Instance
- #print_exception_cause(exception) ⇒ Object
- #register(tx) ⇒ Object
-
#run(run_in_tx = true) ⇒ Object
Runs the given block in a new transaction.
- #unregister(tx) ⇒ Object
- #unregister_current ⇒ Object
Instance Method Details
#current ⇒ Neo4j::Transaction
115 116 117 |
# File 'lib/neo4j/transaction.rb', line 115 def current Thread.current[:neo4j_curr_tx] end |
#new(current = Session.current!) ⇒ Neo4j::Transaction::Instance
92 93 94 |
# File 'lib/neo4j/transaction.rb', line 92 def new(current = Session.current!) current.begin_tx end |
#print_exception_cause(exception) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/neo4j/transaction.rb', line 120 def print_exception_cause(exception) return if !exception.respond_to?(:cause) || !exception.cause.respond_to?(:print_stack_trace) puts "Java Exception in a transaction, cause: #{exception.cause}" exception.cause.print_stack_trace end |
#register(tx) ⇒ Object
133 134 135 136 137 |
# File 'lib/neo4j/transaction.rb', line 133 def register(tx) # we don't support running more then one transaction per thread fail 'Already running a transaction' if current Thread.current[:neo4j_curr_tx] = tx end |
#run(run_in_tx = true) ⇒ Object
Runs the given block in a new transaction. @@yield [Neo4j::Transaction::Instance]
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/neo4j/transaction.rb', line 99 def run(run_in_tx = true) fail ArgumentError, 'Expected a block to run in Transaction.run' unless block_given? return yield(nil) unless run_in_tx tx = Neo4j::Transaction.new yield tx rescue Exception => e # rubocop:disable Lint/RescueException print_exception_cause(e) tx.mark_failed unless tx.nil? raise ensure tx.close unless tx.nil? end |
#unregister(tx) ⇒ Object
128 129 130 |
# File 'lib/neo4j/transaction.rb', line 128 def unregister(tx) Thread.current[:neo4j_curr_tx] = nil if tx == Thread.current[:neo4j_curr_tx] end |
#unregister_current ⇒ Object
140 141 142 |
# File 'lib/neo4j/transaction.rb', line 140 def unregister_current Thread.current[:neo4j_curr_tx] = nil end |