db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1310413 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
Date Fri, 06 Apr 2012 15:51:30 GMT
Author: kahatlen
Date: Fri Apr  6 15:51:29 2012
New Revision: 1310413

URL: http://svn.apache.org/viewvc?rev=1310413&view=rev
Log:
DERBY-5683: BaseJDBCTestCase.getDatabaseProperty() should close resources before returning

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1310413&r1=1310412&r2=1310413&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri
Apr  6 15:51:29 2012
@@ -155,6 +155,22 @@ public abstract class BaseJDBCTestCase
     }
 
     /**
+     * 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
+     * statements that are only used for a short time, as the memory footprint
+     * may become big if all the statements are held until tearDown().
+     *
+     * @param s the statement to close and forget
+     * @throws SQLException if closing the statement fails
+     */
+    public void closeStatement(Statement s) throws SQLException {
+        s.close();
+        if (statements != null) {
+            statements.remove(s);
+        }
+    }
+
+    /**
      * Utility method to create a Statement using the connection
      * returned by getConnection.
      * The returned statement object will be closed automatically
@@ -639,8 +655,13 @@ public abstract class BaseJDBCTestCase
         ResultSet rs = ps.executeQuery();
         
         rs.next();
-        
-        return rs.getString(1);
+
+        String val = rs.getString(1);
+
+        rs.close();
+        closeStatement(ps);
+
+        return val;
     }
 
     /**



Mime
View raw message