You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2011/06/13 19:51:31 UTC

svn commit: r1135201 - in /commons/proper/dbcp/trunk/src: java/org/apache/commons/dbcp2/ java/org/apache/commons/dbcp2/datasources/ test/org/apache/commons/dbcp2/

Author: markt
Date: Mon Jun 13 17:51:30 2011
New Revision: 1135201

URL: http://svn.apache.org/viewvc?rev=1135201&view=rev
Log:
Update for recent pool2 changes

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/AbandonedObjectPool.java Mon Jun 13 17:51:30 2011
@@ -53,8 +53,8 @@ public class AbandonedObjectPool extends
      */
     public AbandonedObjectPool(PoolableObjectFactory factory,
                                AbandonedConfig config) {
-        super(factory);
         this.config = config;
+        this.setFactory(factory);
     }
 
     /**

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java Mon Jun 13 17:51:30 2011
@@ -31,10 +31,10 @@ import java.sql.SQLException;
 import javax.sql.DataSource;
 
 import org.apache.commons.pool2.KeyedObjectPoolFactory;
-import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolFactory;
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.commons.pool2.impl.WhenExhaustedAction;
 
 
@@ -291,7 +291,7 @@ public class BasicDataSource implements 
      * means that the pool behaves as a FIFO queue - connections are taken from
      * the idle instance pool in the order that they are returned to the pool.
      */
-    private boolean lifo = GenericObjectPool.DEFAULT_LIFO;
+    private boolean lifo = GenericObjectPoolConfig.DEFAULT_LIFO;
 
     /**
      * Returns the LIFO property. 
@@ -322,7 +322,7 @@ public class BasicDataSource implements 
      * The maximum number of active connections that can be allocated from
      * this pool at the same time, or negative for no limit.
      */
-    protected int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
+    protected int maxActive = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
 
     /**
      * <p>Returns the maximum number of active connections that can be
@@ -360,7 +360,7 @@ public class BasicDataSource implements 
      * connections to rise above maxIdle. The best value for maxIdle for heavily
      * loaded system will vary but the default is a good starting point.
      */
-    protected int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
+    protected int maxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
 
     /**
      * <p>Returns the maximum number of connections that can remain idle in the
@@ -395,7 +395,7 @@ public class BasicDataSource implements 
      * runs. The value of this property has no effect unless {@link #timeBetweenEvictionRunsMillis}
      * has a positive value.
      */
-    protected int minIdle = GenericObjectPool.DEFAULT_MIN_IDLE;
+    protected int minIdle = GenericObjectPoolConfig.DEFAULT_MIN_IDLE;
 
     /**
      * Returns the minimum number of idle connections in the pool. The pool attempts
@@ -464,7 +464,7 @@ public class BasicDataSource implements 
      * are no available connections) for a connection to be returned before
      * throwing an exception, or <= 0 to wait indefinitely.
      */
-    protected long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
+    protected long maxWait = GenericObjectPoolConfig.DEFAULT_MAX_WAIT;
 
     /**
      * <p>Returns the maximum number of milliseconds that the pool will wait
@@ -638,7 +638,7 @@ public class BasicDataSource implements 
      * be run.
      */
     protected long timeBetweenEvictionRunsMillis =
-        GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
+        GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
         
     /**
      * Returns the value of the {@link #timeBetweenEvictionRunsMillis}
@@ -669,7 +669,7 @@ public class BasicDataSource implements 
      * evictor thread (if any).
      */
     protected int numTestsPerEvictionRun =
-        GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
 
     /**
      * Returns the value of the {@link #numTestsPerEvictionRun} property.
@@ -701,7 +701,7 @@ public class BasicDataSource implements 
      * is eligible for eviction by the idle object evictor (if any).
      */
     protected long minEvictableIdleTimeMillis =
-        GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+        GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
 
     /**
      * Returns the {@link #minEvictableIdleTimeMillis} property.
@@ -734,7 +734,8 @@ public class BasicDataSource implements 
      * Note that {@code minEvictableIdleTimeMillis} takes precedence over this
      * parameter.  See {@link #getSoftMinEvictableIdleTimeMillis()}.
      */
