You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2013/04/05 14:31:36 UTC
svn commit: r1464951 - in /db/derby/code/branches/10.8: ./
java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Author: kmarsden
Date: Fri Apr 5 12:31:35 2013
New Revision: 1464951
URL: http://svn.apache.org/r1464951
Log:
DERBY-6150 Add automatic cleanup of connections opened with openDefaultConnection()
Modified:
db/derby/code/branches/10.8/ (props changed)
db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Propchange: db/derby/code/branches/10.8/
------------------------------------------------------------------------------
Merged /db/derby/code/branches/10.9:r1373148
Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1464951&r1=1464950&r2=1464951&view=diff
==============================================================================
--- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri Apr 5 12:31:35 2013
@@ -73,6 +73,8 @@ public abstract class BaseJDBCTestCase
*/
private List statements;
+ private List connections;
+
/**
* Create a test case with the given name.
*
@@ -156,6 +158,18 @@ public abstract class BaseJDBCTestCase
}
/**
+ * 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);
+
+ }
+
+ /**
* Utility method to create a Statement using the connection
* returned by getConnection.
* The returned statement object will be closed automatically
@@ -404,8 +418,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;
}
@@ -426,6 +447,7 @@ public abstract class BaseJDBCTestCase
public Connection openDefaultConnection()
throws SQLException {
Connection conn = getTestConfiguration().openDefaultConnection();
+ addConnection(conn);
initializeConnection(conn);
return conn;
}
@@ -448,6 +470,7 @@ public abstract class BaseJDBCTestCase
public Connection openDefaultConnection(TestConfiguration tc)
throws SQLException {
Connection conn = tc.openDefaultConnection();
+ addConnection(conn);
initializeConnection(conn);
return conn;
}
@@ -471,6 +494,7 @@ public abstract class BaseJDBCTestCase
{
Connection conn = getTestConfiguration().openDefaultConnection(user,
password);
+ addConnection(conn);
initializeConnection(conn);
return conn;
}
@@ -524,6 +548,7 @@ public abstract class BaseJDBCTestCase
public Connection openConnection(String databaseName)
throws SQLException {
Connection conn = getTestConfiguration().openConnection(databaseName);
+ addConnection(conn);
initializeConnection(conn);
return conn;
}