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 2014/02/04 14:44:13 UTC

svn commit: r1564298 - in /commons/proper/dbcp/trunk/src: changes/ main/java/org/apache/commons/dbcp2/ main/java/org/apache/commons/dbcp2/datasources/ main/java/org/apache/commons/dbcp2/managed/ test/java/org/apache/commons/dbcp2/ test/java/org/apache/...

Author: markt
Date: Tue Feb  4 13:44:12 2014
New Revision: 1564298

URL: http://svn.apache.org/r1564298
Log:
Fix DBCP-358
The equals() implementations of the DelegatingXxx classes are now symmetric.
There are some important API changes underlying this fix:
- two DelegatingXxx instances are no longer considered equal if they have the same innermost delegate;
- a DelegatingXxx instance is not considered equal to its innermost delegate;
- the getInnermostDelegateInternal() method has been made public (but remains part of the internal API) to allow classes extending this implementation to access the innermost delegate when required.

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java
    commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java
    commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.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=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Tue Feb  4 13:44:12 2014
@@ -112,6 +112,16 @@ The <action> type attribute can be add,u
         BasicDataSourceFactory so a cast is not required to use BasicDataSource
         specific methods.
       </action>
+      <action dev="markt" issue="DBCP-358" type="fix">
+        The equals() implementations of the DelegatingXxx classes are now
+        symmetric. There are some important API changes underlying this fix.
+        Firstly, two DelegatingXxx instances are no longer considered equal if
+        they have the same innermost delegate. Secondly, a DelegatingXxx
+        instance is not considered equal to its innermost delegate. The
+        getInnermostDelegateInternal() method has been made public (but remains
+        part of the internal API) to allow classes extending this implementation
+        to access the innermost delegate when required.
+      </action>
     </release>
     <release version="1.5.1" date="TBD" description="TBD">
       <action dev="markt" issue="DBCP-400" type="fix">

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java Tue Feb  4 13:44:12 2014
@@ -164,38 +164,6 @@ public class DelegatingConnection<C exte
         }
     }
 
