public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
try {
if (method.getDeclaringClass() == DataSource.class
&& "getConnection".equals(method.getName())) {
Connection conn = (Connection)method.invoke(_delegate, args);
print("getConnection (tx=" + conn.getTransactionIsolation() + ")");
return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(),
new Class[] {Connection.class}, new LoggingInterceptor<Connection>(conn, _log));
} else if (method.getDeclaringClass() == Connection.class
&& Statement.class.isAssignableFrom(method.getReturnType())) {
Statement stmt = (Statement)method.invoke(_delegate, args);
print(method, args);
return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(),
new Class[] {method.getReturnType()}, new LoggingInterceptor<Statement>(stmt, _log));
} else {
print(method, args);
return method.invoke(_delegate, args);
}
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}