longzenvo / log4jdbc

Automatically exported from code.google.com/p/log4jdbc
0 stars 0 forks source link

support AOP #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
package net.sf.log4jdbc;

import java.sql.Connection;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class DataSourceSpyInterceptor implements MethodInterceptor {

    private RdbmsSpecifics rdbmsSpecifics = null;

    private RdbmsSpecifics getRdbmsSpecifics(Connection conn) {
        if(rdbmsSpecifics == null) {
            rdbmsSpecifics = DriverSpy.getRdbmsSpecifics(conn);
        }
        return rdbmsSpecifics;
    }

    public Object invoke(MethodInvocation invocation) throws Throwable {
        Object result = invocation.proceed();
        if(SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled()) {
            if(result instanceof Connection) {
                Connection conn = (Connection)result;
                return new ConnectionSpy(conn,getRdbmsSpecifics(conn));
            }
        }
        return result;
    }

}

spring config:

{{{
<bean id="log4jdbcInterceptor" class="net.sf.log4jdbc.DataSourceSpyInterceptor" 
/>
   <bean id="dataSourceLog4jdbcAutoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="interceptorNames">
          <list>
             <value>log4jdbcInterceptor</value>        
          </list>
      </property>
      <property name="beanNames">
          <list>
             <value>dataSource</value>
          </list>
      </property>
   </bean>
}}}

Original issue reported on code.google.com by bad...@gmail.com on 20 Aug 2010 at 3:25

GoogleCodeExporter commented 9 years ago
not planning to add aop support.

Original comment by arthur.b...@gmail.com on 15 Jun 2011 at 2:01

GoogleCodeExporter commented 9 years ago
See https://code.google.com/p/log4jdbc/issues/detail?id=60
It may help

Original comment by MatveevA...@gmail.com on 19 Mar 2013 at 2:25