db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1465267 - in /db/derby/code/branches/10.10: ./ java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Date Sat, 06 Apr 2013 16:01:40 GMT
Author: kmarsden
Date: Sat Apr  6 16:01:39 2013
New Revision: 1465267

URL: http://svn.apache.org/r1465267
Log:
DERBY-6150 Add automatic clean up of connections opened with openDefaultConnection()


Modified:
    db/derby/code/branches/10.10/   (props changed)
    db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
  Reverse-merged /db/derby/code/trunk:r1063809
  Merged /db/derby/code/branches/10.9:r1373148
  Merged /db/derby/code/trunk:r1465187
  Merged /db/derby/code/branches/10.8:r1464951

Modified: db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1465267&r1=1465266&r2=1465267&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
(original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Sat Apr  6 16:01:39 2013
@@ -72,6 +72,13 @@ public abstract class BaseJDBCTestCase
      * them at teardown.
      */
     private List statements;
+
+    /**
+     * Maintain a list of connection objects that
+     * were returned by utility methods and close
+     * them at teardown.
+     */
+    private List connections;
     
     /**
      * Create a test case with the given name.
@@ -154,7 +161,18 @@ public abstract class BaseJDBCTestCase
             statements = new ArrayList();
         statements.add(s);
     }
-
+    
+    /**
+     * Add connection to the list. We will close at tearDown
+     * @param c
+     */
+    private void addConnection(Connection c)
+    {
+        if (connections == null)
+            connections = new ArrayList();
+        connections.add(c);     
+    }
+    
     /**
      * Close a statement and remove it from the list of statements to close
      * at tearDown(). Useful for test cases that create a large number of
@@ -464,8 +482,15 @@ public abstract class BaseJDBCTestCase
             // Allow gc'ing of all those statements.
             statements = null;
         }
-        
-        JDBC.cleanup(conn);
+        if (connections != null) {
+            for (Iterator i = connections.iterator(); i.hasNext(); )
+            {
+                Connection c = (Connection) i.next();
+                JDBC.cleanup(c);
+            }
+            // Allow gc'ing of all those connections.
+            connections = null;
+        }
         conn = null;
     }
 
@@ -486,6 +511,7 @@ public abstract class BaseJDBCTestCase
     public Connection openDefaultConnection()
         throws SQLException {
         Connection conn =  getTestConfiguration().openDefaultConnection();
+        addConnection(conn);
         initializeConnection(conn);
         return conn;
     }
@@ -508,6 +534,7 @@ public abstract class BaseJDBCTestCase
     public Connection openDefaultConnection(TestConfiguration tc)
         throws SQLException {
         Connection conn =  tc.openDefaultConnection();
+        addConnection(conn);
         initializeConnection(conn);
         return conn;
     }
@@ -531,6 +558,7 @@ public abstract class BaseJDBCTestCase
     {
         Connection conn =  getTestConfiguration().openDefaultConnection(user,
                 password);
+        addConnection(conn);
         initializeConnection(conn);
         return conn;        
     }
@@ -584,6 +612,7 @@ public abstract class BaseJDBCTestCase
     public Connection openConnection(String databaseName)
         throws SQLException {
         Connection conn =  getTestConfiguration().openConnection(databaseName);
+        addConnection(conn);
         initializeConnection(conn);
         return conn;
     }



Mime
View raw message