Class: Seasar::DBI::TxInterceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/seasar/dbi/tx-interceptor.rb

Instance Method Summary collapse

Constructor Details

#initializeTxInterceptor

  • args

    • none



27
28
29
# File 'lib/seasar/dbi/tx-interceptor.rb', line 27

def initialize
  @dbh = :di, ::DBI::DatabaseHandle
end

Instance Method Details

#call(invocation) ⇒ Object

  • args

    1. Seasar::Aop::MethodInvocation invocation

  • return

    • Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/seasar/dbi/tx-interceptor.rb', line 37

def call(invocation)
  result = nil
  @dbh['AutoCommit'] = false
  begin
    result = invocation.proceed
    @dbh.commit
  rescue
    s2logger.info(self.class.name){"doing rollback..."}
    @dbh.rollback
    s2logger.info(self.class.name){"rollback has occured."}
    raise
  ensure
    @dbh['AutoCommit'] = true
  end
  return result
end