Author: fhanik
Date: Fri Nov 14 19:51:51 2008
New Revision: 714217

URL: http://svn.apache.org/viewvc?rev=714217&view=rev
Log:
Only apply state once, so if the connection state interceptor is not applied, 
then we need to do it in the pool
Add abstract interceptor to handle statement wrappers and creation, to be used 
later when we do a clean up and performance interceptor

Added:
    
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
Modified:
    
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java

Modified: 
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=714217&r1=714216&r2=714217&view=diff
==============================================================================
--- 
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
 (original)
+++ 
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
 Fri Nov 14 19:51:51 2008
@@ -24,6 +24,8 @@
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
+
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
@@ -80,12 +82,13 @@
         poolProperties.getDbProperties().setProperty("user", usr);
         poolProperties.getDbProperties().setProperty("password", pwd);
         connection = driver.connect(driverURL, 
poolProperties.getDbProperties());
-        //set up the default state
-        if (poolProperties.getDefaultReadOnly()!=null) 
connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
-        if (poolProperties.getDefaultAutoCommit()!=null) 
connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
-        if (poolProperties.getDefaultCatalog()!=null) 
connection.setCatalog(poolProperties.getDefaultCatalog());
-        if 
(poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION)
 
connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
-        
+        //set up the default state, unless we expect the interceptor to do it
+        if (poolProperties.getJdbcInterceptors()==null || 
poolProperties.getJdbcInterceptors().indexOf(ConnectionState.class.getName())<0)
 {
+            if (poolProperties.getDefaultReadOnly()!=null) 
connection.setReadOnly(poolProperties.getDefaultReadOnly().booleanValue());
+            if (poolProperties.getDefaultAutoCommit()!=null) 
connection.setAutoCommit(poolProperties.getDefaultAutoCommit().booleanValue());
+            if (poolProperties.getDefaultCatalog()!=null) 
connection.setCatalog(poolProperties.getDefaultCatalog());
+            if 
(poolProperties.getDefaultTransactionIsolation()!=DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION)
 
connection.setTransactionIsolation(poolProperties.getDefaultTransactionIsolation());
+        }        
         this.discarded = false;
     }
 

Added: 
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=714217&view=auto
==============================================================================
--- 
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
 (added)
+++ 
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/interceptor/AbstractCreateStatementInterceptor.java
 Fri Nov 14 19:51:51 2008
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.jdbc.pool.interceptor;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.sql.CallableStatement;
+import java.sql.SQLException;
+
+import org.apache.tomcat.jdbc.pool.ConnectionPool;
+import org.apache.tomcat.jdbc.pool.JdbcInterceptor;
+import org.apache.tomcat.jdbc.pool.PooledConnection;
+
+/**
+ * @author Filip Hanik
+ * @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"};
+
+    public  AbstractCreateStatementInterceptor() {
+        super();
+    }
+
+    public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable {
+        boolean process = false;
+        process = process(statements, method, process);
+        if (process) {
+            Object statement = super.invoke(proxy,method,args);
+            return createStatement(proxy,method,args,statement);
+        } else {
+            return super.invoke(proxy,method,args);
+        }
+    }
+    
+    /**
+     * This method should return a wrapper object around a
+     * java.sql.Statement, java.sql.PreparedStatement or 
java.sql.CallableStatement
+     * @param proxy
+     * @param method
+     * @param args
+     * @param statement
+     * @return
+     */
+    public abstract Object createStatement(Object proxy, Method method, 
Object[] args, Object statement);
+
+    protected boolean process(String[] names, Method method, boolean process) {
+        for (int i=0; (!process) && i<names.length; i++) {
+            process = (method.getName()==names[i]);
+        }
+        return process;
+    }
+    
+    public void reset(ConnectionPool parent, PooledConnection con) {
+
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to