1 16 package com.ibatis.common.jdbc.logging; 17 18 import com.ibatis.common.beans.ClassInfo; 19 import com.ibatis.common.logging.Log; 20 import com.ibatis.common.logging.LogFactory; 21 22 import java.lang.reflect.InvocationHandler ; 23 import java.lang.reflect.Method ; 24 import java.lang.reflect.Proxy ; 25 import java.sql.ResultSet ; 26 import java.sql.Statement ; 27 28 31 public class StatementLogProxy extends BaseLogProxy implements InvocationHandler { 32 33 private static final Log log = LogFactory.getLog(Statement .class); 34 35 private Statement statement; 36 37 private StatementLogProxy(Statement stmt) { 38 super(); 39 this.statement = stmt; 40 } 41 42 public Object invoke(Object proxy, Method method, Object [] params) throws Throwable { 43 try { 44 if (EXECUTE_METHODS.contains(method.getName())) { 45 if (log.isDebugEnabled()) { 46 log.debug("{stmt-" + id + "} Statement: " + removeBreakingWhitespace((String ) params[0])); 47 } 48 if ("executeQuery".equals(method.getName())) { 49 ResultSet rs = (ResultSet ) method.invoke(statement, params); 50 if ( rs != null ) { 51 return ResultSetLogProxy.newInstance(rs); 52 } 53 else { 54 return null; 55 } 56 } else { 57 return method.invoke(statement, params); 58 } 59 } else if ("getResultSet".equals(method.getName())) { 60 ResultSet rs = (ResultSet ) method.invoke(statement, params); 61 if ( rs != null ) { 62 return ResultSetLogProxy.newInstance(rs); 63 } 64 else { 65 return null; 66 } 67 } else { 68 return method.invoke(statement, params); 69 } 70 } catch (Throwable t) { 71 throw ClassInfo.unwrapThrowable(t); 72 } 73 } 74 75 80 public static Statement newInstance(Statement stmt) { 81 InvocationHandler handler = new StatementLogProxy(stmt); 82 ClassLoader cl = Statement .class.getClassLoader(); 83 return (Statement ) Proxy.newProxyInstance(cl, new Class []{Statement .class}, handler); 84 } 85 86 } 87 | Popular Tags |