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 2006/08/16 21:25:32 UTC

svn commit: r431999 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/jdbcapi/ util/

Author: djd
Date: Wed Aug 16 12:25:31 2006
New Revision: 431999

URL: http://svn.apache.org/viewvc?rev=431999&view=rev
Log:
DERBY-1555 DERBY-1701 (partial) Improve the BaseJDBCTest by adding support for a default connection
exactly like BaseJDBCTestSetup. Provides consistent handling for a connection in the common case
of a test using just one. Removes duplicated/inconistent code across many tests. First step
has the getConnection method called getXConnection until all the tests ahve stopped using the getConnection
static method and instead use the openDefaultConnection method.
Change the tests in jdbcapi to the new scheme.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java
    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/ProcedureTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BLOBDataModelSetup.java Wed Aug 16 12:25:31 2006
@@ -19,6 +19,7 @@
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 import org.apache.derbyTesting.functionTests.util.BaseJDBCTestCase;
+import org.apache.derbyTesting.functionTests.util.BaseJDBCTestSetup;
 import org.apache.derbyTesting.functionTests.util.TestInputStream;
 import junit.extensions.TestSetup;
 import junit.framework.Test;
@@ -37,7 +38,7 @@
  *
  * @author Andreas Korneliussen
  */
-final public class BLOBDataModelSetup extends TestSetup
+final public class BLOBDataModelSetup extends BaseJDBCTestSetup
 {
     
     /** 
@@ -57,7 +58,7 @@
     protected final void setUp() 
         throws Exception
     {
-        con = BaseJDBCTestCase.getConnection();
+        Connection con = getConnection();
         con.setAutoCommit(false);
         
         // Create table:
@@ -106,14 +107,16 @@
         throws Exception
     {
         try { 
+            Connection con = getConnection();
             Statement statement = con.createStatement();
             statement.execute("DROP TABLE " + tableName);
             statement.close();
             con.commit();
-            con.close();
         } catch (SQLException e) {
             BaseJDBCTestCase.printStackTrace(e);
-        }      
+        }  
+        
+        super.tearDown();
     }
 
     /**
@@ -136,9 +139,6 @@
     
     /** Val for big  record */
     final static int bigVal = regularBlobs + 1;
-    
-    /** JDBC Connection */        
-    private Connection con;
     
     /** Name of table */
     private static final String tableName = "TESTBLOBTABLE";

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=431999&r1=431998&r2=431999&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 Aug 16 12:25:31 2006
@@ -44,7 +44,6 @@
     public BLOBTest(String name) 
     {
         super(name);
-        con = null;
     }
 
     
@@ -58,7 +57,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+            getXConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT * from " + 
@@ -87,7 +86,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+            getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT * from " + 
@@ -117,7 +116,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+            getXConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT * from " + 
@@ -148,7 +147,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+            getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT * from " + 
@@ -178,7 +177,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+            getXConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT data,val,length from " + 
@@ -208,7 +207,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+            getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT data,val,length from " + 
@@ -239,7 +238,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+            getXConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT data from " + 
@@ -272,7 +271,7 @@
         throws SQLException, IOException
     {
         final Statement stmt = 
-            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+            getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                 ResultSet.CONCUR_UPDATABLE);
         final ResultSet rs = 
             stmt.executeQuery("SELECT data from " + 
@@ -332,7 +331,7 @@
                                                     final int newSize) 
         throws SQLException, IOException
     {
-        final PreparedStatement preparedStatement = con.prepareStatement
+        final PreparedStatement preparedStatement = getXConnection().prepareStatement
             ("UPDATE " + BLOBDataModelSetup.getBlobTableName() +
              " SET val=?, length = ?, data = ? WHERE CURRENT OF " +
              rs.getCursorName());
@@ -365,7 +364,7 @@
     {
         println("Verify new value in table: " + newVal);
         
-        final Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        final Statement stmt = getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                                    ResultSet.CONCUR_READ_ONLY);
         
         final ResultSet rs = 
@@ -439,27 +438,6 @@
         throws Exception
     {
         println("Setup of: " + getName());
-        con = getConnection();
-        con.setAutoCommit(false);
+        getXConnection().setAutoCommit(false);
     }
-    
-    /**
-     * Teardown test.
-     * Rollback connection and close it.
-     * @exception Exceptions causes the test to fail with error
-     */
-    public final void tearDown() 
-        throws Exception
-    {
-        println("Teardown of: " + getName());
-        try { 
-            con.rollback();
-            con.close();
-        } catch (SQLException e) {
-            printStackTrace(e);
-        }      
-    }
-    
-    /** JDBC Connection */        
-    private Connection con;
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ProcedureTest.java Wed Aug 16 12:25:31 2006
@@ -38,9 +38,6 @@
  */
 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 +55,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteQueryWithNoDynamicResultSets() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         try {
             stmt.executeQuery("CALL RETRIEVE_DYNAMIC_RESULTS(0)");
             fail("executeQuery() didn't fail.");
@@ -74,7 +71,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteQueryWithOneDynamicResultSet() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().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 +87,7 @@
     public void testExecuteQueryWithMoreThanOneDynamicResultSet()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         try {
             stmt.executeQuery("CALL RETRIEVE_DYNAMIC_RESULTS(2)");
             fail("executeQuery() didn't fail.");
@@ -111,7 +108,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 +120,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testExecuteUpdateWithOneDynamicResultSet() throws SQLException {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         try {
             stmt.executeUpdate("CALL RETRIEVE_DYNAMIC_RESULTS(1)");
             fail("executeUpdate() didn't fail.");
@@ -142,7 +139,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 +160,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 +178,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 +201,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 +223,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 +243,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 +263,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 +281,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 +303,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 +319,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,6 +337,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testRollbackStoredProcWithExecuteQuery() throws SQLException {
+        Connection conn = getXConnection();
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("CALL PROC_WITH_SIDE_EFFECTS(1)");
         rs.close();
@@ -359,6 +357,7 @@
      * @exception SQLException if a database error occurs
      */
     public void testRollbackStoredProcWithExecuteUpdate() throws SQLException {
+        Connection conn = getXConnection();
         Statement stmt = conn.createStatement();
         stmt.executeUpdate("CALL PROC_WITH_SIDE_EFFECTS(0)");
         conn.rollback();
@@ -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,6 +560,7 @@
     public void testClosedDynamicResultSetsFromExecuteQuery()
         throws SQLException
     {
+        Connection conn = getXConnection();
         Statement stmt = conn.createStatement();
         try {
             ResultSet rs = stmt.executeQuery("CALL RETRIEVE_CLOSED_RESULT()");
@@ -573,7 +579,7 @@
     public void testClosedDynamicResultSetsFromExecuteUpdate()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         stmt.executeUpdate("CALL RETRIEVE_CLOSED_RESULT()");
         stmt.close();
     }
@@ -586,7 +592,7 @@
     public void testDynamicResultSetsFromOtherConnectionWithExecuteQuery()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         try {
             ResultSet rs = stmt.executeQuery("CALL RETRIEVE_EXTERNAL_RESULT()");
             fail("executeQuery() didn't fail.");
@@ -604,7 +610,7 @@
     public void testDynamicResultSetsFromOtherConnectionWithExecuteUpdate()
         throws SQLException
     {
-        Statement stmt = conn.createStatement();
+        Statement stmt = getXConnection().createStatement();
         stmt.executeUpdate("CALL RETRIEVE_EXTERNAL_RESULT()");
         stmt.close();
     }
@@ -754,7 +760,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++) {
@@ -762,15 +768,6 @@
         }
         s.close();
         conn.commit();
-    }
-
-    /**
-     * Closes the connection for a test case.
-     * @exception SQLException if a database error occurs
-     */
-    public void tearDown() throws SQLException {
-        conn.rollback();
-        conn.close();
     }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ResultSetCloseTest.java Wed Aug 16 12:25:31 2006
@@ -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();
-        
-        ps1 = con.prepareStatement("select * from t1");
+        s.close();
         
-        ps2 = con.prepareStatement("select 10/a from t1");
+        con.commit();
     }
     
     /**
@@ -90,10 +82,15 @@
      *
      */
     public void testResultSetDoesNotClose() throws SQLException {
-        rs1 = ps1.executeQuery();
+        Connection con = getXConnection();
+        
+        PreparedStatement ps1 = con.prepareStatement("select * from t1");
+        PreparedStatement ps2 = con.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 +98,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();
-        }
+        ps1.getConnection().commit();
         
-        con = null;
+        rs1.close();
+        ps1.close();
+        ps2.close();
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java Wed Aug 16 12:25:31 2006
@@ -64,7 +64,7 @@
      * Set up the connection to the database.
      */
     public void setUp() throws  Exception {       
-        con = getConnection();
+        Connection con = getXConnection();
         con.setAutoCommit(true);
 
         String createTableWithPK = "CREATE TABLE tableWithPK (" +
@@ -84,7 +84,7 @@
      */
     public void tearDown() throws Exception {
         println("TearDown");
-        Statement s = con.createStatement();
+        Statement s = getXConnection().createStatement();
         try { 
             
             s.executeUpdate("DROP TABLE tableWithPK");
@@ -92,8 +92,8 @@
             printStackTrace(e);
         }    
         s.close();
-        JDBC.cleanup(con);
-        con = null;
+        super.tearDown();
+
     }
     
     /**
@@ -102,6 +102,7 @@
      */
     public void testNextOnLastRowForwardOnly()  throws SQLException{
 
+        Connection con = getXConnection();
         con.setAutoCommit(true);
         con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
         Statement roStmt = con.createStatement(
@@ -134,6 +135,7 @@
      */
     public void testNextOnLastRowScrollable()  throws SQLException{
 
+        Connection con = getXConnection();
         con.setAutoCommit(true);
         con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
         Statement roStmt = con.createStatement(
@@ -153,8 +155,5 @@
         rs.close();
 
     }
-
-    /* Connection established in setUp() */
-    protected Connection con = null;
        
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/URCoveringIndexTest.java Wed Aug 16 12:25:31 2006
@@ -43,7 +43,7 @@
      * Set up the connection to the database.
      */
     public void setUp() throws  Exception {       
-        con = getConnection();
+        Connection con = getXConnection();
         con.setAutoCommit(false);
 
         String createTableWithPK = "CREATE TABLE tableWithPK (" +
@@ -58,15 +58,6 @@
         stmt.close();
     }
     
-    /**
-     * Rollback the transaction
-     */
-    public void tearDown() throws Exception {
-        println("TearDown");
-        JDBC.cleanup(con);
-        con = null;
-    }
-    
     private void testUpdateUpdatedTupleWithCoveringIndex(
             boolean scroll,
             boolean usePositionedUpdate) throws SQLException{
@@ -75,6 +66,8 @@
         int resultsetType = scroll ? ResultSet.TYPE_SCROLL_INSENSITIVE :
                 ResultSet.TYPE_FORWARD_ONLY;
         
+        Connection con = getXConnection();
+        
         if (!(con.getMetaData().supportsResultSetConcurrency(resultsetType,
                 ResultSet.CONCUR_UPDATABLE))) {
             return;
@@ -145,8 +138,4 @@
     public void testUpdateUpdatedTupleFOUpdateRow()  throws SQLException{
         testUpdateUpdatedTupleWithCoveringIndex(false, false);
     }
-
-
-    protected Connection con = null; // Connection established in setUp()
-       
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java Wed Aug 16 12:25:31 2006
@@ -83,8 +83,9 @@
     public void setUp()
         throws Exception
     {
+        Connection con = getXConnection();
         try {
-            con = getConnection();
+            
             con.setAutoCommit(false);
             
             Statement stmt = con.createStatement();
@@ -129,22 +130,6 @@
             throw e;
         }
     }
-
-    /**
-     * Teardown test.
-     * Rollback connection and close it.
-     * @exception Exceptions causes the test to fail with error
-     */
-    public void tearDown() 
-        throws Exception 
-    {
-        try { 
-            con.rollback();
-            con.close();
-        } catch (SQLException e) {
-            printStackTrace(e);
-        }      
-    }
         
     /**
      * Tests calling updateString on all columns of the row.
@@ -317,7 +302,7 @@
     {
         rs.close();
         
-        rs = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        rs = getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                  ResultSet.CONCUR_READ_ONLY).
             executeQuery(SELECT_STMT);
         
@@ -343,7 +328,7 @@
     {
         rs.close();
         
-        rs = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        rs = getXConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                  ResultSet.CONCUR_READ_ONLY).
             executeQuery(SELECT_STMT);
         
@@ -363,9 +348,6 @@
     
     /* Updatable ResultSet */
     private ResultSet rs = null;
-    
-    /* Connection */
-    private Connection con = null;
     
     /* Table name */
     private static final String TABLE_NAME = "MultiTypeTable";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java?rev=431999&r1=431998&r2=431999&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/BaseJDBCTestCase.java Wed Aug 16 12:25:31 2006
@@ -33,12 +33,57 @@
     extends BaseTestCase {
 
     /**
+     * Maintain a single connection to the default
+     * database, opened at the first call to getConnection.
+     * Typical setup will just require a single connection.
+     * @see BaseJDBCTestSetup#getConnection()
+     */
+    private Connection conn;
+    
+    /**
      * Create a test case with the given name.
      *
      * @param name of the test case.
      */
     public BaseJDBCTestCase(String name) {
         super(name);
+    }
+    
+    /**
+     * Obtain the connection to the default database.
+     * This class maintains a single connection returned
+     * by this class, it is opened on the first call to
+     * this method. Subsequent calls will return the same
+     * connection object unless it has been closed. In that
+     * case a new connection object will be returned.
+     * <P>
+     * The tearDown method will close the connection if
+     * it is open.
+     * @see TestConfiguration#openDefaultConnection()
+     */
+    // TEMP NAME - WILL BE getConnection() once all uses of the
+    // static getConnection() have been converted to openDefaultConnection
+    public final Connection getXConnection() throws SQLException
+    {
+        if (conn != null)
+        {
+            if (!conn.isClosed())
+                return conn;
+            conn = null;
+        }
+        return conn = getTestConfiguration().openDefaultConnection();
+    }
+    
+    /**
+     * Tear down this fixture, sub-classes should call
+     * super.tearDown(). This cleanups & closes the connection
+     * if it is open.
+     */
+    protected void tearDown()
+    throws java.lang.Exception
+    {
+        JDBC.cleanup(conn);
+        conn = null;
     }
 
     // TEMP