db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r1539540 - in /db/derby/code/trunk/java/client/org/apache/derby/client: am/ClientConnection.java am/ClientPreparedStatement.java am/ClientResultSet.java am/ClientStatement.java am/MaterialStatement.java net/NetResultSet.java
Date Thu, 07 Nov 2013 07:47:59 GMT
Author: dyre
Date: Thu Nov  7 07:47:58 2013
New Revision: 1539540

URL: http://svn.apache.org/r1539540
Log:
DERBY-6082: Removed re-prepares trigged by openOnServer_

Changed piggy-backing of prepare of preparedStatementForAutogeneratedKeys_ so that it doesn't
need openOnServer_ 

Removed MaterialStatement.markClosedOnServer and implementation since it did not do anything.

Since this reduced ClientStatement.markClosedOnServer() to a cleanup-method for section_,
it was removed and section_ was encapsulated as a private member where setSection is responsible
for cleanup.

Patch file derby-6082a.diff. (+ review comment) 

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientConnection.java Thu Nov
 7 07:47:58 2013
@@ -1187,8 +1187,7 @@ public abstract class ClientConnection
             // cached isolation level to TRANSACTION_UNKNOWN which will trigger
             // a refresh from the server.
             if (getTransactionIsolationPrepStmt == null  || 
-                    !(getTransactionIsolationPrepStmt.openOnClient_ &&
-                            getTransactionIsolationPrepStmt.openOnServer_)) {
+                    !getTransactionIsolationPrepStmt.openOnClient_) {
             	getTransactionIsolationPrepStmt =
                         prepareStatementX(
                                 "VALUES CURRENT ISOLATION",

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientPreparedStatement.java
Thu Nov  7 07:47:58 2013
@@ -200,7 +200,7 @@ public class ClientPreparedStatement ext
         isPreparedStatement_ = true;
 
         parseSqlAndSetSqlModes(sql_);
-        section_ = section;
+        setSection(section);
     }
 
     /**
@@ -279,9 +279,9 @@ public class ClientPreparedStatement ext
         if (cursorName != null) {
             positionedUpdateCursorName_ = cursorName;
             // Get a new section from the same package as the query section
-            section_ = agent_.sectionManager_.getPositionedUpdateSection(cursorName, false);
// false means get a regular section
+            setSection(agent_.sectionManager_.getPositionedUpdateSection(cursorName, false));
// false means get a regular section
 
-            if (section_ == null) {
+            if (getSection() == null) {
                 throw new SqlException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.CURSOR_INVALID_CURSOR_NAME), cursorName);
             }
@@ -294,16 +294,16 @@ public class ClientPreparedStatement ext
             // if the cursor name supplied in the sql string is different from the cursorName
             // set by setCursorName(), then server will return "cursor name not defined"
error,
             // and no subsititution is made here.
-            if (section_.getClientCursorName() != null && // cursor name is user
defined
-                    cursorName.compareTo(section_.getClientCursorName()) == 0)
+            if (getSection().getClientCursorName() != null && // cursor name is user
defined
+                    cursorName.compareTo(getSection().getClientCursorName()) == 0)
             // client's cursor name is substituted with section's server cursor name
             {
-                sql_ = substituteClientCursorNameWithServerCursorName(sql_, section_);
+                sql_ = substituteClientCursorNameWithServerCursorName(sql_, getSection());
             }
         } else {
             // We don't need to analyze the sql text to determine if it is a query or not.
             // This is up to the server to decide, we just pass thru the sql on flowPrepare().
-            section_ = agent_.sectionManager_.getDynamicSection(resultSetHoldability_);
+            setSection(agent_.sectionManager_.getDynamicSection(resultSetHoldability_));
         }
     }
 
@@ -1904,8 +1904,8 @@ public class ClientPreparedStatement ext
 
     private void writePrepareDescribeInputOutput() throws SqlException {
         // Notice that sql_ is passed in since in general ad hoc sql must be passed in for
unprepared statements
-        writePrepareDescribeOutput(sql_, section_);
-        writeDescribeInput(section_);
+        writePrepareDescribeOutput(sql_, getSection());
+        writeDescribeInput(getSection());
     }
 
     private void readPrepareDescribeInputOutput() throws SqlException {
@@ -1917,8 +1917,8 @@ public class ClientPreparedStatement ext
     private void writePrepareDescribeInput() throws SqlException {
         // performance will be better if we flow prepare with output enable vs. prepare then
describe input for callable
         // Notice that sql_ is passed in since in general ad hoc sql must be passed in for
unprepared statements
-        writePrepare(sql_, section_);
-        writeDescribeInput(section_);
+        writePrepare(sql_, getSection());
+        writeDescribeInput(getSection());
     }
 
     private void readPrepareDescribeInput() throws SqlException {
@@ -2021,6 +2021,7 @@ public class ClientPreparedStatement ext
             boolean repositionedCursor = false;
             boolean timeoutSent = false;
             ClientResultSet scrollableRS = null;
+            boolean prepareSentForAutoGeneratedKeys = false;
 
             if (doWriteTimeout) {
                 timeoutArrayList.set(0, TIMEOUT_STATEMENT + timeout_);
@@ -2044,7 +2045,7 @@ public class ClientPreparedStatement ext
                 chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_;
 
                 boolean chainOpenQueryForAutoGeneratedKeys = (sqlUpdateMode_ == isInsertSql__
&& autoGeneratedKeys_ == RETURN_GENERATED_KEYS);
-                writeExecute(section_,
+                writeExecute(getSection(),
                         parameterMetaData_,
                         parameters_,
                         numInputColumns,
@@ -2053,8 +2054,13 @@ public class ClientPreparedStatement ext
                 ); // chain flag
 
                 if (chainOpenQueryForAutoGeneratedKeys) {
-                    prepareAutoGeneratedKeysStatement();
-                    writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_,
+                    if (preparedStatementForAutoGeneratedKeys_ == null) {
+                        preparedStatementForAutoGeneratedKeys_ =
+                                prepareAutoGeneratedKeysStatement(connection_);
+                        prepareSentForAutoGeneratedKeys = true;
+                    }
+                  
+                    writeOpenQuery(preparedStatementForAutoGeneratedKeys_.getSection(),
                             preparedStatementForAutoGeneratedKeys_.fetchSize_,
                             preparedStatementForAutoGeneratedKeys_.resultSetType_);
                 }
@@ -2076,7 +2082,7 @@ public class ClientPreparedStatement ext
                 break;
 
             case isQuery__:
-                writeOpenQuery(section_,
+                writeOpenQuery(getSection(),
                         fetchSize_,
                         resultSetType_,
                         numInputColumns,
@@ -2086,8 +2092,7 @@ public class ClientPreparedStatement ext
 
             case isCall__:
                 writeExecuteCall(outputRegistered_, // if no out/inout parameter, outputExpected
= false
-                        null,
-                        section_,
+                        null, getSection(),
                         fetchSize_,
                         false, // do not suppress ResultSets for regular CALLs
                         resultSetType_,
@@ -2124,7 +2129,10 @@ public class ClientPreparedStatement ext
                     readExecute();
 
                     if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ ==
RETURN_GENERATED_KEYS) {
-                        readPrepareAutoGeneratedKeysStatement();
+                        if (prepareSentForAutoGeneratedKeys) {
+                            preparedStatementForAutoGeneratedKeys_.materialPreparedStatement_.readPrepareDescribeOutput_();
+                        }
+          
                         preparedStatementForAutoGeneratedKeys_.readOpenQuery();
                         generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_;
                         preparedStatementForAutoGeneratedKeys_.resultSet_ = null;
@@ -2290,7 +2298,7 @@ public class ClientPreparedStatement ext
                     throw new SqlException(se);
                 }
 
-                writeExecute(section_,
+                writeExecute(getSection(),
                         parameterMetaData_,
                         parameters_,
                         numInputColumns,
@@ -2303,8 +2311,7 @@ public class ClientPreparedStatement ext
                     (Object [])null, updateCounts, null );
             } else {
                 writeExecuteCall(false, // no output expected for batched CALLs
-                        null, // no procedure name supplied for prepared CALLs
-                        section_,
+                        null, getSection(),
                         fetchSize_,
                         true, // suppress ResultSets for batch
                         resultSetType_,
@@ -2391,18 +2398,14 @@ public class ClientPreparedStatement ext
         }
     }
 
+    @Override
     public void completeLocalCommit(Iterator listenerIterator) {
-        if (section_ != null) {
-            openOnServer_ = false;
-        }
         listenerIterator.remove();
         listenToUnitOfWork_ = false;
     }
 
+    @Override
     public void completeLocalRollback(Iterator listenerIterator) {
-        if (section_ != null) {
-            openOnServer_ = false;
-        }
         listenerIterator.remove();
         listenToUnitOfWork_ = false;
     }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientResultSet.java Thu Nov
 7 07:47:58 2013
@@ -501,7 +501,7 @@ public abstract class ClientResultSet im
         // close cursor if autoCommit is true.
         autoCommitted_ = false;
         if (generatedSection_ == null) { // none call statement result set case
-            writeCursorClose_(statement_.section_);
+            writeCursorClose_(statement_.getSection());
         } else { // call statement result set(s) case
             writeCursorClose_(generatedSection_);
         }
@@ -519,7 +519,7 @@ public abstract class ClientResultSet im
         // close cursor if autoCommit is true.
         autoCommitted_ = false;
         if (generatedSection_ == null) { // none call statement result set case
-            writeCursorClose_(statement_.section_);
+            writeCursorClose_(statement_.getSection());
         } else { // call statement result set(s) case
             writeCursorClose_(generatedSection_);
         }
@@ -1948,7 +1948,7 @@ public abstract class ClientResultSet im
                     return "stored procedure generated cursor:" + generatedSection_.getServerCursorName();
                 }
                 if (statement_.cursorName_ == null) {// cursor name is not assigned yet
-                    statement_.cursorName_ = statement_.section_.getServerCursorName();
+                    statement_.cursorName_ = statement_.getSection().getServerCursorName();
                 }
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "getCursorName", statement_.cursorName_);
@@ -4054,7 +4054,7 @@ public abstract class ClientResultSet im
 
         // if rowToFetch is zero, already positioned on the current row
         if (rowToFetch != 0) {
-            writePositioningFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+            writePositioningFetch_((generatedSection_ == null) ? statement_.getSection()
: generatedSection_,
                     scrollOrientation_relative__,
                     rowToFetch);
             // adjust the absolute position on the client
@@ -4072,7 +4072,7 @@ public abstract class ClientResultSet im
         try {
             agent_.beginWriteChain(statement_);
 
-            writePositioningFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+            writePositioningFetch_((generatedSection_ == null) ? statement_.getSection()
: generatedSection_,
                     scrollOrientation,
                     rowToFetch);
 
@@ -4096,16 +4096,10 @@ public abstract class ClientResultSet im
         if (resultSetType_ != ResultSet.TYPE_FORWARD_ONLY &&
                 (currentRowPosRelativeToAbsoluteRowPos != 0 ||
                 (currentRowPosRelativeToAbsoluteRowPos == 0 && cursorUnpositionedOnServer_)))
{
-            writePositioningFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+            writePositioningFetch_((generatedSection_ == null) ? statement_.getSection()
: generatedSection_,
                     scrollOrientation_relative__,
                     currentRowPosRelativeToAbsoluteRowPos);
         }
-
-        // re-prepare the update statement if repreparing is needed after a commit.
-        if (!preparedStatementForUpdate_.openOnServer_) {
-            preparedStatementForUpdate_.materialPreparedStatement_.writePrepare_(preparedStatementForUpdate_.sql_,
-                    preparedStatementForUpdate_.section_);
-        }
         
         try {
             writeUpdateRow(false);
@@ -4127,10 +4121,6 @@ public abstract class ClientResultSet im
             listenToUnitOfWork();
         }
 
-        // read prepare replies if the update statement is re-prepared after a commit.
-        if (!preparedStatementForUpdate_.openOnServer_) {
-            preparedStatementForUpdate_.materialPreparedStatement_.readPrepare_();
-        }
         readUpdateRow();
 
         agent_.endReadChain();
@@ -4139,13 +4129,6 @@ public abstract class ClientResultSet im
     private void insert() throws SqlException {
         agent_.beginWriteChain(statement_);
 
-        // re-prepare the insert statement if repreparing is needed after a commit.
-        if (!preparedStatementForInsert_.openOnServer_) {
-            preparedStatementForInsert_.materialPreparedStatement_.writePrepare_(
-                    preparedStatementForInsert_.sql_,
-                    preparedStatementForInsert_.section_);
-        }
-
         try {
             writeInsertRow(false);
         } catch (SQLException se ) {
@@ -4154,11 +4137,6 @@ public abstract class ClientResultSet im
 
         agent_.flow(statement_);
 
-        // read prepare replies if the update statement is re-prepared after a commit.
-        if (!preparedStatementForInsert_.openOnServer_) {
-            preparedStatementForInsert_.materialPreparedStatement_.readPrepare_();
-        }
-
         readInsertRow();
 
         agent_.endReadChain();
@@ -4168,12 +4146,6 @@ public abstract class ClientResultSet im
     private void update() throws SqlException {
         agent_.beginWriteChain(statement_);
 
-        // re-prepare the update statement if repreparing is needed after a commit.
-        if (!preparedStatementForUpdate_.openOnServer_) {
-            preparedStatementForUpdate_.materialPreparedStatement_.writePrepare_(preparedStatementForUpdate_.sql_,
-                    preparedStatementForUpdate_.section_);
-        }
-
         if (isRowsetCursor_) {
             try {
                 preparedStatementForUpdate_.setInt(updatedColumns_.length + 1, (int) (currentRowInRowset_
+ 1));
@@ -4194,11 +4166,6 @@ public abstract class ClientResultSet im
 
         agent_.flow(statement_);
 
-        // read prepare replies if the update statement is re-prepared after a commit.
-        if (!preparedStatementForUpdate_.openOnServer_) {
-            preparedStatementForUpdate_.materialPreparedStatement_.readPrepare_();
-        }
-
         readUpdateRow();
 
         if (chainAutoCommit) {
@@ -4218,17 +4185,11 @@ public abstract class ClientResultSet im
         if (resultSetType_ != ResultSet.TYPE_FORWARD_ONLY &&
                 (currentRowPosRelativeToAbsoluteRowPos != 0 ||
                 (currentRowPosRelativeToAbsoluteRowPos == 0 && cursorUnpositionedOnServer_)))
{
-            writePositioningFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+            writePositioningFetch_((generatedSection_ == null) ? statement_.getSection()
: generatedSection_,
                     scrollOrientation_relative__,
                     currentRowPosRelativeToAbsoluteRowPos);
         }
 
-        // re-prepare the update statement if repreparing is needed after a commit.
-        if (!preparedStatementForDelete_.openOnServer_) {
-            preparedStatementForDelete_.materialPreparedStatement_.writePrepare_(preparedStatementForDelete_.sql_,
-                    preparedStatementForDelete_.section_);
-        }
-
         try {
             writeDeleteRow();
         } catch ( SQLException sqle ) {
@@ -4248,10 +4209,6 @@ public abstract class ClientResultSet im
             listenToUnitOfWork();
         }
 
-        // read prepare replies if the update statement is re-prepared after a commit.
-        if (!preparedStatementForDelete_.openOnServer_) {
-            preparedStatementForDelete_.materialPreparedStatement_.readPrepare_();
-        }
         readDeleteRow();
 
         agent_.endReadChain();
@@ -4262,12 +4219,6 @@ public abstract class ClientResultSet im
         {
             agent_.beginWriteChain(statement_);
 
-            // re-prepare the update statement if repreparing is needed after a commit.
-            if (!preparedStatementForDelete_.openOnServer_) {
-                preparedStatementForDelete_.materialPreparedStatement_.writePrepare_(preparedStatementForDelete_.sql_,
-                        preparedStatementForDelete_.section_);
-            }
-
             if (isRowsetCursor_) {
                 preparedStatementForDelete_.setInt(1, (int) (currentRowInRowset_ + 1));
             }
@@ -4280,10 +4231,6 @@ public abstract class ClientResultSet im
 
             agent_.flow(statement_);
 
-            // read prepare replies if the update statement is re-prepared after a commit.
-            if (!preparedStatementForDelete_.openOnServer_) {
-                preparedStatementForDelete_.materialPreparedStatement_.readPrepare_();
-            }
             readDeleteRow();
             if (connection_.autoCommit_) {
                 connection_.readAutoCommit();
@@ -4349,7 +4296,7 @@ public abstract class ClientResultSet im
         try
         {
             preparedStatementForInsert_.materialPreparedStatement_.writeExecute_(
-                    preparedStatementForInsert_.section_,
+                    preparedStatementForInsert_.getSection(),
                     preparedStatementForInsert_.parameterMetaData_,
                     preparedStatementForInsert_.parameters_,
                     (preparedStatementForInsert_.parameterMetaData_ == null ? 0 : 
@@ -4367,7 +4314,7 @@ public abstract class ClientResultSet im
             throws SQLException {
         try
         {
-            preparedStatementForUpdate_.materialPreparedStatement_.writeExecute_(preparedStatementForUpdate_.section_,
+            preparedStatementForUpdate_.materialPreparedStatement_.writeExecute_(preparedStatementForUpdate_.getSection(),
                     preparedStatementForUpdate_.parameterMetaData_,
                     preparedStatementForUpdate_.parameters_,
                     preparedStatementForUpdate_.parameterMetaData_.getColumnCount(),
@@ -4384,14 +4331,14 @@ public abstract class ClientResultSet im
         try
         {
             if (isRowsetCursor_) {
-                preparedStatementForDelete_.materialPreparedStatement_.writeExecute_(preparedStatementForDelete_.section_,
+                preparedStatementForDelete_.materialPreparedStatement_.writeExecute_(preparedStatementForDelete_.getSection(),
                         preparedStatementForDelete_.parameterMetaData_,
                         preparedStatementForDelete_.parameters_,
                         preparedStatementForDelete_.parameterMetaData_.getColumnCount(),
                         false, // false means we're not expecting output
                         false);  // false means we don't chain anything after the execute
             } else {
-                preparedStatementForDelete_.materialPreparedStatement_.writeExecute_(preparedStatementForDelete_.section_,
+                preparedStatementForDelete_.materialPreparedStatement_.writeExecute_(preparedStatementForDelete_.getSection(),
                         null, // do not need parameterMetaData since there is no input
                         null, // no inputs
                         0, // number of input columns is 0 for positioned delete
@@ -4709,7 +4656,7 @@ public abstract class ClientResultSet im
     }
 
     private String getServerCursorName() throws SqlException {
-        return statement_.section_.getServerCursorName();
+        return statement_.getSection().getServerCursorName();
     }
 
     private void getPreparedStatementForInsert() throws SqlException {
@@ -4734,7 +4681,7 @@ public abstract class ClientResultSet im
         }
         preparedStatementForUpdate_ =
                 statement_.connection_.preparePositionedUpdateStatement(updateString,
-                        statement_.section_.getPositionedUpdateSection());
+                        statement_.getSection().getPositionedUpdateSection());
 
     }
 
@@ -4744,7 +4691,7 @@ public abstract class ClientResultSet im
 
         preparedStatementForDelete_ =
                 statement_.connection_.preparePositionedUpdateStatement(deleteString,
-                        statement_.section_.getPositionedUpdateSection()); // update section
+                        statement_.getSection().getPositionedUpdateSection()); // update
section
     }
 
     private final void resetUpdatedColumnsForInsert() {
@@ -5002,7 +4949,7 @@ public abstract class ClientResultSet im
 
         agent_.beginWriteChain(statement_);
 
-        Section section = (generatedSection_ == null) ? statement_.section_ : generatedSection_;
+        Section section = (generatedSection_ == null) ? statement_.getSection() : generatedSection_;
 
         // send the first CNTQRY to place cursor after last to retrieve the rowCount_.
         writePositioningFetch_(section, scrollOrientation_after__, 0);
@@ -5039,7 +4986,7 @@ public abstract class ClientResultSet im
         cursor_.resetDataBuffer();
         agent_.beginWriteChain(statement_);
         
-        writeScrollableFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+        writeScrollableFetch_((generatedSection_ == null) ? statement_.getSection() : generatedSection_,
                 fetchSize_,
                 orientation,
                 rowNumber,

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientStatement.java Thu Nov
 7 07:47:58 2013
@@ -66,7 +66,7 @@ public class ClientStatement implements 
     }
 
     ClientConnection connection_;
-    public Section section_;
+    private Section section_;
     Agent agent_;
 
     /** The owner of this statement, if any. */
@@ -141,13 +141,6 @@ public class ClientStatement implements 
     // This value is set to true when the statement object is constructed, and will not change
     // until statement.close() is called either directly or via connection.close(), finalizer,
or other methods.
     boolean openOnClient_ = true;
-    // This means a DERBY server-side section for this statement is in the prepared state.
-    // A client-side jdbc statement may remain open across commits (openOnClient=true),
-    // but the server-side DERBY section moves to an unprepared state (openOnServer=false)
across commits,
-    // requiring an implicit re-prepare "under the covers" by the driver.
-    // Unprepared jdbc query statements still have prepared sections on the server.
-    // This openOnServer_ only has implications for preparedstatement
-    boolean openOnServer_ = false;
 
 
     private int indexOfCurrentResultSet_ = -1;
@@ -265,7 +258,6 @@ public class ClientStatement implements 
         resultSet_ = null;
         updateCount_ = -1L;
         openOnClient_ = true;
-        openOnServer_ = false;
         indexOfCurrentResultSet_ = -1;
         resultSetList_ = null;
         isCatalogQuery_ = false;
@@ -1766,7 +1758,6 @@ public class ClientStatement implements 
         if (sqlca != null && sqlca.getSqlCode() < 0) {
             return;
         }
-        openOnServer_ = true;
         resultSet.cursor_.rowsRead_ = fetchedRowBase;
 
         // Set fetchSize_ to the default(64) if not set by the user if the resultset is scrollable.
@@ -1798,7 +1789,6 @@ public class ClientStatement implements 
         if (sqlca != null && sqlca.getSqlCode() < 0) {
             return;
         }
-        openOnServer_ = true;
         resultSet.cursor_.rowsRead_ = fetchedRowBase;
 
         resultSet.generatedSection_ = generatedSection;
@@ -2126,20 +2116,6 @@ public class ClientStatement implements 
     public void completeExecuteSetStatement(Sqlca sqlca) {
     }
 
-    private void markClosedOnServer() {
-        if (section_ != null) {
-            section_.free();
-            section_ = null;
-        }
-        openOnServer_ = false;
-        // if an error occurs during the middle of the reset, before the statement
-        // has a chance to reset its materialStatement_, and Agent.disconnectEvent() is called,
-        // then the materialStatement_ here can be null.
-        if (materialStatement_ != null) {
-            materialStatement_.markClosedOnServer_();
-        }
-    }
-
     /**
      * This method cleans up client-side resources held by this Statement. 
      * The Statement will not be removed from the open statements list and 
@@ -2147,7 +2123,7 @@ public class ClientStatement implements 
      * listeners list in <code>org.apache.derby.client.am.Connection</code>.
      * 
      * This method is called from:
-     * 1. finalize() - For the finaizer to be called, the Statement 
+     * 1. finalize() - For the finalizer to be called, the Statement 
      * should not have any references and so it should have been already 
      * removed from the lists.  
      * 
@@ -2191,7 +2167,7 @@ public class ClientStatement implements 
         // cursorName form the cache.
         removeClientCursorNameFromCache();
         markPreparedStatementForAutoGeneratedKeysClosed();
-        markClosedOnServer();
+        setSection(null);
 
         // mark close ResultSetMetaData
         if (resultSetMetaData_ != null) {
@@ -2287,6 +2263,7 @@ public class ClientStatement implements 
             ClientResultSet scrollableRS = null;
             Section newSection = null;
             boolean repositionedCursor = false;
+            boolean prepareSentForAutoGeneratedKeys = false;
 
             // DERBY-1692: Statement objects need to send the timeout value for
             // each execution since the server will create a new statement
@@ -2350,8 +2327,12 @@ public class ClientStatement implements 
                     writeExecuteImmediate(sql, newSection);
                     if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ ==
RETURN_GENERATED_KEYS) {
                         // chain a "select from identity_val_local()" to the insert statement
-                        prepareAutoGeneratedKeysStatement();
-                        writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_,
+                        if (preparedStatementForAutoGeneratedKeys_ == null) {
+                            preparedStatementForAutoGeneratedKeys_ =
+                                 prepareAutoGeneratedKeysStatement(connection_);
+                            prepareSentForAutoGeneratedKeys = true;
+                        }
+                        writeOpenQuery(preparedStatementForAutoGeneratedKeys_.getSection(),
                                 preparedStatementForAutoGeneratedKeys_.fetchSize_,
                                 preparedStatementForAutoGeneratedKeys_.resultSetType_);
                     }
@@ -2384,8 +2365,7 @@ public class ClientStatement implements 
             }
 
             markResultSetsClosed(true); // true means remove from list of commit and rollback
listeners
-            markClosedOnServer();
-            section_ = newSection;
+            setSection(newSection);
 
             switch (sqlMode_) {
             case isQuery__:
@@ -2420,7 +2400,9 @@ public class ClientStatement implements 
                 readExecuteImmediate();
 
                 if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS)
{
-                    readPrepareAutoGeneratedKeysStatement();
+                    if (prepareSentForAutoGeneratedKeys) {
+                        preparedStatementForAutoGeneratedKeys_.materialPreparedStatement_.readPrepareDescribeOutput_();
+                    }
                     preparedStatementForAutoGeneratedKeys_.readOpenQuery();
                     generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_;
                     preparedStatementForAutoGeneratedKeys_.resultSet_ = null;
@@ -2487,15 +2469,11 @@ public class ClientStatement implements 
             // need to trap the exceptions coming back from writeExecuteImmediate and continue
on with a -3
             // net will need to be able to reset the send buffer
             if (flowSQL) {
-                if (section_ != null) {
-                    section_.free();
-                }
                 if (sqlMode_ != isCall__) {
-                    section_ =
-                            agent_.sectionManager_.getDynamicSection(resultSetHoldability_);
-                    writeExecuteImmediate(sql, section_);
+                    setSection(agent_.sectionManager_.getDynamicSection(resultSetHoldability_));
+                    writeExecuteImmediate(sql, getSection());
                 } else {
-                    section_ = writeExecuteCall(sql, true);
+                    setSection(writeExecuteCall(sql, true));
                 }
             }
         }
@@ -2603,8 +2581,6 @@ public class ClientStatement implements 
     }
 
     private void markPrepared() {
-        //openOnClient_ = true;
-        openOnServer_ = true;
         listenToUnitOfWork();
     }
 
@@ -2958,8 +2934,8 @@ public class ClientStatement implements 
             // whenever the result set produced by this statement
             // is referenced in a positioned update/delete statement.
             agent_.sectionManager_.mapCursorNameToQuerySection
-                (cursorName_, section_);
-            section_.setClientCursorName(cursorName_);
+                (cursorName_, getSection());
+            getSection().setClientCursorName(cursorName_);
             
             // Update cache to avoid duplicates of user set cursor name.
             connection_.clientCursorNameCache_.put(cursorName_, 
@@ -2967,7 +2943,7 @@ public class ClientStatement implements 
         } else {
         // canned cursor name
         agent_.sectionManager_.mapCursorNameToQuerySection
-                (section_.getServerCursorName(), section_);
+                (getSection().getServerCursorName(), getSection());
     }
 
         // If client's cursor name is set, map the client's cursor name to the
@@ -3043,17 +3019,17 @@ public class ClientStatement implements 
         // If Statement.close() is called before ResultSet.close(), then statement_.section
is null.
         if (section_ != null) {
             agent_.sectionManager_.removeCursorNameToResultSetMapping(cursorName_,
-                    section_.getServerCursorNameForPositionedUpdate());
+                    getSection().getServerCursorNameForPositionedUpdate());
 
             // remove resultset mapping for other cursors (other than positioned
             // update statements) - DERBY-210
             agent_.sectionManager_.removeCursorNameToResultSetMapping(cursorName_,
-                    section_.getServerCursorName());
+                    getSection().getServerCursorName());
 
             // Remove client and server cursorName -> QuerySection mapping from the hashtable
             // if one exists
             agent_.sectionManager_.removeCursorNameToQuerySectionMapping(cursorName_,
-                    section_.getServerCursorNameForPositionedUpdate());
+                    getSection().getServerCursorNameForPositionedUpdate());
         }
 
         // client cursor name will be set to null when it is removed from the
@@ -3065,7 +3041,7 @@ public class ClientStatement implements 
         if (cursorName_ != null) {
             agent_.sectionManager_.mapCursorNameToResultSet(cursorName_, resultSet_);
         } else {
-            agent_.sectionManager_.mapCursorNameToResultSet(section_.getServerCursorName(),
resultSet_);
+            agent_.sectionManager_.mapCursorNameToResultSet(getSection().getServerCursorName(),
resultSet_);
         }
     }
 
@@ -3121,14 +3097,12 @@ public class ClientStatement implements 
                 : cursorAttributes.toString();
     }
 
-  
-
-    private void getPreparedStatementForAutoGeneratedKeys()
+    protected static ClientPreparedStatement 
+            prepareAutoGeneratedKeysStatement(ClientConnection cc) 
             throws SqlException {
-        if (preparedStatementForAutoGeneratedKeys_ == null) {
-            String s = "select IDENTITY_VAL_LOCAL() from SYSIBM.SYSDUMMY1";
-            preparedStatementForAutoGeneratedKeys_ =
-                    connection_.newPreparedStatement_(s,
+        String s = "select IDENTITY_VAL_LOCAL() from SYSIBM.SYSDUMMY1";
+        ClientPreparedStatement cps =
+                    cc.newPreparedStatement_(s,
                             ResultSet.TYPE_FORWARD_ONLY,
                             ResultSet.CONCUR_READ_ONLY,
                             ResultSet.HOLD_CURSORS_OVER_COMMIT,
@@ -3139,24 +3113,10 @@ public class ClientStatement implements 
             //  We need to figure how some way to get code reuse here, ie. to consolidate
to just one special casing rather than two?
             // Maybe just call prepareStatementX() or use some special purpose prepare method
like the ones in Connection.
             // Something more abstract so that we don't have to special case the WITH HOLD
thing twice.
-            StringBuffer cursorAttributes = new StringBuffer();
-            cursorAttributes.append(Configuration.cursorAttribute_WithHold);
-            preparedStatementForAutoGeneratedKeys_.cursorAttributesToSendOnPrepare_ = cursorAttributes.toString();
-        }
-    }
-
-    void prepareAutoGeneratedKeysStatement() throws SqlException {
-        getPreparedStatementForAutoGeneratedKeys();
-        if (!preparedStatementForAutoGeneratedKeys_.openOnServer_) {
-            preparedStatementForAutoGeneratedKeys_.materialPreparedStatement_.writePrepareDescribeOutput_(preparedStatementForAutoGeneratedKeys_.sql_,
-                    preparedStatementForAutoGeneratedKeys_.section_);
-        }
-    }
-
-    void readPrepareAutoGeneratedKeysStatement() throws SqlException {
-        if (!preparedStatementForAutoGeneratedKeys_.openOnServer_) {
-            preparedStatementForAutoGeneratedKeys_.materialPreparedStatement_.readPrepareDescribeOutput_();
-        }
+            
+            cps.cursorAttributesToSendOnPrepare_ = Configuration.cursorAttribute_WithHold;

+            cps.materialPreparedStatement_.writePrepareDescribeOutput_(cps.sql_, cps.getSection());
+            return cps;
     }
 
     void checkAutoGeneratedKeysParameters() throws SqlException {
@@ -3340,4 +3300,24 @@ public class ClientStatement implements 
     void resetResultSetList() {
         indexOfCurrentResultSet_ = -1; //reset ResultSetList
     }
+
+    /**
+     * Provides public access for section_. This is necessary as the section concept
+     * is shared between client.am and net. Seems like it really belongs in net
+     * as it is tied to the particular protocol used.
+     * @return section_
+     */
+    public Section getSection() {
+        return section_;
+    }
+
+    /**
+     * Assigns a new value (even null) to section_.
+     * The existing section_ (if any) is freed.
+     * @param s the section_ to set. 
+     */
+    protected void setSection(Section s) {
+        if (section_ != null) { section_.free(); }
+        section_ = s;
+    }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/MaterialStatement.java Thu
Nov  7 07:47:58 2013
@@ -61,8 +61,6 @@ public interface MaterialStatement {
 
     public abstract void readPrepare_() throws SqlException;
 
-    public abstract void markClosedOnServer_();
-
     public abstract void writeSetSpecialRegister_(
         Section section, ArrayList sqlsttList) throws SqlException;
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java?rev=1539540&r1=1539539&r2=1539540&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetResultSet.java Thu Nov
 7 07:47:58 2013
@@ -172,7 +172,7 @@ class NetResultSet extends ClientResultS
         try {
             agent_.beginWriteChain(statement_);
 
-            writeScrollableFetch_((generatedSection_ == null) ? statement_.section_ : generatedSection_,
+            writeScrollableFetch_((generatedSection_ == null) ? statement_.getSection() :
generatedSection_,
                     fetchSize_ - rowsReceivedInCurrentRowset_,
                     scrollOrientation_relative__,
                     1,
@@ -267,7 +267,7 @@ class NetResultSet extends ClientResultS
     void flowFetch() throws DisconnectException, SqlException {
         agent_.beginWriteChain(statement_);
         writeFetch_((generatedSection_ == null) ?
-                statement_.section_ :
+                statement_.getSection() :
                 generatedSection_);
         agent_.flow(statement_);
         readFetch_();



Mime
View raw message