Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47612
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 5 Aug 2009 16:19:34 +0000 (16:19 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 5 Aug 2009 16:19:34 +0000 (16:19 +0000)
patch provided by sebb
Abstract classes, private-> protected for subclass access

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@801284 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractQueryReport.java

index b74d0c8..b7fe9a1 100644 (file)
@@ -30,8 +30,22 @@ import org.apache.tomcat.jdbc.pool.PooledConnection;
  * @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 @@ public abstract class  AbstractCreateStatementInterceptor extends JdbcIntercepto
             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 @@ public abstract class  AbstractCreateStatementInterceptor extends JdbcIntercepto
      * 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 class  AbstractCreateStatementInterceptor extends JdbcIntercepto
     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
index fc7c0e2..e57784a 100644 (file)
@@ -48,7 +48,7 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
      * 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 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
         //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 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
         //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 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
         //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 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
             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 @@ public abstract class AbstractQueryReport extends AbstractCreateStatementInterce
             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;