Method: Bdb::Environment#transaction

Defined in:
lib/bdb/environment.rb

#transaction(nested = true) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bdb/environment.rb', line 84

def transaction(nested = true)
  return @transaction unless block_given?
  return yield if disable_transactions?

  synchronize do
    parent = @transaction
    begin
      @transaction = env.txn_begin(nested ? parent : nil, 0)
      value = yield
      @transaction.commit(0)
      @transaction = nil
      value
    ensure
      @transaction.abort if @transaction
      @transaction = parent
    end
  end
end