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 dj...@apache.org on 2008/01/30 23:24:14 UTC

svn commit: r616924 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: functionTests/tests/jdbcapi/ functionTests/tests/lang/ junit/

Author: djd
Date: Wed Jan 30 14:24:12 2008
New Revision: 616924

URL: http://svn.apache.org/viewvc?rev=616924&view=rev
Log:
Complete the set of utility methods that return JDBC statements in BaseJDBCTestCase.
Ensure all the statement utility methods close the statement at teardown time.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java?rev=616924&r1=616923&r2=616924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBTest.java Wed Jan 30 14:24:12 2008
@@ -331,7 +331,7 @@
                                                     final int newSize) 
         throws SQLException, IOException
     {
-        final PreparedStatement preparedStatement = getConnection().prepareStatement
+        final PreparedStatement preparedStatement = prepareStatement
             ("UPDATE " + BLOBDataModelSetup.getBlobTableName() +
              " SET val=?, length = ?, data = ? WHERE CURRENT OF " +
              rs.getCursorName());

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java?rev=616924&r1=616923&r2=616924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/CallableTest.java Wed Jan 30 14:24:12 2008
@@ -301,7 +301,7 @@
      */
     public void norun_testSystemOutPrintlnProc() throws SQLException
     {
-        CallableStatement cs = getConnection().prepareCall
+        CallableStatement cs = prepareCall
             ("call SYSTEM_OUT_PRINTLN_PROC()");
         cs.execute();
         cs.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java?rev=616924&r1=616923&r2=616924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/Bug5052rtsTest.java Wed Jan 30 14:24:12 2008
@@ -94,7 +94,7 @@
         }
 
         // set the runtime statistics on now.
-        cs = getConnection().prepareCall(
+        cs = prepareCall(
                 "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
         cs.setInt(1, 1);
         cs.execute();
@@ -102,7 +102,7 @@
 
         rs.close();
 
-        cs = getConnection().prepareCall(
+        cs = prepareCall(
                 "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
         cs.setInt(1, 0);
         cs.execute();
@@ -115,7 +115,7 @@
             // System.out.println(rs.getString(1));
         }
         // set the runtime statistics on now.
-        cs = getConnection().prepareCall(
+        cs = prepareCall(
                 "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(?)");
         cs.setInt(1, 1);
         cs.execute();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java?rev=616924&r1=616923&r2=616924&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/UpdatableResultSetTest.java Wed Jan 30 14:24:12 2008
@@ -1127,7 +1127,7 @@
      */
     public void testDeleteRowWithPreparedStatement() throws SQLException {
         createTableT1();
-        PreparedStatement pStmt = getConnection().prepareStatement(
+        PreparedStatement pStmt = prepareStatement(
                 "select * from t1 where c1 > ?",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         assertEquals("FAIL - wrong result set type",
@@ -1185,7 +1185,7 @@
      */
     public void testUpdateXXXWithPreparedStatement() throws SQLException {
         createTableT1();
-        PreparedStatement pStmt = getConnection().prepareStatement(
+        PreparedStatement pStmt = prepareStatement(
                 "select * from t1 where c1>? for update",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         assertEquals("FAIL - wrong result set type",
@@ -1265,7 +1265,7 @@
             throws SQLException 
     {
         createTableT1();
-        CallableStatement callStmt = getConnection().prepareCall(
+        CallableStatement callStmt = prepareCall(
                 "select * from t1",
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = callStmt.executeQuery();
@@ -2480,7 +2480,7 @@
     {
         createAllDatatypesTable();
         commit();
-        PreparedStatement pstmt = getConnection().prepareStatement(
+        PreparedStatement pstmt = prepareStatement(
                 "SELECT * FROM AllDataTypesForTestingTable FOR UPDATE", 
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         PreparedStatement pstmt1 = prepareStatement(
@@ -2765,7 +2765,7 @@
     {
         createAllDatatypesTable();
         commit();
-        PreparedStatement pstmt = getConnection().prepareStatement(
+        PreparedStatement pstmt = prepareStatement(
                 "SELECT * FROM AllDataTypesForTestingTable FOR UPDATE", 
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         PreparedStatement pstmt1 = prepareStatement(
@@ -4019,7 +4019,7 @@
         Statement stmt = createStatement();
         stmt.executeUpdate("DELETE FROM AllDataTypesForTestingTable");
         
-        PreparedStatement pstmti = getConnection().prepareStatement(
+        PreparedStatement pstmti = prepareStatement(
                 "SELECT * FROM AllDataTypesForTestingTable FOR UPDATE", 
                 ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         PreparedStatement pstmt1i = prepareStatement(

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=616924&r1=616923&r2=616924&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 Wed Jan 30 14:24:12 2008
@@ -192,7 +192,43 @@
         PreparedStatement ps = getConnection().prepareStatement(sql);
         addStatement(ps);
         return ps;
-    }    
+    }
+    
+    /**
+     * Utility method to create a PreparedStatement using the connection
+     * returned by getConnection with result set type and concurrency.
+     * The returned statement object will be closed automatically
+     * at tearDown() but may be closed earlier by the test if required.
+     * @return Statement object from
+     * getConnection.prepareStatement(sql)
+     * @throws SQLException
+     */
+    public PreparedStatement prepareStatement(String sql,
+            int resultSetType, int resultSetConcurrency) throws SQLException
+    {
+        PreparedStatement ps = getConnection().prepareStatement(sql,
+                resultSetType, resultSetConcurrency);
+        addStatement(ps);
+        return ps;
+    }
+    /**
+     * Utility method to create a PreparedStatement using the connection
+     * returned by getConnection with result set type and concurrency.
+     * The returned statement object will be closed automatically
+     * at tearDown() but may be closed earlier by the test if required.
+     * @return Statement object from
+     * getConnection.prepareStatement(sql)
+     * @throws SQLException
+     */
+    public PreparedStatement prepareStatement(String sql,
+            int resultSetType, int resultSetConcurrency,
+            int resultSetHoldability) throws SQLException
+    {
+        PreparedStatement ps = getConnection().prepareStatement(sql,
+                resultSetType, resultSetConcurrency, resultSetHoldability);
+        addStatement(ps);
+        return ps;
+    }
     /**
      * Utility method to create a PreparedStatement using the connection
      * returned by getConnection and a flag that signals the driver whether
@@ -279,6 +315,8 @@
     /**
      * Utility method to create a CallableStatement using the connection
      * returned by getConnection.
+     * The returned statement object will be closed automatically
+     * at tearDown() but may be closed earlier by the test if required.
      * @return Statement object from
      * getConnection().prepareCall(sql, resultSetType, resultSetConcurrency)
      * @throws SQLException
@@ -287,12 +325,17 @@
 					int resultSetType, 
 					int resultSetConcurrency) throws SQLException
     {
-        return getConnection().prepareCall(sql, resultSetType, resultSetConcurrency);
+        CallableStatement cs = getConnection().prepareCall(sql, resultSetType,
+                resultSetConcurrency);
+        addStatement(cs);
+        return cs;
     }
 
     /**
      * Utility method to create a CallableStatement using the connection
      * returned by getConnection.
+     * The returned statement object will be closed automatically
+     * at tearDown() but may be closed earlier by the test if required.
      * @return Statement object from
      * getConnection().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability)
      * @throws SQLException
@@ -302,7 +345,10 @@
                                         int resultSetConcurrency,
 					 int resultSetHoldability) throws SQLException
     {
-        return getConnection().prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+        CallableStatement cs = getConnection().prepareCall(sql,
+                resultSetType, resultSetConcurrency, resultSetHoldability);
+        addStatement(cs);
+        return cs;
     }
     
     /**