db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r432679 [2/3] - in /db/derby/code/branches/10.2: ./ java/client/org/apache/derby/client/am/ java/drda/org/apache/derby/impl/drda/ java/engine/org/apache/derby/impl/sql/compile/ java/testing/ java/testing/org/apache/derbyTesting/functionTest...
Date Fri, 18 Aug 2006 18:54:32 GMT
Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java Fri Aug 18 11:54:23 2006
@@ -21,7 +21,7 @@
 import junit.framework.*;
 import java.sql.*;
 
-import org.apache.derbyTesting.functionTests.util.JDBC;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Testing concurrency behaviour in derby when creating the resultsets with
@@ -41,30 +41,24 @@
     public void setUp() 
         throws Exception 
     {      
-        try {
-            super.setUp();
-        } catch (SQLException e) {
-            if (con!=null) tearDown();
-            throw e;
-        }
         // For the concurrency tests, we recreate the model
         // for each testcase (since we do commits)
         SURDataModelSetup.createDataModel
-            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, con);
-        con.commit();
+            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, getXConnection());
+        commit();
     }
     
-    public void tearDown() 
+    public void tearDown() throws Exception 
     {
         try {
-            con.rollback();
-            Statement dropStatement = con.createStatement();
+            rollback();
+            Statement dropStatement = createStatement();
             dropStatement.execute("drop table t1");
-            con.commit();
-            con.close();
+            dropStatement.close();
         } catch (SQLException e) {
             printStackTrace(e); // Want to propagate the real exception.
         }
+        super.tearDown();
     }
     
     /**
@@ -75,7 +69,7 @@
     public void testUpdateLockDownGrade1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1 for update");
         
@@ -99,6 +93,11 @@
             con2.rollback();
         }
         assertTrue("Expected Derby to hold updatelocks in RR mode", false);
+        
+        s2.close();
+        con2.close();
+        
+        s.close();
     }
     
     /**
@@ -108,7 +107,7 @@
     public void testAquireUpdateLock1()
         throws SQLException 
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery("select * from t1");
         
         // After navigating through the resultset, 
@@ -126,6 +125,10 @@
         } finally {
             con2.rollback();
         }
+        
+        s2.close();
+        con2.close();
+        s.close();
     }
     
     /*
@@ -135,7 +138,7 @@
     public void testSharedLocks1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_READ_ONLY);
         final ResultSet rs = s.executeQuery("select * from t1");
         scrollForward(rs);
@@ -150,6 +153,8 @@
             con2.rollback();
             con2.close();
         }
+        
+        s.close();
     }
     
     /*
@@ -159,7 +164,7 @@
     public void testSharedLocks2()
         throws SQLException 
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery("select * from t1");
         scrollForward(rs);
         Connection con2 = getNewConnection();
@@ -172,6 +177,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /*
@@ -180,7 +186,7 @@
      **/
     public void testSharedAndUpdateLocks1()
         throws SQLException {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         
         ResultSet rs = s.executeQuery("select * from t1");
@@ -196,6 +202,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /*
@@ -206,7 +213,7 @@
     public void testSharedAndUpdateLocks2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1 for update");
         scrollForward(rs);
@@ -221,6 +228,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /**
@@ -232,8 +240,8 @@
     public void testUpdatePurgedTuple1()
         throws SQLException
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -294,7 +302,7 @@
         println("T1: updateInt(2, 3);");
         rs.updateRow();
         println("T1: updateRow()");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         println("T3: select * from table");
@@ -304,6 +312,9 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
+        s.close();
     }
     
     /**
@@ -313,8 +324,8 @@
     public void testUpdatePurgedTuple2()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -346,14 +357,14 @@
                 rs.getInt(2) + "," +
                 rs.getInt(3) + ")");
         
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("update T1 set a=? where current of " + rs.getCursorName());
         ps.setInt(1, 3);
         int updateCount = ps.executeUpdate();
         println("T1: update table, set a=3 where current of " + 
                 rs.getCursorName());
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T3: Tuple:(" + rs.getInt(1) + "," +
@@ -361,6 +372,8 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
     }
     
     /**
@@ -370,8 +383,8 @@
     public void testUpdatePurgedTuple3()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -426,7 +439,7 @@
         rs.updateRow();
         println("T1: updated column 2, to value=3");
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T5: Read Tuple:(" + rs.getInt(1) + "," +
@@ -434,6 +447,8 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
     }
     
     /**
@@ -443,8 +458,8 @@
     public void testUpdatePurgedTuple4()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -511,7 +526,7 @@
         rs.updateRow();
         println("T1: updated column 2, to value=3");
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T4: Read next Tuple:(" + rs.getInt(1) + "," +
@@ -528,8 +543,8 @@
     public void testUpdateModifiedTuple1()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -564,7 +579,7 @@
         rs.updateInt(2, 3);
         rs.updateRow();
         println("T1: updated column 2, to value=3");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
@@ -582,8 +597,8 @@
     public void testUpdateModifiedTuple2()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -618,7 +633,7 @@
         rs.updateInt(3, 9999);
         rs.updateRow();
         println("T1: updated column 3, to value=9999");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
@@ -637,8 +652,8 @@
     public void testTableIntentLock1()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         println("T1: select * from t1");
         ResultSet rs = s.executeQuery("select * from t1 for update");
@@ -678,8 +693,8 @@
     public void testUpdateLockInReadUncommitted()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -701,7 +716,9 @@
                          e.getSQLState());
         } finally {
             con2.rollback();
-        }          
+        }
+        con2.close();
+        s.close();
     }
     
     /**
@@ -731,8 +748,8 @@
                                         boolean testTruncate)
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement delStatement = con.createStatement();
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement delStatement = createStatement();
         // First delete all records except the last and first
         int deleted = delStatement.executeUpdate
             ("delete from T1 where id>0 and id<" + (recordCount-1));
@@ -740,10 +757,10 @@
         println("T1: delete records");
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         println("T1: commit");
         
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -798,7 +815,7 @@
         println("T1: updateInt(2, 3);");
         rs.updateRow();
         println("T1: updateRow()");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         println("T4: select * from table");

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourcePropertiesTest.java Fri Aug 18 11:54:23 2006
@@ -29,9 +29,10 @@
 import javax.sql.XADataSource;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
 import org.apache.derbyTesting.functionTests.util.TestDataSourceFactory;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * This class tests that properties of data sources are handled correctly.
@@ -50,20 +51,34 @@
 
     /** Creates a test suite with all test cases. */
     public static Test suite() {
+        
+        
         TestSuite suite = new TestSuite();
-        Method[] methods = DataSourcePropertiesTest.class.getMethods();
-        // Add all methods starting with 'test'.
-        // When using embedded, add all methods starting with 'embedded'.
-        for (int i = 0; i < methods.length; i++) {
-            Method m = methods[i];
-            if (m.getParameterTypes().length > 0 ||
-                    m.getReturnType() != Void.TYPE) {
-                continue;
-            }
-            String name = m.getName();
-            if (name.startsWith("test") ||
-                    (name.startsWith("embedded") && usingEmbedded())) {
-                suite.addTest(new DataSourcePropertiesTest(name));
+        
+        // TODO: Run fixtures in J2ME and JDBC2 (with extensions)
+        // that can be supported there. This disabling matches
+        // the original _app.properties file. Concern was over
+        // XA support (which is supported in JDBC 2 with extensions).
+        if (JDBC.vmSupportsJDBC3()) {
+        
+            // Add all methods starting with 'test'.
+            //suite.addTestSuite(DataSourcePropertiesTest.class);
+            
+            if (usingEmbedded()) {
+           
+                // When using embedded, add all methods starting with 'embedded'.
+                Method[] methods = DataSourcePropertiesTest.class.getMethods();
+                for (int i = 0; i < methods.length; i++) {
+                    Method m = methods[i];
+                    if (m.getParameterTypes().length > 0 ||
+                            m.getReturnType().equals(Void.TYPE)) {
+                        continue;
+                    }
+                    String name = m.getName();
+                    if (name.startsWith("embedded")) {
+                        suite.addTest(new DataSourcePropertiesTest(name));
+                    }
+                }
             }
         }
         return suite;

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java Fri Aug 18 11:54:23 2006
@@ -21,6 +21,8 @@
 import junit.framework.*;
 import java.sql.*;
 
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+
 /**
  * Tests holdable resultsets.
  */
@@ -40,7 +42,7 @@
         
         suite.addTestSuite(HoldabilityTest.class);
         
-        return suite;
+        return new CleanDatabaseTestSetup(suite);
 
     }
 
@@ -50,37 +52,32 @@
     public void setUp() 
         throws Exception 
     {      
-        try {
-            super.setUp();
-        } catch (SQLException e) {
-            if (con!=null) tearDown();
-            throw e;
-        }
-        // For the holdability tests, we recreate the model
+       // For the holdability tests, we recreate the model
         // for each testcase (since we do commits)
         
         // We also use more records to ensure that the disk
         // is being used.
         SURDataModelSetup.createDataModel
-            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, con,
+            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, getXConnection(),
              recordCount);
-        con.commit();
+        commit();
     }
     
     /**
      * Drop the data model, and close the connection
+     * @throws Exception 
      */
-    public void tearDown() 
+    public void tearDown() throws Exception 
     {
         try {            
-            con.rollback();
-            Statement dropStatement = con.createStatement();
+            rollback();
+            Statement dropStatement = createStatement();
             dropStatement.execute("drop table t1");
-            con.commit();
-            con.close();
+            dropStatement.close();
         } catch (SQLException e) {
             printStackTrace(e); // Want to propagate the real exception.
         }
+        super.tearDown();
     }
     
     /**
@@ -90,12 +87,13 @@
     public void testHeldForwardOnlyResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery(selectStatement);
         
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
+        s.close();
     }
     
     /**
@@ -105,18 +103,19 @@
     public void testHeldForwardOnlyResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery(selectStatement);
 
         for (int i=0; i<this.recordCount/2; i++) {
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
+        s.close();
     }
 
     /**
@@ -126,13 +125,14 @@
     public void testHeldForwardOnlyUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         rs.next();    // naviagate to a new tuple
         updateTuple(rs); // Updatable
         scrollForward(rs);
+        s.close();
     }
     
     
@@ -144,7 +144,7 @@
     public void testCompressOnHeldForwardOnlyUpdatableResultSetScanInProgress()
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -153,10 +153,11 @@
             verifyTuple(rs);
         }
         updateTuple(rs);
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        s.close();
         
     }
 
@@ -168,13 +169,14 @@
     public void testCompressOnHeldForwardOnlyUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        s.close();
     }
         
     /**
@@ -184,7 +186,7 @@
     public void testHeldForwardOnlyUpdatableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -193,12 +195,13 @@
             verifyTuple(rs);
         }
         updateTuple(rs);
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         rs.next();
         updateTuple(rs); // Still updatable
         while (rs.next()) {
             verifyTuple(rs); // complete the scan
         }
+        s.close();
     }
     
     /**
@@ -208,14 +211,16 @@
     public void testHeldScrollableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
         
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
         scrollBackward(rs);
+        
+        s.close();
     }
         
     /**
@@ -225,7 +230,7 @@
     public void testHeldScrollableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -233,12 +238,13 @@
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
         scrollBackward(rs);
+        s.close();
     }
 
     /**
@@ -248,15 +254,16 @@
     public void testHeldScrollableResultSetScanDone() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
         
         scrollForward(rs); // Scan is done
         
-        con.commit();
+        commit();
         
         scrollBackward(rs);
+        s.close();
     }
 
     /**
@@ -266,7 +273,7 @@
     public void testHeldScrollableUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -274,10 +281,12 @@
             assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
                        false);
         }
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }    
     
     /**
@@ -287,7 +296,7 @@
     public void testHeldScrollableUpdatableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -298,12 +307,14 @@
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }
 
     /**
@@ -313,7 +324,7 @@
     public void testHeldScrollableUpdatableResultSetScanDone() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -324,9 +335,11 @@
       
         scrollForward(rs); // Scan is done
         
-        con.commit();
+        commit();
         
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }
 
     /**
@@ -336,7 +349,7 @@
     public void testUpdateRowAfterCommitOnHeldForwardOnlyResultSet() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -345,7 +358,7 @@
                        false);
         }
         rs.next();
-        con.commit();
+        commit();
         try {
             rs.updateInt(2, -100);
             rs.updateRow();
@@ -354,6 +367,7 @@
             assertEquals("Unexpected SQLState",
                          INVALID_CURSOR_STATE_NO_CURRENT_ROW, e.getSQLState());
         }
+        s.close();
     }
 
     /**
@@ -363,7 +377,7 @@
     public void testUpdateRowAfterCommitOnHeldScrollInsensitiveResultSet() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -372,7 +386,7 @@
                        false);
         }
         rs.next();
-        con.commit();
+        commit();
         try {
             rs.updateInt(2, -100);
             rs.updateRow();
@@ -381,6 +395,7 @@
             assertEquals("Unexpected SQLState",
                          INVALID_CURSOR_STATE_NO_CURRENT_ROW, e.getSQLState());
         }
+        s.close();
     }
 
     /**
@@ -392,7 +407,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         
         ResultSet rs = s.executeQuery(selectStatement);
@@ -400,10 +415,12 @@
             assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
                        false);
         }
-        con.commit(); // commit
+        commit(); // commit
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        
+        s.close();
     }
 
     /**
@@ -415,7 +432,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -424,9 +441,11 @@
         }
         rs.next(); // Scan is in progress.
         
-        con.commit(); // commit, releases the lock on the records
+        commit(); // commit, releases the lock on the records
         
         verifyCompressInvalidation(rs);
+        
+        s.close();
     }
     
     /**
@@ -438,7 +457,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -448,9 +467,10 @@
         
         scrollForward(rs); // scan is done
         
-        con.commit(); // commit, releases the lock on the records
+        commit(); // commit, releases the lock on the records
         
         verifyCompressInvalidation(rs);
+        s.close();
     }
 
     /**
@@ -461,19 +481,19 @@
         throws SQLException
     {
                 // Delete all records except the first:
-        Statement delStatement = con.createStatement();
+        Statement delStatement = createStatement();
         int deleted = delStatement.executeUpdate("delete from T1 where id>0");
         int expectedDeleted = recordCount-1;    
         
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         
         // Execute online compress
         onlineCompress(true, true, true);
         
         // Now reinsert the tuples:
-        PreparedStatement ps = con.
+        PreparedStatement ps = 
             prepareStatement("insert into t1 values (?,?,?,?)");
         
         for (int i=0; i<recordCount*2; i++) {
@@ -485,7 +505,7 @@
             ps.addBatch();
         }
         ps.executeBatch();
-        con.commit();
+        commit();
 
         rs.next();
         updateTuple(rs);
@@ -510,10 +530,10 @@
             assertNull("Expected no warning when updating this row", warn);
         }
         
-        con.commit();
+        commit();
         
         // Verify data
-        rs = con.createStatement().executeQuery(selectStatement);
+        rs = createStatement().executeQuery(selectStatement);
         while (rs.next()) {            
             verifyTuple(rs);
         }
@@ -529,19 +549,20 @@
     {
         
         // Delete all records except the first:
-        Statement delStatement = con.createStatement();
+        Statement delStatement = createStatement();
         int deleted = delStatement.executeUpdate("delete from T1 where id>0");
         int expectedDeleted = recordCount-1;    
+        delStatement.close();
         
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         
         // Execute online compress
         onlineCompress(true, true, true);
         
         // Now reinsert the tuples:
-        PreparedStatement ps = con.
+        PreparedStatement ps = 
             prepareStatement("insert into t1 values (?,?,?,?)");
         
         for (int i=0; i<recordCount*2; i++) {
@@ -553,7 +574,8 @@
             ps.addBatch();
         }
         ps.executeBatch();
-        con.commit();
+        ps.close();
+        commit();
         
         // Update last tuple
         rs.last();         
@@ -569,10 +591,10 @@
         updateTuple(rs); 
         warn = rs.getWarnings();
         assertWarning(warn, CURSOR_OPERATION_CONFLICT);
-        con.commit();
+        commit();
         
         // Verify data
-        rs = con.createStatement().executeQuery(selectStatement);
+        rs = createStatement().executeQuery(selectStatement);
         while (rs.next()) {            
             // This will fail if we managed to update reinserted tuple
             verifyTuple(rs); 
@@ -605,6 +627,7 @@
         
         try { 
             ps2.executeUpdate();
+            ps2.close();
             con2.commit();
         } finally {
             con2.close();

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java Fri Aug 18 11:54:23 2006
@@ -29,18 +29,16 @@
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestSetup;
-import org.apache.derbyTesting.functionTests.util.JDBC;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.junit.JDBC;
 
 /**
  * Tests of stored procedures.
  */
 public class ProcedureTest extends BaseJDBCTestCase {
 
-    /** Connection used by the test cases. Auto-commit is turned off. */
-    private Connection conn;
-
     /**
      * Creates a new <code>ProcedureTest</code> instance.
      *
@@ -58,7 +56,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteQueryWithNoDynamicResultSets() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         try {
             stmt.executeQuery("CALL RETRIEVE_DYNAMIC_RESULTS(0)");
             fail("executeQuery() didn't fail.");
@@ -74,7 +72,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteQueryWithOneDynamicResultSet() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         ResultSet rs = stmt.executeQuery("CALL RETRIEVE_DYNAMIC_RESULTS(1)");
         assertNotNull("executeQuery() returned null.", rs);
         assertTrue("Result set has no data.", rs.next());
@@ -90,7 +88,7 @@
     public void testExecuteQueryWithMoreThanOneDynamicResultSet()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         try {
             stmt.executeQuery("CALL RETRIEVE_DYNAMIC_RESULTS(2)");
             fail("executeQuery() didn't fail.");
@@ -111,7 +109,7 @@
     public void xtestExecuteUpdateWithNoDynamicResultSets()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         int count = stmt.executeUpdate("CALL RETRIEVE_DYNAMIC_RESULTS(0)");
         assertEquals("Wrong update count.", 0, count);
         stmt.close();
@@ -123,7 +121,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteUpdateWithOneDynamicResultSet() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         try {
             stmt.executeUpdate("CALL RETRIEVE_DYNAMIC_RESULTS(1)");
             fail("executeUpdate() didn't fail.");
@@ -142,7 +140,7 @@
         throws SQLException
     {
         PreparedStatement ps =
-            conn.prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         ps.setInt(1, 0);
         try {
             ps.executeQuery();
@@ -163,7 +161,7 @@
         throws SQLException
     {
         PreparedStatement ps =
-            conn.prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         ps.setInt(1, 1);
         ResultSet rs = ps.executeQuery();
         assertNotNull("executeQuery() returned null.", rs);
@@ -181,7 +179,7 @@
         throws SQLException
     {
         PreparedStatement ps =
-            conn.prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         ps.setInt(1, 2);
         try {
             ps.executeQuery();
@@ -204,7 +202,7 @@
         throws SQLException
     {
         PreparedStatement ps =
-            conn.prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         ps.setInt(1, 0);
         int count = ps.executeUpdate();
         assertEquals("Wrong update count.", 0, count);
@@ -226,7 +224,7 @@
         throws SQLException
     {
         PreparedStatement ps =
-            conn.prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareStatement("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         ps.setInt(1, 1);
         try {
             ps.executeUpdate();
@@ -246,7 +244,7 @@
         throws SQLException
     {
         CallableStatement cs =
-            conn.prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         cs.setInt(1, 0);
         try {
             cs.executeQuery();
@@ -266,7 +264,7 @@
         throws SQLException
     {
         CallableStatement cs =
-            conn.prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         cs.setInt(1, 1);
         ResultSet rs = cs.executeQuery();
         assertNotNull("executeQuery() returned null.", rs);
@@ -284,7 +282,7 @@
         throws SQLException
     {
         CallableStatement cs =
-            conn.prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         cs.setInt(1, 2);
         try {
             cs.executeQuery();
@@ -306,7 +304,7 @@
         throws SQLException
     {
         CallableStatement cs =
-            conn.prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         cs.setInt(1, 0);
         int count = cs.executeUpdate();
         assertEquals("Wrong update count.", 0, count);
@@ -322,7 +320,7 @@
         throws SQLException
     {
         CallableStatement cs =
-            conn.prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
+            getXConnection().prepareCall("CALL RETRIEVE_DYNAMIC_RESULTS(?)");
         cs.setInt(1, 1);
         try {
             cs.executeUpdate();
@@ -340,10 +338,11 @@
      * @exception SQLException if a database error occurs
      */
     public void testRollbackStoredProcWithExecuteQuery() throws SQLException {
-        Statement stmt = conn.createStatement();
+
+        Statement stmt = createStatement();
         ResultSet rs = stmt.executeQuery("CALL PROC_WITH_SIDE_EFFECTS(1)");
         rs.close();
-        conn.rollback();
+        stmt.getConnection().rollback();
         ResultSet tableRs = stmt.executeQuery("SELECT * FROM SIMPLE_TABLE");
         // table should be empty after rollback
         assertFalse("Side effects from stored procedure not rolled back.",
@@ -359,9 +358,9 @@
      * @exception SQLException if a database error occurs
      */
     public void testRollbackStoredProcWithExecuteUpdate() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         stmt.executeUpdate("CALL PROC_WITH_SIDE_EFFECTS(0)");
-        conn.rollback();
+        stmt.getConnection().rollback();
         ResultSet rs = stmt.executeQuery("SELECT * FROM SIMPLE_TABLE");
         // table should be empty after rollback
         assertFalse("Side effects from stored procedure not rolled back.",
@@ -382,6 +381,7 @@
     public void xtestRollbackStoredProcWhenExecuteQueryReturnsNothing()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         Statement stmt = conn.createStatement();
         try {
@@ -410,6 +410,7 @@
     public void xtestRollbackStoredProcWhenExecuteQueryReturnsTooMuch()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         Statement stmt = conn.createStatement();
         try {
@@ -437,6 +438,7 @@
     public void xtestRollbackStoredProcWhenExecuteUpdateReturnsResults()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         Statement stmt = conn.createStatement();
         try {
@@ -464,6 +466,7 @@
     public void xtestRollbackStoredProcWhenExecuteQueryReturnsNothing_prepared()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         PreparedStatement ps =
             conn.prepareStatement("CALL PROC_WITH_SIDE_EFFECTS(?)");
@@ -496,6 +499,7 @@
     public void xtestRollbackStoredProcWhenExecuteQueryReturnsTooMuch_prepared()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         PreparedStatement ps =
             conn.prepareStatement("CALL PROC_WITH_SIDE_EFFECTS(?)");
@@ -528,6 +532,7 @@
         xtestRollbackStoredProcWhenExecuteUpdateReturnsResults_prepared()
         throws SQLException
     {
+        Connection conn = getXConnection();
         conn.setAutoCommit(true);
         PreparedStatement ps =
             conn.prepareStatement("CALL PROC_WITH_SIDE_EFFECTS(?)");
@@ -555,7 +560,7 @@
     public void testClosedDynamicResultSetsFromExecuteQuery()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         try {
             ResultSet rs = stmt.executeQuery("CALL RETRIEVE_CLOSED_RESULT()");
             fail("executeQuery() didn't fail.");
@@ -573,7 +578,7 @@
     public void testClosedDynamicResultSetsFromExecuteUpdate()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = createStatement();
         stmt.executeUpdate("CALL RETRIEVE_CLOSED_RESULT()");
         stmt.close();
     }
@@ -586,14 +591,19 @@
     public void testDynamicResultSetsFromOtherConnectionWithExecuteQuery()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        PreparedStatement ps =
+            getXConnection().prepareStatement("CALL RETRIEVE_EXTERNAL_RESULT(?,?,?)");
+        
+        ps.setString(1, getTestConfiguration().getDatabaseName());
+        ps.setString(2, getTestConfiguration().getUserName());
+        ps.setString(3, getTestConfiguration().getUserPassword());
         try {
-            ResultSet rs = stmt.executeQuery("CALL RETRIEVE_EXTERNAL_RESULT()");
+            ps.executeQuery();
             fail("executeQuery() didn't fail.");
         } catch (SQLException sqle) {
             assertNoResultSetFromExecuteQuery(sqle);
         }
-        stmt.close();
+        ps.close();
     }
 
     /**
@@ -604,9 +614,15 @@
     public void testDynamicResultSetsFromOtherConnectionWithExecuteUpdate()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
-        stmt.executeUpdate("CALL RETRIEVE_EXTERNAL_RESULT()");
-        stmt.close();
+        PreparedStatement ps =
+            getXConnection().prepareStatement("CALL RETRIEVE_EXTERNAL_RESULT(?,?,?)");
+        
+        ps.setString(1, getTestConfiguration().getDatabaseName());
+        ps.setString(2, getTestConfiguration().getUserName());
+        ps.setString(3, getTestConfiguration().getUserPassword());
+        
+        ps.executeUpdate();
+        ps.close();
     }
 
     // UTILITY METHODS
@@ -705,7 +721,7 @@
                   "_prepared"));
         }
         }
-        return new BaseJDBCTestSetup(suite) {
+        Test test = new BaseJDBCTestSetup(suite) {
             /**
              * Creates the tables and the stored procedures used in the test
              * cases.
@@ -746,6 +762,8 @@
                 super.tearDown();
             }
         };
+        
+        return new CleanDatabaseTestSetup(test);
     }
 
     /**
@@ -754,7 +772,7 @@
      * @exception SQLException if a database error occurs
      */
     public void setUp() throws SQLException {
-        conn = getConnection();
+        Connection conn = getXConnection();
         conn.setAutoCommit(false);
         Statement s = conn.createStatement();
         for (int i = 0; i < TABLES.length; i++) {
@@ -765,15 +783,6 @@
     }
 
     /**
-     * Closes the connection for a test case.
-     * @exception SQLException if a database error occurs
-     */
-    public void tearDown() throws SQLException {
-        conn.rollback();
-        conn.close();
-    }
-
-    /**
      * Procedures that should be created before the tests are run and
      * dropped when the tests have finished. First element in each row
      * is the name of the procedure, second element is SQL which
@@ -793,7 +802,8 @@
           "DYNAMIC RESULT SETS 1"
         },
         { "RETRIEVE_EXTERNAL_RESULT",
-          "CREATE PROCEDURE RETRIEVE_EXTERNAL_RESULT() LANGUAGE JAVA " +
+          "CREATE PROCEDURE RETRIEVE_EXTERNAL_RESULT(" +
+          "DBNAME VARCHAR(128), DBUSER VARCHAR(128), DBPWD VARCHAR(128)) LANGUAGE JAVA " +
           "PARAMETER STYLE JAVA EXTERNAL NAME '" +
           ProcedureTest.class.getName() + ".retrieveExternalResult' " +
           "DYNAMIC RESULT SETS 1"
@@ -875,11 +885,17 @@
      * @param external result set from another connection
      * @exception SQLException if a database error occurs
      */
-    public static void retrieveExternalResult(ResultSet[] external)
+    public static void retrieveExternalResult(String dbName, 
+            String user, String password, ResultSet[] external)
         throws SQLException
     {
+        // Use a server-side connection to the same database.
+        String url = "jdbc:derby:" + dbName;
+        
+        Connection conn = DriverManager.getConnection(url, user, password);
+        
         external[0] =
-            getConnection().createStatement().executeQuery("VALUES(1)");
+            conn.createStatement().executeQuery("VALUES(1)");
     }
 
     /**

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java Fri Aug 18 11:54:23 2006
@@ -23,7 +23,7 @@
 
 import junit.framework.*;
 
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 
 import java.sql.*;
 
@@ -43,24 +43,18 @@
  *
  */
 public class ResultSetCloseTest extends BaseJDBCTestCase {
-    
-    Connection con        = null;
-    Statement  s          = null;
-    PreparedStatement ps1 = null;
-    PreparedStatement ps2 = null;
-    ResultSet         rs1 = null;
-    ResultSet         rs2 = null;
-    
+  
+   
     /**
      * Create the tables and the Connection and PreparedStatements that will
      * be used in this test.
      */
     public void setUp()
     throws SQLException {
-        con = getConnection();
+        Connection con = getXConnection();
         con.setAutoCommit(false);
         
-        s = con.createStatement();
+        Statement s = con.createStatement();
         
         s.execute("create table t1 (a int)");
         
@@ -69,11 +63,9 @@
         s.execute("insert into t1 values(2)");
         s.execute("insert into t1 values(3)");
         
-        con.commit();
+        s.close();
         
-        ps1 = con.prepareStatement("select * from t1");
-        
-        ps2 = con.prepareStatement("select 10/a from t1");
+        con.commit();
     }
     
     /**
@@ -90,10 +82,14 @@
      *
      */
     public void testResultSetDoesNotClose() throws SQLException {
-        rs1 = ps1.executeQuery();
+        
+        PreparedStatement ps1 = prepareStatement("select * from t1");
+        PreparedStatement ps2 = prepareStatement("select 10/a from t1");
+        
+        ResultSet rs1 = ps1.executeQuery();
         
         try {
-            rs2 = ps2.executeQuery();
+            ResultSet rs2 = ps2.executeQuery();
             while(rs2.next());
         } catch(SQLException sqle) {
             //Do Nothing expected exception
@@ -101,20 +97,11 @@
         
         while(rs1.next());
         
-        con.commit();
-    }
-    
-    /**
-     * Destroy the objects used in this test.
-     */
-    public void tearDown()
-    throws SQLException {
-        if (con != null && !con.isClosed()) {
-            con.rollback();
-            con.close();
-        }
+        commit();
         
-        con = null;
+        rs1.close();
+        ps1.close();
+        ps2.close();
     }
     
     /**
@@ -130,7 +117,17 @@
      * Create test suite for this test.
      */
     public static Test suite() {
-        return new TestSuite(ResultSetCloseTest.class,"ResultSetCloseTest suite");
+        
+        TestSuite suite = new TestSuite("ResultSetCloseTest");
+        
+        // DB2 client doesn't implement result set closing
+        // correctly wrt ensuring all its methods subsequently
+        // throw an exception.
+        if (usingDerbyNet())
+            return suite;
+        
+        suite.addTestSuite(ResultSetCloseTest.class);
+        return suite;
     }
     
 }

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java Fri Aug 18 11:54:23 2006
@@ -18,7 +18,9 @@
  * language governing permissions and limitations under the License.
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+
 import junit.framework.*;
 import java.sql.*;
 
@@ -46,6 +48,16 @@
     }
     
     /**
+     * Override the default connection's to ensure it
+     * is always in autocommit false and repeatable
+     * read as a starting point.
+     */
+    protected void initializeConnection(Connection conn) throws SQLException {
+        conn.setAutoCommit(false);
+        conn.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);   
+    }
+    
+    /**
      * Get a JDBC Connection to the Derby database.
      * The autocommit flag is set to false, and the isolation level
      * for the transactions is set to repeatable read.
@@ -53,10 +65,9 @@
     protected Connection getNewConnection() 
         throws SQLException
     {
-        final Connection rcon = getConnection();
-        rcon.setAutoCommit(false);
-        rcon.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
-        return rcon;
+        final Connection rcon = openDefaultConnection();
+        initializeConnection(rcon);
+       return rcon;
     }
 
     /**
@@ -64,20 +75,9 @@
      */
     public void setUp() throws  Exception {       
         println("SetUp");
-        con = getNewConnection();
-    }
-    
-    /**
-     * Rollback the transaction
-     */
-    public void tearDown() throws Exception {
-        println("TearDown");
-        try { 
-            con.rollback();
-            con.close();
-        } catch (SQLException e) {
-            printStackTrace(e);
-        }      
+        // temp save the connection in this class as con
+        // as well as the default connection in the parent
+        con = getXConnection();
     }
     
     /**
@@ -100,8 +100,8 @@
      * updateRow()
      */
     protected void updateTuple(ResultSet rs) throws SQLException {
-        assertTrue("Cannot use updateRow() in autocommit mode", 
-                   !con.getAutoCommit());
+        assertFalse("Cannot use updateRow() in autocommit mode", 
+                   rs.getStatement().getConnection().getAutoCommit());
         int id = rs.getInt(1);
         int a = rs.getInt(2);
         int b = rs.getInt(3);        
@@ -122,7 +122,7 @@
         int b = rs.getInt(3);        
         int newA = a*2 +id + 37;
         int newB = newA + id + 17;
-        PreparedStatement ps = con.
+        PreparedStatement ps = 
             prepareStatement("update T1 set a=?,b=? where current of " +
                              rs.getCursorName());
         ps.setInt(1, newA);

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURDataModelSetup.java Fri Aug 18 11:54:23 2006
@@ -19,12 +19,14 @@
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 import org.apache.derbyTesting.functionTests.util.TestUtil;
-import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseJDBCTestSetup;
+import org.apache.derbyTesting.junit.BaseTestCase;
+
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Statement;
-import junit.extensions.TestSetup;
 import junit.framework.Test;
 import java.util.Set;
 import java.util.HashSet;
@@ -36,7 +38,7 @@
  * tests.  It sets up a datamodel and populates it with data.
  * @author Andreas Korneliussen
  */
-public class SURDataModelSetup extends TestSetup
+public class SURDataModelSetup extends BaseJDBCTestSetup
 {  
     /**
      * Constructor.
@@ -60,8 +62,10 @@
                                        int records) 
         throws SQLException
     {
+        Statement statement = con.createStatement();
+        
         try { 
-            con.createStatement().execute("drop table t1"); 
+            statement.execute("drop table t1"); 
         } catch (SQLException e) {
             assertEquals("'drop table t1' failed with unexpected SQL State",
                          TABLE_EXISTS_SQL_STATE, e.getSQLState());
@@ -78,16 +82,16 @@
             
         };
         
-        Statement statement = con.createStatement();
+        
         
         /** Create the table */
         statement.execute(model.getCreateTableStatement());
-        println(model.getCreateTableStatement());
+        BaseTestCase.println(model.getCreateTableStatement());
         
         /** Create secondary index */
         if (model.hasSecondaryKey()) {
             statement.execute("create index a_on_t on t1(a)");
-            println("create index a_on_t on t1(a)");
+            BaseTestCase.println("create index a_on_t on t1(a)");
         }
         
         /** Populate with data */
@@ -102,6 +106,8 @@
             ps.addBatch();
         }
         ps.executeBatch();
+        ps.close();
+        statement.close();
         con.commit();
     }
     
@@ -125,8 +131,10 @@
      */
     protected void setUp() throws  Exception {       
         println("Setting up datamodel: " + model);
+
         try {
-            con = getNewConnection();
+            Connection con = getConnection();
+            con.setAutoCommit(false);
             createDataModel(model, con);
         } catch (SQLException e) {
             printStackTrace(e); // Print the entire stack
@@ -141,31 +149,20 @@
         throws Exception
     {
         try {
+            Connection con = getConnection();
             con.rollback();
             con.createStatement().execute("drop table t1");
             con.commit();
-            con.close();
         } catch (SQLException e) {
             printStackTrace(e);
         }
+        super.tearDown();
     }
     
     public String toString() {
         return "SURDataModel tests with model: " + model;
     }
 
-    /**
-     * Get a JDBC Connection to the Derby database
-     */
-    private Connection getNewConnection() 
-        throws SQLException
-    {
-        final Connection rcon = SURBaseTest.getConnection();
-        rcon.setAutoCommit(false);
-        return rcon;
-    }
-
-    private Connection con = null;
     private final SURDataModel model;
     final static int recordCount = 10;  // Number of records in data model.  
         
@@ -248,16 +245,6 @@
         private final String name;
     }
 
-    /**
-     * <p>
-     * Println code to print chatty informational messages.
-     * </p>
-     */
-    public static void println(String text)
-    {
-        BaseJDBCTestCase.println(text);
-    }
-    
     /**
      * Prints the stack trace. If run in the harness, the
      * harness will mark the test as failed if this method

Modified: db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java?rev=432679&r1=432678&r2=432679&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java (original)
+++ db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java Fri Aug 18 11:54:23 2006
@@ -73,13 +73,13 @@
         throws SQLException
     {
         println(query);
-        DatabaseMetaData dbMeta = con.getMetaData();
+        DatabaseMetaData dbMeta = getXConnection().getMetaData();
                 
         if (dbMeta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
             checkRowDeleted = true;
         }
         
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         
         s.setCursorName(cursorName);
@@ -138,6 +138,7 @@
         }
         
         rs.close();
+        s.close();
     }
     
     /**
@@ -233,7 +234,7 @@
             rs.absolute(key.intValue());            
             if (rs.rowDeleted()) continue; // skip deleting row if already deleted
             if (positioned) {
-                con.createStatement().executeUpdate
+                createStatement().executeUpdate
                         ("DELETE FROM T1 WHERE CURRENT OF \"" + cursorName + 
                          "\"");
             } else {
@@ -325,7 +326,7 @@
         sb.append(cursorName);
         sb.append("\"");
         println(sb.toString());
-        PreparedStatement ps = con.prepareStatement(sb.toString());
+        PreparedStatement ps = prepareStatement(sb.toString());
         
         for (int column = 1; column<=meta.getColumnCount(); column++) {
            if (meta.getColumnType(column)==Types.INTEGER) {



Mime
View raw message