commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1097625 - in /commons/proper/dbcp/trunk/src: changes/ java/org/apache/commons/dbcp/ test/org/apache/commons/dbcp/
Date Thu, 28 Apr 2011 21:46:48 GMT
Author: psteitz
Date: Thu Apr 28 21:46:47 2011
New Revision: 1097625

URL: http://svn.apache.org/viewvc?rev=1097625&view=rev
Log:
Made equals reflexive in DelegatingStatement (and subclasses), DelegatingMetaData,
DelegatingResultSet and PoolingDriver#PoolGuardConnectionWrapper.
JIRA: DBCP-337
Reported and patched by Rob Gansevles

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingStatement.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingCallableStatement.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingDatabaseMetaData.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingPreparedStatement.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingStatement.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=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Thu Apr 28 21:46:47 2011
@@ -41,6 +41,10 @@ The <action> type attribute can be add,u
     <release version="2.0" date="TBD" description="TBD">
     </release>
     <release version="1.4.1" date="TBD" description="TBD">
+      <action dev="psteitz" issue="DBCP-337" type="fix" due-to="Rob Gansevles">
+        Made equals reflexive in DelegatingStatement (and subclasses), DelegatingMetaData,
+        DelegatingResultSet and PoolingDriver#PoolGuardConnectionWrapper.
+      </action>
       <action dev="psteitz" issue="DBCP-342" type="fix" due-to="Byungchol Kim">
         Modified createDataSource method in BasicDataSource to ensure that GenericObjectPool
         Evictor tasks are not started and orphaned when BasicDataSource encounters errors
on

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingCallableStatement.java
Thu Apr 28 21:46:47 2011
@@ -72,6 +72,7 @@ public class DelegatingCallableStatement
     }
 
     public boolean equals(Object obj) {
+    	if (this == obj) return true;
         CallableStatement delegate = (CallableStatement) getInnermostDelegate();
         if (delegate == null) {
             return false;

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingDatabaseMetaData.java
Thu Apr 28 21:46:47 2011
@@ -53,6 +53,7 @@ public class DelegatingDatabaseMetaData 
     }
 
     public boolean equals(Object obj) {
+    	if (this == obj) return true;
         DatabaseMetaData delegate = getInnermostDelegate();
         if (delegate == null) {
             return false;

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingPreparedStatement.java
Thu Apr 28 21:46:47 2011
@@ -71,6 +71,7 @@ public class DelegatingPreparedStatement
     }
 
     public boolean equals(Object obj) {
+    	if (this == obj) return true;
         PreparedStatement delegate = (PreparedStatement) getInnermostDelegate();
         if (delegate == null) {
             return false;

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingResultSet.java Thu
Apr 28 21:46:47 2011
@@ -118,6 +118,7 @@ public class DelegatingResultSet extends
     }
 
     public boolean equals(Object obj) {
+    	if (this == obj) return true;
         ResultSet delegate = getInnermostDelegate();
         if (delegate == null) {
             return false;

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingStatement.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingStatement.java Thu
Apr 28 21:46:47 2011
@@ -73,10 +73,17 @@ public class DelegatingStatement extends
     }
 
     /**
-     * This method considers two objects to be equal 
-     * if the underlying jdbc objects are equal.
+     * <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>
+     * 
      */
     public boolean equals(Object obj) {
+    	if (obj == this) return true;
         Statement delegate = getInnermostDelegate();
         if (delegate == null) {
             return false;

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java Thu Apr
28 21:46:47 2011
@@ -304,6 +304,7 @@ public class PoolingDriver implements Dr
         }
 
         public boolean equals(Object obj) {
+            if (this == obj) return true;
             if (delegate == null){
                 return false;
             }

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingCallableStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingCallableStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingCallableStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingCallableStatement.java
Thu Apr 28 21:46:47 2011
@@ -105,7 +105,7 @@ public class TestDelegatingCallableState
         // Check self-equals
         assertTrue(stmt1.equals(stmt1));
         assertTrue(stmt2.equals(stmt2));
-        assertFalse(stmt3.equals(stmt3)); // because underlying statement is null
+        assertTrue(stmt3.equals(stmt3)); 
         assertTrue(stmt4.equals(stmt4));
         
         DelegatingStatement dstmt1 = stmt1;
@@ -113,6 +113,9 @@ public class TestDelegatingCallableState
         // 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/org/apache/commons/dbcp/TestDelegatingConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
Thu Apr 28 21:46:47 2011
@@ -78,6 +78,9 @@ public class TestDelegatingConnection ex
         assertTrue(conn.equals(conn2));
         assertTrue(!conn.equals(conn3));
         assertTrue(conn.equals(conn));
+        assertTrue(conn3.equals(conn3));
+        assertTrue(conn.equals(conn));
+        assertTrue(conn2.equals(conn2));
     }
     
     public void testCheckOpen() throws Exception {

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingDatabaseMetaData.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingDatabaseMetaData.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingDatabaseMetaData.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingDatabaseMetaData.java
Thu Apr 28 21:46:47 2011
@@ -83,6 +83,9 @@ public class TestDelegatingDatabaseMetaD
         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 */

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingPreparedStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingPreparedStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingPreparedStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingPreparedStatement.java
Thu Apr 28 21:46:47 2011
@@ -107,7 +107,7 @@ public class TestDelegatingPreparedState
         // Check self-equals
         assertTrue(stmt1.equals(stmt1));
         assertTrue(stmt2.equals(stmt2));
-        assertFalse(stmt3.equals(stmt3)); // because underlying statement is null
+        assertTrue(stmt3.equals(stmt3)); 
         assertTrue(stmt4.equals(stmt4));
         
         DelegatingStatement dstmt1 = stmt1;
@@ -115,6 +115,9 @@ public class TestDelegatingPreparedState
         // 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/org/apache/commons/dbcp/TestDelegatingStatement.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java?rev=1097625&r1=1097624&r2=1097625&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingStatement.java
Thu Apr 28 21:46:47 2011
@@ -63,7 +63,9 @@ public class TestDelegatingStatement ext
         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());
     }
     
     public void testEquals() {
@@ -71,10 +73,25 @@ public class TestDelegatingStatement ext
         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 {



Mime
View raw message