public static Statement newInstance(Statement stmt, Log statementLog, int queryStack) { InvocationHandler handler = new StatementLogger(stmt, statementLog, queryStack); ClassLoader cl = Statement.class.getClassLoader(); return (Statement) Proxy.newProxyInstance(cl, new Class[]{Statement.class}, handler); }
@Override public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { try { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, params); } if (EXECUTE_METHODS.contains(method.getName())) { if (isDebugEnabled()) { debug(" Executing: " + removeBreakingWhitespace((String) params[0]), true); } if ("executeQuery".equals(method.getName())) { ResultSet rs = (ResultSet) method.invoke(statement, params); return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack); } else { return method.invoke(statement, params); } } else if ("getResultSet".equals(method.getName())) { ResultSet rs = (ResultSet) method.invoke(statement, params); return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack); } else { return method.invoke(statement, params); } } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } }
} else if ("createStatement".equals(method.getName())) { Statement stmt = (Statement) method.invoke(connection, params); stmt = StatementLogger.newInstance(stmt, statementLog, queryStack); return stmt; } else {
if (EXECUTE_METHODS.contains(method.getName())) { if (log.isDebugEnabled()) { log.debug("==> Executing: " + removeBreakingWhitespace((String) params[0]));
} else if ("createStatement".equals(method.getName())) { Statement stmt = (Statement) method.invoke(connection, params); stmt = StatementLogger.newInstance(stmt, statementLog, queryStack); return stmt; } else {
@Override public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { try { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, params); } if (EXECUTE_METHODS.contains(method.getName())) { if (isDebugEnabled()) { debug(" Executing: " + removeBreakingWhitespace((String) params[0]), true); } if ("executeQuery".equals(method.getName())) { ResultSet rs = (ResultSet) method.invoke(statement, params); return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack); } else { return method.invoke(statement, params); } } else if ("getResultSet".equals(method.getName())) { ResultSet rs = (ResultSet) method.invoke(statement, params); return rs == null ? null : ResultSetLogger.newInstance(rs, statementLog, queryStack); } else { return method.invoke(statement, params); } } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } }
/** * Creates a logging version of a Statement * * @param stmt - the statement * @return - the proxy */ public static Statement newInstance(Statement stmt, Log statementLog, int queryStack) { InvocationHandler handler = new StatementLogger(stmt, statementLog, queryStack); ClassLoader cl = Statement.class.getClassLoader(); return (Statement) Proxy.newProxyInstance(cl, new Class[]{Statement.class}, handler); }
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { try { if ("prepareStatement".equals(method.getName())) { PreparedStatement stmt = (PreparedStatement) method.invoke(connection, params); stmt = PreparedStatementLogger.newInstance(stmt, (String) params[0]); return stmt; } else if ("prepareCall".equals(method.getName())) { PreparedStatement stmt = (PreparedStatement) method.invoke(connection, params); stmt = PreparedStatementLogger.newInstance(stmt, (String) params[0]); return stmt; } else if ("createStatement".equals(method.getName())) { Statement stmt = (Statement) method.invoke(connection, params); stmt = StatementLogger.newInstance(stmt); return stmt; } else if ("close".equals(method.getName())) { if (log.isDebugEnabled()) { log.debug("xxx Connection Closed"); } return method.invoke(connection, params); } else { return method.invoke(connection, params); } } catch (Throwable t) { Throwable t1 = ExceptionUtil.unwrapThrowable(t); log.error("Error calling Connection." + method.getName() + ':', t1); throw t1; } }
/** * Creates a logging version of a Statement * * @param stmt - the statement * @return - the proxy */ public static Statement newInstance(Statement stmt) { InvocationHandler handler = new StatementLogger(stmt); ClassLoader cl = Statement.class.getClassLoader(); return (Statement) Proxy.newProxyInstance(cl, new Class[]{Statement.class}, handler); }