1
2
3
4
5
6
7
8
9
10
11
12package jdbc_wrapper;
13
14import java.lang.reflect.Method;
15import java.util.logging.Logger;
16
17import org.aopalliance.intercept.MethodInterceptor;
18import org.aopalliance.intercept.MethodInvocation;
19
20public class JDBCLoggingInterceptor implements MethodInterceptor
21{
22 private static final Logger LOG = Logger.getLogger("jdbc.trace");
23
24 public Object invoke(MethodInvocation invocation) throws Throwable
25 {
26 Method method = invocation.getMethod();
27 if (method.getDeclaringClass() == Object.class)
28 {
29
30 return invocation.proceed();
31 }
32
33 String className = invocation.getThis().getClass().getName();
34 String methodName = method.getName();
35
36 LOG.entering(className, methodName, invocation.getArguments());
37 Object result = invocation.proceed();
38 LOG.exiting(className, methodName, result);
39
40 return result;
41 }
42
43}
// Copyright 2007, Tim Vernum
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package jdbc_wrapper;
import java.lang.reflect.Method;
import java.util.logging.Logger;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class JDBCLoggingInterceptor implements MethodInterceptor
{
private static final Logger LOG = Logger.getLogger("jdbc.trace");
public Object invoke(MethodInvocation invocation) throws Throwable
{
Method method = invocation.getMethod();
if (method.getDeclaringClass() == Object.class)
{
// Don't log "toString", "hashCode", etc
return invocation.proceed();
}
String className = invocation.getThis().getClass().getName();
String methodName = method.getName();
LOG.entering(className, methodName, invocation.getArguments());
Object result = invocation.proceed();
LOG.exiting(className, methodName, result);
return result;
}
}