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

#currentNeo4j::Transaction



97
98
99
# File 'lib/neo4j/transaction.rb', line 97

def current
  Thread.current[:neo4j_curr_tx]
end

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



68
69
70
# File 'lib/neo4j/transaction.rb', line 68

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

#run(run_in_tx = true) ⇒ Object

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

Raises:

  • (ArgumentError)


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

def run(run_in_tx=true)
  raise ArgumentError.new("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
    if e.respond_to?(:cause) && e.cause
      puts "Java Exception in a transaction, cause: #{e.cause}"
      e.cause.print_stack_trace
    end
    tx.failure unless tx.nil?
    raise
  ensure
    tx.close unless tx.nil?
  end
  ret
end