-    /**
-     * This method considers two objects to be equal
-     * if the underlying jdbc objects are equal.
-     */
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        if (obj == this) {
-            return true;
-        }
-        Connection delegate = getInnermostDelegateInternal();
-        if (obj instanceof DelegatingConnection) {
-            DelegatingConnection<?> c = (DelegatingConnection<?>) obj;
-            Connection cDelegate = c.getInnermostDelegateInternal();
-            return delegate == cDelegate || (delegate != null && delegate.equals(cDelegate));
-        }
-        else {
-            return delegate.equals(obj);
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        Object obj = getInnermostDelegateInternal();
-        if (obj == null) {
-            return 0;
-        }
-        return obj.hashCode();
-    }
-
 
     /**
      * If my underlying {@link Connection} is not a
@@ -216,7 +184,13 @@ public class DelegatingConnection<C exte
         return getInnermostDelegateInternal();
     }
 
-    protected final Connection getInnermostDelegateInternal() {
+
+    /**
+     * Although this method is public, it is part of the internal API and should
+     * not be used by clients. The signature of this method may change at any
+     * time including in ways that break backwards compatibility.
+     */
+    public final Connection getInnermostDelegateInternal() {
         Connection c = _conn;
         while(c != null && c instanceof DelegatingConnection) {
             c = ((DelegatingConnection<?>)c).getDelegateInternal();

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingDatabaseMetaData.java Tue Feb  4 13:44:12 2014
@@ -51,31 +51,6 @@ public class DelegatingDatabaseMetaData 
         return _meta;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-    	if (this == obj) return true;
-        DatabaseMetaData delegate = getInnermostDelegate();
-        if (delegate == null) {
-            return false;
-        }
-        if (obj instanceof DelegatingDatabaseMetaData) {
-            DelegatingDatabaseMetaData s = (DelegatingDatabaseMetaData) obj;
-            return delegate.equals(s.getInnermostDelegate());
-        }
-        else {
-            return delegate.equals(obj);
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        Object obj = getInnermostDelegate();
-        if (obj == null) {
-            return 0;
-        }
-        return obj.hashCode();
-    }
-
     /**
      * If my underlying {@link ResultSet} is not a
      * <tt>DelegatingResultSet</tt>, returns it,

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingResultSet.java Tue Feb  4 13:44:12 2014
@@ -123,31 +123,6 @@ public class DelegatingResultSet extends
         return _res;
     }
 
-    @Override
-    public boolean equals(Object obj) {
-    	if (this == obj) return true;
-        ResultSet delegate = getInnermostDelegate();
-        if (delegate == null) {
-            return false;
-        }
-        if (obj instanceof DelegatingResultSet) {
-            DelegatingResultSet s = (DelegatingResultSet) obj;
-            return delegate.equals(s.getInnermostDelegate());
-        }
-        else {
-            return delegate.equals(obj);
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        Object obj = getInnermostDelegate();
-        if (obj == null) {
-            return 0;
-        }
-        return obj.hashCode();
-    }
-
     /**
      * If my underlying {@link ResultSet} is not a
      * <tt>DelegatingResultSet</tt>, returns it,

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/DelegatingStatement.java Tue Feb  4 13:44:12 2014
@@ -71,40 +71,6 @@ public class DelegatingStatement extends
         return _stmt;
     }
 
-    /**
-     * <p>This method considers two objects to be equal
-     * if the underlying jdbc objects are equal.</p>
-     *
-     * <p>If {@code obj} is a DelegatingStatement, this DelegatingStatement's
-     * {@link #getInnermostDelegate() innermostDelegate} is compared with
-     * the innermost delegate of obj; otherwise obj itself is compared with the
-     * the Statement returned by {@link #getInnermostDelegate()}.</p>
-     *
-     */
-    @Override
-    public boolean equals(Object obj) {
-    	if (obj == this) return true;
-        Statement delegate = getInnermostDelegate();
-        if (delegate == null) {
-            return false;
-        }
-        if (obj instanceof DelegatingStatement) {
-            DelegatingStatement s = (DelegatingStatement) obj;
-            return delegate.equals(s.getInnermostDelegate());
-        }
-        else {
-            return delegate.equals(obj);
-        }
-    }
-
-    @Override
-    public int hashCode() {
-        Object obj = getInnermostDelegate();
-        if (obj == null) {
-            return 0;
-        }
-        return obj.hashCode();
-    }
 
     /**
      * If my underlying {@link Statement} is not a

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyObjectFactory.java Tue Feb  4 13:44:12 2014
@@ -51,7 +51,7 @@ abstract class InstanceKeyObjectFactory 
             String s = i.next();
             if (s != null) {
                 try {
-                    max = Math.max(max, Integer.valueOf(s).intValue());
+                    max = Math.max(max, Integer.parseInt(s));
                 } catch (NumberFormatException e) {
                     // no sweat, ignore those keys
                 }

Modified: commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java (original)
+++ commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/managed/TransactionRegistry.java Tue Feb  4 13:44:12 2014
@@ -28,6 +28,8 @@ import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAResource;
 
+import org.apache.commons.dbcp2.DelegatingConnection;
+
 
 /**
  * TransactionRegistry tracks Connections and XAResources in a transacted environment for a single XAConnectionFactory.
@@ -74,7 +76,8 @@ public class TransactionRegistry {
      */
     public synchronized XAResource getXAResource(Connection connection) throws SQLException {
         if (connection == null) throw new NullPointerException("connection is null");
-        XAResource xaResource = xaResources.get(connection);
+        Connection key = getConnectionKey(connection);
+        XAResource xaResource = xaResources.get(key);
         if (xaResource == null) {
             throw new SQLException("Connection does not have a registered XAResource " + connection);
         }
@@ -121,7 +124,19 @@ public class TransactionRegistry {
      * @param connection
      */
     public synchronized void unregisterConnection(Connection connection) {
-        xaResources.remove(connection);
+        Connection key = getConnectionKey(connection);
+        xaResources.remove(key);
+    }
+
+
+    private Connection getConnectionKey(Connection connection) {
+        Connection result;
+        if (connection instanceof DelegatingConnection) {
+            result = ((DelegatingConnection<?>) connection).getInnermostDelegateInternal();
+        } else {
+            result = connection;
+        }
+        return result;
     }
 }
 

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingCallableStatement.java Tue Feb  4 13:44:12 2014
@@ -64,62 +64,4 @@ public class TestDelegatingCallableState
         stmt = new DelegatingCallableStatement(conn,delegateStmt);
         assertEquals(delegateStmt,stmt.getDelegate());
     }
-
-    public void testHashCodeNull() {
-        stmt = new DelegatingCallableStatement(conn, null);
-        assertEquals(0, stmt.hashCode());
-    }
-
-    public void testHashCode() throws Exception {
-        delegateStmt = new TesterCallableStatement(delegateConn,"select * from foo");
-        DelegatingCallableStatement stmt1 = new DelegatingCallableStatement(conn,delegateStmt);
-        DelegatingCallableStatement stmt2 = new DelegatingCallableStatement(conn,delegateStmt);
-        assertEquals(stmt1.hashCode(), stmt2.hashCode());
-        stmt1.close();
-        stmt2.close();
-    }
-
-    public void testEquals() {
-        delegateStmt = new TesterCallableStatement(delegateConn,"select * from foo");
-        CallableStatement del = new TesterCallableStatement(delegateConn,"select * from foo");
-        DelegatingCallableStatement stmt1 = new DelegatingCallableStatement(conn, delegateStmt);
-        DelegatingCallableStatement stmt2 = new DelegatingCallableStatement(conn, delegateStmt);
-        DelegatingCallableStatement stmt3 = new DelegatingCallableStatement(conn, null);
-        DelegatingCallableStatement stmt4 = new DelegatingCallableStatement(conn, del);
-
-        // Nothing is equal to null
-        assertFalse(stmt1.equals(null));
-        assertFalse(stmt2.equals(null));
-        assertFalse(stmt3.equals(null));
-        assertFalse(stmt4.equals(null));
-
-        // 1 & 2 are equivalent
-        assertTrue(stmt1.equals(stmt2));
-        assertTrue(stmt2.equals(stmt1)); // reflexive
-
-        // 1 & 3 are not (different statements, one null)
-        assertFalse(stmt1.equals(stmt3));
-        assertFalse(stmt3.equals(stmt1)); // reflexive
-
-        // 1 & 4 are not (different statements)
-        assertFalse(stmt1.equals(stmt4));
-        assertFalse(stmt4.equals(stmt1)); // reflexive
-
-        // Check self-equals
-        assertTrue(stmt1.equals(stmt1));
-        assertTrue(stmt2.equals(stmt2));
-        assertTrue(stmt3.equals(stmt3));
-        assertTrue(stmt4.equals(stmt4));
-
-        DelegatingStatement dstmt1 = stmt1;
-
-        // 1 & 2 are equivalent
-        assertTrue(dstmt1.equals(stmt2));
-        assertTrue(stmt2.equals(dstmt1)); // reflexive
-
-        // innermost delegate itself - bugged behavior?
-        assertTrue(stmt1.equals(delegateStmt));
-
-    }
-
 }

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java Tue Feb  4 13:44:12 2014
@@ -61,32 +61,6 @@ public class TestDelegatingConnection ex
         assertTrue(s.length() > 0);
     }
 
