Class: Seasar::DBI::DBIInterceptor
- Inherits:
-
Object
- Object
- Seasar::DBI::DBIInterceptor
- Defined in:
- lib/seasar/dbi/dbi-interceptor.rb
Defined Under Namespace
Classes: ConnectError
Instance Attribute Summary collapse
-
#auto_finish ⇒ Object
Returns the value of attribute auto_finish.
Instance Method Summary collapse
-
#call(invocation) ⇒ Object
-
args 1.
-
-
#finish_all ⇒ Object
-
args - none - return - none.
-
-
#initialize ⇒ DBIInterceptor
constructor
-
args - none.
-
Constructor Details
#initialize ⇒ DBIInterceptor
-
args
-
none
-
28 29 30 31 32 |
# File 'lib/seasar/dbi/dbi-interceptor.rb', line 28 def initialize @dbh = :di, ::DBI::DatabaseHandle @statements = {} @auto_finish = true end |
Instance Attribute Details
#auto_finish ⇒ Object
Returns the value of attribute auto_finish.
33 34 35 |
# File 'lib/seasar/dbi/dbi-interceptor.rb', line 33 def auto_finish @auto_finish end |
Instance Method Details
#call(invocation) ⇒ Object
-
args
-
Seasar::Aop::MethodInvocation invocation
-
-
return
-
Object
-
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/seasar/dbi/dbi-interceptor.rb', line 42 def call(invocation) sql, context = invocation.proceed sql.strip! context = invocation.args if context.nil? if !context.is_a?(Array) && !context.is_a?(Hash) context = [context] end if not @statements.key?(sql) or @statements[sql].finished? s2logger.debug(self.class.name){"#{sql} : (#{context.inspect})"} @statements[sql] = @dbh.prepare(sql) end begin if context.is_a?(Array) @statements[sql].execute(*context) else @statements[sql].execute(context) end rescue => e @statements[sql].finish raise e end if @statements[sql].column_names.size == 0 result = @statements[sql].rows else result = [] @statements[sql].fetch_hash {|row| result << row} end @statements[sql].finish if @auto_finish return result end |
#finish_all ⇒ Object
-
args
-
none
-
-
return
-
none
-
82 83 84 |
# File 'lib/seasar/dbi/dbi-interceptor.rb', line 82 def finish_all @statements.each {|key, val| val.finish if not val.finished? } end |