preparedstatement.java
来自「derby database source code.good for you.」· Java 代码 · 共 1,533 行 · 第 1/5 页
JAVA
1,533 行
agent_.endReadChain(); } else { writePrepareDescribeInputOutput(); agent_.flow(this); readPrepareDescribeInputOutput(); agent_.endReadChain(); } } void flowExecute(int executeType) throws SqlException { super.checkForClosedStatement(); super.clearWarningsX(); super.checkForAppropriateSqlMode(executeType, sqlMode_); checkThatAllParametersAreSet(); if (sqlMode_ == isUpdate__) { updateCount_ = 0; } else { updateCount_ = -1; } java.util.Timer queryTimer = null; QueryTimerTask queryTimerTask = null; if (timeout_ != 0) { queryTimer = new java.util.Timer(); // A thread that ticks the seconds queryTimerTask = new QueryTimerTask(this, queryTimer); queryTimer.schedule(queryTimerTask, 1000 * timeout_); } try { agent_.beginWriteChain(this); boolean piggybackedAutocommit = super.writeCloseResultSets(true); // true means permit auto-commits int numInputColumns = (parameterMetaData_ != null) ? parameterMetaData_.getColumnCount() : 0; boolean outputExpected = (resultSetMetaData_ != null && resultSetMetaData_.getColumnCount() > 0); boolean chainAutoCommit = false; boolean commitSubstituted = false; boolean repositionedCursor = false; ResultSet scrollableRS = null; switch (sqlMode_) { case isUpdate__: if (positionedUpdateCursorName_ != null) { scrollableRS = agent_.sectionManager_.getPositionedUpdateResultSet(positionedUpdateCursorName_); } if (scrollableRS != null && !scrollableRS.isRowsetCursor_) { repositionedCursor = scrollableRS.repositionScrollableResultSetBeforeJDBC1PositionedUpdateDelete(); if (!repositionedCursor) { scrollableRS = null; } } chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_; if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { writeOpenQuery(section_, fetchSize_, resultSetType_, numInputColumns, parameterMetaData_, parameters_); } else { boolean chainOpenQueryForAutoGeneratedKeys = (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS); writeExecute(section_, parameterMetaData_, parameters_, numInputColumns, outputExpected, (chainAutoCommit || chainOpenQueryForAutoGeneratedKeys)// chain flag ); // chain flag if (chainOpenQueryForAutoGeneratedKeys) { prepareAutoGeneratedKeysStatement(); writeOpenQuery(preparedStatementForAutoGeneratedKeys_.section_, preparedStatementForAutoGeneratedKeys_.fetchSize_, preparedStatementForAutoGeneratedKeys_.resultSetType_); } } if (chainAutoCommit) { // we have encountered an error in writing the execute, so do not // flow an autocommit if (agent_.accumulatedReadExceptions_ != null) { // currently, the only write exception we encounter is for // data truncation: SQLSTATE 01004, so we don't bother checking for this connection_.writeCommitSubstitute_(); commitSubstituted = true; } else { // there is no write error, so flow the commit connection_.writeCommit(); } } break; case isQuery__: writeOpenQuery(section_, fetchSize_, resultSetType_, numInputColumns, parameterMetaData_, parameters_); break; case isCall__: writeExecuteCall(outputRegistered_, // if no out/inout parameter, outputExpected = false null, section_, fetchSize_, false, // do not suppress ResultSets for regular CALLs resultSetType_, parameterMetaData_, parameters_); // cross conversion break; } agent_.flow(this); super.readCloseResultSets(true); // true means permit auto-commits // turn inUnitOfWork_ flag back on and add statement // back on commitListeners_ list if they were off // by an autocommit chained to a close cursor. if (piggybackedAutocommit) { connection_.completeTransactionStart(); } super.markResultSetsClosed(true); // true means remove from list of commit and rollback listeners switch (sqlMode_) { case isUpdate__: // do not need to reposition for a rowset cursor if (scrollableRS != null && !scrollableRS.isRowsetCursor_) { scrollableRS.readPositioningFetch_(); } if (sqlUpdateMode_ == isInsertSql__ && generatedKeysColumnNames_ != null) { readOpenQuery(); if (resultSet_ != null) { generatedKeysResultSet_ = resultSet_; resultSet_ = null; updateCount_ = 1; } } else { readExecute(); if (sqlUpdateMode_ == isInsertSql__ && autoGeneratedKeys_ == RETURN_GENERATED_KEYS) { readPrepareAutoGeneratedKeysStatement(); preparedStatementForAutoGeneratedKeys_.readOpenQuery(); generatedKeysResultSet_ = preparedStatementForAutoGeneratedKeys_.resultSet_; preparedStatementForAutoGeneratedKeys_.resultSet_ = null; } } if (chainAutoCommit) { if (commitSubstituted) { connection_.readCommitSubstitute_(); } else { connection_.readCommit(); } } break; case isQuery__: try { readOpenQuery(); } catch (DisconnectException dise) { throw dise; } catch (SqlException e) { throw e; } // resultSet_ is null if open query failed. // check for null resultSet_ before using it. if (resultSet_ != null) { resultSet_.parseScrollableRowset(); //if (resultSet_.scrollable_) resultSet_.getRowCount(); // If client's cursor name is set, map the client's cursor name to the ResultSet // Else map the server's cursor name to the ResultSet mapCursorNameToResultSet(); } break; case isCall__: readExecuteCall(); break; } try { agent_.endReadChain(); } catch (SqlException e) { throw e; } if (sqlMode_ == isCall__) { parseStorProcReturnedScrollableRowset(); // When there are no result sets back, we will commit immediately when autocommit is true. // make sure a commit is not performed when making the call to the sqlca message procedure if (connection_.autoCommit_ && resultSet_ == null && resultSetList_ == null && isAutoCommittableStatement_) { connection_.flowAutoCommit(); } } // Throw an exception if holdability returned by the server is different from requested. if (resultSet_ != null && resultSet_.resultSetHoldability_ != resultSetHoldability_ && sqlMode_ != isCall__) { throw new SqlException(agent_.logWriter_, "Unable to open resultSet with requested " + "holdability " + resultSetHoldability_ + "."); } } finally { if (timeout_ != 0) { // query timers need to be cancelled. queryTimer.cancel(); queryTimerTask.cancel(); } } } public int[] executeBatchX(boolean supportsQueryBatchRequest) throws SqlException, BatchUpdateException { synchronized (connection_) { checkForClosedStatement(); // Per jdbc spec (see Statement.close() javadoc) clearWarningsX(); // Per jdbc spec 0.7, also see getWarnings() javadoc return executeBatchRequestX(supportsQueryBatchRequest); } } private int[] executeBatchRequestX(boolean supportsQueryBatchRequest) throws SqlException, BatchUpdateException { SqlException chainBreaker = null; int batchSize = batch_.size(); int[] updateCounts = new int[batchSize]; int numInputColumns = parameterMetaData_ == null ? 0 : parameterMetaData_.getColumnCount(); Object[] savedInputs = null; // used to save/restore existing parameters if (batchSize == 0) { return updateCounts; } // Initialize all the updateCounts to indicate failure // This is done to account for "chain-breaking" errors where we cannot // read any more replies for (int i = 0; i < batchSize; i++) { updateCounts[i] = -3; } if (!supportsQueryBatchRequest && sqlMode_ == isQuery__) { throw new BatchUpdateException(agent_.logWriter_, "Batching of queries not allowed by J2EE compliance", updateCounts); } if (supportsQueryBatchRequest && sqlMode_ != isQuery__) { throw new BatchUpdateException(agent_.logWriter_, "Query batch requested on a non-query statement", updateCounts); } resultSetList_ = null; if (sqlMode_ == isQuery__) { indexOfCurrentResultSet_ = -1; //reset ResultSetList resultSetList_ = new ResultSet[batchSize]; } //save the current input set so it can be restored savedInputs = parameters_; agent_.beginBatchedWriteChain(this); boolean chainAutoCommit = connection_.willAutoCommitGenerateFlow() && isAutoCommittableStatement_; for (int i = 0; i < batchSize; i++) { parameters_ = (Object[]) batch_.get(i); if (sqlMode_ != isCall__) { boolean outputExpected = (resultSetMetaData_ != null && resultSetMetaData_.getColumnCount() > 0); writeExecute(section_, parameterMetaData_, parameters_, numInputColumns, outputExpected, chainAutoCommit || (i != batchSize - 1)); // more statements to chain } else if (outputRegistered_) // make sure no output parameters are registered { throw new BatchUpdateException(agent_.logWriter_, "No output parameters are allowed in batch updates", updateCounts); } else { writeExecuteCall(false, // no output expected for batched CALLs null, // no procedure name supplied for prepared CALLs section_, fetchSize_, true, // suppress ResultSets for batch resultSetType_, parameterMetaData_, parameters_); } } boolean commitSubstituted = false; if (chainAutoCommit) { // we have encountered an error in writing the execute, so do not // flow an autocommit if (agent_.accumulatedReadExceptions_ != null) { // currently, the only write exception we encounter is
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?