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 27 30 public class ResultSetLogProxy extends BaseLogProxy implements InvocationHandler { 31 32 private static final Log log = LogFactory.getLog(ResultSet .class); 33 34 boolean first = true; 35 private ResultSet rs; 36 37 private ResultSetLogProxy(ResultSet rs) { 38 super(); 39 this.rs = rs; 40 if (log.isDebugEnabled()) { 41 log.debug("{rset-" + id + "} ResultSet"); 42 } 43 } 44 45 public Object invoke(Object proxy, Method method, Object [] params) throws Throwable { 46 try { 47 Object o = method.invoke(rs, params); 48 if (GET_METHODS.contains(method.getName())) { 49 if (params[0] instanceof String ) { 50 setColumn(params[0], o); 51 } 55 } else if ("next".equals(method.getName())) { 56 String s = getValueString(); 57 if (!"[]".equals(s)) { 58 if (first) { 59 first = false; 60 if (log.isDebugEnabled()) { 61 log.debug("{rset-" + id + "} Header: " + getColumnString()); 62 } 63 } 64 if (log.isDebugEnabled()) { 65 log.debug("{rset-" + id + "} Result: " + s); 66 } 67 } 68 clearColumnInfo(); 69 } 70 return o; 71 } catch (Throwable t) { 72 throw ClassInfo.unwrapThrowable(t); 73 } 74 } 75 76 82 public static ResultSet newInstance(ResultSet rs) { 83 InvocationHandler handler = new ResultSetLogProxy(rs); 84 ClassLoader cl = ResultSet .class.getClassLoader(); 85 return (ResultSet ) Proxy.newProxyInstance(cl, new Class []{ResultSet .class}, handler); 86 } 87 88 89 } 90 | Popular Tags |