⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statement.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    //    boolean writeCloseResultSets(int number, boolean allowAutoCommits) throws SqlException {        boolean requiresAutocommit = false;        if (resultSetList_ != null) {            for (int i = 0; i < number; i++) {                if (resultSetList_[i] != null) {                    if (resultSetList_[i].openOnServer_) {                        resultSetList_[i].writeClose();                    }                    if (!resultSetList_[i].autoCommitted_ && allowAutoCommits) {                        requiresAutocommit = true;                    }                }            }        } else if (generatedKeysResultSet_ != null && generatedKeysResultSet_.openOnServer_) {            generatedKeysResultSet_.writeClose();        } else if (resultSet_ != null) {            if (resultSet_.openOnServer_) {                resultSet_.writeClose();            }            if (!resultSet_.autoCommitted_ && allowAutoCommits) {                requiresAutocommit = true;            }        }        if (connection_.autoCommit_ && requiresAutocommit && isAutoCommittableStatement_) {            connection_.writeAutoCommit();            if (connection_.isXAConnection_) {                return (connection_.getXAState() == Connection.XA_T0_NOT_ASSOCIATED) ;            } else {                return true;            }        }        return false;    }    // Helper method for S.flowCloseResultSets() and PS.flowExecute()    void readCloseResultSets(boolean allowAutoCommits) throws SqlException {        int numberOfResultSetsToClose = (resultSetList_ == null) ? 0 : resultSetList_.length;        readCloseResultSets(numberOfResultSetsToClose, allowAutoCommits);    }    void readCloseResultSets(int number, boolean allowAutoCommits) throws SqlException {        boolean requiredAutocommit = false;        if (resultSetList_ != null) {            for (int i = 0; i < number; i++) {                if (resultSetList_[i] != null) {                    if (resultSetList_[i].openOnServer_) {                        resultSetList_[i].readClose();                    } else {                        resultSetList_[i].markClosed();                    }                    if (!resultSetList_[i].autoCommitted_ && allowAutoCommits) {                        requiredAutocommit = true;                    }                }            }        } else if (generatedKeysResultSet_ != null) {            if (generatedKeysResultSet_.openOnServer_) {                generatedKeysResultSet_.readClose();            } else {                generatedKeysResultSet_.markClosed();            }        } else if (resultSet_ != null) {            if (resultSet_.openOnServer_) {                resultSet_.readClose();            } else {                resultSet_.markClosed();            }            if (!resultSet_.autoCommitted_ && allowAutoCommits) {                requiredAutocommit = true;            }        }        // we only commit when auto commit is turned on and at least one result set needed closing on server.        if (connection_.autoCommit_ && requiredAutocommit && isAutoCommittableStatement_) {            connection_.readAutoCommit();        }    }    private void flowCloseRetrievedResultSets() throws SqlException {        int numberOfResultSetsToClose = (resultSetList_ == null) ? 0 : indexOfCurrentResultSet_ + 1;        agent_.beginWriteChain(this);        // Need to refactor the ResultSet.readClose() path to check if we are the        // last result set closed in a set of multiple result sets of the owning statement,        // if so, we need to flow the auto-commit (but only then).        // currently, the code to do this is only in the closeX() path, which isn't called here        writeCloseResultSets(numberOfResultSetsToClose, false);        agent_.flow(this);        readCloseResultSets(numberOfResultSetsToClose, false);  // true means permit auto-commits        agent_.endReadChain();    }    private void flowCloseRetrievedResultSetsOutsideUOW() throws SqlException {        int numberOfResultSetsToClose = (resultSetList_ == null) ? 0 : indexOfCurrentResultSet_ + 1;        agent_.beginWriteChainOutsideUOW();        // Need to refactor the ResultSet.readClose() path to check if we are the        // last result set closed in a set of multiple result sets of the owning statement,        // if so, we need to flow the auto-commit (but only then).        // currently, the code to do this is only in the closeX() path, which isn't called here        writeCloseResultSets(numberOfResultSetsToClose, false);        agent_.flowOutsideUOW();        readCloseResultSets(numberOfResultSetsToClose, false);  // true means permit auto-commits        agent_.endReadChain();    }    public int completeSqlca(Sqlca sqlca) {        if (sqlca == null) {            return 0;        }        int sqlcode = sqlca.getSqlCode();        if (sqlcode < 0) {            connection_.agent_.accumulateReadException(new SqlException(agent_.logWriter_, sqlca));        } else if (sqlcode > 0) {            accumulateWarning(new SqlWarning(agent_.logWriter_, sqlca));        }        return sqlcode;    }    public void completeExecuteSetStatement(Sqlca sqlca) {    }    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      * PreparedStatement will also not be removed from the commit and rollback      * 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      * should not have any references and so it should have been already      * removed from the lists.       *      * 2. <code>org.apache.derby.client.am.Connection#markStatementsClosed</code>      * This method explicitly removes the Statement from open statements list.     *       * 3. To close positioned update statements - These statements are not     * added to the list of open statements.     */    void markClosed() {    	markClosed(false);    }        /**     * This method cleans up client-side resources held by this Statement.      * If removeListener is true, the Statement is removed from open statements     * list and PreparedStatement is also removed from commit and rollback      * listeners list. This is called from the close methods.     *      * @param removeListener if true the Statement will be removed     * from the open statements list and PreparedStatement will also be removed     * from commit and rollback listeners list in      * <code>org.apache.derby.client.am.Connection</code>.     */    void markClosed(boolean removeListener) {        openOnClient_ = false;        markResultSetsClosed();        // in case a cursorName was set on the Statement but the Statement was        // never used to execute a query, the cursorName will not be removed        // when the resultSets are mark closed, so we need to remove the        // cursorName form the cache.        removeClientCursorNameFromCache();        markPreparedStatementForAutoGeneratedKeysClosed();        markClosedOnServer();        // mark close ResultSetMetaData        if (resultSetMetaData_ != null) {            resultSetMetaData_.markClosed();            resultSetMetaData_ = null;        }                if(removeListener)        	connection_.openStatements_.remove(this);    }    void markPreparedStatementForAutoGeneratedKeysClosed() {        if (preparedStatementForAutoGeneratedKeys_ != null) {            preparedStatementForAutoGeneratedKeys_.markClosed();        }    }    /**     * Mark all ResultSets associated with this statement as     * closed. The ResultSets will not be removed from the commit and     * rollback listeners list in     * <code>org.apache.derby.client.am.Connection</code>.     */    void markResultSetsClosed() {        markResultSetsClosed(false);    }    /**     * Mark all ResultSets associated with this statement as     * closed.     *     * @param removeListener if true the ResultSets will be removed     * from the commit and rollback listeners list in     * <code>org.apache.derby.client.am.Connection</code>.     */    void markResultSetsClosed(boolean removeListener) {        if (resultSetList_ != null) {            for (int i = 0; i < resultSetList_.length; i++) {                if (resultSetList_[i] != null) {                    resultSetList_[i].markClosed(removeListener);                }                resultSetList_[i] = null;            }        }        if (generatedKeysResultSet_ != null) {            generatedKeysResultSet_.markClosed(removeListener);        }        if (resultSet_ != null) {            resultSet_.markClosed(removeListener);        }        resultSet_ = null;        resultSetList_ = null;        generatedKeysResultSet_ = null;    }    private void flowExecute(int executeType, String sql) throws SqlException {        checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)        checkAutoGeneratedKeysParameters();        clearWarningsX(); // Per jdbc spec 0.7, and getWarnings() javadoc        sql = escape(sql);        parseSqlAndSetSqlModes(sql);        if (sqlMode_ == isUpdate__) {            updateCount_ = 0;        } else {            updateCount_ = -1;        }        checkForAppropriateSqlMode(executeType, sqlMode_);        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_);        }        // enclose the processing in a try finally block in order to make sure        // the query timeout is cancelled at the end of this method.        try {            agent_.beginWriteChain(this);            boolean piggybackedAutoCommit = writeCloseResultSets(true);  // true means permit auto-commits            ResultSet scrollableRS = null;            Section newSection = null;            boolean repositionedCursor = false;            switch (sqlMode_) {            case isQuery__:                newSection = agent_.sectionManager_.getDynamicSection(resultSetHoldability_);                // if client's cursor name is set, map it to the query section in the hashtable                // after we obtain the section.                if (cursorName_ != null) {                    agent_.sectionManager_.mapCursorNameToQuerySection(cursorName_, newSection);                    // This means we must subtitute the <users-cursor-name> with the <canned-cursor-name>                    // in the pass-thru sql string "...where current of <canned-cursor-name>".                    newSection.setClientCursorName(cursorName_);                }                writePrepareDescribeOutput(sql, newSection);                writeOpenQuery(newSection,                        fetchSize_,                        resultSetType_);                break;            case isUpdate__:                String cursorName = null;                if (sqlUpdateMode_ == isDeleteSql__ || sqlUpdateMode_ == isUpdateSql__) {                    String[] sqlAndCursorName = extractCursorNameFromWhereCurrentOf(sql);                    if (sqlAndCursorName != null) {                        cursorName = sqlAndCursorName[0];                        sql = sqlAndCursorName[1];                    }                }                if (cursorName != null) {                    newSection = agent_.sectionManager_.getPositionedUpdateSection(cursorName, true); // true means get an execute immediate section                    if (newSection == null) {                        throw new SqlException(agent_.logWriter_, "Invalid cursor name \"" + cursorName +                                "\" in the Update/Delete statement.");                    }                    scrollableRS = agent_.sectionManager_.getPositionedUpdateResultSet(cursorName);                    // do not need to reposition for rowset cursors                    if (scrollableRS != null && !scrollableRS.isRowsetCursor_) {                        repositionedCursor =                                scrollableRS.repositionScrollableResultSetBeforeJDBC1PositionedUpdateDelete();                        if (!repositionedCursor) {                            scrollableRS = null;                        }                    }                    // if client's cursor name is set, and the cursor name in the positioned update                    // string is the same as the client's cursor name, replace client's cursor name                    // with the server's cursor name.       

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -