Author: markt
Date: Tue Jul 19 21:45:45 2011
New Revision: 1148559
URL: http://svn.apache.org/viewvc?rev=1148559&view=rev
Log:
Generics
Note that this showed the Objects created were all instances of
DelegatingPreparedStatement which allowed some unused code to be identified and
removed
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingConnection.java
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingConnection.java
URL:
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingConnection.java?rev=1148559&r1=1148558&r2=1148559&view=diff
==============================================================================
---
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingConnection.java
(original)
+++
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingConnection.java
Tue Jul 19 21:45:45 2011
@@ -43,7 +43,7 @@ import org.apache.commons.pool2.KeyedPoo
* @version $Revision$ $Date$
*/
public class PoolingConnection extends DelegatingConnection
- implements KeyedPoolableObjectFactory {
+ implements
KeyedPoolableObjectFactory<PStmtKey,DelegatingPreparedStatement> {
/** Pool of {@link PreparedStatement}s. and {@link CallableStatement}s */
protected KeyedObjectPool<PStmtKey,PreparedStatement> _pstmtPool = null;
@@ -279,11 +279,11 @@ public class PoolingConnection extends D
* @see #createKey(String, int, int, byte)
*/
@Override
- public Object makeObject(Object obj) throws Exception {
- if(null == obj || !(obj instanceof PStmtKey)) {
+ public DelegatingPreparedStatement makeObject(PStmtKey key)
+ throws Exception {
+ if(null == key) {
throw new IllegalArgumentException("Prepared statement key is null
or invalid.");
} else {
- PStmtKey key = (PStmtKey)obj;
if( null == key._resultSetType && null ==
key._resultSetConcurrency ) {
if (key._stmtType == STATEMENT_PREPAREDSTMT ) {
return new
PoolablePreparedStatement(getDelegate().prepareStatement( key._sql), key,
_pstmtPool, this);
@@ -311,12 +311,9 @@ public class PoolingConnection extends D
* @param obj the pooled statement to be destroyed.
*/
@Override
- public void destroyObject(Object key, Object obj) throws Exception {
- if(obj instanceof DelegatingPreparedStatement) {
- ((DelegatingPreparedStatement)obj).getInnermostDelegate().close();
- } else {
- ((PreparedStatement)obj).close();
- }
+ public void destroyObject(PStmtKey key, DelegatingPreparedStatement dps)
+ throws Exception {
+ dps.getInnermostDelegate().close();
}
/**
@@ -328,7 +325,8 @@ public class PoolingConnection extends D
* @return <tt>true</tt>
*/
@Override
- public boolean validateObject(Object key, Object obj) {
+ public boolean validateObject(PStmtKey key,
+ DelegatingPreparedStatement obj) {
return true;
}
@@ -340,8 +338,9 @@ public class PoolingConnection extends D
* @param obj pooled statement to be activated
*/
@Override
- public void activateObject(Object key, Object obj) throws Exception {
- ((DelegatingPreparedStatement)obj).activate();
+ public void activateObject(PStmtKey key,
+ DelegatingPreparedStatement dps) throws Exception {
+ dps.activate();
}
/**
@@ -353,9 +352,10 @@ public class PoolingConnection extends D
* @param obj a {@link PreparedStatement}
*/
@Override
- public void passivateObject(Object key, Object obj) throws Exception {
- ((PreparedStatement)obj).clearParameters();
- ((DelegatingPreparedStatement)obj).passivate();
+ public void passivateObject(PStmtKey key,
+ DelegatingPreparedStatement dps) throws Exception {
+ dps.clearParameters();
+ dps.passivate();
}
@Override