db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r432438 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests: tests/jdbcapi/SURBaseTest.java util/BaseJDBCTestCase.java
Date Fri, 18 Aug 2006 00:00:20 GMT
Author: djd
Date: Thu Aug 17 17:00:20 2006
New Revision: 432438

URL: http://svn.apache.org/viewvc?rev=432438&view=rev
Log:
DERBY-1555 DERBY-1701 (partial) Incremental step in changing the tests that extend
SURBaseTest to use the single connection provided by BaseJDBCTestCase. Added
initialize method to BaseJDBCTestCase to allow tests to have a consistent
initial state for a connection. The SURBaseTest still has its con variable,
will be cleaned up in subsequent commits.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.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/SURBaseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java?rev=432438&r1=432437&r2=432438&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURBaseTest.java
Thu Aug 17 17:00:20 2006
@@ -48,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.
@@ -56,9 +66,8 @@
         throws SQLException
     {
         final Connection rcon = openDefaultConnection();
-        rcon.setAutoCommit(false);
-        rcon.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
-        return rcon;
+        initializeConnection(rcon);
+       return rcon;
     }
 
     /**
@@ -66,16 +75,9 @@
      */
     public void setUp() throws  Exception {       
         println("SetUp");
-        con = getNewConnection();
-    }
-    
-    /**
-     * Rollback the transaction
-     */
-    public void tearDown() throws Exception {
-        println("TearDown");
-       JDBC.cleanup(con);
-        con = null;
+        // temp save the connection in this class as con
+        // as well as the default connection in the parent
+        con = getXConnection();
     }
     
     /**
@@ -98,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);        
@@ -120,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/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=432438&r1=432437&r2=432438&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
Thu Aug 17 17:00:20 2006
@@ -71,7 +71,22 @@
                 return conn;
             conn = null;
         }
-        return conn = getTestConfiguration().openDefaultConnection();
+        conn = getTestConfiguration().openDefaultConnection();
+        initializeConnection(conn);
+        return conn;
+    }
+    
+    /**
+     * Allow a sub-class to initialize a connection to provide
+     * consistent connection state for its tests. Called only
+     * when getConnection() opens a new connection. Default
+     * action is to not modify the connection's state from
+     * the initialization provided by the data source.
+     * @param conn Connection to be intialized
+     * @throws SQLException Error setting the initial state.
+     */
+    protected void initializeConnection(Connection conn) throws SQLException
+    {
     }
     
     /**



Mime
View raw message