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 ka...@apache.org on 2006/04/18 08:41:04 UTC

svn commit: r394859 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/ testing/org/apache/derbyTesting/functionTests/master/DerbyNet/ testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/ testing/org/apache/derbyTesting/fun...

Author: kahatlen
Date: Mon Apr 17 23:41:04 2006
New Revision: 394859

URL: http://svn.apache.org/viewcvs?rev=394859&view=rev
Log:
DERBY-822: Client driver: Pre-fetch data on executeQuery()

This patch makes the network server include query data when it replies
to an OPNQRY command. (Query data is only included when there are no
LOB columns and the protocol is limited block protocol.)

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/supersimple.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/forupdate.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/supersimple.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/values1.inc

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Mon Apr 17 23:41:04 2006
@@ -574,6 +574,41 @@
 		}
 	}
 
+    /**
+     * Cleans up and closes a result set if an exception is thrown
+     * when collecting QRYDTA in response to OPNQRY or CNTQRY.
+     *
+     * @param stmt the DRDA statement to clean up
+     * @param sqle the exception that was thrown
+     * @param writerMark start index for the first DSS to clear from
+     * the output buffer
+     * @exception DRDAProtocolException if a DRDA protocol error is
+     * detected
+     */
+    private void cleanUpAndCloseResultSet(DRDAStatement stmt,
+                                          SQLException sqle,
+                                          int writerMark)
+        throws DRDAProtocolException
+    {
+        if (stmt != null) {
+            writer.clearDSSesBackToMark(writerMark);
+            if (!stmt.rsIsClosed()) {
+                try {
+                    stmt.rsClose();
+                } catch (SQLException ec) {
+                    if (SanityManager.DEBUG) {
+                        trace("Warning: Error closing result set");
+                    }
+                }
+                writeABNUOWRM();
+                writeSQLCARD(sqle, CodePoint.SVRCOD_ERROR, 0, 0);
+            }
+        } else {
+            writeSQLCARDs(sqle, 0);
+        }
+        errorInChain(sqle);
+    }
+
 	/**
 	 * Process DRDA commands we can receive once server attributes have been
 	 * exchanged.
@@ -614,30 +649,9 @@
 					}
 					catch(SQLException e)
 					{
-						if (stmt != null)
- 						{
-							// if we got a SQLException we need to clean up and
- 							// close the statement Beetle 4758
-							writer.clearDSSesBackToMark(writerMark);
- 							if (! stmt.rsIsClosed())
- 							{
- 								try {
- 									stmt.rsClose();
- 								}
- 								catch (SQLException ec)
- 								{
- 									if (SanityManager.DEBUG)
- 										trace("Warning: Error closing statement");
-								}
-								writeABNUOWRM();
-								writeSQLCARD(e,CodePoint.SVRCOD_ERROR,0,0);
-							}
-						}
-						else 
-						{
-							writeSQLCARDs(e, 0);
-						}
-						errorInChain(e);
+						// if we got a SQLException we need to clean up and
+						// close the result set Beetle 4758
+						cleanUpAndCloseResultSet(stmt, e, writerMark);
 					}
 					break;
 				case CodePoint.EXCSQLIMM:
@@ -737,11 +751,25 @@
 							checkWarning(null, ps, null, 0, false, true);
 
 							writeQRYDSC(stmt, false);
-							// We could send QRYDTA here if there's no LOB data
-							// in the result set, and if we are using LMTBLKPRC, as
-							// allowed by drda spec, as an option.
 
 							stmt.rsSuspend();
+
+							if (stmt.getQryprctyp() == CodePoint.LMTBLKPRC) {
+								// The DRDA spec allows us to send
+								// QRYDTA here if there are no LOB
+								// columns.
+								DRDAResultSet drdars =
+									stmt.getCurrentDrdaResultSet();
+								try {
+									if (drdars != null &&
+										!drdars.hasLobColumns()) {
+										writeQRYDTA(stmt);
+									}
+								} catch (SQLException sqle) {
+									cleanUpAndCloseResultSet(stmt, sqle,
+															 writerMark);
+								}
+							}
 						}
 					}
 					catch (SQLException e)

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java Mon Apr 17 23:41:04 2006
@@ -439,7 +439,7 @@
 	 *  column; false otherwise.
 	 ****/
  
