Method: Zermelo::Records::ClassMethods#transaction

Defined in:
lib/zermelo/records/class_methods.rb

#transaction(&block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/zermelo/records/class_methods.rb', line 53

def transaction(&block)
  failed = false

  backend.begin_transaction

  begin
    yield
  rescue Exception => e
    backend.abort_transaction
    # p e.message
    # puts e.backtrace.join("\n")
    failed = true
  ensure
    backend.commit_transaction unless failed
  end

  # TODO include exception info
  raise "Transaction failed" if failed
end