-    public void testHashCodeEqual() throws Exception {
-        DelegatingConnection<Connection> conn2 = new DelegatingConnection<>(delegateConn);
-        assertEquals(conn.hashCode(), conn2.hashCode());
-        conn2.close();
-    }
-
-    public void testHashCodeNotEqual() throws Exception {
-        DelegatingConnection<Connection> conn2 = new DelegatingConnection<>(delegateConn2);
-        assertTrue(conn.hashCode() != conn2.hashCode());
-        conn2.close();
-    }
-
-    public void testEquals() {
-        DelegatingConnection<Connection> conn2 = new DelegatingConnection<>(delegateConn);
-        DelegatingConnection<Connection> conn3 = new DelegatingConnection<>(null);
-
-        assertTrue(!conn.equals(null));
-        assertTrue(conn.equals(conn2));
-        assertTrue(!conn.equals(conn3));
-        assertTrue(conn.equals(conn));
-        assertTrue(conn3.equals(conn3));
-        assertTrue(conn.equals(conn));
-        assertTrue(conn2.equals(conn2));
-        assertTrue(conn3.equals(new DelegatingConnection<>(null)));
-    }
-
     public void testCheckOpen() throws Exception {
         conn.checkOpen();
         conn.close();

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingDatabaseMetaData.java Tue Feb  4 13:44:12 2014
@@ -20,8 +20,6 @@ package org.apache.commons.dbcp2;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
-import java.sql.SQLException;
-
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
@@ -55,40 +53,6 @@ public class TestDelegatingDatabaseMetaD
         assertEquals(delegateMeta,meta.getDelegate());
     }
 
