Module: Neon::TransactionHelpers::Embedded
- Included in:
- PropertyContainer::Embedded
- Defined in:
- lib/helpers/transaction_helpers.rb
Instance Method Summary collapse
-
#run_in_transaction(&block) ⇒ Object
Used by objects to run a block of code inside a fresh transaction associated.
Instance Method Details
#run_in_transaction(&block) ⇒ Object
Used by objects to run a block of code inside a fresh transaction associated
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/helpers/transaction_helpers.rb', line 21 def run_in_transaction(&block) # Retrieve appropriate session based on current type # REST: # Session: self # Entity: @session # Embedded: # Session: self # Entity: get_graph_database if respond_to?(:get_graph_database) begin tx = get_graph_database.begin_tx result = yield if block_given? tx.success tx.close rescue Exception => e # Roll back the transaction tx.failure tx.close raise e # Let the exception bubble up end else session = @session || self result = if session.auto_tx r = Transaction.run(session, &block) r.pop r = r.pop if r.length == 1 r else yield if block_given? end end result end |