db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r629712 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/master/jdk16/ testing/org/apache/derbyTesting/functionTests/tests...
Date Thu, 21 Feb 2008 08:04:18 GMT
Author: kahatlen
Date: Thu Feb 21 00:04:17 2008
New Revision: 629712

URL: http://svn.apache.org/viewvc?rev=629712&view=rev
Log:
DERBY-3404: EmbedResultSet.getString() returns wrong value after auto-commit with CLOSE_CURSORS_AT_COMMIT

Made EmbedResultSet.checkIfClose() detect that the language ResultSet
had been closed because of the auto-commit, and throw an SQLException.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/closed.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk16/closed.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Thu Feb
21 00:04:17 2008
@@ -2240,7 +2240,6 @@
 	//1)Make sure JDBC ResultSet is not closed
 	//2)Make sure this is an updatable ResultSet
 	//3)Make sure JDBC ResultSet is positioned on a row
-	//4)Make sure underneath language resultset is not closed
 	protected void checksBeforeUpdateOrDelete(String methodName, int columnIndex) throws SQLException
{
 
       //1)Make sure JDBC ResultSet is not closed
@@ -2251,13 +2250,6 @@
 
       //3)Make sure JDBC ResultSet is positioned on a row
       if (!isOnInsertRow) checkOnRow(); // make sure there's a current row
-      //in case of autocommit on, if there was an exception which caused runtime rollback
in this transaction prior to this call,
-      //the rollback code will mark the language resultset closed (it doesn't mark the JDBC
ResultSet closed).
-      //That is why alongwith the earlier checkIfClosed call in this method, there is a check
for language resultset close as well.
-
-      //4)Make sure underneath language resultset is not closed
-      if (theResults.isClosed())
-        throw Util.generateCsSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, methodName);
 	}
 
 	//mark the column as updated and return DataValueDescriptor for it. It will be used by updateXXX
methods to put new values
@@ -2273,7 +2265,6 @@
      * 1) Make sure JDBC ResultSet is not closed
      * 2) Make sure this is an updatable ResultSet
      * 3) Make sure JDBC ResultSet is positioned on insertRow
-     * 4) Make sure underneath language resultset is not closed
      */
     protected void checksBeforeInsert() throws SQLException {
         // 1)Make sure JDBC ResultSet is not closed
@@ -2287,11 +2278,6 @@
         if (!isOnInsertRow) {
             throw newSQLException(SQLState.CURSOR_NOT_POSITIONED_ON_INSERT_ROW);
         }
-
-        // 4)Make sure underneath language resultset is not closed
-        if (theResults.isClosed()) {
-            throw Util.generateCsSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, "insertRow");
-        }
     }
 
     /**
@@ -4248,7 +4234,21 @@
 	 * @exception SQLException		Thrown if this ResultSet is closed.
 	 */
 	final void checkIfClosed(String operation) throws SQLException {
-		if (isClosed) {
+		// If the JDBC ResultSet has been explicitly closed, isClosed is
+		// true. In some cases, the underlying language ResultSet can be closed
+		// without setting isClosed in the JDBC ResultSet. This happens if the
+		// ResultSet is non-holdable and the transaction has been committed, or
+		// if an error in auto-commit mode causes a rollback of the
+		// transaction.
+		if (isClosed || theResults.isClosed()) {
+
+			// The JDBC ResultSet hasn't been explicitly closed. Perform some
+			// basic cleanup and mark it as closed.
+			if (!isClosed) {
+				closeCurrentStream();
+				isClosed = true;
+			}
+
 			throw newSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, operation);
 		}
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/closed.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/closed.out?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/closed.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/closed.out
Thu Feb 21 00:04:17 2008
@@ -8,7 +8,7 @@
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
-ERROR 08003: No current connection.
+ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is
OFF.
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
 Test database shutdown ...

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk16/closed.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk16/closed.out?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk16/closed.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/jdk16/closed.out
Thu Feb 21 00:04:17 2008
@@ -8,7 +8,7 @@
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
-ERROR 08003: No current connection.
+ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is
OFF.
 ERROR 08003: No current connection.
 ERROR 08003: No current connection.
 Test database shutdown ...

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/nestedCommit.out
Thu Feb 21 00:04:17 2008
@@ -69,8 +69,7 @@
 values doConnCommitInt();
 1          
 -----------
-1          
-ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is
OFF.
+ERROR XCL16: ResultSet not open. Operation 'getString' not permitted. Verify that autocommit
is OFF.
 ij> -- values doConnStmtInt('commit');
 -- values doConnStmtInt('rollback');
 -- values doConnStmtInt('call doConnStmt(''call doConnStmt(''''commit'''')'')');

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ResultSetTest.java
Thu Feb 21 00:04:17 2008
@@ -1611,6 +1611,22 @@
         stmt.close();
         stmt2.close();
     }
+
+    /**
+     * Test that a {@code ResultSet} is marked as closed after commit if its
+     * holdability is {@code CLOSE_CURSORS_AT_COMMIT} (DERBY-3404).
+     */
+    public void testIsClosedOnNonHoldableResultSet() throws SQLException {
+        getConnection().setAutoCommit(false);
+        getConnection().setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+        ResultSet rs = createStatement().executeQuery(
+            "SELECT TABLENAME FROM SYS.SYSTABLES");
+        assertEquals("ResultSet shouldn't be holdable",
+                     ResultSet.CLOSE_CURSORS_AT_COMMIT, rs.getHoldability());
+        commit();
+        assertTrue("Commit should have closed the ResultSet", rs.isClosed());
+    }
+
     /**
      * Test that an exception is thrown when methods are called
      * on a closed result set (DERBY-1060).

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java?rev=629712&r1=629711&r2=629712&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/J2EEDataSourceTest.java
Thu Feb 21 00:04:17 2008
@@ -2511,10 +2511,7 @@
             rsh.next();
             fail("rsh's connection not active id ");
         } catch (SQLException sqle) {
-            if (usingEmbedded())
-                assertSQLState("08003", sqle);
-            else if (usingDerbyNetClient())
-                assertSQLState("XCL16", sqle);
+            assertSQLState("XCL16", sqle);
         }
 
         // resume XA transaction and keep using rs");



Mime
View raw message