commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r469008 - in /jakarta/commons/proper/dbcp/trunk/src: java/org/apache/commons/dbcp/ test/org/apache/commons/dbcp/
Date Sun, 29 Oct 2006 21:48:02 GMT
Author: psteitz
Date: Sun Oct 29 13:48:02 2006
New Revision: 469008

URL: http://svn.apache.org/viewvc?view=rev&rev=469008
Log:
Added tests and fixed errors remaining in DelegatingConnection,
PoolGuardConnectionWrapper equals implementations.
JIRA:  DBCP-198

Modified:
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDataSource.java
    jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
    jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolingDataSource.java

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java?view=diff&rev=469008&r1=469007&r2=469008
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/DelegatingConnection.java
Sun Oct 29 13:48:02 2006
@@ -120,15 +120,30 @@
     public Connection getDelegate() {
         return _conn;
     }
+    
+    public boolean innermostDelegateEquals(Connection c) {
+        Connection innerCon = getInnermostDelegate();
+        if (innerCon == null) {
+            return c == null;
+        } else {
+            return innerCon.equals(c);
+        }
+    }
 
     public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
         Connection delegate = getInnermostDelegate();
         if (delegate == null) {
             return false;
         }
-        if (obj instanceof DelegatingConnection) {
+        if (obj instanceof DelegatingConnection) {    
             DelegatingConnection c = (DelegatingConnection) obj;
-            return delegate.equals(c.getInnermostDelegate());
+            return c.innermostDelegateEquals(delegate);
         }
         else {
             return delegate.equals(obj);

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDataSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDataSource.java?view=diff&rev=469008&r1=469007&r2=469008
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDataSource.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDataSource.java
Sun Oct 29 13:48:02 2006
@@ -209,25 +209,15 @@
             return delegate.createStatement(resultSetType, resultSetConcurrency);
         }
 
-        
-        public boolean equals(Object obj) {
-            if (obj == null) {
-                return false;
-            }
-            if (obj == this) {
-                return true;
-            }
-            if (delegate == null) {
-                return false;
-            }
-            if (obj instanceof PoolGuardConnectionWrapper) {
-                PoolGuardConnectionWrapper w = (PoolGuardConnectionWrapper) obj;
-                return delegate.equals(w.delegate);
+        public boolean innermostDelegateEquals(Connection c) {
+            Connection innerCon = super.getInnermostDelegate();
+            if (innerCon == null) {
+                return c == null;
             } else {
-                return delegate.equals(obj);
+                return innerCon.equals(c);
             }
         }
-
+        
         public boolean getAutoCommit() throws SQLException {
             checkOpen();
             return delegate.getAutoCommit();
@@ -263,6 +253,27 @@
                 return 0;
             }
             return delegate.hashCode();
+        }
+        
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            }
+            if (obj == this) {
+                return true;
+            }
+            // Use superclass accessor to skip access test
+            Connection delegate = super.getInnermostDelegate();
+            if (delegate == null) {
+                return false;
+            }
+            if (obj instanceof DelegatingConnection) {    
+                DelegatingConnection c = (DelegatingConnection) obj;
+                return c.innermostDelegateEquals(delegate);
+            }
+            else {
+                return delegate.equals(obj);
+            }
         }
 
         public boolean isReadOnly() throws SQLException {

Modified: jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java?view=diff&rev=469008&r1=469007&r2=469008
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestDelegatingConnection.java
Sun Oct 29 13:48:02 2006
@@ -77,6 +77,7 @@
         assertTrue(!conn.equals(null));
         assertTrue(conn.equals(conn2));
         assertTrue(!conn.equals(conn3));
+        assertTrue(conn.equals(conn));
     }
     
     public void testCheckOpen() throws Exception {

Modified: jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolingDataSource.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolingDataSource.java?view=diff&rev=469008&r1=469007&r2=469008
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolingDataSource.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolingDataSource.java
Sun Oct 29 13:48:02 2006
@@ -143,6 +143,18 @@
         con1.close();
     }
     
+    public void testestPoolGuardConnectionWrapperEqualInnermost() throws Exception {
+        ds.setAccessToUnderlyingConnectionAllowed(true);
+        DelegatingConnection con = (DelegatingConnection) ds.getConnection();
+        Connection inner = con.getInnermostDelegate();
+        ds.setAccessToUnderlyingConnectionAllowed(false);
+        DelegatingConnection con2 = new DelegatingConnection(inner);
+        assertTrue(con2.equals(con));
+        assertTrue(con.innermostDelegateEquals(con2.getInnermostDelegate()));
+        assertTrue(con2.innermostDelegateEquals(inner));
+        assertTrue(con.equals(con2));
+    }
+    
     /** Factory to return non-delegating connections for DBCP-198 test */
     private class NonDelegatingPoolableConnectionFactory extends
         PoolableConnectionFactory {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message