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/03 17:23:46 UTC
svn commit: r1131072 - in /commons/proper/dbcp/trunk/src:
java/org/apache/commons/dbcp2/ java/org/apache/commons/dbcp2/cpdsadapter/
java/org/apache/commons/dbcp2/datasources/ test/org/apache/commons/dbcp2/
test/org/apache/commons/dbcp2/datasources/
Author: markt
Date: Fri Jun 3 15:23:46 2011
New Revision: 1131072
URL: http://svn.apache.org/viewvc?rev=1131072&view=rev
Log:
Update for KeyedObjectPool refactoring
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/BasicDataSource.java
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/datasources/SharedPoolDataSource.java
commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPStmtPooling.java
commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java
commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java
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=1131072&r1=1131071&r2=1131072&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 Fri Jun 3 15:23:46 2011
@@ -32,6 +32,7 @@ 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.WhenExhaustedAction;
@@ -535,7 +536,8 @@ public class BasicDataSource implements
* and <code>maxOpenPreparedStatements</code> limits the total number of prepared or callable statements
* that may be in use at a given time.</p>
*/
- protected int maxOpenPreparedStatements = GenericKeyedObjectPool.DEFAULT_MAX_TOTAL;
+ protected int maxOpenPreparedStatements =
+ GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
/**
* Gets the value of the {@link #maxOpenPreparedStatements} property.
@@ -1532,12 +1534,15 @@ public class BasicDataSource implements
// Set up statement pool, if desired
GenericKeyedObjectPoolFactory statementPoolFactory = null;
if (isPoolPreparedStatements()) {
- statementPoolFactory = new GenericKeyedObjectPoolFactory(null,
- -1, // unlimited maxActive (per key)
- WhenExhaustedAction.FAIL,
- 0, // maxWait
- 1, // maxIdle (per key)
- maxOpenPreparedStatements);
+ GenericKeyedObjectPoolConfig config =
+ new GenericKeyedObjectPoolConfig();
+ config.setMaxTotalPerKey(-1);
+ config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
+ config.setMaxWait(0);
+ config.setMaxIdle(1);
+ config.setMaxTotal(maxOpenPreparedStatements);
+ statementPoolFactory =
+ new GenericKeyedObjectPoolFactory(config);
}
// Set up the poolable connection factory
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java?rev=1131072&r1=1131071&r2=1131072&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java Fri Jun 3 15:23:46 2011
@@ -36,6 +36,7 @@ import javax.naming.NamingException;
import org.apache.commons.pool2.KeyedObjectPool;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.apache.commons.pool2.impl.WhenExhaustedAction;
/**
@@ -172,27 +173,31 @@ public class DriverAdapterCPDS
*/
KeyedObjectPool stmtPool = null;
if (isPoolPreparedStatements()) {
+ GenericKeyedObjectPoolConfig config =
+ new GenericKeyedObjectPoolConfig();
+ config.setMaxTotalPerKey(Integer.MAX_VALUE);
+ config.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
+ config.setMaxWait(0);
+ config.setMaxIdle(getMaxIdle());
if (getMaxPreparedStatements() <= 0)
{
// since there is no limit, create a prepared statement pool with an eviction thread
// evictor settings are the same as the connection pool settings.
- stmtPool = new GenericKeyedObjectPool(null,
- Integer.MAX_VALUE, WhenExhaustedAction.FAIL, 0,
- getMaxIdle(), false, false,
- getTimeBetweenEvictionRunsMillis(),getNumTestsPerEvictionRun(),getMinEvictableIdleTimeMillis(),
- false);
+ config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
+ config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
+ config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
}
else
{
// since there is limit, create a prepared statement pool without an eviction thread
// pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
// see org.apache.commons.pool2.impl.GenericKeyedObjectPool.clearOldest method
- stmtPool = new GenericKeyedObjectPool(null,
- Integer.MAX_VALUE, WhenExhaustedAction.FAIL, 0,
- getMaxIdle(), getMaxPreparedStatements(), false, false,
- -1,0,0, // -1 tells the pool that there should be no eviction thread.
- false);
+ config.setMaxTotal(getMaxPreparedStatements());
+ config.setTimeBetweenEvictionRunsMillis(-1);
+ config.setNumTestsPerEvictionRun(0);
+ config.setMinEvictableIdleTimeMillis(0);
}
+ stmtPool = new GenericKeyedObjectPool(config);
}
// Workaround for buggy WebLogic 5.1 classloader - ignore the
// exception upon first invocation.
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=1131072&r1=1131071&r2=1131072&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 Fri Jun 3 15:23:46 2011
@@ -214,14 +214,14 @@ public class SharedPoolDataSource
ConnectionPoolDataSource cpds = testCPDS(username, password);
// Create an object pool to contain our PooledConnections
- GenericKeyedObjectPool tmpPool = new GenericKeyedObjectPool(null);
- tmpPool.setMaxActive(getMaxActive());
+ GenericKeyedObjectPool tmpPool = new GenericKeyedObjectPool();
+ tmpPool.setMaxTotalPerKey(getMaxActive());
tmpPool.setMaxIdle(getMaxIdle());
tmpPool.setMaxWait(getMaxWait());
tmpPool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
if (maxActive <= 0) {
tmpPool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
- tmpPool.setMaxActive(Integer.MAX_VALUE);
+ tmpPool.setMaxTotalPerKey(Integer.MAX_VALUE);
}
if (maxWait == 0) {
tmpPool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPStmtPooling.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPStmtPooling.java?rev=1131072&r1=1131071&r2=1131072&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPStmtPooling.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPStmtPooling.java Fri Jun 3 15:23:46 2011
@@ -29,6 +29,7 @@ import junit.framework.TestSuite;
import org.apache.commons.pool2.KeyedObjectPoolFactory;
import org.apache.commons.pool2.ObjectPool;
+import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;
@@ -53,7 +54,9 @@ public class TestPStmtPooling extends Te
"jdbc:apache:commons:testdriver","u1","p1");
ObjectPool connPool = new GenericObjectPool();
- KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);
+ KeyedObjectPoolFactory stmtPoolFactory =
+ new GenericKeyedObjectPoolFactory(
+ new GenericKeyedObjectPoolConfig());
new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
null, false, true);
@@ -76,7 +79,9 @@ public class TestPStmtPooling extends Te
"jdbc:apache:commons:testdriver","u1","p1");
ObjectPool connPool = new GenericObjectPool();
- KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);
+ KeyedObjectPoolFactory stmtPoolFactory =
+ new GenericKeyedObjectPoolFactory(
+ new GenericKeyedObjectPoolConfig());
new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
null, false, true);
@@ -112,7 +117,9 @@ public class TestPStmtPooling extends Te
"jdbc:apache:commons:testdriver","u1","p1");
ObjectPool connPool = new GenericObjectPool();
- KeyedObjectPoolFactory stmtPoolFactory = new GenericKeyedObjectPoolFactory(null);
+ KeyedObjectPoolFactory stmtPoolFactory =
+ new GenericKeyedObjectPoolFactory(
+ new GenericKeyedObjectPoolConfig());
new PoolableConnectionFactory(connFactory, connPool, stmtPoolFactory,
null, false, true);
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=1131072&r1=1131071&r2=1131072&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 Fri Jun 3 15:23:46 2011
@@ -29,6 +29,7 @@ import junit.framework.TestSuite;
import org.apache.commons.pool2.ObjectPool;
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.WhenExhaustedAction;
@@ -60,7 +61,19 @@ public class TestPoolingDriver extends T
super.setUp();
GenericObjectPool pool = new GenericObjectPool(null, getMaxActive(), WhenExhaustedAction.BLOCK, getMaxWait(), 10, true, true, 10000L, 5, 5000L, true);
DriverConnectionFactory cf = new DriverConnectionFactory(new TesterDriver(),"jdbc:apache:commons:testdriver",null);
- GenericKeyedObjectPoolFactory opf = new GenericKeyedObjectPoolFactory(null, 10, WhenExhaustedAction.BLOCK, 2000L, 10, true, true, 10000L, 5, 5000L, true);
+ GenericKeyedObjectPoolConfig config =
+ new GenericKeyedObjectPoolConfig();
+ config.setMaxTotalPerKey(10);
+ config.setMaxWait(2000);
+ config.setMaxIdle(10);
+ config.setTestOnBorrow(true);
+ config.setTestOnReturn(true);
+ config.setTestWhileIdle(true);
+ config.setTimeBetweenEvictionRunsMillis(10000);
+ config.setNumTestsPerEvictionRun(5);
+ config.setMinEvictableIdleTimeMillis(5000);
+ GenericKeyedObjectPoolFactory opf =
+ new GenericKeyedObjectPoolFactory(config);
PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf, pool, opf, "SELECT COUNT(*) FROM DUAL", false, true);
assertNotNull(pcf);
driver = new PoolingDriver();
Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java?rev=1131072&r1=1131071&r2=1131072&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestKeyedCPDSConnectionFactory.java Fri Jun 3 15:23:46 2011
@@ -89,7 +89,7 @@ public class TestKeyedCPDSConnectionFact
public void testConnectionErrorCleanup() throws Exception {
// Setup factory
UserPassKey key = new UserPassKey("username", "password");
- GenericKeyedObjectPool pool = new GenericKeyedObjectPool(null);
+ GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
KeyedCPDSConnectionFactory factory =
new KeyedCPDSConnectionFactory(cpds, pool, null, false);