module Neo4j::Transaction

Public Instance Methods

current_for(session) click to toggle source
    # File lib/neo4j/transaction.rb
160 def current_for(session)
161   stack_for(session).first
162 end
new(session = Session.current!) click to toggle source

@return [Neo4j::Transaction::Instance]

    # File lib/neo4j/transaction.rb
120 def new(session = Session.current!)
121   session.transaction
122 end
run(*args) { |nil| ... } click to toggle source

Runs the given block in a new transaction. @param [Boolean] run_in_tx if true a new transaction will not be created, instead if will simply yield to the given block @@yield [Neo4j::Transaction::Instance]

    # File lib/neo4j/transaction.rb
127 def run(*args)
128   session, run_in_tx = session_and_run_in_tx_from_args(args)
129 
130   fail ArgumentError, 'Expected a block to run in Transaction.run' unless block_given?
131 
132   return yield(nil) unless run_in_tx
133 
134   tx = Neo4j::Transaction.new(session)
135   yield tx
136 rescue Exception => e # rubocop:disable Lint/RescueException
137   # print_exception_cause(e)
138 
139   tx.mark_failed unless tx.nil?
140   raise e
141 ensure
142   tx.close unless tx.nil?
143 end
session_and_run_in_tx_from_args(args) click to toggle source

To support old syntax of providing run_in_tx first But session first is ideal

    # File lib/neo4j/transaction.rb
147 def session_and_run_in_tx_from_args(args)
148   fail ArgumentError, 'Too few arguments' if args.empty?
149   fail ArgumentError, 'Too many arguments' if args.size > 2
150 
151   if args.size == 1
152     fail ArgumentError, 'Session must be specified' if !args[0].is_a?(Neo4j::Core::CypherSession)
153 
154     [args[0], true]
155   else
156     [true, false].include?(args[0]) ? args.reverse : args.dup
157   end
158 end
stack_for(session) click to toggle source
    # File lib/neo4j/transaction.rb
164 def stack_for(session)
165   TransactionsRegistry.transactions_by_session_id ||= {}
166   TransactionsRegistry.transactions_by_session_id[session.object_id] ||= []
167 end

Private Instance Methods

print_exception_cause(exception) click to toggle source