Return-Path: Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: (qmail 97448 invoked from network); 5 Aug 2009 16:19:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Aug 2009 16:19:54 -0000 Received: (qmail 57736 invoked by uid 500); 5 Aug 2009 16:20:00 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 57637 invoked by uid 500); 5 Aug 2009 16:20:00 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 57625 invoked by uid 99); 5 Aug 2009 16:20:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2009 16:20:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Aug 2009 16:19:56 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 806902388895; Wed, 5 Aug 2009 16:19:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r801284 - in /tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor: AbstractCreateStatementInterceptor.java AbstractQueryReport.java Date: Wed, 05 Aug 2009 16:19:35 -0000 To: dev@tomcat.apache.org From: fhanik@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090805161935.806902388895@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org