Author: markt Date: Thu Aug 4 20:43:40 2011 New Revision: 1154001 URL: http://svn.apache.org/viewvc?rev=1154001&view=rev Log: Generics. All this to remove a single cast.
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PoolablePreparedStatementStub.java commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java?rev=1154001&r1=1154000&r2=1154001&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolablePreparedStatement.java Thu Aug 4 20:43:40 2011 @@ -38,11 +38,12 @@ import org.apache.commons.pool2.KeyedObj * @author Dirk Verbeeck * @version $Revision$ $Date$ */ -public class PoolablePreparedStatement<K, S extends DelegatingPreparedStatement> extends DelegatingPreparedStatement { +public class PoolablePreparedStatement<K, S extends PoolablePreparedStatement<K,S>> + extends DelegatingPreparedStatement { /** * The {@link KeyedObjectPool} from which I was obtained. */ - protected KeyedObjectPool<K, S> _pool = null; + protected KeyedObjectPool<K, PoolablePreparedStatement<K,S>> _pool = null; /** * My "key" as used by {@link KeyedObjectPool}. @@ -59,7 +60,7 @@ public class PoolablePreparedStatement<K * @param conn the {@link Connection} from which I was created */ public PoolablePreparedStatement(PreparedStatement stmt, K key, - KeyedObjectPool<K, S> pool, + KeyedObjectPool<K, PoolablePreparedStatement<K,S>> pool, Connection conn) { super((DelegatingConnection) conn, stmt); _pool = pool; @@ -98,7 +99,7 @@ public class PoolablePreparedStatement<K // calling close twice should have no effect if (!isClosed()) { try { - _pool.returnObject(_key, (S) this); + _pool.returnObject(_key, this); } catch(SQLException e) { throw e; } catch(RuntimeException e) { @@ -110,7 +111,7 @@ public class PoolablePreparedStatement<K } @Override - protected void activate() throws SQLException{ + public void activate() throws SQLException{ _closed = false; if(_conn != null) { _conn.addTrace(this); @@ -119,7 +120,7 @@ public class PoolablePreparedStatement<K } @Override - protected void passivate() throws SQLException { + public void passivate() throws SQLException { _closed = true; if(_conn != null) { _conn.removeTrace(this); 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=1154001&r1=1154000&r2=1154001&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 Thu Aug 4 20:43:40 2011 @@ -34,6 +34,7 @@ import javax.naming.RefAddr; import javax.naming.StringRefAddr; import javax.naming.NamingException; +import org.apache.commons.dbcp2.PoolablePreparedStatement; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; @@ -189,10 +190,10 @@ public class DriverAdapterCPDS pci.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed()); return pci; } - KeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatementStub> stmtPool = null; + KeyedObjectPool<PStmtKeyCPDS, PoolablePreparedStatement<PStmtKeyCPDS, PoolablePreparedStatementStub>> stmtPool = null; if (isPoolPreparedStatements()) { - GenericKeyedObjectPoolConfig<PStmtKeyCPDS,PoolablePreparedStatementStub> config = - new GenericKeyedObjectPoolConfig<PStmtKeyCPDS,PoolablePreparedStatementStub>(); + GenericKeyedObjectPoolConfig<PStmtKeyCPDS,PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub>> config = + new GenericKeyedObjectPoolConfig<PStmtKeyCPDS,PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub>>(); config.setMaxTotalPerKey(Integer.MAX_VALUE); config.setWhenExhaustedAction(WhenExhaustedAction.FAIL); config.setMaxWait(0); @@ -215,7 +216,7 @@ public class DriverAdapterCPDS config.setNumTestsPerEvictionRun(0); config.setMinEvictableIdleTimeMillis(0); } - stmtPool = new GenericKeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatementStub>(pci, config); + stmtPool = new GenericKeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub>>(pci, config); pci.setStatementPool(stmtPool); } return pci; Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PoolablePreparedStatementStub.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PoolablePreparedStatementStub.java?rev=1154001&r1=1154000&r2=1154001&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PoolablePreparedStatementStub.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PoolablePreparedStatementStub.java Thu Aug 4 20:43:40 2011 @@ -42,18 +42,18 @@ class PoolablePreparedStatementStub exte */ public PoolablePreparedStatementStub(PreparedStatement stmt, PStmtKeyCPDS key, - KeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatementStub> pool, + KeyedObjectPool<PStmtKeyCPDS, PoolablePreparedStatement<PStmtKeyCPDS, PoolablePreparedStatementStub>> pool, Connection conn) { super(stmt, key, pool, conn); } @Override - protected void activate() throws SQLException { + public void activate() throws SQLException { super.activate(); } @Override - protected void passivate() throws SQLException { + public void passivate() throws SQLException { super.passivate(); } } Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java?rev=1154001&r1=1154000&r2=1154001&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/cpdsadapter/PooledConnectionImpl.java Thu Aug 4 20:43:40 2011 @@ -30,6 +30,7 @@ import javax.sql.StatementEventListener; /* JDBC_4_ANT_KEY_END */ import org.apache.commons.dbcp2.DelegatingConnection; +import org.apache.commons.dbcp2.PoolablePreparedStatement; import org.apache.commons.pool2.KeyedObjectPool; import org.apache.commons.pool2.KeyedPoolableObjectFactory; @@ -41,7 +42,7 @@ import org.apache.commons.pool2.KeyedPoo * @version $Revision$ $Date$ */ class PooledConnectionImpl implements PooledConnection, - KeyedPoolableObjectFactory<PStmtKeyCPDS,PoolablePreparedStatementStub> { + KeyedPoolableObjectFactory<PStmtKeyCPDS,PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub>> { private static final String CLOSED = "Attempted to use PooledConnection after closed() was called."; @@ -79,7 +80,7 @@ class PooledConnectionImpl implements Po /** My pool of {*link PreparedStatement}s. */ // TODO - make final? - protected KeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatementStub> pstmtPool = null; + protected KeyedObjectPool<PStmtKeyCPDS, PoolablePreparedStatement<PStmtKeyCPDS, PoolablePreparedStatementStub>> pstmtPool = null; /** * Controls access to the underlying connection @@ -103,7 +104,7 @@ class PooledConnectionImpl implements Po } public void setStatementPool( - KeyedObjectPool<PStmtKeyCPDS,PoolablePreparedStatementStub> statementPool) { + KeyedObjectPool<PStmtKeyCPDS, PoolablePreparedStatement<PStmtKeyCPDS, PoolablePreparedStatementStub>> statementPool) { pstmtPool = statementPool; } @@ -426,7 +427,7 @@ class PooledConnectionImpl implements Po * @param obj the key for the {*link PreparedStatement} to be created */ @Override - public PoolablePreparedStatementStub makeObject(PStmtKeyCPDS key) throws Exception { + public PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub> makeObject(PStmtKeyCPDS key) throws Exception { if (null == key) { throw new IllegalArgumentException(); } else { @@ -460,7 +461,7 @@ class PooledConnectionImpl implements Po * @param obj the {*link PreparedStatement} to be destroyed. */ @Override - public void destroyObject(PStmtKeyCPDS key, PoolablePreparedStatementStub ppss) + public void destroyObject(PStmtKeyCPDS key, PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub> ppss) throws Exception { ppss.getInnermostDelegate().close(); } @@ -473,7 +474,7 @@ class PooledConnectionImpl implements Po * @return <tt>true</tt> */ @Override - public boolean validateObject(PStmtKeyCPDS key, PoolablePreparedStatementStub ppss) { + public boolean validateObject(PStmtKeyCPDS key, PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub> ppss) { return true; } @@ -484,7 +485,7 @@ class PooledConnectionImpl implements Po * @param obj ignored */ @Override - public void activateObject(PStmtKeyCPDS key, PoolablePreparedStatementStub ppss) + public void activateObject(PStmtKeyCPDS key, PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub> ppss) throws Exception { ppss.activate(); } @@ -496,7 +497,7 @@ class PooledConnectionImpl implements Po * @param obj a {*link PreparedStatement} */ @Override - public void passivateObject(PStmtKeyCPDS key, PoolablePreparedStatementStub ppss) + public void passivateObject(PStmtKeyCPDS key, PoolablePreparedStatement<PStmtKeyCPDS,PoolablePreparedStatementStub> ppss) throws Exception { ppss.clearParameters(); ppss.passivate();