Implemented a way to get a delegate using standard APIs rather than custom handling
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Dec 2008 22:11:41 +0000 (22:11 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 22 Dec 2008 22:11:41 +0000 (22:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@728806 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/.classpath
modules/jdbc-pool/build.xml
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/JdbcInterceptor.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ProxyConnection.java
modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestGetConnection.java [new file with mode: 0644]

index 9930b5a..861273b 100644 (file)
@@ -2,10 +2,10 @@
 <classpath>
        <classpathentry kind="src" path="java"/>
        <classpathentry kind="src" path="test"/>
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry combineaccessrules="false" kind="src" path="/tomcat-trunk"/>
        <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
        <classpathentry kind="var" path="TOMCAT_LIBS_BASE/tomcat6-deps/dbcp/tomcat-dbcp.jar"/>
        <classpathentry kind="lib" path="mysql-connector-java-5.1.6-bin.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 0cf0bba..cffd9fa 100644 (file)
@@ -23,7 +23,7 @@
   <!-- See "build.properties.sample" in the top level directory for all     -->
   <property name="version.major"         value="1" />
   <property name="version.minor"         value="0" />
-  <property name="version.build"         value="10" />
+  <property name="version.build"         value="11" />
   <property name="version.patch"         value="-beta" />
   <property name="version"               value="${version.major}.${version.minor}.${version.build}${version.patch}" />
   <!-- property values you must customize for successful building!!!        -->
index afaebf6..b6f07e2 100644 (file)
@@ -248,7 +248,7 @@ public class ConnectionPool {
     public Constructor getProxyConstructor() throws NoSuchMethodException {
         //cache the constructor
         if (proxyClassConstructor == null ) {
-            Class proxyClass = Proxy.getProxyClass(ConnectionPool.class.getClassLoader(), new Class[] {java.sql.Connection.class});
+            Class proxyClass = Proxy.getProxyClass(ConnectionPool.class.getClassLoader(), new Class[] {java.sql.Connection.class,javax.sql.PooledConnection.class});
             proxyClassConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
         }
         return proxyClassConstructor;
index 6c56842..7d14c42 100644 (file)
@@ -29,9 +29,10 @@ import org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty;
  * @version 1.0
  */
 public abstract class JdbcInterceptor implements InvocationHandler {
-    public  static final String CLOSE_VAL = "close";
-    public  static final String TOSTRING_VAL = "toString";
-    public  static final String ISCLOSED_VAL = "isClosed"; 
+    public static final String CLOSE_VAL = "close";
+    public static final String TOSTRING_VAL = "toString";
+    public static final String ISCLOSED_VAL = "isClosed"; 
+    public static final String GETCONNECTION_VAL = "getConnection";
     
     protected Map<String,InterceptorProperty> properties = null; 
     
index a3094da..da62ebb 100644 (file)
@@ -80,6 +80,8 @@ public class ProxyConnection extends JdbcInterceptor {
             return null;
         } else if (compare(TOSTRING_VAL,method)) {
             return this.toString();
+        } else if (compare(GETCONNECTION_VAL,method) && connection!=null) {
+            return connection.getConnection();
         }
         if (isClosed()) throw new SQLException("Connection has already been closed.");
         return method.invoke(connection.getConnection(),args);
diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestGetConnection.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/TestGetConnection.java
new file mode 100644 (file)
index 0000000..4bf2c27
--- /dev/null
@@ -0,0 +1,23 @@
+package org.apache.tomcat.jdbc.test;
+
+import java.sql.Connection;
+
+import javax.sql.PooledConnection;
+
+public class TestGetConnection extends DefaultTestCase {
+
+    public TestGetConnection(String name) {
+        super(name);
+    }
+    
+    public void testGetConnection() throws Exception {
+        this.init();
+        Connection con = this.datasource.getConnection();
+        assertTrue("Connection should implement javax.sql.PooledConnection",con instanceof PooledConnection);
+        Connection actual = ((PooledConnection)con).getConnection();
+        assertNotNull("Connection delegate should not be null.",actual);
+        System.out.println("Actual connection:"+actual.getClass().getName());
+        
+    }
+
+}