db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r629395 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
Date Wed, 20 Feb 2008 09:34:57 GMT
Author: kahatlen
Date: Wed Feb 20 01:34:56 2008
New Revision: 629395

URL: http://svn.apache.org/viewvc?rev=629395&view=rev
Log:
DERBY-3422: Embedded returns wrong value for DatabaseMetaData.autoCommitFailureClosesAllResultSets()

Return the correct value (true) and update the test so that it is able
to detect differences between returned value and actual behaviour.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java?rev=629395&r1=629394&r2=629395&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedDatabaseMetaData40.java
Wed Feb 20 01:34:56 2008
@@ -64,10 +64,16 @@
     public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
         return true;
     }
-     
+
+    /**
+     * Returns whether or not all open {@code ResultSet}s on a {@code
+     * Connection} are closed if an error occurs when auto-commit in enabled.
+     *
+     * @return {@code true}, since the embedded driver will close the open
+     * {@code ResultSet}s
+     */
     public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
-        // TODO - find out what this really should be 
-        return false;
+        return true;
     }
    
     public boolean providesQueryObjectGenerator() throws SQLException {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java?rev=629395&r1=629394&r2=629395&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/TestDbMetaData.java
Wed Feb 20 01:34:56 2008
@@ -102,7 +102,11 @@
     }
 
     public void testAutoCommitFailureClosesAllResultSets() throws SQLException {
-        assertFalse(meta.autoCommitFailureClosesAllResultSets());
+        if (usingEmbedded()) {
+            assertTrue(meta.autoCommitFailureClosesAllResultSets());
+        } else {
+            assertFalse(meta.autoCommitFailureClosesAllResultSets());
+        }
     }
 
     public void testGetClientInfoProperties() throws SQLException {
@@ -470,33 +474,57 @@
      * @exception SQLException if an unexpected database error occurs
      */
     public void testAutoCommitFailure() throws SQLException {
-        Connection con = getConnection();
-        con.setAutoCommit(true);
 
-        Statement s1 =
-            con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
-                                ResultSet.CONCUR_READ_ONLY,
-                                ResultSet.HOLD_CURSORS_OVER_COMMIT);
-        ResultSet resultSet = s1.executeQuery("VALUES (1, 2), (3, 4)");
+        // IMPORTANT: use auto-commit
+        getConnection().setAutoCommit(true);
+
+        ResultSet[] rss = new ResultSet[2];
+        // Use different statements so that both result sets are kept open
+        rss[0] = createStatement().executeQuery("VALUES 1, 2, 3, 4");
+        rss[1] = createStatement().executeQuery(
+                "SELECT * FROM SYSIBM.SYSDUMMY1");
+
+        // We want to test holdable result sets
+        for (ResultSet rs : rss) {
+            assertEquals("ResultSet should be holdable",
+                         ResultSet.HOLD_CURSORS_OVER_COMMIT,
+                         rs.getHoldability());
+        }
 
-        Statement s2 = con.createStatement();
         try {
             String query =
                 "SELECT dummy, nonexistent, phony FROM imaginarytable34521";
-            s2.execute(query);
+            // Create a new statement so we don't close any of the open result
+            // sets by re-executing a statement.
+            createStatement().execute(query);
             fail("Query didn't fail.");
         } catch (SQLException e) {
             // should fail, but we don't care how
         }
 
+        int closedResultSets = 0;
+        for (ResultSet rs : rss) {
+            // check if an operation fails with "ResultSet is closed"
+            try {
+                rs.next();
+                // OK, didn't fail, ResultSet wasn't closed
+            } catch (SQLException sqle) {
+                assertSQLState("XCL16", sqle);
+                // OK, ResultSet is closed, increase counter
+                closedResultSets++;
+            }
+        }
+
+        boolean allResultSetsWereClosed = (closedResultSets == rss.length);
+
         assertEquals("autoCommitFailureClosesAllResultSets() returned value " +
                      "which doesn't match actual behaviour.",
-                     resultSet.isClosed(),
+                     allResultSetsWereClosed,
                      meta.autoCommitFailureClosesAllResultSets());
 
-        resultSet.close();
-        s1.close();
-        s2.close();
+        for (ResultSet rs : rss) {
+            rs.close();
+        }
     }
 
     public void testIsWrapperForPositive() throws SQLException {



Mime
View raw message