resultset.java

来自「derby database source code.good for you.」· Java 代码 · 共 1,556 行 · 第 1/5 页

JAVA
1,556
字号
                }                if (sqlException != null) {                    throw sqlException;                }            }        }        // for scrollable ResultSet's,        // if the "next" request is still fetching within the current rowset,        //   update column info from cache and increment the current row index        // else        //   fetch the next rowset from the server        else {            // These flags will only be used for dynamic cursors where we don't know the row count            // and can't keep track of the absolute position of the cursor.            isAfterLast_ = false;            isLast_ = false;            // if the next row is still within the current rowset            if (rowIsInCurrentRowset(firstRowInRowset_ + currentRowInRowset_ + 1, scrollOrientation_next__)) {                isValidCursorPosition_ = true;                currentRowInRowset_++;            } else {                checkAndThrowReceivedQueryTerminatingException();                isValidCursorPosition_ = getNextRowset();            }            if (isValidCursorPosition_) {                updateColumnInfoFromCache();                // check if there is a non-null SQLCA for the current row for rowset cursors                checkRowsetSqlca();                if (isBeforeFirst_) {                    isFirst_ = true;                }                isBeforeFirst_ = false;            } else {                isFirst_ = false;                return isValidCursorPosition_;            }        }        // for forward-only cursors, check if rowsRead_ > maxRows_.        // for scrollable cursors, check if absolute row number > maxRows_.        // maxRows_ will be ignored by sensitive dynamic cursors since we don't know the rowCount        if (!openOnClient_) {            isValidCursorPosition_ = false;        } else if (sensitivity_ != sensitivity_sensitive_dynamic__ && statement_.maxRows_ > 0 &&                (firstRowInRowset_ + currentRowInRowset_ > statement_.maxRows_)) {            isValidCursorPosition_ = false;        }        return isValidCursorPosition_;    }    public void close() throws SqlException {        synchronized (connection_) {            if (agent_.loggingEnabled()) {                agent_.logWriter_.traceEntry(this, "close");            }            closeX();        }    }    // TO DO: when parseEndqryrm() notifies common w/ endQueryCloseOnlyEvent() we need to mark something    // that we later check to drive a commit.    // An untraced version of close()    public final void closeX() throws SqlException {        if (!openOnClient_) {            return;        }        try {            if (openOnServer_) {                flowCloseAndAutoCommitIfNotAutoCommitted();            } else {                flowAutoCommitIfNotAutoCommitted(); // in case of early close            }        } finally {            markClosed(true);        }        flowAutoCommitIfLastOpenMultipleResultSetWasJustClosed();        if (statement_.openOnClient_ && statement_.isCatalogQuery_) {            statement_.closeX();        }        nullDataForGC();    }    public void nullDataForGC() {        // This method is called by closeX().  We cannot call this if cursor is cached,        // otherwise it will cause NullPointerException's when cursor is reused.        // Cursor is only cached for PreparedStatement's.        if (cursor_ != null && !statement_.isPreparedStatement_) {            cursor_.nullDataForGC();        }        cursor_ = null;        resultSetMetaData_ = null;    }    void flowCloseAndAutoCommitIfNotAutoCommitted() throws SqlException {        agent_.beginWriteChain(statement_);        writeCloseAndAutoCommitIfNotAutoCommitted();        agent_.flow(statement_);        readCloseAndAutoCommitIfNotAutoCommitted();        agent_.endReadChain();    }    private void writeCloseAndAutoCommitIfNotAutoCommitted() throws SqlException {        // set autoCommitted_ to false so commit will flow following        // close cursor if autoCommit is true.        autoCommitted_ = false;        if (generatedSection_ == null) { // none call statement result set case            writeCursorClose_(statement_.section_);            writeAutoCommitIfNotAutoCommitted();        } else { // call statement result set(s) case            writeCursorClose_(generatedSection_);        }    }    private void readCloseAndAutoCommitIfNotAutoCommitted() throws SqlException {        if (generatedSection_ == null) { // none call statement result set case            readCursorClose_();            readAutoCommitIfNotAutoCommitted();        } else { // call statement result set(s) case            readCursorClose_();        }    }    void writeClose() throws SqlException {        // set autoCommitted_ to false so commit will flow following        // close cursor if autoCommit is true.        autoCommitted_ = false;        if (generatedSection_ == null) { // none call statement result set case            writeCursorClose_(statement_.section_);        } else { // call statement result set(s) case            writeCursorClose_(generatedSection_);        }    }    void readClose() throws SqlException {        try {            if (generatedSection_ == null) { // none call statement result set case                readCursorClose_();            } else { // call statement result set(s) case                readCursorClose_();            }        } finally {            markClosed();        }    }    void flowAutoCommitIfNotAutoCommitted() throws SqlException {        if (generatedSection_ == null && connection_.autoCommit_ && !autoCommitted_) {            connection_.flowAutoCommit();            markAutoCommitted();        }    }    // precondition: transaction state allows for auto commit to generate flow    private void writeAutoCommitIfNotAutoCommitted() throws SqlException {        if (connection_.autoCommit_ && !autoCommitted_) {            connection_.writeAutoCommit();        }    }    private void readAutoCommitIfNotAutoCommitted() throws SqlException {        if (connection_.autoCommit_ && !autoCommitted_) {            connection_.readAutoCommit();            markAutoCommitted();        }    }    private void flowAutoCommitIfLastOpenMultipleResultSetWasJustClosed() throws SqlException {        // After this call, the generatedSection_ is reset to null to avoid repeating the commit.        if (generatedSection_ != null && statement_ != null && statement_.resultSetList_ != null) {            int count = 0;            for (int i = 0; i < statement_.resultSetList_.length; i++) {                if (statement_.resultSetList_[i] == null) {                    count++;                }            }            if (count == statement_.resultSetList_.length) {                if (connection_.autoCommit_ && !autoCommitted_) {                    connection_.flowAutoCommit();                    markAutoCommitted();                }            }        }        generatedSection_ = null; // this is prevent a subsequent close() call from doing another autocommit.    }    public boolean wasNull() throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "wasNull");        }        checkForClosedResultSet();        if (wasNull_ == ResultSet.WAS_NULL_UNSET) {            throw new SqlException(agent_.logWriter_, "Invalid operation: wasNull() called with no data retrieved");        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "wasNull", wasNull_ == ResultSet.WAS_NULL);        }        return wasNull_ == ResultSet.WAS_NULL;    }    //------------------- getters on column index --------------------------------    // Live life on the edge and run unsynchronized    public boolean getBoolean(int column) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "getBoolean", column);        }        checkGetterPreconditions(column);        boolean result = false;        if (wasNonNullSensitiveUpdate(column)) {            result = agent_.crossConverters_.setBooleanFromObject(updatedColumns_[column - 1],                    resultSetMetaData_.types_[column - 1]);        } else {            result = isNull(column) ? false : cursor_.getBoolean(column);        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "getBoolean", result);        }        setWasNull(column);  // Placed close to the return to minimize risk of thread interference        return result;    }    // Live life on the edge and run unsynchronized    public byte getByte(int column) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "getByte", column);        }        checkGetterPreconditions(column);        byte result = 0;        if (wasNonNullSensitiveUpdate(column)) {            result = agent_.crossConverters_.setByteFromObject(updatedColumns_[column - 1],                    resultSetMetaData_.types_[column - 1]);        } else {            result = isNull(column) ? 0 : cursor_.getByte(column);        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "getByte", result);        }        setWasNull(column);  // Placed close to the return to minimize risk of thread interference        return result;    }    // Live life on the edge and run unsynchronized    public short getShort(int column) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "getShort", column);        }        checkGetterPreconditions(column);        short result = 0;        if (wasNonNullSensitiveUpdate(column)) {            result = ((Short) agent_.crossConverters_.setObject(java.sql.Types.SMALLINT,                    updatedColumns_[column - 1])).shortValue();        } else {            result = isNull(column) ? 0 : cursor_.getShort(column);        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "getShort", result);        }        setWasNull(column);  // Placed close to the return to minimize risk of thread interference        return result;    }    // Live life on the edge and run unsynchronized    public int getInt(int column) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "getInt", column);        }        checkGetterPreconditions(column);        int result = 0;        if (wasNonNullSensitiveUpdate(column)) {            result = ((Integer) agent_.crossConverters_.setObject(java.sql.Types.INTEGER,                    updatedColumns_[column - 1])).intValue();        } else {            result = isNull(column) ? 0 : cursor_.getInt(column);        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "getInt", result);        }        setWasNull(column); // this is placed here close to the return to minimize risk of race condition.        return result;    }    // Live life on the edge and run unsynchronized    public long getLong(int column) throws SqlException {        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceEntry(this, "getLong", column);        }        checkGetterPreconditions(column);        long result = 0;        if (wasNonNullSensitiveUpdate(column)) {            result = ((Long) agent_.crossConverters_.setObject(java.sql.Types.BIGINT,                    updatedColumns_[column - 1])).longValue();        } else {            result = isNull(column) ? 0 : cursor_.getLong(column);        }        if (agent_.loggingEnabled()) {            agent_.logWriter_.traceExit(this, "getLong", result);        }        setWasNull(column);  // Placed close to the return to minimize risk of thread interference        return result;    }    // Live life on the edge and run unsynchronized

⌨️ 快捷键说明

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