Author: markt Date: Tue Dec 3 09:36:12 2013 New Revision: 1547326 URL: http://svn.apache.org/r1547326 Log: DBCP-384 Fix threading issues with PoolingDriver.accessToUnderlyingConnectionAllowed
Modified: commons/proper/dbcp/trunk/src/changes/changes.xml 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/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1547326&r1=1547325&r2=1547326&view=diff ============================================================================== --- commons/proper/dbcp/trunk/src/changes/changes.xml (original) +++ commons/proper/dbcp/trunk/src/changes/changes.xml Tue Dec 3 09:36:12 2013 @@ -78,6 +78,10 @@ The <action> type attribute can be add,u <action dev="markt" issue="DBCP-143" type="update"> Remove deprecated SQLNestedException. </action> + <action dev="markt" issue="DBCP-384" type="fix"> + Fix threading issues with accessToUnderlyingConnectionAllowed attribute + of PoolingDriver which is used to support unit testing. + </action> </release> <release version="1.5.1" date="TBD" description="TBD"> <action dev="markt" issue="DBCP-405" type="fix"> 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=1547326&r1=1547325&r2=1547326&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 09:36:12 2013 @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.commons.dbcp2; import java.sql.CallableStatement; @@ -61,29 +60,27 @@ public class PoolingDriver implements Dr new HashMap<>(); /** Controls access to the underlying connection */ - private static boolean accessToUnderlyingConnectionAllowed = false; + private final boolean accessToUnderlyingConnectionAllowed; public PoolingDriver() { + this(true); } /** - * Returns the value of the accessToUnderlyingConnectionAllowed property. - * - * @return true if access to the underlying is allowed, false otherwise. + * For unit testing purposes. */ - public static synchronized boolean isAccessToUnderlyingConnectionAllowed() { - return accessToUnderlyingConnectionAllowed; + protected PoolingDriver(boolean accessToUnderlyingConnectionAllowed) { + this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed; } - + + /** - * Sets the value of the accessToUnderlyingConnectionAllowed property. - * It controls if the PoolGuard allows access to the underlying connection. - * (Default: false) + * Returns the value of the accessToUnderlyingConnectionAllowed property. * - * @param allow Access to the underlying connection is granted when true. + * @return true if access to the underlying is allowed, false otherwise. */ - public static synchronized void setAccessToUnderlyingConnectionAllowed(boolean allow) { - accessToUnderlyingConnectionAllowed = allow; + protected boolean isAccessToUnderlyingConnectionAllowed() { + return accessToUnderlyingConnectionAllowed; } public synchronized ObjectPool<Connection> getConnectionPool(String name) @@ -219,7 +216,7 @@ public class PoolingDriver implements Dr * PoolGuardConnectionWrapper is a Connection wrapper that makes sure a * closed connection cannot be used anymore. */ - static private class PoolGuardConnectionWrapper extends DelegatingConnection { + private class PoolGuardConnectionWrapper extends DelegatingConnection { private final ObjectPool<Connection> pool; private Connection delegate; 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=1547326&r1=1547325&r2=1547326&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 09:36:12 2013 @@ -80,9 +80,8 @@ public class TestPoolingDriver extends T pcf.setPool(pool); assertNotNull(pcf); - driver = new PoolingDriver(); + driver = new PoolingDriver(true); driver.registerPool("test",pool); - PoolingDriver.setAccessToUnderlyingConnectionAllowed(true); } @Override