-	private boolean hasLobColumns()	throws SQLException
+	protected boolean hasLobColumns() throws SQLException
 	{
 		ResultSetMetaData rsmd = rs.getMetaData();
 		int ncols = rsmd.getColumnCount();
@@ -562,5 +562,15 @@
 		this.qryrowset = qryrowset;
 		this.qryclsimp = (qryclsimpl == CodePoint.QRYCLSIMP_SERVER_CHOICE)
 			? DRDAResultSet.QRYCLSIMP_DEFAULT : qryclsimpl;
+
+		// Assume that we are returning data until a CNTQRY command
+		// tells us otherwise. (DERBY-822)
+		qryrtndta = true;
+
+		// For scrollable result sets, we don't know the fetch
+		// orientation until we get a CNTQRY command. Set orientation
+		// and row number to make pre-fetching possible. (DERBY-822)
+		qryscrorn = CodePoint.QRYSCRREL;
+		qryrownbr = 1;
 	}
 }

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java Mon Apr 17 23:41:04 2006
@@ -306,13 +306,25 @@
 	
 
 	/**
-	 * Delegation method to call DRDAResultSet to set query 
-	 * options sent on OPNQRY.
+	 * Set query options sent on OPNQRY and pass options down to the
+	 * current <code>DRDAResultSet</code> object.
+	 *
+	 * @param blksize QRYBLKSZ (Query Block Size)
+	 * @param qryblkctl QRYPRCTYP (Query Protocol Type)
+	 * @param maxblkext MAXBLKEXT (Maximum Number of Extra Blocks)
+	 * @param outovropt OUTOVROPT (Output Override Option)
+	 * @param qryrowset QRYROWSET (Query Rowset Size)
+	 * @param qryclsimpl QRYCLSIMP (Query Close Implicit)
 	 * @see DRDAResultSet#setOPNQRYOptions(int, int, int, int, int, int)
 	 */
 	protected void setOPNQRYOptions(int blksize, int qryblkctl,
 								  int maxblkext, int outovropt,int qryrowset,int qryclsimpl)
 	{
+		this.blksize = blksize;
+		this.qryprctyp = qryblkctl;
+		this.maxblkext = maxblkext;
+		this.outovropt = outovropt;
+		this.qryrowset = qryrowset;
 		currentDrdaRs.setOPNQRYOptions( blksize, qryblkctl, maxblkext, 
 				outovropt, qryrowset, qryclsimpl);
 	}

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/supersimple.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/supersimple.out?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/supersimple.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/supersimple.out Mon Apr 17 23:41:04 2006
@@ -149,12 +149,8 @@
 NoHoldForConnection;
 ij(CONNECTION1)> prepare s1 as 'select * from t';
 ij(CONNECTION1)> execute s1;
-I          
------
 ERROR 40XL1: A lock could not be obtained within the time requested
 ij(CONNECTION1)> execute s1;
-I          
------
 ERROR 40XL1: A lock could not be obtained within the time requested
 ij(CONNECTION1)> -- Bug 5967 - Selecting from 2 lob columns w/ the first one having data of length 0
 create table t1 (c1 clob(10), c2 clob(10));

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/forupdate.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/forupdate.out?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/forupdate.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/forupdate.out Mon Apr 17 23:41:04 2006
@@ -43,7 +43,7 @@
 ----- with a 'cursor not updatable' message
 get cursor c as 'select i, v from t1, t2';
 ij> delete from t1 where current of c;
-ERROR 42X23: Cursor SQL_CURLH000C1 is not updatable.
+ERROR 42X30: Cursor 'SQL_CURLH000C1' not found. Verify that autocommit is OFF.
 ij> --  cursor with same name already exists
 get cursor c as 'select i, v from t1, t2';
 ERROR (no SQLState): Duplicate cursor names are not allowed.
@@ -62,13 +62,13 @@
 ----- we know because the delete is refused with a 'cursor not updatable' message
 get cursor c2 as 'select i, v from t1, t2 for read only';
 ij> delete from t1 where current of c2;
-ERROR 42X23: Cursor SQL_CURLH000C1 is not updatable.
+ERROR 42X30: Cursor 'SQL_CURLH000C1' not found. Verify that autocommit is OFF.
 ij> close c2;
 ij> -- . read only for updatable cursor spec
 ----- we know because the delete is refused with a 'cursor not updatable' message
 get cursor c3 as 'select i, v from t1 where i is not null for read only';
 ij> delete from t1 where current of c3;
-ERROR 42X23: Cursor SQL_CURLH000C1 is not updatable.
+ERROR 42X30: Cursor 'SQL_CURLH000C1' not found. Verify that autocommit is OFF.
 ij> close c3;
 ij> -- . for update col not in select list
 ----- this is allowed:

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/supersimple.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/supersimple.out?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/supersimple.out (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNetClient/supersimple.out Mon Apr 17 23:41:04 2006
@@ -149,12 +149,8 @@
 NoHoldForConnection;
 ij(CONNECTION1)> prepare s1 as 'select * from t';
 ij(CONNECTION1)> execute s1;
-I          
------
 ERROR 40XL1: A lock could not be obtained within the time requested
 ij(CONNECTION1)> execute s1;
-I          
------
 ERROR 40XL1: A lock could not be obtained within the time requested
 ij(CONNECTION1)> -- Bug 5967 - Selecting from 2 lob columns w/ the first one having data of length 0
 create table t1 (c1 clob(10), c2 clob(10));

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/values1.inc
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/values1.inc?rev=394859&r1=394858&r2=394859&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/values1.inc (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/values1.inc Mon Apr 17 23:41:04 2006
@@ -35,5 +35,12 @@
 endDdm
 endDss
 flush
-skipDss	//ignore OPNQRYRM
-skipDss	//ignore QRYDSC
+readReplyDss
+readLengthAndCodepoint OPNQRYRM
+skipBytes
+readReplyDss
+readLengthAndCodepoint QRYDSC
+skipBytes
+readReplyDss
+readLengthAndCodepoint QRYDTA
+skipBytes