public static ResultSet newInstance(ResultSet rs, Log statementLog, int queryStack) { InvocationHandler handler = new ResultSetLogger(rs, statementLog, queryStack); ClassLoader cl = ResultSet.class.getClassLoader(); return (ResultSet) Proxy.newProxyInstance(cl, new Class[]{ResultSet.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); } Object o = method.invoke(rs, params); if ("next".equals(method.getName())) { if ((Boolean) o) { rows++; if (isTraceEnabled()) { ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); if (first) { first = false; printColumnHeaders(rsmd, columnCount); } printColumnValues(columnCount); } } else { debug(" Total: " + rows, false); } } clearColumnInfo(); return o; } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } }
private void printColumnHeaders(ResultSetMetaData rsmd, int columnCount) throws SQLException { StringBuilder row = new StringBuilder(); row.append(" Columns: "); for (int i = 1; i <= columnCount; i++) { if (BLOB_TYPES.contains(rsmd.getColumnType(i))) { blobColumns.add(i); } String colname = rsmd.getColumnLabel(i); row.append(colname); if (i != columnCount) { row.append(", "); } } trace(row.toString(), false); }
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { try { Object o = method.invoke(rs, params); if ("next".equals(method.getName())) { if (((Boolean) o)) { ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); if (log.isDebugEnabled()) { if (first) { first = false; printColumnHeaders(rsmd, columnCount); } printColumnValues(columnCount); } } } clearColumnInfo(); return o; } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } }
@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); } }
@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); } }
@Override public Object invoke(Object proxy, Method method, Object[] params) throws Throwable { try { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, params); } Object o = method.invoke(rs, params); if ("next".equals(method.getName())) { if (((Boolean) o)) { rows++; if (isTraceEnabled()) { ResultSetMetaData rsmd = rs.getMetaData(); final int columnCount = rsmd.getColumnCount(); if (first) { first = false; printColumnHeaders(rsmd, columnCount); } printColumnValues(columnCount); } } else { debug(" Total: " + rows, false); } } clearColumnInfo(); return o; } catch (Throwable t) { throw ExceptionUtil.unwrapThrowable(t); } }
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 if ("getUpdateCount".equals(method.getName())) { int updateCount = (Integer) method.invoke(statement, params);
/** * Creates a logging version of a ResultSet * * @param rs - the ResultSet to proxy * @return - the ResultSet with logging */ public static ResultSet newInstance(ResultSet rs, Log statementLog, int queryStack) { InvocationHandler handler = new ResultSetLogger(rs, statementLog, queryStack); ClassLoader cl = ResultSet.class.getClassLoader(); return (ResultSet) Proxy.newProxyInstance(cl, new Class[]{ResultSet.class}, handler); }
private void printColumnHeaders(ResultSetMetaData rsmd, int columnCount) throws SQLException { StringBuilder row = new StringBuilder(); row.append(" Columns: "); for (int i = 1; i <= columnCount; i++) { if (BLOB_TYPES.contains(rsmd.getColumnType(i))) { blobColumns.add(i); } String colname = rsmd.getColumnLabel(i); row.append(colname); if (i != columnCount) { row.append(", "); } } trace(row.toString(), false); }
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 if ("getUpdateCount".equals(method.getName())) { int updateCount = (Integer) method.invoke(statement, params);
/** * Creates a logging version of a ResultSet * * @param rs - the ResultSet to proxy * @return - the ResultSet with logging */ public static ResultSet newInstance(ResultSet rs) { InvocationHandler handler = new ResultSetLogger(rs); ClassLoader cl = ResultSet.class.getClassLoader(); return (ResultSet) Proxy.newProxyInstance(cl, new Class[]{ResultSet.class}, handler); }
private void printColumnValues(int columnCount) { StringBuilder row = new StringBuilder(); row.append(" Row: "); for (int i = 1; i <= columnCount; i++) { String colname; try { if (blobColumns.contains(i)) { colname = "<<BLOB>>"; } else { colname = rs.getString(i); } } catch (SQLException e) { // generally can't call getString() on a BLOB column colname = "<<Cannot Display>>"; } row.append(colname); if (i != columnCount) { row.append(", "); } } trace(row.toString(), false); }
ResultSet rs = (ResultSet) method.invoke(statement, params); if (rs != null) { return ResultSetLogger.newInstance(rs); } else { return null; ResultSet rs = (ResultSet) method.invoke(statement, params); if (rs != null) { return ResultSetLogger.newInstance(rs); } else { return null;
private void printColumnValues(int columnCount) { StringBuilder row = new StringBuilder(); row.append(" Row: "); for (int i = 1; i <= columnCount; i++) { String colname; try { if (blobColumns.contains(i)) { colname = "<<BLOB>>"; } else { colname = rs.getString(i); } } catch (SQLException e) { // generally can't call getString() on a BLOB column colname = "<<Cannot Display>>"; } row.append(colname); if (i != columnCount) { row.append(", "); } } trace(row.toString(), false); }
ResultSet rs = (ResultSet) method.invoke(statement, params); if (rs != null) { return ResultSetLogger.newInstance(rs); } else { return null; ResultSet rs = (ResultSet) method.invoke(statement, params); if (rs != null) { return ResultSetLogger.newInstance(rs); } else { return null;