-    public void testHashCode() {
-        try {
-            delegateMeta = conn.getMetaData();
-        } catch (SQLException e) {
-            fail("No exception expected retrieving meta data");
-        }
-        DelegatingDatabaseMetaData meta1 =
-            new DelegatingDatabaseMetaData(conn,delegateMeta);
-        DelegatingDatabaseMetaData meta2 =
-            new DelegatingDatabaseMetaData(conn,delegateMeta);
-        assertEquals(meta1.hashCode(), meta2.hashCode());
-    }
-
-    public void testEquals() {
-        try {
-            delegateMeta = conn.getMetaData();
-        } catch (SQLException e) {
-            fail("No exception expected retrieving meta data");
-        }
-        DelegatingDatabaseMetaData meta1 =
-            new DelegatingDatabaseMetaData(conn,delegateMeta);
-        DelegatingDatabaseMetaData meta2 =
-            new DelegatingDatabaseMetaData(conn,delegateMeta);
-        DelegatingDatabaseMetaData meta3 =
-            new DelegatingDatabaseMetaData(conn,null);
-
-        assertTrue(!meta1.equals(null));
-        assertTrue(meta1.equals(meta2));
-        assertTrue(!meta1.equals(meta3));
-        assertTrue(meta1.equals(meta1));
-        assertTrue(meta2.equals(meta2));
-        assertTrue(meta3.equals(meta3));
-    }
-
     /* JDBC_4_ANT_KEY_BEGIN */
     public void testCheckOpen() throws Exception {
         ResultSet rst = meta.getSchemas();

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingPreparedStatement.java Tue Feb  4 13:44:12 2014
@@ -66,62 +66,4 @@ public class TestDelegatingPreparedState
         stmt = new DelegatingPreparedStatement(conn,delegateStmt);
         assertEquals(delegateStmt,stmt.getDelegate());
     }
