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 2013/12/04 00:40:32 UTC
svn commit: r1547646 - in /commons/proper/dbcp/trunk:
doc/PoolingDriverExample.java
src/java/org/apache/commons/dbcp2/PoolingDriver.java
src/test/org/apache/commons/dbcp2/TestPoolingDriver.java
Author: markt
Date: Tue Dec 3 23:40:32 2013
New Revision: 1547646
URL: http://svn.apache.org/r1547646
Log:
Fix the PoolingDriver related generics warnings
Modified:
commons/proper/dbcp/trunk/doc/PoolingDriverExample.java
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDriver.java
commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestPoolingDriver.java
Modified: commons/proper/dbcp/trunk/doc/PoolingDriverExample.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDriverExample.java?rev=1547646&r1=1547645&r2=1547646&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/doc/PoolingDriverExample.java (original)
+++ commons/proper/dbcp/trunk/doc/PoolingDriverExample.java Tue Dec 3 23:40:32 2013
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,6 +30,7 @@ import java.sql.SQLException;
import org.apache.commons.pool2.ObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.apache.commons.dbcp2.ConnectionFactory;
+import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolingDriver;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
@@ -171,8 +172,8 @@ public class PoolingDriverExample {
// We'll use a GenericObjectPool instance, although
// any ObjectPool implementation will suffice.
//
- ObjectPool connectionPool =
- new GenericObjectPool(poolableConnectionFactory);
+ ObjectPool<PoolableConnection> connectionPool =
+ new GenericObjectPool<>(poolableConnectionFactory);
//
// Finally, we create the PoolingDriver itself...
@@ -193,8 +194,8 @@ public class PoolingDriverExample {
public static void printDriverStats() throws Exception {
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
- ObjectPool connectionPool = driver.getConnectionPool("example");
-
+ ObjectPool<? extends Connection> connectionPool = driver.getConnectionPool("example");
+
System.out.println("NumActive: " + connectionPool.getNumActive());
System.out.println("NumIdle: " + connectionPool.getNumIdle());
}
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDriver.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDriver.java?rev=1547646&r1=1547645&r2=1547646&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDriver.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDriver.java Tue Dec 3 23:40:32 2013
@@ -50,7 +50,7 @@ public class PoolingDriver implements Dr
}
/** The map of registered pools. */
- protected static final HashMap<String,ObjectPool<Connection>> _pools =
+ protected static final HashMap<String,ObjectPool<? extends Connection>> _pools =
new HashMap<>();
/** Controls access to the underlying connection */
@@ -66,8 +66,8 @@ public class PoolingDriver implements Dr
protected PoolingDriver(boolean accessToUnderlyingConnectionAllowed) {
this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed;
}
-
-
+
+
/**
* Returns the value of the accessToUnderlyingConnectionAllowed property.
*
@@ -77,9 +77,9 @@ public class PoolingDriver implements Dr
return accessToUnderlyingConnectionAllowed;
}
- public synchronized ObjectPool<Connection> getConnectionPool(String name)
+ public synchronized ObjectPool<? extends Connection> getConnectionPool(String name)
throws SQLException {
- ObjectPool<Connection> pool = _pools.get(name);
+ ObjectPool<? extends Connection> pool = _pools.get(name);
if (null == pool) {
throw new SQLException("Pool not registered.");
}
@@ -87,12 +87,12 @@ public class PoolingDriver implements Dr
}
public synchronized void registerPool(String name,
- ObjectPool<Connection> pool) {
+ ObjectPool<? extends Connection> pool) {
_pools.put(name,pool);
}
public synchronized void closePool(String name) throws SQLException {
- ObjectPool<Connection> pool = _pools.get(name);
+ ObjectPool<? extends Connection> pool = _pools.get(name);
if (pool != null) {
_pools.remove(name);
try {
@@ -121,17 +121,17 @@ public class PoolingDriver implements Dr
@Override
public Connection connect(String url, Properties info) throws SQLException {
if(acceptsURL(url)) {
- ObjectPool<Connection> pool =
+ ObjectPool<? extends Connection> pool =
getConnectionPool(url.substring(URL_PREFIX_LEN));
if(null == pool) {
throw new SQLException("No pool found for " + url + ".");
} else {
try {
Connection conn = pool.borrowObject();
- if (conn != null) {
- conn = new PoolGuardConnectionWrapper(pool, conn);
+ if (conn == null) {
+ return null;
}
- return conn;
+ return new PoolGuardConnectionWrapper(pool, conn);
} catch(SQLException e) {
throw e;
} catch(NoSuchElementException e) {
@@ -164,7 +164,8 @@ public class PoolingDriver implements Dr
public void invalidateConnection(Connection conn) throws SQLException {
if (conn instanceof PoolGuardConnectionWrapper) { // normal case
PoolGuardConnectionWrapper pgconn = (PoolGuardConnectionWrapper) conn;
- ObjectPool<Connection> pool = pgconn.pool;
+ @SuppressWarnings("unchecked")
+ ObjectPool<Connection> pool = (ObjectPool<Connection>) pgconn.pool;
try {
pool.invalidateObject(pgconn.getDelegateInternal());
}
@@ -208,11 +209,11 @@ public class PoolingDriver implements Dr
* PoolGuardConnectionWrapper is a Connection wrapper that makes sure a
* closed connection cannot be used anymore.
*/
- private class PoolGuardConnectionWrapper extends DelegatingConnection {
+ private class PoolGuardConnectionWrapper extends DelegatingConnection<Connection> {
- private final ObjectPool<Connection> pool;
+ private final ObjectPool<? extends Connection> pool;
- PoolGuardConnectionWrapper(ObjectPool<Connection> pool,
+ PoolGuardConnectionWrapper(ObjectPool<? extends Connection> pool,
Connection delegate) {
super(delegate);
this.pool = pool;
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=1547646&r1=1547645&r2=1547646&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 Tue Dec 3 23:40:32 2013
@@ -76,7 +76,7 @@ public class TestPoolingDriver extends T
poolConfig.setNumTestsPerEvictionRun(5);
poolConfig.setMinEvictableIdleTimeMillis(5000L);
- GenericObjectPool pool = new GenericObjectPool(pcf, poolConfig);
+ GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<>(pcf, poolConfig);
pcf.setPool(pool);
assertNotNull(pcf);
@@ -107,7 +107,7 @@ public class TestPoolingDriver extends T
new PoolableConnectionFactory(connectionFactory);
pcf.setDefaultReadOnly(false);
pcf.setDefaultAutoCommit(true);
- GenericObjectPool connectionPool = new GenericObjectPool(pcf);
+ GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(pcf);
PoolingDriver driver2 = new PoolingDriver();
driver2.registerPool("example",connectionPool);
}
@@ -147,8 +147,8 @@ public class TestPoolingDriver extends T
new PoolableConnectionFactory(connectionFactory);
poolableConnectionFactory.setDefaultReadOnly(false);
poolableConnectionFactory.setDefaultAutoCommit(true);
- ObjectPool connectionPool =
- new GenericObjectPool(poolableConnectionFactory,config);
+ ObjectPool<PoolableConnection> connectionPool =
+ new GenericObjectPool<>(poolableConnectionFactory,config);
poolableConnectionFactory.setPool(connectionPool);
assertNotNull(poolableConnectionFactory);
PoolingDriver driver2 = new PoolingDriver();