Author: fhanik Date: Wed Aug 5 16:19:34 2009 New Revision: 801284 URL: http://svn.apache.org/viewvc?rev=801284&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47612 patch provided by sebb Abstract classes, private-> protected for subclass access
Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java?rev=801284&r1=801283&r2=801284&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java (original) +++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java Wed Aug 5 16:19:34 2009 @@ -30,8 +30,22 @@ * @version 1.0 */ public abstract class AbstractCreateStatementInterceptor extends JdbcInterceptor { - public static final String[] statements = {"createStatement","prepareStatement","prepareCall"}; - public static final String[] executes = {"execute","executeQuery","executeUpdate","executeBatch"}; + protected static final String CREATE_STATEMENT = "createStatement"; + protected static final int CREATE_STATEMENT_IDX = 0; + protected static final String PREPARE_STATEMENT = "prepareStatement"; + protected static final int PREPARE_STATEMENT_IDX = 1; + protected static final String PREPARE_CALL = "prepareCall"; + protected static final int PREPARE_IDX = 2; + + protected static final String[] STATEMENT_TYPES = {CREATE_STATEMENT, PREPARE_STATEMENT, PREPARE_CALL}; + protected static final int STATEMENT_TYPE_COUNT = STATEMENT_TYPES.length; + + protected static final String EXECUTE = "execute"; + protected static final String EXECUTE_QUERY = "executeQuery"; + protected static final String EXECUTE_UPDATE = "executeUpdate"; + protected static final String EXECUTE_BATCH = "executeBatch"; + + protected static final String[] EXECUTE_TYPES = {EXECUTE, EXECUTE_QUERY, EXECUTE_UPDATE, EXECUTE_BATCH}; public AbstractCreateStatementInterceptor() { super(); @@ -47,7 +61,7 @@ return super.invoke(proxy, method, args); } else { boolean process = false; - process = process(statements, method, process); + process = isStatement(method, process); if (process) { long start = System.currentTimeMillis(); Object statement = super.invoke(proxy,method,args); @@ -65,7 +79,7 @@ * If this method returns a wrapper then it should return a wrapper object that implements one of the following interfaces. * {...@link java.sql.Statement}, {...@link java.sql.PreparedStatement} or {...@link java.sql.CallableStatement} * @param proxy the actual proxy object - * @param method the method that was called. It will be one of the methods defined in {...@link #statements} + * @param method the method that was called. It will be one of the methods defined in {...@link #STATEMENT_TYPES} * @param args the arguments to the method * @param statement the statement that the underlying connection created * @return a {...@link java.sql.Statement} object @@ -78,6 +92,28 @@ public abstract void closeInvoked(); /** + * Returns true if the method that is being invoked matches one of the statement types. + * + * @param method the method being invoked on the proxy + * @param process boolean result used for recursion + * @return returns true if the method name matched + */ + protected boolean isStatement(Method method, boolean process){ + return process(STATEMENT_TYPES, method, process); + } + + /** + * Returns true if the method that is being invoked matches one of the execute types. + * + * @param method the method being invoked on the proxy + * @param process boolean result used for recursion + * @return returns true if the method name matched + */ + protected boolean isExecute(Method method, boolean process){ + return process(EXECUTE_TYPES, method, process); + } + + /* * Returns true if the method that is being invoked matches one of the method names passed in * @param names list of method names that we want to intercept * @param method the method being invoked on the proxy Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java?rev=801284&r1=801283&r2=801284&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java (original) +++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java Wed Aug 5 16:19:34 2009 @@ -48,7 +48,7 @@ * the constructors that are used to create statement proxies */ protected static final Constructor<?>[] constructors = - new Constructor[AbstractCreateStatementInterceptor.statements.length]; + new Constructor[AbstractCreateStatementInterceptor.STATEMENT_TYPE_COUNT]; public AbstractQueryReport() { @@ -82,7 +82,7 @@ //extract the query string String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query; //if we do batch execution, then we name the query 'batch' - if (sql==null && compare(executes[3],name)) { + if (sql==null && compare(EXECUTE_BATCH,name)) { sql = "batch"; } return sql; @@ -101,7 +101,7 @@ //extract the query string String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query; //if we do batch execution, then we name the query 'batch' - if (sql==null && compare(executes[3],name)) { + if (sql==null && compare(EXECUTE_BATCH,name)) { sql = "batch"; } return sql; @@ -120,7 +120,7 @@ //extract the query string String sql = (query==null && args!=null && args.length>0)?(String)args[0]:query; //if we do batch execution, then we name the query 'batch' - if (sql==null && compare(executes[3],name)) { + if (sql==null && compare(EXECUTE_BATCH,name)) { sql = "batch"; } return sql; @@ -169,20 +169,20 @@ String name = method.getName(); String sql = null; Constructor<?> constructor = null; - if (compare(statements[0],name)) { + if (compare(CREATE_STATEMENT,name)) { //createStatement - constructor = getConstructor(0,Statement.class); - }else if (compare(statements[1],name)) { + constructor = getConstructor(CREATE_STATEMENT_IDX,Statement.class); + }else if (compare(PREPARE_STATEMENT,name)) { //prepareStatement sql = (String)args[0]; - constructor = getConstructor(1,PreparedStatement.class); + constructor = getConstructor(PREPARE_STATEMENT_IDX,PreparedStatement.class); if (sql!=null) { prepareStatement(sql, time); } - }else if (compare(statements[2],name)) { + }else if (compare(PREPARE_CALL,name)) { //prepareCall sql = (String)args[0]; - constructor = getConstructor(2,CallableStatement.class); + constructor = getConstructor(PREPARE_IDX,CallableStatement.class); prepareCall(sql,time); }else { //do nothing, might be a future unsupported method @@ -225,7 +225,7 @@ if (closed) throw new SQLException("Statement closed."); boolean process = false; //check to see if we are about to execute a query - process = process(executes, method, process); + process = isExecute( method, process); //if we are executing, get the current time long start = (process)?System.currentTimeMillis():0; Object result = null; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org