-    private long softMinEvictableIdleTimeMillis = GenericObjectPool.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
+    private long softMinEvictableIdleTimeMillis =
+        GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS;
     
     /**
      * Sets the minimum amount of time a connection may sit idle in the pool

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java Mon Jun 13 17:51:30 2011
@@ -34,8 +34,7 @@ import javax.sql.ConnectionPoolDataSourc
 import javax.sql.DataSource;
 import javax.sql.PooledConnection;
 
-import org.apache.commons.pool2.impl.GenericObjectPool;
-import org.apache.commons.pool2.impl.WhenExhaustedAction;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 
 /**
  * <p>The base class for <code>SharedPoolDataSource</code> and 
@@ -122,17 +121,20 @@ public abstract class InstanceKeyDataSou
     private PrintWriter logWriter = null;
     
     // Pool properties
-    private boolean _testOnBorrow = GenericObjectPool.DEFAULT_TEST_ON_BORROW;
-    private boolean _testOnReturn = GenericObjectPool.DEFAULT_TEST_ON_RETURN;
+    private boolean _testOnBorrow =
+        GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
+    private boolean _testOnReturn =
+        GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
     private int _timeBetweenEvictionRunsMillis = (int)
         Math.min(Integer.MAX_VALUE,
-                 GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
+                 GenericObjectPoolConfig.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
     private int _numTestsPerEvictionRun = 
-        GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+        GenericObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
     private int _minEvictableIdleTimeMillis = (int)
     Math.min(Integer.MAX_VALUE,
-             GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
-    private boolean _testWhileIdle = GenericObjectPool.DEFAULT_TEST_WHILE_IDLE;
+            GenericObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
+    private boolean _testWhileIdle =
+        GenericObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
     private String validationQuery = null;
     private boolean rollbackAfterValidation = false;
     

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/PerUserPoolDataSource.java Mon Jun 13 17:51:30 2011
@@ -33,6 +33,7 @@ import javax.sql.ConnectionPoolDataSourc
 
 import org.apache.commons.pool2.ObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.commons.pool2.impl.WhenExhaustedAction;
 
 /**
@@ -61,10 +62,10 @@ public class PerUserPoolDataSource
 
     private static final long serialVersionUID = -3104731034410444060L;
 
-    private int defaultMaxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
-    private int defaultMaxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
+    private int defaultMaxActive = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
+    private int defaultMaxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
     private int defaultMaxWait = (int)Math.min(Integer.MAX_VALUE,
-        GenericObjectPool.DEFAULT_MAX_WAIT);
+            GenericObjectPoolConfig.DEFAULT_MAX_WAIT);
     Map perUserDefaultAutoCommit = null;    
     Map perUserDefaultTransactionIsolation = null;
     Map perUserMaxActive = null;    

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java Mon Jun 13 17:51:30 2011
@@ -30,6 +30,7 @@ import javax.sql.ConnectionPoolDataSourc
 import org.apache.commons.pool2.KeyedObjectPool;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.commons.pool2.impl.WhenExhaustedAction;
 
 /**
@@ -54,10 +55,10 @@ public class SharedPoolDataSource
 
     private static final long serialVersionUID = -8132305535403690372L;
 
-    private int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
-    private int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
+    private int maxActive = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL;
+    private int maxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE;
     private int maxWait = (int)Math.min(Integer.MAX_VALUE,
-        GenericObjectPool.DEFAULT_MAX_WAIT);
+            GenericObjectPoolConfig.DEFAULT_MAX_WAIT);
     private transient KeyedObjectPool pool = null;
     private transient KeyedCPDSConnectionFactory factory = null;
 

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java Mon Jun 13 17:51:30 2011
@@ -22,6 +22,7 @@ import java.sql.Connection;
 import javax.sql.DataSource;
 
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.commons.pool2.impl.WhenExhaustedAction;
 
 import junit.framework.Test;
@@ -48,8 +49,10 @@ public class TestDriverManagerConnection
     public void testDriverManagerInit() throws Exception {
         System.setProperty("jdbc.drivers",
                 "org.apache.commons.dbcp2.TesterDriver");
-        GenericObjectPool connectionPool = new GenericObjectPool(null, 10,
-                WhenExhaustedAction.BLOCK, -1, 0);
+        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+        config.setMaxTotal(10);
+        config.setMaxIdle(0);
+        GenericObjectPool connectionPool = new GenericObjectPool(config);
         final ConnectionFactory connectionFactory =
             new DriverManagerConnectionFactory(
                     "jdbc:apache:commons:testdriver",

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java?rev=1135201&r1=1135200&r2=1135201&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java Mon Jun 13 17:51:30 2011
@@ -32,6 +32,7 @@ import org.apache.commons.pool2.impl.Gen
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPoolFactory;
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
 import org.apache.commons.pool2.impl.WhenExhaustedAction;
 
 /**
@@ -59,21 +60,34 @@ public class TestPoolingDriver extends T
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        GenericObjectPool pool = new GenericObjectPool(null, getMaxActive(), WhenExhaustedAction.BLOCK, getMaxWait(), 10, true, true, 10000L, 5, 5000L, true);
+        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
+        poolConfig.setMaxTotal(getMaxActive());
+        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 config =
+
+        GenericKeyedObjectPoolConfig keyedPoolConfig =
             new GenericKeyedObjectPoolConfig();
-        config.setMaxTotalPerKey(10);
-        config.setMaxWait(2000);
-        config.setMaxIdlePerKey(10);
-        config.setTestOnBorrow(true);
-        config.setTestOnReturn(true);
-        config.setTestWhileIdle(true);
-        config.setTimeBetweenEvictionRunsMillis(10000);
-        config.setNumTestsPerEvictionRun(5);
-        config.setMinEvictableIdleTimeMillis(5000);
+        keyedPoolConfig.setMaxTotalPerKey(10);
+        keyedPoolConfig.setMaxWait(2000);
+        keyedPoolConfig.setMaxIdlePerKey(10);
+        keyedPoolConfig.setTestOnBorrow(true);
+        keyedPoolConfig.setTestOnReturn(true);
+        keyedPoolConfig.setTestWhileIdle(true);
+        keyedPoolConfig.setTimeBetweenEvictionRunsMillis(10000);
+        keyedPoolConfig.setNumTestsPerEvictionRun(5);
+        keyedPoolConfig.setMinEvictableIdleTimeMillis(5000);
         GenericKeyedObjectPoolFactory opf =
-            new GenericKeyedObjectPoolFactory(config);
+            new GenericKeyedObjectPoolFactory(keyedPoolConfig);
+
         PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
         assertNotNull(pcf);
         driver = new PoolingDriver();
@@ -88,14 +102,14 @@ public class TestPoolingDriver extends T
     }
     
     public void test1() {
-        GenericObjectPool connectionPool = new GenericObjectPool(null);
+        GenericObjectPool connectionPool = new GenericObjectPool();
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string","username","password");
         new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
         new PoolingDataSource(connectionPool);
     }
 
     public void test2() {
-        GenericObjectPool connectionPool = new GenericObjectPool(null);
+        GenericObjectPool connectionPool = new GenericObjectPool();
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:some:connect:string","username","password");
         new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
         PoolingDriver driver2 = new PoolingDriver();
@@ -125,12 +139,11 @@ public class TestPoolingDriver extends T
     
     /** @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=12400" */
     public void testReportedBug12400() throws Exception {
-        ObjectPool connectionPool = new GenericObjectPool(
-            null,
-            70,
-            WhenExhaustedAction.BLOCK,
-            60000,
-            10);
+        GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+        config.setMaxTotal(70);
+        config.setMaxWait(60000);
+        config.setMaxIdle(10);
+        ObjectPool connectionPool = new GenericObjectPool(config);
         ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
             "jdbc:apache:commons:testdriver", 
             "username",