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 an...@apache.org on 2006/06/08 20:31:46 UTC
svn commit: r412831 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/jdbc/
testing/org/apache/derbyTesting/functionTests/suites/
testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
testing/org/apache/derbyTesting/functionTests/util/
Author: andreask
Date: Thu Jun 8 11:31:45 2006
New Revision: 412831
URL: http://svn.apache.org/viewvc?rev=412831&view=rev
Log:
DERBY-1295 contributed by Fernanda Pizzorno. Scroll insensitive resultset should not implicitly close due to positioning in autocommit mode
Added:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java (with props)
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties (with props)
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.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=412831&r1=412830&r2=412831&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 Jun 8 11:31:45 2006
@@ -487,16 +487,9 @@
//if (onRow && !(currentRow instanceof org.apache.derby.impl.sql.execute.ValueRow))
// System.out.println(currentRow.getClass());
- /*
- Connection.setAutoCommit says that a statement completes,
- and will autoCommit, when it fetches the last row or is closed.
- This means a close will get a "Cursor already closed" error.
- This rule only applies when doing a next() - if it were applied
- to scrolling actions (like FIRST or LAST) it would close
- the cursor when doing any operation on a scrolling cursor.
-
- if autocommit, this will commit
- */
+ // The ResultSet may implicitly close when when the ResultSet type
+ // is TYPE_FORWARD_ONLY and the next method of ResultSet returns
+ // false. This will cause a commit if autocommit = true.
if (!onRow && (position == NEXT)) {
// In case of resultset for MetaData, we will only commit
@@ -514,9 +507,11 @@
if (forMetaData && (lcc.getActivationCount() > 1)) {
// we do not want to commit here as there seems to be other
// statements/resultSets currently opened for this connection.
- } else if (owningStmt != null)
+ } else if (owningStmt != null &&
+ owningStmt.getResultSetType() == TYPE_FORWARD_ONLY) {
// allow the satement to commit if required.
owningStmt.resultSetClosing(this);
+ }
}
// Clear the indication of which columns were fetched as streams.
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall?rev=412831&r1=412830&r2=412831&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall Thu Jun 8 11:31:45 2006
@@ -24,5 +24,6 @@
jdbcapi/UpdateXXXTest.junit
jdbcapi/SURQueryMixTest.junit
jdbcapi/SURTest.junit
+jdbcapi/ScrollResultSetTest.junit
jdbcapi/URCoveringIndexTest.junit
jdbcapi/SURTest_ij.sql
Added: 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=412831&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java Thu Jun 8 11:31:45 2006
@@ -0,0 +1,143 @@
+/*
+ *
+ * Derby - Class ScrollResultSetTest
+ *
+ * Copyright 2006 The Apache Software Foundation or its
+ * licensors, as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * 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.functionTests.util.SQLStateConstants;
+import junit.framework.*;
+import java.sql.*;
+
+/**
+ * Tests scrollable result sets
+ *
+ * @author Fernanda Pizzorno
+ *
+ * Tests:
+ * - testNextOnLastRowForwardOnly: tests that the result set is closed when all
+ * rows have been retreived and next has been called from the last row,
+ * autocommit = true, the result set is not holdable and type forward
+ * only. (DERBY-1295)
+ * - testNextOnLastRowScrollable: tests that the result set is not closed when
+ * next is called while the result set is positioned in the last row,
+ * autocommit = true, the result set is not holdable type scrollable
+ * insensitive. (DERBY-1295)
+ *
+ */
+public class ScrollResultSetTest extends BaseJDBCTestCase {
+
+ /** Creates a new instance of ScrollResultSetTest */
+ public ScrollResultSetTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up the connection to the database.
+ */
+ public void setUp() throws Exception {
+ con = getConnection();
+ con.setAutoCommit(true);
+
+ String createTableWithPK = "CREATE TABLE tableWithPK (" +
+ "c1 int primary key," +
+ "c2 int)";
+ String insertData = "INSERT INTO tableWithPK values " +
+ "(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)";
+ Statement stmt = con.createStatement();
+ stmt.execute(createTableWithPK);
+
+ stmt.execute(insertData);
+ }
+
+ /**
+ * Drop the table
+ */
+ public void tearDown() throws Exception {
+ println("TearDown");
+ try {
+ con.createStatement().executeUpdate("DROP TABLE tableWithPK");
+ con.commit();
+ con.close();
+ } catch (SQLException e) {
+ printStackTrace(e);
+ }
+ }
+
+ /**
+ * Test that moving to next row after positioned at the last row on a
+ * forward only result set will close the result set
+ */
+ public void testNextOnLastRowForwardOnly() throws SQLException{
+
+ con.setAutoCommit(true);
+ con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+ Statement roStmt = con.createStatement(
+ ResultSet.TYPE_FORWARD_ONLY,
+ ResultSet.CONCUR_READ_ONLY);
+
+ ResultSet rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK");
+
+ // call next until positioned after last
+ while (rs.next());
+
+ try {
+ // forward only result set should be closed now, an exception will
+ // be thrown
+ rs.next();
+ assertTrue("Excepted exception to be thrown - result set is closed",
+ false);
+ } catch (SQLException se) {
+ if (!usingDerbyNet()) {
+ assertSQLState("Unexpected SQL State",
+ SQLStateConstants.RESULT_SET_IS_CLOSED, se);
+ }
+ }
+
+ }
+
+ /**
+ * Test that moving to next row after positioned at the last row on a
+ * scrollable result set will not close the result set
+ */
+ public void testNextOnLastRowScrollable() throws SQLException{
+
+ con.setAutoCommit(true);
+ con.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
+ Statement roStmt = con.createStatement(
+ ResultSet.TYPE_SCROLL_INSENSITIVE,
+ ResultSet.CONCUR_READ_ONLY);
+
+ ResultSet rs = roStmt.executeQuery("SELECT c1 FROM tableWithPK");
+ // move to last position and then call next
+ rs.last();
+ rs.next();
+
+ // scrollable result set should still be open and not throw no
+ // exception will be thrown
+ assertFalse("Calling next while positioned after last returns " +
+ "false", rs.next());
+ assertTrue("Moving to absolute(2) returns true", rs.absolute(2));
+ rs.close();
+
+ }
+
+ /* Connection established in setUp() */
+ protected Connection con = null;
+
+}
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties?rev=412831&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties Thu Jun 8 11:31:45 2006
@@ -0,0 +1,3 @@
+runwithibm13=false
+runwithjdk13=false
+runwithjdk12=false
Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ScrollResultSetTest_app.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml?rev=412831&r1=412830&r2=412831&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/build.xml Thu Jun 8 11:31:45 2006
@@ -82,6 +82,7 @@
<exclude name="${this.dir}/xaJNDI.java"/>
<exclude name="${this.dir}/lobStreams.java"/>
<exclude name="${this.dir}/XATest.java"/>
+ <exclude name="${this.dir}/ScrollResultSetTest.java"/>
</javac>
</target>
@@ -101,6 +102,7 @@
destdir="${out.dir}">
<classpath>
<pathelement path="${java14compile.classpath}"/>
+ <pathelement path="${junit}"/>
</classpath>
<!--exclude name=""/-->
<include name="${this.dir}/autoGeneratedJdbc30.java"/>
@@ -113,6 +115,7 @@
<include name="${this.dir}/statementJdbc30.java"/>
<include name="${this.dir}/lobStreams.java"/>
<include name="${this.dir}/XATest.java"/>
+ <include name="${this.dir}/ScrollResultSetTest.java"/>
</javac>
</target>
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java?rev=412831&r1=412830&r2=412831&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/SQLStateConstants.java Thu Jun 8 11:31:45 2006
@@ -336,6 +336,8 @@
= "01004";
public static final String WITH_CHECK_OPTION_VIOLATION_NO_SUBCLASS
= "44000";
+ // The SQLState when calling next on a result set which is closed.
+ public static final String RESULT_SET_IS_CLOSED = "XCL16";
//The SQLState of the SQLExcepion thrown when a class for which
//isWrapperFor returns false is passed as a parameter to the
//unwrap method.