[Proxool-cvs] proxool/src/java/org/logicalcobwebs/proxool AbstractProxyStatement.java,1.12,1.13 Prox
UNMAINTAINED!
Brought to you by:
billhorsman
From: <bil...@us...> - 2003-10-18 20:50:55
|
Update of /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool In directory sc8-pr-cvs1:/tmp/cvs-serv9584 Modified Files: AbstractProxyStatement.java ProxyStatement.java Log Message: Better SQL logging (embed parameter values within SQL call) and works properly with batched statements now. Index: AbstractProxyStatement.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/AbstractProxyStatement.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** AbstractProxyStatement.java 30 Sep 2003 18:39:07 -0000 1.12 --- AbstractProxyStatement.java 18 Oct 2003 20:44:48 -0000 1.13 *************** *** 20,24 **** * statement. The subclass of this defines how we delegate to the * real statement. - * @version $Revision$, $Date$ * @author bill --- 20,23 ---- *************** *** 40,43 **** --- 39,44 ---- private String sqlStatement; + private StringBuffer sqlLog = new StringBuffer(); + /** * @param statement the real statement that we will delegate to *************** *** 146,150 **** Object key = new Integer(index); if (value == null) { ! parameters.put(key, "*"); } else if (value instanceof String) { parameters.put(key, "'" + value + "'"); --- 147,151 ---- Object key = new Integer(index); if (value == null) { ! parameters.put(key, "NULL"); } else if (value instanceof String) { parameters.put(key, "'" + value + "'"); *************** *** 171,183 **** // Log if configured to if (connectionPool.getLog().isDebugEnabled() && connectionPool.getDefinition().isTrace()) { ! if (parameters != null) { ! connectionPool.getLog().debug(parameters + " -> " + sqlStatement + " (" + (System.currentTimeMillis() - startTime) + " milliseconds)"); ! } else { ! connectionPool.getLog().debug(sqlStatement + " (" + (System.currentTimeMillis() - startTime) + " milliseconds)"); ! } } // Send to any listener ! connectionPool.onExecute(parameters + " -> " + sqlStatement, (System.currentTimeMillis() - startTime), exception); // Clear parameters for next time --- 172,180 ---- // Log if configured to if (connectionPool.getLog().isDebugEnabled() && connectionPool.getDefinition().isTrace()) { ! connectionPool.getLog().debug(sqlLog.toString() + " (" + (System.currentTimeMillis() - startTime) + " milliseconds" + (exception != null ? ", threw " + exception.getMessage() + ")" : ")")); } // Send to any listener ! connectionPool.onExecute(sqlLog.toString(), (System.currentTimeMillis() - startTime), exception); // Clear parameters for next time *************** *** 186,192 **** --- 183,220 ---- } sqlStatement = null; + sqlLog.setLength(0); } + /** + * Get the parameters that have been built up and use them to fill in any parameters + * withing the sqlStatement and produce a log. If the log already exists (for instance, + * if a batch is being peformed) then it is appended to the end. + */ + protected void appendToSqlLog() { + int parameterIndex = 0; + StringTokenizer st = new StringTokenizer(sqlStatement, "?"); + while (st.hasMoreTokens()) { + if (parameterIndex > 0) { + if (parameters != null) { + final Object value = parameters.get(new Integer(parameterIndex)); + if (value != null) { + sqlLog.append(value); + } else { + sqlLog.append("?"); + } + } else { + sqlLog.append("?"); + } + } + parameterIndex++; + sqlLog.append(st.nextToken()); + } + sqlLog.append("; "); + if (parameters != null) { + parameters.clear(); + } + } + protected boolean isTrace() { boolean isTrace = getConnectionPool().isConnectionListenedTo() || (getConnectionPool().getDefinition().isTrace() && getConnectionPool().getLog().isDebugEnabled()); *************** *** 209,212 **** --- 237,243 ---- Revision history: $Log$ + Revision 1.13 2003/10/18 20:44:48 billhorsman + Better SQL logging (embed parameter values within SQL call) and works properly with batched statements now. + Revision 1.12 2003/09/30 18:39:07 billhorsman New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. Index: ProxyStatement.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/proxool/ProxyStatement.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ProxyStatement.java 30 Sep 2003 18:39:08 -0000 1.22 --- ProxyStatement.java 18 Oct 2003 20:44:48 -0000 1.23 *************** *** 29,32 **** --- 29,36 ---- private static final String EXECUTE_FRAGMENT = "execute"; + private static final String EXECUTE_BATCH_METHOD = "executeBatch"; + + private static final String ADD_BATCH_METHOD = "addBatch"; + private static final String EQUALS_METHOD = "equals"; *************** *** 93,101 **** } finally { ! // If we executed something then we should tell the listener. ! if (method.getName().startsWith(EXECUTE_FRAGMENT)) { if (argCount > 0 && args[0] instanceof String) { setSqlStatementIfNull((String) args[0]); } trace(startTime, exception); } --- 97,115 ---- } finally { ! if (method.getName().equals(ADD_BATCH_METHOD)) { ! // If we have just added a batch call then we need to update the sql log if (argCount > 0 && args[0] instanceof String) { setSqlStatementIfNull((String) args[0]); } + appendToSqlLog(); + } else if (method.getName().equals(EXECUTE_BATCH_METHOD)) { + // executing a batch should do a trace + trace(startTime, exception); + } else if (method.getName().startsWith(EXECUTE_FRAGMENT)) { + // executing should update the log and do a trace + if (argCount > 0 && args[0] instanceof String) { + setSqlStatementIfNull((String) args[0]); + } + appendToSqlLog(); trace(startTime, exception); } *************** *** 112,115 **** --- 126,132 ---- Revision history: $Log$ + Revision 1.23 2003/10/18 20:44:48 billhorsman + Better SQL logging (embed parameter values within SQL call) and works properly with batched statements now. + Revision 1.22 2003/09/30 18:39:08 billhorsman New test-before-use, test-after-use and fatal-sql-exception-wrapper-class properties. |