commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject svn commit: r153465 - in jakarta/commons/proper/dbcp/trunk/src: java/org/apache/commons/dbcp/PoolingDriver.java test/org/apache/commons/dbcp/TestManual.java
Date Fri, 11 Feb 2005 22:16:48 GMT
Author: dirkv
Date: Fri Feb 11 14:16:47 2005
New Revision: 153465

URL: http://svn.apache.org/viewcvs?view=rev&rev=153465
Log:
Bugzilla 33528 [dbcp] add DriverManager.invalidateConnection

Modified:
    jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
    jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestManual.java

Modified: jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java?view=diff&r1=153464&r2=153465
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
(original)
+++ jakarta/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/PoolingDriver.java
Fri Feb 11 14:16:47 2005
@@ -46,7 +46,7 @@
  *
  * @author Rodney Waldhoff
  * @author Dirk Verbeeck
- * @version $Revision: 1.12 $ $Date: 2004/05/17 18:39:44 $
+ * @version $Revision: 1.12 $ $Date$
  */
 public class PoolingDriver implements Driver {
     /** Register an myself with the {@link DriverManager}. */
@@ -174,7 +174,7 @@
                 try {
                     Connection conn = (Connection)(pool.borrowObject());
                     if (conn != null) {
-                        conn = new PoolGuardConnectionWrapper(conn);
+                        conn = new PoolGuardConnectionWrapper(pool, conn);
                     } 
                     return conn;
                 } catch(SQLException e) {
@@ -192,6 +192,23 @@
         }
     }
 
+    public void invalidateConnection(Connection conn) throws SQLException {
+        if (conn instanceof PoolGuardConnectionWrapper) { // normal case
+            PoolGuardConnectionWrapper pgconn = (PoolGuardConnectionWrapper) conn;
+            ObjectPool pool = pgconn.pool;
+            Connection delegate = pgconn.delegate;
+            try {
+                pool.invalidateObject(delegate);
+            } 
+            catch (Exception e) { 
+            }
+            pgconn.delegate = null;
+        }
+        else {
+            throw new SQLException("Invalid connection class");
+        }
+    }
+
     public int getMajorVersion() {
         return MAJOR_VERSION;
     }
@@ -222,10 +239,12 @@
      */
     private class PoolGuardConnectionWrapper extends DelegatingConnection {
 
+        private ObjectPool pool;
         private Connection delegate;
     
-        PoolGuardConnectionWrapper(Connection delegate) {
+        PoolGuardConnectionWrapper(ObjectPool pool, Connection delegate) {
             super(delegate);
+            this.pool = pool;
             this.delegate = delegate;
         }
 

Modified: jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestManual.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestManual.java?view=diff&r1=153464&r2=153465
==============================================================================
--- jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestManual.java (original)
+++ jakarta/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestManual.java Fri
Feb 11 14:16:47 2005
@@ -35,7 +35,7 @@
  * based {@link PoolingDriver}.
  * @author Rodney Waldhoff
  * @author Sean C. Sullivan
- * @version $Revision: 1.21 $ $Date: 2004/07/11 19:09:50 $
+ * @version $Revision: 1.21 $ $Date$
  */
 public class TestManual extends TestConnectionPool {
     public TestManual(String testName) {
@@ -155,6 +155,22 @@
         }
     }
     
+    public void testInvalidateConnection() throws Exception {
+        Connection conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:test");
+        assertNotNull(conn);
+
+        ObjectPool pool = driver.getConnectionPool("test");
+        assertEquals(1, pool.getNumActive());
+        assertEquals(0, pool.getNumIdle());
+
+        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
+        driver.invalidateConnection(conn);
+
+        assertEquals(0, pool.getNumActive());
+        assertEquals(0, pool.getNumIdle());
+        assertTrue(conn.isClosed());
+    }
+
     public void testLogWriter() throws Exception {
         PrintStream ps = System.out;
         PrintWriter pw = new PrintWriter(System.err);



---------------------------------------------------------------------
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