Author: markt Date: Tue Dec 3 21:35:28 2013 New Revision: 1547594 URL: http://svn.apache.org/r1547594 Log: Make some progress (finally) with using generics and reducing the number of warnings in the code.
Modified: commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.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 Modified: commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java?rev=1547594&r1=1547593&r2=1547594&view=diff ============================================================================== --- commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java (original) +++ commons/proper/dbcp/trunk/doc/PoolingDataSourceExample.java Tue Dec 3 21:35:28 2013 @@ -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.PoolingDataSource; import org.apache.commons.dbcp2.PoolableConnectionFactory; import org.apache.commons.dbcp2.DriverManagerConnectionFactory; @@ -155,14 +156,15 @@ public class PoolingDataSourceExample { // 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, // passing in the object pool we created. // - PoolingDataSource dataSource = new PoolingDataSource(connectionPool); + PoolingDataSource<PoolableConnection> dataSource = + new PoolingDataSource<>(connectionPool); return dataSource; } Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java?rev=1547594&r1=1547593&r2=1547594&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java (original) +++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp2/PoolingDataSource.java Tue Dec 3 21:35:28 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. @@ -38,20 +38,20 @@ import org.apache.commons.pool2.ObjectPo * @author Dirk Verbeeck * @version $Revision$ $Date$ */ -public class PoolingDataSource implements DataSource { +public class PoolingDataSource<C extends Connection> implements DataSource { /** Controls access to the underlying connection */ - private boolean accessToUnderlyingConnectionAllowed = false; + private boolean accessToUnderlyingConnectionAllowed = false; public PoolingDataSource() { this(null); } - public PoolingDataSource(ObjectPool<Connection> pool) { + public PoolingDataSource(ObjectPool<C> pool) { _pool = pool; } - public void setPool(ObjectPool<Connection> pool) + public void setPool(ObjectPool<C> pool) throws IllegalStateException, NullPointerException { if(null != _pool) { throw new IllegalStateException("Pool already set"); @@ -64,7 +64,7 @@ public class PoolingDataSource implement /** * Returns the value of the accessToUnderlyingConnectionAllowed property. - * + * * @return true if access to the underlying is allowed, false otherwise. */ public boolean isAccessToUnderlyingConnectionAllowed() { @@ -75,7 +75,7 @@ public class PoolingDataSource implement * Sets the value of the accessToUnderlyingConnectionAllowed property. * It controls if the PoolGuard allows access to the underlying connection. * (Default: false) - * + * * @param allow Access to the underlying connection is granted when true. */ public void setAccessToUnderlyingConnectionAllowed(boolean allow) { @@ -93,7 +93,7 @@ public class PoolingDataSource implement throw new SQLException("PoolingDataSource is not a wrapper."); } /* JDBC_4_ANT_KEY_END */ - + @Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { throw new SQLFeatureNotSupportedException(); @@ -111,7 +111,7 @@ public class PoolingDataSource implement Connection conn = _pool.borrowObject(); if (conn != null) { conn = new PoolGuardConnectionWrapper(conn); - } + } return conn; } catch(SQLException e) { throw e; @@ -175,10 +175,10 @@ public class PoolingDataSource implement /** My log writer. */ protected PrintWriter _logWriter = null; - protected ObjectPool<Connection> _pool = null; + protected ObjectPool<C> _pool = null; /** - * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a + * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a * closed connection cannot be used anymore. */ private class PoolGuardConnectionWrapper extends DelegatingConnection { 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=1547594&r1=1547593&r2=1547594&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 Tue Dec 3 21:35:28 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. @@ -36,7 +36,7 @@ import junit.framework.TestSuite; * @version $Revision$ $Date$ */ public class TestDriverManagerConnectionFactory extends TestCase { - + public TestDriverManagerConnectionFactory(String testName) { super(testName); } @@ -60,15 +60,15 @@ public class TestDriverManagerConnection poolableConnectionFactory.setDefaultReadOnly(false); poolableConnectionFactory.setDefaultAutoCommit(true); - GenericObjectPool connectionPool = - new GenericObjectPool(poolableConnectionFactory, config); + GenericObjectPool<PoolableConnection> connectionPool = + new GenericObjectPool<>(poolableConnectionFactory, config); poolableConnectionFactory.setPool(connectionPool); - PoolingDataSource dataSource = - new PoolingDataSource(connectionPool); + PoolingDataSource<PoolableConnection> dataSource = + new PoolingDataSource<>(connectionPool); ConnectionThread[] connectionThreads = new ConnectionThread[10]; Thread[] threads = new Thread[10]; - + for (int i = 0; i < 10; i++) { connectionThreads[i] = new ConnectionThread(dataSource); threads[i] = new Thread(connectionThreads[i]); @@ -85,11 +85,11 @@ public class TestDriverManagerConnection } } } - + private static final class ConnectionThread implements Runnable { private DataSource ds; private volatile boolean result = true; - + private ConnectionThread(DataSource ds) { this.ds = ds; } @@ -107,13 +107,13 @@ public class TestDriverManagerConnection try { conn.close(); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); result = false; } } } } - + public boolean getResult() { return result; } 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=1547594&r1=1547593&r2=1547594&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 Tue Dec 3 21:35:28 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. @@ -32,7 +32,7 @@ import org.apache.commons.pool2.impl.Gen /** * TestSuite for BasicDataSource with prepared statement pooling enabled - * + * * @author Dirk Verbeeck * @version $Revision$ $Date$ */ @@ -55,9 +55,9 @@ public class TestPStmtPooling extends Te pcf.setPoolStatements(true); pcf.setDefaultReadOnly(false); pcf.setDefaultAutoCommit(true); - ObjectPool<? extends Connection> connPool = new GenericObjectPool<>(pcf); + ObjectPool<PoolableConnection> connPool = new GenericObjectPool<>(pcf); - DataSource ds = new PoolingDataSource((ObjectPool<Connection>) connPool); + DataSource ds = new PoolingDataSource<>(connPool); Connection conn = ds.getConnection(); Statement stmt1 = conn.prepareStatement("select 1 from dual"); @@ -68,7 +68,7 @@ public class TestPStmtPooling extends Te stmt2.close(); assertSame(ustmt1, ustmt2); } - + public void testCallableStatementPooling() throws Exception { new TesterDriver(); ConnectionFactory connFactory = new DriverManagerConnectionFactory( @@ -80,9 +80,9 @@ public class TestPStmtPooling extends Te pcf.setDefaultReadOnly(false); pcf.setDefaultAutoCommit(true); - ObjectPool connPool = new GenericObjectPool(pcf); + ObjectPool<PoolableConnection> connPool = new GenericObjectPool<>(pcf); - DataSource ds = new PoolingDataSource(connPool); + DataSource ds = new PoolingDataSource<>(connPool); Connection conn = ds.getConnection(); Statement stmt1 = conn.prepareStatement("select 1 from dual"); @@ -106,7 +106,7 @@ public class TestPStmtPooling extends Te assertNotSame(ustmt1, ustmt3); assertNotSame(ustmt3, ucstmt1); } - + public void testClosePool() throws Exception { new TesterDriver(); ConnectionFactory connFactory = new DriverManagerConnectionFactory( @@ -118,16 +118,16 @@ public class TestPStmtPooling extends Te pcf.setDefaultReadOnly(false); pcf.setDefaultAutoCommit(true); - ObjectPool connPool = new GenericObjectPool(pcf); + ObjectPool<PoolableConnection> connPool = new GenericObjectPool<>(pcf); - DataSource ds = new PoolingDataSource(connPool); - ((PoolingDataSource) ds).setAccessToUnderlyingConnectionAllowed(true); + DataSource ds = new PoolingDataSource<>(connPool); + ((PoolingDataSource<?>) ds).setAccessToUnderlyingConnectionAllowed(true); Connection conn = ds.getConnection(); conn.prepareStatement("select 1 from dual"); - + Connection poolableConnection = ((DelegatingConnection) conn).getDelegate(); - Connection poolingConnection = + Connection poolingConnection = ((DelegatingConnection) poolableConnection).getDelegate(); poolingConnection.close(); try { @@ -135,6 +135,6 @@ public class TestPStmtPooling extends Te fail("Expecting SQLException"); } catch (SQLException ex) { assertTrue(ex.getMessage().endsWith("invalid PoolingConnection.")); - } + } } } 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=1547594&r1=1547593&r2=1547594&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 21:35:28 2013 @@ -96,8 +96,9 @@ public class TestPoolingDriver extends T new PoolableConnectionFactory(connectionFactory); pcf.setDefaultReadOnly(false); pcf.setDefaultAutoCommit(true); - GenericObjectPool connectionPool = new GenericObjectPool(pcf); - new PoolingDataSource(connectionPool); + GenericObjectPool<PoolableConnection> connectionPool = + new GenericObjectPool<>(pcf); + new PoolingDataSource<>(connectionPool); } public void test2() {