Module: Neo4j::Transaction

Extended by:
Transaction
Included in:
Transaction
Defined in:
lib/neo4j/transaction.rb

Defined Under Namespace

Modules: Instance

Instance Method Summary (collapse)

Instance Method Details

- (Neo4j::Transaction) current

Returns:

[View source]

99
100
101
# File 'lib/neo4j/transaction.rb', line 99

def current
  Thread.current[:neo4j_curr_tx]
end

- (Neo4j::Transaction::Instance) new(current = Session.current!)

[View source]

70
71
72
# File 'lib/neo4j/transaction.rb', line 70

def new(current = Session.current!)
  current.begin_tx
end

- (Object) run(run_in_tx = true)

Runs the given block in a new transaction. @@yield [Neo4j::Transaction::Instance]

Parameters:

  • run_in_tx (Boolean) (defaults to: true)

    if true a new transaction will not be created, instead if will simply yield to the given block

[View source]

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/neo4j/transaction.rb', line 77

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

  begin
    tx = Neo4j::Transaction.new
    ret = yield tx
  rescue Exception => e # rubocop:disable Lint/RescueException
    if e.respond_to?(:cause) && e.cause.respond_to?(:print_stack_trace)
      puts "Java Exception in a transaction, cause: #{e.cause}"
      e.cause.print_stack_trace
    end
    tx.mark_failed unless tx.nil?
    raise
  ensure
    tx.close unless tx.nil?
  end
  ret
end