Update DBCP for latest pool2 changes (removing setFactory() from GOP)
authorMark Thomas <markt@apache.org>
Sat, 25 Jun 2011 23:26:50 +0000 (23:26 +0000)
committerMark Thomas <markt@apache.org>
Sat, 25 Jun 2011 23:26:50 +0000 (23:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/dbcp/trunk@1139667 13f79535-47bb-0310-9956-ffa450edef68

16 files changed:
doc/PoolingDataSourceExample.java
doc/PoolingDriverExample.java
src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java
src/java/org/apache/commons/dbcp2/BasicDataSource.java
src/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
src/java/org/apache/commons/dbcp2/datasources/CPDSConnectionFactory.java
src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
src/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java
src/java/org/apache/commons/dbcp2/managed/PoolableManagedConnectionFactory.java
src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
src/test/org/apache/commons/dbcp2/TestPStmtPooling.java
src/test/org/apache/commons/dbcp2/TestPoolableConnection.java
src/test/org/apache/commons/dbcp2/TestPoolingDataSource.java
src/test/org/apache/commons/dbcp2/TestPoolingDriver.java
src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
src/test/org/apache/commons/dbcp2/managed/TestManagedDataSource.java

index 32c969f..2213d53 100644 (file)
@@ -131,16 +131,7 @@ public class PoolingDataSourceExample {
 
     public static DataSource setupDataSource(String connectURI) {
         //
-        // First, we'll need a ObjectPool that serves as the
-        // actual pool of connections.
-        //
-        // We'll use a GenericObjectPool instance, although
-        // any ObjectPool implementation will suffice.
-        //
-        ObjectPool connectionPool = new GenericObjectPool(null);
-
-        //
-        // Next, we'll create a ConnectionFactory that the
+        // First, we'll create a ConnectionFactory that the
         // pool will use to create Connections.
         // We'll use the DriverManagerConnectionFactory,
         // using the connect string passed in the command line
@@ -149,11 +140,20 @@ public class PoolingDataSourceExample {
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
 
         //
-        // Now we'll create the PoolableConnectionFactory, which wraps
+        // Next we'll create the PoolableConnectionFactory, which wraps
         // the "real" Connections created by the ConnectionFactory with
         // the classes that implement the pooling functionality.
         //
-        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,null,null,false,true);
+
+        //
+        // Now we'll need a ObjectPool that serves as the
+        // actual pool of connections.
+        //
+        // We'll use a GenericObjectPool instance, although
+        // any ObjectPool implementation will suffice.
+        //
+        ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
 
         //
         // Finally, we create the PoolingDriver itself,
index ff2efde..ce4b421 100644 (file)
@@ -147,16 +147,7 @@ public class PoolingDriverExample {
 
     public static void setupDriver(String connectURI) throws Exception {
         //
-        // First, we'll need a ObjectPool that serves as the
-        // actual pool of connections.
-        //
-        // We'll use a GenericObjectPool instance, although
-        // any ObjectPool implementation will suffice.
-        //
-        ObjectPool connectionPool = new GenericObjectPool(null);
-
-        //
-        // Next, we'll create a ConnectionFactory that the
+        // First, we'll create a ConnectionFactory that the
         // pool will use to create Connections.
         // We'll use the DriverManagerConnectionFactory,
         // using the connect string passed in the command line
@@ -165,11 +156,20 @@ public class PoolingDriverExample {
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);
 
         //
-        // Now we'll create the PoolableConnectionFactory, which wraps
+        // Next, we'll create the PoolableConnectionFactory, which wraps
         // the "real" Connections created by the ConnectionFactory with
         // the classes that implement the pooling functionality.
         //
-        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,null,null,false,true);
+
+        //
+        // Now we'll need a ObjectPool that serves as the
+        // actual pool of connections.
+        //
+        // We'll use a GenericObjectPool instance, although
+        // any ObjectPool implementation will suffice.
+        //
+        ObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
 
         //
         // Finally, we create the PoolingDriver itself...
index b39f9c2..75bdbfd 100644 (file)
@@ -53,8 +53,8 @@ public class AbandonedObjectPool extends GenericObjectPool {
      */
     public AbandonedObjectPool(PoolableObjectFactory factory,
                                AbandonedConfig config) {
+        super(factory);
         this.config = config;
-        this.setFactory(factory);
     }
 
     /**
index 9d95b70..ec2405e 100644 (file)
@@ -31,6 +31,7 @@ import java.sql.SQLException;
 import javax.sql.DataSource;
 
 import org.apache.commons.pool2.KeyedObjectPoolFactory;
+import org.apache.commons.pool2.PoolableObjectFactory;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolFactory;
 import org.apache.commons.pool2.impl.GenericObjectPool;
@@ -1529,9 +1530,6 @@ public class BasicDataSource implements DataSource {
             // create factory which returns raw physical connections
             ConnectionFactory driverConnectionFactory = createConnectionFactory();
     
-            // create a pool for our connections
-            createConnectionPool();
-    
             // Set up statement pool, if desired
             GenericKeyedObjectPoolFactory statementPoolFactory = null;
             if (isPoolPreparedStatements()) {
@@ -1548,9 +1546,11 @@ public class BasicDataSource implements DataSource {
     
             // Set up the poolable connection factory
             boolean success = false;
+            PoolableConnectionFactory poolableConnectionFactory;
             try {
-                createPoolableConnectionFactory(driverConnectionFactory,
-                        statementPoolFactory, abandonedConfig);
+                poolableConnectionFactory = createPoolableConnectionFactory(
+                        driverConnectionFactory, statementPoolFactory,
+                        abandonedConfig);
                 success = true;
             } catch (SQLException se) {
                 throw se;
@@ -1558,10 +1558,11 @@ public class BasicDataSource implements DataSource {
                 throw rte; 
             } catch (Exception ex) {
                 throw new SQLException("Error creating connection factory", ex);
-            } finally {
-                if (!success) {
-                    closeConnectionPool();
-                }
+            }
+
+            if (success) {
+                // create a pool for our connections
+                createConnectionPool(poolableConnectionFactory);
             }
             
             // Create the pooling data source to manage connections
@@ -1698,14 +1699,14 @@ public class BasicDataSource implements DataSource {
      * to a positive value causes {@link GenericObjectPool}'s eviction timer
      * to be started.
      */
-    protected void createConnectionPool() {
+    protected void createConnectionPool(PoolableConnectionFactory factory) {
         // Create an object pool to contain our active connections
         GenericObjectPool gop;
         if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) {
-            gop = new AbandonedObjectPool(null,abandonedConfig);
+            gop = new AbandonedObjectPool(factory,abandonedConfig);
         }
         else {
-            gop = new GenericObjectPool();
+            gop = new GenericObjectPool(factory);
         }
         gop.setMaxTotal(maxTotal);
         gop.setMaxIdle(maxIdle);
@@ -1717,6 +1718,7 @@ public class BasicDataSource implements DataSource {
         gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
         gop.setTestWhileIdle(testWhileIdle);
         gop.setLifo(lifo);
+        factory.setPool(gop);
         connectionPool = gop;
     }
     
@@ -1767,13 +1769,12 @@ public class BasicDataSource implements DataSource {
      * @param configuration abandoned connection tracking configuration (null if no tracking)
      * @throws SQLException if an error occurs creating the PoolableConnectionFactory
      */
-    protected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
+    protected PoolableConnectionFactory createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
             KeyedObjectPoolFactory statementPoolFactory, AbandonedConfig configuration) throws SQLException {
         PoolableConnectionFactory connectionFactory = null;
         try {
             connectionFactory =
                 new PoolableConnectionFactory(driverConnectionFactory,
-                                              connectionPool,
                                               statementPoolFactory,
                                               validationQuery,
                                               validationQueryTimeout,
@@ -1790,6 +1791,7 @@ public class BasicDataSource implements DataSource {
         } catch (Exception e) {
             throw new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
         }
+        return connectionFactory;
     }
 
     protected static void validateConnectionFactory(PoolableConnectionFactory connectionFactory) throws Exception {
index 796fd4e..6ec6143 100644 (file)
@@ -42,16 +42,13 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
@@ -61,7 +58,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param connectionInitSqls a Collection of SQL statements to initialize {@link Connection}s. Using <tt>null</tt> turns off initialization.
@@ -69,10 +65,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _connectionInitSqls = connectionInitSqls;
@@ -83,7 +77,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -91,10 +84,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, boolean defaultReadOnly, boolean defaultAutoCommit) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, boolean defaultReadOnly, boolean defaultAutoCommit) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -105,7 +96,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -114,10 +104,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -129,17 +117,14 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      * @param defaultTransactionIsolation the default "Transaction Isolation" setting for returned {@link Connection}s
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
@@ -150,7 +135,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param connectionInitSqls a Collection of SQL statement to initialize {@link Connection}s. Using <tt>null</tt> turns off initialization.
@@ -159,10 +143,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultTransactionIsolation the default "Transaction Isolation" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _connectionInitSqls = connectionInitSqls;
@@ -174,7 +156,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -183,10 +164,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultTransactionIsolation the default "Transaction Isolation" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -198,7 +177,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -208,10 +186,8 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      * @param defaultTransactionIsolation the default "Transaction Isolation" setting for returned {@link Connection}s
      * @since 1.3
      */
-    public PoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
+    public PoolableConnectionFactory(ConnectionFactory connFactory, KeyedObjectPoolFactory stmtPoolFactory, String validationQuery, int validationQueryTimeout, Collection connectionInitSqls, boolean defaultReadOnly, boolean defaultAutoCommit, int defaultTransactionIsolation) {
         _connFactory = connFactory;
-        _pool = pool;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -224,7 +200,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
@@ -233,7 +208,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         boolean defaultReadOnly,
@@ -241,9 +215,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
@@ -253,7 +225,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
@@ -263,7 +234,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         boolean defaultReadOnly,
@@ -272,9 +242,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
@@ -285,7 +253,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
@@ -296,7 +263,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         boolean defaultReadOnly,
@@ -306,9 +272,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly ? Boolean.TRUE : Boolean.FALSE;
@@ -320,7 +284,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param defaultReadOnly the default "read only" setting for borrowed {@link Connection}s
@@ -331,7 +294,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         Boolean defaultReadOnly,
@@ -341,9 +303,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _defaultReadOnly = defaultReadOnly;
@@ -355,7 +315,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param connectionInitSqls a Collection of SQL statements to initialize {@link Connection}s. Using <tt>null</tt> turns off initialization.
@@ -368,7 +327,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         Collection connectionInitSqls,
@@ -379,9 +337,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _connectionInitSqls = connectionInitSqls;
@@ -394,7 +350,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -407,7 +362,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         int validationQueryTimeout,
@@ -418,9 +372,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -433,7 +385,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -448,7 +399,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         int validationQueryTimeout,
@@ -460,9 +410,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
@@ -476,7 +424,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
     /**
      * Create a new <tt>PoolableConnectionFactory</tt>.
      * @param connFactory the {@link ConnectionFactory} from which to obtain base {@link Connection}s
-     * @param pool the {@link ObjectPool} in which to pool those {@link Connection}s
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.  Should return at least one row. Using <tt>null</tt> turns off validation.
      * @param validationQueryTimeout the number of seconds that validation queries will wait for database response before failing.  Use a value less than or equal to 0 for no timeout.
@@ -491,7 +438,6 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
      */
     public PoolableConnectionFactory(
         ConnectionFactory connFactory,
-        ObjectPool pool,
         KeyedObjectPoolFactory stmtPoolFactory,
         String validationQuery,
         int validationQueryTimeout,
@@ -504,9 +450,7 @@ public class PoolableConnectionFactory implements PoolableObjectFactory {
         AbandonedConfig config) {
 
         _connFactory = connFactory;
-        _pool = pool;
         _config = config;
-        _pool.setFactory(this);
         _stmtPoolFactory = stmtPoolFactory;
         _validationQuery = validationQuery;
         _validationQueryTimeout = validationQueryTimeout;
index e91675f..8ff5886 100644 (file)
@@ -50,7 +50,7 @@ class CPDSConnectionFactory
     private final ConnectionPoolDataSource _cpds;
     private final String _validationQuery;
     private final boolean _rollbackAfterValidation;
-    private final ObjectPool _pool;
+    private ObjectPool _pool;
     private String _username = null;
     private String _password = null;
 
@@ -70,8 +70,6 @@ class CPDSConnectionFactory
      * 
      * @param cpds the ConnectionPoolDataSource from which to obtain
      * PooledConnection's
-     * @param pool the {@link ObjectPool} in which to pool those
-     * {@link Connection}s
      * @param validationQuery a query to use to {@link #validateObject validate}
      * {@link Connection}s. Should return at least one row. May be 
      * <tt>null</tt>
@@ -79,11 +77,10 @@ class CPDSConnectionFactory
      * @param password
      */
     public CPDSConnectionFactory(ConnectionPoolDataSource cpds,
-                                 ObjectPool pool,
                                  String validationQuery,
                                  String username,
                                  String password) {
-        this(cpds, pool, validationQuery, false, username, password);
+        this(cpds, validationQuery, false, username, password);
     }
     
     /**
@@ -91,8 +88,6 @@ class CPDSConnectionFactory
      * 
      * @param cpds the ConnectionPoolDataSource from which to obtain
      * PooledConnection's
-     * @param pool the {@link ObjectPool} in which to pool those {@link
-     * Connection}s
      * @param validationQuery a query to use to {@link #validateObject
      * validate} {@link Connection}s. Should return at least one row.
      * May be <tt>null</tt>
@@ -102,20 +97,17 @@ class CPDSConnectionFactory
      * @param password
      */
     public CPDSConnectionFactory(ConnectionPoolDataSource cpds,
-                                 ObjectPool pool,
                                  String validationQuery,
                                  boolean rollbackAfterValidation,
                                  String username,
                                  String password) {
         _cpds = cpds;
-        _pool = pool;
-        pool.setFactory(this);
         _validationQuery = validationQuery;
         _username = username;
         _password = password;
         _rollbackAfterValidation = rollbackAfterValidation;
     }
-     
+
     /**
      * Returns the object pool used to pool connections created by this factory.
      * 
@@ -125,6 +117,15 @@ class CPDSConnectionFactory
         return _pool;
     }
 
+    /**
+     * 
+     * @param pool the {@link ObjectPool} in which to pool those {@link
+     * Connection}s
+     */
+    public void setPool(ObjectPool pool) {
+        this._pool = pool;
+    }
+
     @Override
     public synchronized Object makeObject() {
         Object obj;
index 2017dd0..b80ee20 100644 (file)
@@ -506,8 +506,16 @@ public class PerUserPoolDataSource
         int maxWait = (userMax == null) ?
             getDefaultMaxWait() : userMax.intValue();
 
+        // Set up the factory we will use (passing the pool associates
+        // the factory with the pool, so we do not have to do so
+        // explicitly)
+        CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds,
+                getValidationQuery(), isRollbackAfterValidation(), username,
+                password);
+               
         // Create an object pool to contain our PooledConnections
-        GenericObjectPool pool = new GenericObjectPool();
+        GenericObjectPool pool = new GenericObjectPool(factory);
+        factory.setPool(pool);
         pool.setMaxTotal(maxTotal);
         pool.setMaxIdle(maxIdle);
         pool.setMaxWait(maxWait);
@@ -527,12 +535,6 @@ public class PerUserPoolDataSource
         pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
         pool.setTestWhileIdle(getTestWhileIdle());
                 
-        // Set up the factory we will use (passing the pool associates
-        // the factory with the pool, so we do not have to do so
-        // explicitly)
-        CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, pool, getValidationQuery(),
-                isRollbackAfterValidation(), username, password);
-           
         Object old = managers.put(getPoolKey(username,password), factory);
         if (old != null) {
             throw new IllegalStateException("Pool already contains an entry for this user/password: "+username);
index d1bbdf1..6e11f25 100644 (file)
@@ -180,13 +180,14 @@ public class BasicManagedDataSource extends BasicDataSource {
      * @throws SQLException if an error occurs creating the PoolableConnectionFactory
      */
     @Override
-    protected void createPoolableConnectionFactory(ConnectionFactory driverConnectionFactory,
-            KeyedObjectPoolFactory statementPoolFactory, AbandonedConfig abandonedConfig) throws SQLException {
+    protected PoolableConnectionFactory createPoolableConnectionFactory(
+            ConnectionFactory driverConnectionFactory,
+            KeyedObjectPoolFactory statementPoolFactory,
+            AbandonedConfig abandonedConfig) throws SQLException {
         PoolableConnectionFactory connectionFactory = null;
         try {
             connectionFactory =
                 new PoolableManagedConnectionFactory((XAConnectionFactory) driverConnectionFactory,
-                                              connectionPool,
                                               statementPoolFactory,
                                               validationQuery,
                                               validationQueryTimeout,
@@ -202,5 +203,6 @@ public class BasicManagedDataSource extends BasicDataSource {
         } catch (Exception e) {
             throw (SQLException)new SQLException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")").initCause(e);
         }
+        return connectionFactory;
     }
 }
index c26e132..ce78027 100644 (file)
@@ -40,7 +40,6 @@ public class PoolableManagedConnectionFactory extends PoolableConnectionFactory
      * Create a PoolableManagedConnectionFactory and attach it to a connection pool.
      * 
      * @param connFactory XAConnectionFactory
-     * @param pool connection pool 
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling
      * {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.
@@ -49,10 +48,10 @@ public class PoolableManagedConnectionFactory extends PoolableConnectionFactory
      * @param defaultAutoCommit the default "auto commit" setting for returned {@link Connection}s
      */
     public PoolableManagedConnectionFactory(XAConnectionFactory connFactory,
-            ObjectPool pool, KeyedObjectPoolFactory stmtPoolFactory,
+            KeyedObjectPoolFactory stmtPoolFactory,
             String validationQuery, boolean defaultReadOnly,
             boolean defaultAutoCommit) {
-        super(connFactory, pool, stmtPoolFactory, validationQuery,
+        super(connFactory, stmtPoolFactory, validationQuery,
                 defaultReadOnly, defaultAutoCommit);
         this.transactionRegistry = connFactory.getTransactionRegistry();
     }
@@ -61,7 +60,6 @@ public class PoolableManagedConnectionFactory extends PoolableConnectionFactory
      * Create a PoolableManagedConnectionFactory and attach it to a connection pool.
      * 
      * @param connFactory XAConnectionFactory
-     * @param pool connection pool 
      * @param stmtPoolFactory the {@link KeyedObjectPoolFactory} to use to create {@link KeyedObjectPool}s for pooling
      * {@link java.sql.PreparedStatement}s, or <tt>null</tt> to disable {@link java.sql.PreparedStatement} pooling
      * @param validationQuery a query to use to {@link #validateObject validate} {@link Connection}s.
@@ -77,7 +75,6 @@ public class PoolableManagedConnectionFactory extends PoolableConnectionFactory
      * @param config the AbandonedConfig if tracing SQL objects
      */
     public PoolableManagedConnectionFactory(XAConnectionFactory connFactory,
-            ObjectPool pool,
             KeyedObjectPoolFactory stmtPoolFactory,
             String validationQuery,
             int validationQueryTimeout,
@@ -87,7 +84,7 @@ public class PoolableManagedConnectionFactory extends PoolableConnectionFactory
             int defaultTransactionIsolation,
             String defaultCatalog,
             AbandonedConfig config) {
-        super(connFactory, pool, stmtPoolFactory, validationQuery, validationQueryTimeout, connectionInitSqls,
+        super(connFactory, stmtPoolFactory, validationQuery, validationQueryTimeout, connectionInitSqls,
                 defaultReadOnly, defaultAutoCommit, defaultTransactionIsolation, defaultCatalog, config);
         this.transactionRegistry = connFactory.getTransactionRegistry();
     }
index c64e5df..649f14e 100644 (file)
@@ -52,14 +52,16 @@ public class TestDriverManagerConnectionFactory extends TestCase {
         GenericObjectPoolConfig config = new GenericObjectPoolConfig();
         config.setMaxTotal(10);
         config.setMaxIdle(0);
-        GenericObjectPool connectionPool = new GenericObjectPool(config);
         final ConnectionFactory connectionFactory =
             new DriverManagerConnectionFactory(
                     "jdbc:apache:commons:testdriver",
                     "foo", "bar");
         final PoolableConnectionFactory poolableConnectionFactory =
-            new PoolableConnectionFactory(connectionFactory, connectionPool,
+            new PoolableConnectionFactory(connectionFactory,
                     null, null, false, true);
+        GenericObjectPool connectionPool =
+            new GenericObjectPool(poolableConnectionFactory, config);
+        poolableConnectionFactory.setPool(connectionPool);
         PoolingDataSource dataSource =
             new PoolingDataSource(connectionPool);
 
index 8d2849a..0a7d981 100644 (file)
@@ -53,13 +53,13 @@ public class TestPStmtPooling extends TestCase {
         ConnectionFactory connFactory = new DriverManagerConnectionFactory(
                 "jdbc:apache:commons:testdriver","u1","p1");
 
-        ObjectPool connPool = new GenericObjectPool();
         KeyedObjectPoolFactory stmtPoolFactory =
             new GenericKeyedObjectPoolFactory(
                     new GenericKeyedObjectPoolConfig());
 
-        new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
-                null, false, true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(
+                connFactory, stmtPoolFactory, null, false, true);
+        ObjectPool connPool = new GenericObjectPool(pcf);
 
         DataSource ds = new PoolingDataSource(connPool);
 
@@ -78,13 +78,14 @@ public class TestPStmtPooling extends TestCase {
         ConnectionFactory connFactory = new DriverManagerConnectionFactory(
                 "jdbc:apache:commons:testdriver","u1","p1");
 
-        ObjectPool connPool = new GenericObjectPool();
         KeyedObjectPoolFactory stmtPoolFactory =
             new GenericKeyedObjectPoolFactory(
                     new GenericKeyedObjectPoolConfig());
 
-        new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
-                null, false, true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(
+                connFactory, stmtPoolFactory, null, false, true);
+
+        ObjectPool connPool = new GenericObjectPool(pcf);
 
         DataSource ds = new PoolingDataSource(connPool);
 
@@ -116,13 +117,14 @@ public class TestPStmtPooling extends TestCase {
         ConnectionFactory connFactory = new DriverManagerConnectionFactory(
                 "jdbc:apache:commons:testdriver","u1","p1");
 
-        ObjectPool connPool = new GenericObjectPool();
         KeyedObjectPoolFactory stmtPoolFactory =
             new GenericKeyedObjectPoolFactory(
                     new GenericKeyedObjectPoolConfig());
 
-        new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
-                null, false, true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(
+                connFactory, stmtPoolFactory, null, false, true);
+
+        ObjectPool connPool = new GenericObjectPool(pcf);
 
         DataSource ds = new PoolingDataSource(connPool);
         ((PoolingDataSource) ds).setAccessToUnderlyingConnectionAllowed(true);
index d22c28b..d50d868 100644 (file)
@@ -44,11 +44,12 @@ public class TestPoolableConnection extends TestCase {
 
     @Override
     public void setUp() throws Exception {
-        pool = new GenericObjectPool();
         PoolableConnectionFactory factory = 
             new PoolableConnectionFactory(
                 new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver", null),
-                pool, null, null, true, true);
+                null, null, true, true);
+        pool = new GenericObjectPool(factory);
+        factory.setPool(pool);
     }
 
     public void testConnectionPool() throws Exception {
index 417555b..97fa912 100644 (file)
@@ -23,7 +23,6 @@ import java.util.Properties;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
-import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 
 /**
@@ -51,17 +50,18 @@ public class TestPoolingDataSource extends TestConnectionPool {
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        pool = new GenericObjectPool();
-        pool.setMaxTotal(getMaxTotal());
-        pool.setMaxWait(getMaxWait());
         Properties props = new Properties();
         props.setProperty("user", "username");
         props.setProperty("password", "password");
-        PoolableConnectionFactory factory = 
+         PoolableConnectionFactory factory = 
             new PoolableConnectionFactory(
                 new DriverConnectionFactory(new TesterDriver(),
                         "jdbc:apache:commons:testdriver", props),
-                pool, null, "SELECT DUMMY FROM DUAL", true, true);
+                null, "SELECT DUMMY FROM DUAL", true, true);
+        pool = new GenericObjectPool(factory);
+        factory.setPool(pool);
+        pool.setMaxTotal(getMaxTotal());
+        pool.setMaxWait(getMaxWait());
         ds = new PoolingDataSource(pool);
         ds.setAccessToUnderlyingConnectionAllowed(true);
     }
@@ -109,16 +109,17 @@ public class TestPoolingDataSource extends TestConnectionPool {
         checkPoolGuardConnectionWrapperEqualsReflexive();
         // Force PoolGuardConnectionWrappers to wrap non-Delegating connections
         pool.close();
-        pool = new GenericObjectPool();
-        pool.setMaxTotal(getMaxTotal());
-        pool.setMaxWait(getMaxWait());
+        
         Properties props = new Properties();
         props.setProperty("user", "username");
         props.setProperty("password", "password");
         NonDelegatingPoolableConnectionFactory factory = 
             new NonDelegatingPoolableConnectionFactory(
                 new DriverConnectionFactory(new TesterDriver(),
-                        "jdbc:apache:commons:testdriver", props), pool);
+                        "jdbc:apache:commons:testdriver", props));
+        pool = new GenericObjectPool(factory);
+        pool.setMaxTotal(getMaxTotal());
+        pool.setMaxWait(getMaxWait());
         ds = new PoolingDataSource(pool);
         checkPoolGuardConnectionWrapperEqualsReflexive();
     }
@@ -160,8 +161,8 @@ public class TestPoolingDataSource extends TestConnectionPool {
     /** Factory to return non-delegating connections for DBCP-198 test */
     private static class NonDelegatingPoolableConnectionFactory
             extends PoolableConnectionFactory {
-        public NonDelegatingPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool) {
-            super(connFactory, pool, null, null, true, true);
+        public NonDelegatingPoolableConnectionFactory(ConnectionFactory connFactory) {
+            super(connFactory, null, null, true, true);
         }
     
         @Override
index ddb4002..f924bb5 100644 (file)
@@ -60,18 +60,6 @@ public class TestPoolingDriver extends TestConnectionPool {
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
-        poolConfig.setMaxTotal(getMaxTotal());
-        poolConfig.setMaxWait(getMaxWait());
-        poolConfig.setMinIdle(10);
-        poolConfig.setTestOnBorrow(true);
-        poolConfig.setTestOnReturn(true);
-        poolConfig.setTestWhileIdle(true);
-        poolConfig.setTimeBetweenEvictionRunsMillis(10000L);
-        poolConfig.setNumTestsPerEvictionRun(5);
-        poolConfig.setMinEvictableIdleTimeMillis(5000L);
-        GenericObjectPool pool = new GenericObjectPool(poolConfig);
-
         DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null);
 
         GenericKeyedObjectPoolConfig keyedPoolConfig =
@@ -88,7 +76,22 @@ public class TestPoolingDriver extends TestConnectionPool {
         GenericKeyedObjectPoolFactory opf =
             new GenericKeyedObjectPoolFactory(keyedPoolConfig);
 
-        PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, opf, "SELECT COUNT(*) FROM DUAL", false, true);
+
+        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
+        poolConfig.setMaxTotal(getMaxTotal());
+        poolConfig.setMaxWait(getMaxWait());
+        poolConfig.setMinIdle(10);
+        poolConfig.setTestOnBorrow(true);
+        poolConfig.setTestOnReturn(true);
+        poolConfig.setTestWhileIdle(true);
+        poolConfig.setTimeBetweenEvictionRunsMillis(10000L);
+        poolConfig.setNumTestsPerEvictionRun(5);
+        poolConfig.setMinEvictableIdleTimeMillis(5000L);
+        
+        GenericObjectPool pool = new GenericObjectPool(pcf, poolConfig);
+        pcf.setPool(pool);
+
         assertNotNull(pcf);
         driver = new PoolingDriver();
         driver.registerPool("test",pool);
@@ -102,16 +105,16 @@ public class TestPoolingDriver extends TestConnectionPool {
     }
     
     public void test1() {
-        GenericObjectPool connectionPool = new GenericObjectPool();
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string","username","password");
-        new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(connectionFactory,null,null,false,true);
+        GenericObjectPool connectionPool = new GenericObjectPool(pcf);
         new PoolingDataSource(connectionPool);
     }
 
     public void test2() {
-        GenericObjectPool connectionPool = new GenericObjectPool();
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string","username","password");
-        new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
+        PoolableConnectionFactory pcf = new PoolableConnectionFactory(connectionFactory,null,null,false,true);
+        GenericObjectPool connectionPool = new GenericObjectPool(pcf);
         PoolingDriver driver2 = new PoolingDriver();
         driver2.registerPool("example",connectionPool);
     }
@@ -143,7 +146,6 @@ public class TestPoolingDriver extends TestConnectionPool {
         config.setMaxTotal(70);
         config.setMaxWait(60000);
         config.setMaxIdle(10);
-        ObjectPool connectionPool = new GenericObjectPool(config);
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
             "jdbc:apache:commons:testdriver", 
             "username", 
@@ -151,11 +153,13 @@ public class TestPoolingDriver extends TestConnectionPool {
         PoolableConnectionFactory poolableConnectionFactory = 
             new PoolableConnectionFactory(
                 connectionFactory,
-                connectionPool,
                 null,
                 null,
                 false,
                 true);
+        ObjectPool connectionPool =
+            new GenericObjectPool(poolableConnectionFactory,config);
+        poolableConnectionFactory.setPool(connectionPool);
         assertNotNull(poolableConnectionFactory);
         PoolingDriver driver2 = new PoolingDriver();
         driver2.registerPool("neusoftim",connectionPool);
index 865afae..bc032ef 100644 (file)
@@ -88,9 +88,10 @@ public class TestCPDSConnectionFactory extends TestCase {
      */
     public void testConnectionErrorCleanup() throws Exception {
         // Setup factory
-        GenericObjectPool pool = new GenericObjectPool();
         CPDSConnectionFactory factory = 
-            new CPDSConnectionFactory(cpds, pool, null, "username", "password");
+            new CPDSConnectionFactory(cpds, null, "username", "password");
+        GenericObjectPool pool = new GenericObjectPool(factory);
+        factory.setPool(pool);
         
         // Checkout a pair of connections
         PooledConnection pcon1 = 
index 5dacdb6..3991605 100644 (file)
@@ -26,7 +26,6 @@ import org.apache.commons.dbcp2.PoolableConnectionFactory;
 import org.apache.commons.dbcp2.PoolingDataSource;
 import org.apache.commons.dbcp2.TestConnectionPool;
 import org.apache.commons.dbcp2.TesterDriver;
-import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 
@@ -74,14 +73,15 @@ public class TestManagedDataSource extends TestConnectionPool {
         // wrap it with a LocalXAConnectionFactory
         XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(transactionManager, connectionFactory);
 
+        // create the pool object factory
+        PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, null, "SELECT DUMMY FROM DUAL", true, true);
+
         // create the pool
-        pool = new GenericObjectPool();
+        pool = new GenericObjectPool(factory);
+        factory.setPool(pool);
         pool.setMaxTotal(getMaxTotal());
         pool.setMaxWait(getMaxWait());
 
-        // create the pool object factory
-        PoolableConnectionFactory factory = new PoolableConnectionFactory(xaConnectionFactory, pool, null, "SELECT DUMMY FROM DUAL", true, true);
-
         // finally create the datasource
         ds = new ManagedDataSource(pool, xaConnectionFactory.getTransactionRegistry());
         ds.setAccessToUnderlyingConnectionAllowed(true);
@@ -179,15 +179,15 @@ public class TestManagedDataSource extends TestConnectionPool {
         checkManagedConnectionEqualsReflexive();
 
         // Force ManagedConnections to wrap non-Delegating connections
-        pool.close();
-        pool = new GenericObjectPool();
-        pool.setMaxTotal(getMaxTotal());
-        pool.setMaxWait(getMaxWait());
         Properties props = new Properties();
         props.setProperty("user", "username");
         props.setProperty("password", "password");
         NonDelegatingPoolableConnectionFactory factory = new NonDelegatingPoolableConnectionFactory(
-                new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", props), pool);
+                new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", props));
+        pool.close();
+        pool = new GenericObjectPool(factory);
+        pool.setMaxTotal(getMaxTotal());
+        pool.setMaxWait(getMaxWait());
         ds = new PoolingDataSource(pool);
         checkManagedConnectionEqualsReflexive();
     }
@@ -239,8 +239,8 @@ public class TestManagedDataSource extends TestConnectionPool {
      */
     private static class NonDelegatingPoolableConnectionFactory
             extends PoolableConnectionFactory {
-        public NonDelegatingPoolableConnectionFactory(ConnectionFactory connFactory, ObjectPool pool) {
-            super(connFactory, pool, null, null, true, true);
+        public NonDelegatingPoolableConnectionFactory(ConnectionFactory connFactory) {
+            super(connFactory, null, null, true, true);
         }
 
         @Override