-
-    public void testHashCodeNull() {
-        stmt = new DelegatingPreparedStatement(conn, null);
-        assertEquals(0, stmt.hashCode());
-    }
-
-    public void testHashCode() throws Exception {
-        delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo");
-        DelegatingPreparedStatement stmt1 = new DelegatingPreparedStatement(conn,delegateStmt);
-        DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(conn,delegateStmt);
-        assertEquals(stmt1.hashCode(), stmt2.hashCode());
-        stmt1.close();
-        stmt2.close();
-    }
-
-    public void testEquals() {
-        delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo");
-        PreparedStatement del = new TesterPreparedStatement(delegateConn,"select * from foo");
-        DelegatingPreparedStatement stmt1 = new DelegatingPreparedStatement(conn, delegateStmt);
-        DelegatingPreparedStatement stmt2 = new DelegatingPreparedStatement(conn, delegateStmt);
-        DelegatingPreparedStatement stmt3 = new DelegatingPreparedStatement(conn, null);
-        DelegatingPreparedStatement stmt4 = new DelegatingPreparedStatement(conn, del);
-
-        // Nothing is equal to null
-        assertFalse(stmt1.equals(null));
-        assertFalse(stmt2.equals(null));
-        assertFalse(stmt3.equals(null));
-        assertFalse(stmt4.equals(null));
-
-        // 1 & 2 are equivalent
-        assertTrue(stmt1.equals(stmt2));
-        assertTrue(stmt2.equals(stmt1)); // reflexive
-
-        // 1 & 3 are not (different statements, one null)
-        assertFalse(stmt1.equals(stmt3));
-        assertFalse(stmt3.equals(stmt1)); // reflexive
-
-        // 1 & 4 are not (different statements)
-        assertFalse(stmt1.equals(stmt4));
-        assertFalse(stmt4.equals(stmt1)); // reflexive
-
-        // Check self-equals
-        assertTrue(stmt1.equals(stmt1));
-        assertTrue(stmt2.equals(stmt2));
-        assertTrue(stmt3.equals(stmt3));
-        assertTrue(stmt4.equals(stmt4));
-
-        DelegatingStatement dstmt1 = stmt1;
-
-        // 1 & 2 are equivalent
-        assertTrue(dstmt1.equals(stmt2));
-        assertTrue(stmt2.equals(dstmt1)); // reflexive
-
-        // innermost delegate itself - bugged behavior?
-        assertTrue(stmt1.equals(delegateStmt));
-
-    }
-
 }

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestDelegatingStatement.java Tue Feb  4 13:44:12 2014
@@ -61,44 +61,6 @@ public class TestDelegatingStatement ext
         assertEquals(delegateStmt,stmt.getDelegate());
     }
 
-    public void testHashCode() throws Exception {
-        delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo");
-        DelegatingStatement stmt1 = new DelegatingStatement(conn,delegateStmt);
-        DelegatingStatement stmt2 = new DelegatingStatement(conn,delegateStmt);
-        DelegatingStatement stmt3 = new DelegatingStatement(conn, null);
-        assertEquals(stmt1.hashCode(), stmt2.hashCode());
-        assertTrue(stmt1.hashCode() != stmt3.hashCode());
-        stmt1.close();
-        stmt2.close();
-        stmt3.close();
-    }
-
-    public void testEquals() {
-        delegateStmt = new TesterPreparedStatement(delegateConn,"select * from foo");
-        DelegatingStatement stmt1 = new DelegatingStatement(conn, delegateStmt);
-        DelegatingStatement stmt2 = new DelegatingStatement(conn, delegateStmt);
-        DelegatingStatement stmt3 = new DelegatingStatement(conn, null);
-        DelegatingStatement stmt4 = new DelegatingStatement(conn, stmt1);
-
-        // not null
-        assertTrue(!stmt1.equals(null));
-
-        // same innermost delegate
-        assertTrue(stmt1.equals(stmt2));
-        assertTrue(stmt1.equals(stmt4));
-
-        // innermost delegate itself - bugged behavior?
-        assertTrue(stmt1.equals(delegateStmt));
-
-        // not same delegate
-        assertTrue(!stmt1.equals(stmt3));
-
-        // reflexive
-        assertTrue(stmt1.equals(stmt1));
-        assertTrue(stmt2.equals(stmt2));
-        assertTrue(stmt3.equals(stmt3));
-    }
-
     public void testCheckOpen() throws Exception {
         stmt.checkOpen();
         stmt.close();
@@ -109,7 +71,7 @@ public class TestDelegatingStatement ext
             // expected
         }
     }
