Class: Neo4j::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/transaction.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) current



32
33
34
# File 'lib/neo4j/transaction.rb', line 32

def current
  Thread.current[:neo4j_curr_tx]
end

+ (Object) new(current = Session.current)



3
4
5
# File 'lib/neo4j/transaction.rb', line 3

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

+ (Object) register(tx)



40
41
42
43
44
# File 'lib/neo4j/transaction.rb', line 40

def register(tx)
  # we don't support running more then one transaction per thread
  raise "Already running a transaction" if current
  Thread.current[:neo4j_curr_tx] = tx
end

+ (Object) run(run_in_tx = true)

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/neo4j/transaction.rb', line 10

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
    tx.success
  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.finish unless tx.nil?
  end
  ret
end

+ (Object) unregister(tx)



36
37
38
# File 'lib/neo4j/transaction.rb', line 36

def unregister(tx)
  Thread.current[:neo4j_curr_tx] = nil if tx == Thread.current[:neo4j_curr_tx]
end

+ (Object) unregister_current



46
47
48
# File 'lib/neo4j/transaction.rb', line 46

def unregister_current
  Thread.current[:neo4j_curr_tx] = nil
end