-    
+
     public void testIsWrapperFor() throws Exception {
         TesterConnection tstConn = new TesterConnection("test", "test");
         TesterStatement tstStmt = new TesterStatementNonWrapping(tstConn);
@@ -117,22 +79,22 @@ public class TestDelegatingStatement ext
         DelegatingStatement stamt = new DelegatingStatement(dconn, tstStmt);
 
         Class<?> stmtProxyClass = Proxy.getProxyClass(
-                this.getClass().getClassLoader(), 
+                this.getClass().getClassLoader(),
                 Statement.class);
-        
+
         assertTrue(stamt.isWrapperFor(DelegatingStatement.class));
         assertTrue(stamt.isWrapperFor(TesterStatement.class));
         assertFalse(stamt.isWrapperFor(stmtProxyClass));
-        
+
         stamt.close();
     }
-    
+
     private static class TesterStatementNonWrapping extends TesterStatement {
 
         public TesterStatementNonWrapping(Connection conn) {
             super(conn);
         }
-     
+
         @Override
         public boolean isWrapperFor(Class<?> iface) throws SQLException {
             return false;

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java Tue Feb  4 13:44:12 2014
@@ -24,6 +24,7 @@ import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.commons.pool2.impl.GenericObjectPool;
+import org.junit.Assert;
 
 /**
  * TestSuite for PoolingDataSource
@@ -85,10 +86,12 @@ public class TestPoolingDataSource exten
         ((DelegatingConnection<?>) c[0]).getDelegate().close();
 
         // Grab a new connection - should get c[0]'s closed connection
-        // so should be delegate-equivalent, so equal
+        // so should be delegate-equivalent
         Connection con = newConnection();
-        assertTrue(c[0].equals(con));
-        assertTrue(con.equals(c[0]));
+        Assert.assertNotEquals(c[0], con);
+        Assert.assertEquals(
+                ((DelegatingConnection<?>) c[0]).getInnermostDelegateInternal(),
+                ((DelegatingConnection<?>) con).getInnermostDelegateInternal());
         for (int i = 0; i < c.length; i++) {
             c[i].close();
         }
@@ -134,9 +137,9 @@ public class TestPoolingDataSource exten
         Connection inner = con.getInnermostDelegate();
         ds.setAccessToUnderlyingConnectionAllowed(false);
         DelegatingConnection<Connection> con2 = new DelegatingConnection<>(inner);
-        assertTrue(con2.equals(con));
+        assertFalse(con2.equals(con));
         assertTrue(con.innermostDelegateEquals(con2.getInnermostDelegate()));
         assertTrue(con2.innermostDelegateEquals(inner));
-        assertTrue(con.equals(con2));
+        assertFalse(con.equals(con2));
     }
 }

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/datasources/TestSharedPoolDataSource.java Tue Feb  4 13:44:12 2014
@@ -28,6 +28,7 @@ import javax.sql.DataSource;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.dbcp2.DelegatingStatement;
 import org.apache.commons.dbcp2.TestConnectionPool;
 import org.apache.commons.dbcp2.TesterDriver;
 import org.apache.commons.dbcp2.cpdsadapter.DriverAdapterCPDS;
@@ -511,7 +512,7 @@ public class TestSharedPoolDataSource ex
 
         stmt = callBack.getPreparedStatement();
         assertNotNull(stmt);
-        long l1HashCode = stmt.hashCode();
+        long l1HashCode = ((DelegatingStatement) stmt).getDelegate().hashCode();
         rset = stmt.executeQuery();
         assertNotNull(rset);
         assertTrue(rset.next());
@@ -520,7 +521,7 @@ public class TestSharedPoolDataSource ex
 
         stmt = callBack.getPreparedStatement();
         assertNotNull(stmt);
-        long l2HashCode = stmt.hashCode();
+        long l2HashCode = ((DelegatingStatement) stmt).getDelegate().hashCode();
         rset = stmt.executeQuery();
         assertNotNull(rset);
         assertTrue(rset.next());
@@ -537,7 +538,7 @@ public class TestSharedPoolDataSource ex
 
         stmt = callBack.getPreparedStatement();
         assertNotNull(stmt);
-        long l3HashCode = stmt.hashCode();
+        long l3HashCode = ((DelegatingStatement) stmt).getDelegate().hashCode();
         rset = stmt.executeQuery();
         assertNotNull(rset);
         assertTrue(rset.next());
@@ -546,7 +547,7 @@ public class TestSharedPoolDataSource ex
 
         stmt = callBack.getPreparedStatement();
         assertNotNull(stmt);
-        long l4HashCode = stmt.hashCode();
+        long l4HashCode = ((DelegatingStatement) stmt).getDelegate().hashCode();
         rset = stmt.executeQuery();
         assertNotNull(rset);
         assertTrue(rset.next());

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSource.java Tue Feb  4 13:44:12 2014
@@ -19,6 +19,7 @@ package org.apache.commons.dbcp2.managed
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+
 import org.apache.commons.dbcp2.ConnectionFactory;
 import org.apache.commons.dbcp2.DelegatingConnection;
 import org.apache.commons.dbcp2.DriverConnectionFactory;
@@ -29,8 +30,10 @@ import org.apache.commons.dbcp2.TestConn
 import org.apache.commons.dbcp2.TesterDriver;
 import org.apache.commons.pool2.impl.GenericObjectPool;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+import org.junit.Assert;
 
 import javax.transaction.TransactionManager;
+
 import java.sql.Connection;
 import java.util.Properties;
 
@@ -145,10 +148,12 @@ public class TestManagedDataSource exten
         // Disable access for the new connection
         ds.setAccessToUnderlyingConnectionAllowed(false);
         // Grab a new connection - should get c[0]'s closed connection
-        // so should be delegate-equivalent, so equal
+        // so should be delegate-equivalent
         Connection con = newConnection();
-        assertTrue(c[0].equals(con));
-        assertTrue(con.equals(c[0]));
+        Assert.assertNotEquals(c[0], con);
+        Assert.assertEquals(
+                ((DelegatingConnection<?>) c[0]).getInnermostDelegateInternal(),
+                ((DelegatingConnection<?>) con).getInnermostDelegateInternal());
         for (int i = 0; i < c.length; i++) {
             c[i].close();
         }
@@ -165,10 +170,12 @@ public class TestManagedDataSource exten
         ((DelegatingConnection<?>) c[0]).getDelegate().close();
 
         // Grab a new connection - should get c[0]'s closed connection
-        // so should be delegate-equivalent, so equal
+        // so should be delegate-equivalent
         Connection con = newConnection();
-        assertTrue(c[0].equals(con));
-        assertTrue(con.equals(c[0]));
+        Assert.assertNotEquals(c[0], con);
+        Assert.assertEquals(
+                ((DelegatingConnection<?>) c[0]).getInnermostDelegateInternal(),
+                ((DelegatingConnection<?>) con).getInnermostDelegateInternal());
         for (int i = 0; i < c.length; i++) {
             c[i].close();
         }
@@ -214,9 +221,9 @@ public class TestManagedDataSource exten
         Connection inner = con.getInnermostDelegate();
         ds.setAccessToUnderlyingConnectionAllowed(false);
         DelegatingConnection<Connection> con2 = new DelegatingConnection<>(inner);
-        assertTrue(con2.equals(con));
+        assertFalse(con2.equals(con));
         assertTrue(con.innermostDelegateEquals(con2.getInnermostDelegate()));
         assertTrue(con2.innermostDelegateEquals(inner));
-        assertTrue(con.equals(con2));
+        assertFalse(con.equals(con2));
     }
 }

Modified: commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java?rev=1564298&r1=1564297&r2=1564298&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java (original)
+++ commons/proper/dbcp/trunk/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java Tue Feb  4 13:44:12 2014
@@ -18,6 +18,7 @@
 package org.apache.commons.dbcp2.managed;
 
 import org.apache.commons.dbcp2.DelegatingConnection;
+import org.junit.Assert;
 
 import java.sql.CallableStatement;
 import java.sql.Connection;
@@ -79,9 +80,13 @@ public class TestManagedDataSourceInTx e
             conn[i] = newConnection();
             for(int j=0;j<i;j++) {
                 // two connections should be distinct instances
-                assertNotSame(conn[j], conn[i]);
-                // but they should be equivalent since they are sharing the same underlying connection
-                assertEquals(conn[j], conn[i]);
+                Assert.assertNotSame(conn[j], conn[i]);
+                // neither should they should be equivalent even though they are
+                // sharing the same underlying connection
+                Assert.assertNotEquals(conn[j], conn[i]);
+                // Check underlying connection is the same
+                Assert.assertEquals(((DelegatingConnection<?>) conn[j]).getInnermostDelegateInternal(),
+                        ((DelegatingConnection<?>) conn[i]).getInnermostDelegateInternal());
             }
         }
         for(int i=0;i<conn.length;i++) {
@@ -96,8 +101,8 @@ public class TestManagedDataSourceInTx e
         Connection conn2 = newConnection();
         assertNotNull(conn2);
 
-        // shared connections should have the same hashcode
-        assertEquals(conn1.hashCode(), conn2.hashCode());
+        // shared connections should not have the same hashcode
+        Assert.assertNotEquals(conn1.hashCode(), conn2.hashCode());
     }
 
     @Override
@@ -165,8 +170,8 @@ public class TestManagedDataSourceInTx e
         DelegatingConnection<?> connectionA = (DelegatingConnection<?>) newConnection();
         DelegatingConnection<?> connectionB = (DelegatingConnection<?>) newConnection();
 
-        assertTrue(connectionA.equals(connectionB));
-        assertTrue(connectionB.equals(connectionA));
+        assertFalse(connectionA.equals(connectionB));
+        assertFalse(connectionB.equals(connectionA));
         assertTrue(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
         assertTrue(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));
 
@@ -178,9 +183,9 @@ public class TestManagedDataSourceInTx e
         DelegatingConnection<?> connectionA = (DelegatingConnection<?>) newConnection();
         DelegatingConnection<?> connectionB = (DelegatingConnection<?>) newConnection();
 
-        // in a transaction the connections should be equal
-        assertTrue(connectionA.equals(connectionB));
-        assertTrue(connectionB.equals(connectionA));
+        // in a transaction the inner connections should be equal
+        assertFalse(connectionA.equals(connectionB));
+        assertFalse(connectionB.equals(connectionA));
         assertTrue(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
         assertTrue(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));
 
@@ -190,7 +195,7 @@ public class TestManagedDataSourceInTx e
         connectionA.getAutoCommit();
         connectionB.getAutoCommit();
 
-        // no there is no transaction so connections should not be equal
+        // no there is no transaction so inner connections should not be equal
         assertFalse(connectionA.equals(connectionB));
         assertFalse(connectionB.equals(connectionA));
         assertFalse(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
@@ -202,9 +207,9 @@ public class TestManagedDataSourceInTx e
         connectionA.getAutoCommit();
         connectionB.getAutoCommit();
 
-        // back in a transaction so should be equal again
-        assertTrue(connectionA.equals(connectionB));
-        assertTrue(connectionB.equals(connectionA));
+        // back in a transaction so inner connections should be equal again
+        assertFalse(connectionA.equals(connectionB));
+        assertFalse(connectionB.equals(connectionA));
         assertTrue(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
         assertTrue(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));
 
@@ -216,8 +221,8 @@ public class TestManagedDataSourceInTx e
         DelegatingConnection<?> connectionA = (DelegatingConnection<?>) newConnection();
         DelegatingConnection<?> connectionB = (DelegatingConnection<?>) newConnection();
 
-        assertTrue(connectionA.equals(connectionB));
-        assertTrue(connectionB.equals(connectionA));
+        assertFalse(connectionA.equals(connectionB));
+        assertFalse(connectionB.equals(connectionA));
         assertTrue(connectionA.innermostDelegateEquals(connectionB.getInnermostDelegate()));
         assertTrue(connectionB.innermostDelegateEquals(connectionA.getInnermostDelegate()));