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

📄 netcursor.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*   Derby - Class org.apache.derby.client.net.NetCursor   Copyright (c) 2001, 2005 The Apache Software Foundation or its licensors, where applicable.   Licensed under the Apache License, Version 2.0 (the "License");   you may not use this file except in compliance with the License.   You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0   Unless required by applicable law or agreed to in writing, software   distributed under the License is distributed on an "AS IS" BASIS,   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   See the License for the specific language governing permissions and   limitations under the License.*/package org.apache.derby.client.net;import org.apache.derby.client.am.Agent;import org.apache.derby.client.am.Blob;import org.apache.derby.client.am.Clob;import org.apache.derby.client.am.DisconnectException;import org.apache.derby.client.am.SignedBinary;import org.apache.derby.client.am.SqlException;import org.apache.derby.client.am.SqlWarning;import org.apache.derby.client.am.Types;public class NetCursor extends org.apache.derby.client.am.Cursor {    NetResultSet netResultSet_;    NetAgent netAgent_;    Typdef qrydscTypdef_;    int targetSqlamForTypdef_;    // override column meta data    int numMddOverrides_;    int maximumRowSize_;    boolean blocking_;  // if true, multiple rows may be "blocked" in a single reply    // Raw fdoca column meta data.    int[] typeToUseForComputingDataLength_;    boolean[] isGraphic_;    // key = column position, value = index into extdtaData_    java.util.HashMap extdtaPositions_;    java.util.ArrayList extdtaData_; // queue to hold EXTDTA data that hasn't been correlated to its column #    boolean rtnextrow_ = true;    //-----------------------------constants--------------------------------------    //---------------------constructors/finalizer---------------------------------    NetCursor(NetAgent netAgent) {        super(netAgent);        netAgent_ = netAgent;        numMddOverrides_ = 0;        maximumRowSize_ = 0;        extdtaPositions_ = new java.util.HashMap();        extdtaData_ = new java.util.ArrayList();    }    NetCursor(NetAgent netAgent,              int qryprctyp)  //protocolType, CodePoint.FIXROWPRC | CodePoint.LMTBLKPRC    {        this(netAgent);        if (qryprctyp == CodePoint.FIXROWPRC) {            blocking_ = false;        } else if (qryprctyp == CodePoint.LMTBLKPRC) {            blocking_ = true;        }    }    //-----------------------------parsing the data buffer------------------------    // Pseudo-code:    //   parse thru the current row in dataBuffer computing column offsets    //   if (we hit the super.lastValidBytePosition, ie. encounter partial row) {    //     shift partial row bytes to beginning of dataBuffer (this.shiftPartialRowToBeginning())    //     reset current row position (also done by this.shiftPartialRowToBeginning())    //     send and recv continue-query into commBuffer (rs.flowContinueQuery())    //     parse commBuffer up to QRYDTA (rs.flowContinueQuery())    //     copy query data from reply's commBuffer to our dataBuffer (this.copyQrydta())    //   }    // Returns true if the current row position is a valid row position.    // rename this to parse*()    protected boolean calculateColumnOffsetsForRow_(int rowIndex) throws SqlException, org.apache.derby.client.am.DisconnectException {        int daNullIndicator = CodePoint.NULLDATA;        int colNullIndicator = CodePoint.NULLDATA;        int length;        if (hasLobs_) {            extdtaPositions_.clear();  // reset positions for this row        }        int[] columnDataPosition = null;        int[] columnDataComputedLength = null;        boolean[] columnDataIsNull = null;        if ((position_ == lastValidBytePosition_) &&                (netResultSet_ != null) && (netResultSet_.scrollable_)) {            return false;        }        NetSqlca netSqlca = this.parseSQLCARD(qrydscTypdef_);        if (netSqlca != null) {            int sqlcode = netSqlca.getSqlCode();            if (sqlcode < 0) {                throw new SqlException(netAgent_.logWriter_, netSqlca);            } else {                if (sqlcode > 0) {                    if (sqlcode == 100) {                        allRowsReceivedFromServer_ = true;                        if (netResultSet_ != null && netSqlca.containsSqlcax()) {                            netResultSet_.setRowCountEvent(netSqlca.getRowCount(qrydscTypdef_));                        }                    } else if (netResultSet_ != null) {                        netResultSet_.accumulateWarning(new SqlWarning(agent_.logWriter_, netSqlca));                    }                }            }        }        // If we don't have at least one byte in the buffer for the DA null indicator,        // then we need to send a CNTQRY request to fetch the next block of data.        // Read the DA null indicator.        daNullIndicator = readFdocaOneByte();        // In the case for held cursors, the +100 comes back as part of the QRYDTA, and as        // we are parsing through the row that contains the SQLCA with +100, we mark the        // nextRowPosition_ which is the lastValidBytePosition_, but we don't mark the        // currentRowPosition_ until the next time next() is called causing the check        // cursor_.currentRowPositionIsEqualToNextRowPosition () to fail in getRow() and thus        // not returning 0 when it should. So we need to mark the current row position immediately        // in order for getRow() to be able to pick it up.        // markNextRowPosition() is called again once this method returns, but it is ok        // since it's only resetting nextRowPosition_ to position_ and position_ will        // not change again from this point.        if (allRowsReceivedFromServer_ && (position_ == lastValidBytePosition_)) {            markNextRowPosition();            makeNextRowPositionCurrent();            return false;        }        // If data flows....        if (daNullIndicator == 0x0) {            incrementRowsReadEvent();            // netResultSet_ is null if this method is invoked from Lob.position()            // If row has exceeded the size of the ArrayList, new up a new int[] and add it to the            // ArrayList, otherwise just reuse the int[].            if (netResultSet_ != null && netResultSet_.scrollable_) {                columnDataPosition = allocateColumnDataPositionArray(rowIndex);                columnDataComputedLength = allocateColumnDataComputedLengthArray(rowIndex);                columnDataIsNull = allocateColumnDataIsNullArray(rowIndex);                // Since we are no longer setting the int[]'s to null for a delete/update hole, we need                // another way of keeping track of the delete/update holes.                setIsUpdataDeleteHole(rowIndex, false);            } else {                // Use the arrays defined on the Cursor for forward-only cursors.                // can they ever be null                if (columnDataPosition_ == null || columnDataComputedLength_ == null || isNull_ == null) {                    allocateColumnOffsetAndLengthArrays();                }                columnDataPosition = columnDataPosition_;                columnDataComputedLength = columnDataComputedLength_;                columnDataIsNull = isNull_;            }            // Loop through the columns            for (int index = 0; index < columns_; index++) {                // If column is nullable, read the 1-byte null indicator.                if (nullable_[index])                // Need to pass the column index so all previously calculated offsets can be                // readjusted if the query block splits on a column null indicator.                // null indicators from FD:OCA data                // 0 to 127: a data value will flow.                // -1 to -128: no data value will flow.                {                    colNullIndicator = readFdocaOneByte(index);                }                // If non-null column data                if (!nullable_[index] || (colNullIndicator >= 0 && colNullIndicator <= 127)) {                    // Set the isNull indicator to false                    columnDataIsNull[index] = false;                    switch (typeToUseForComputingDataLength_[index]) {                    // for fixed length data                    case Typdef.FIXEDLENGTH:                        columnDataPosition[index] = position_;                        if (isGraphic_[index]) {                            columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index] * 2, index);                        } else {                            columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index], index);                        }                        break;                        // for variable character string and variable byte string,                        // there are 2-byte of length in front of the data                    case Typdef.TWOBYTELENGTH:                        columnDataPosition[index] = position_;                        length = readFdocaTwoByteLength(index);                        // skip length + the 2-byte length field                        if (isGraphic_[index]) {                            columnDataComputedLength[index] = skipFdocaBytes(length * 2, index) + 2;                        } else {                            columnDataComputedLength[index] = skipFdocaBytes(length, index) + 2;                        }                        break;                        // For decimal columns, determine the precision, scale, and the representation                    case Typdef.DECIMALLENGTH:                        columnDataPosition[index] = position_;                        columnDataComputedLength[index] = skipFdocaBytes(getDecimalLength(index), index);                        break;                    case Typdef.LOBLENGTH:                        columnDataPosition[index] = position_;                        columnDataComputedLength[index] = this.skipFdocaBytes(fdocaLength_[index] & 0x7fff, index);                        break;                        // for short variable character string and short variable byte string,                        // there is a 1-byte length in front of the data                    case Typdef.ONEBYTELENGTH:                        columnDataPosition[index] = position_;                        length = readFdocaOneByte(index);                        // skip length + the 1-byte length field                        if (isGraphic_[index]) {                            columnDataComputedLength[index] = skipFdocaBytes(length * 2, index) + 1;                        } else {                            columnDataComputedLength[index] = skipFdocaBytes(length, index) + 1;                        }                        break;                    default:                        columnDataPosition[index] = position_;                        if (isGraphic_[index]) {                            columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index] * 2, index);                        } else {                            columnDataComputedLength[index] = skipFdocaBytes(fdocaLength_[index], index);                        }                        break;                    }                } else if ((colNullIndicator & 0x80) == 0x80) {                    // Null data. Set the isNull indicator to true.                    columnDataIsNull[index] = true;                }            }            // set column offsets for the current row.            columnDataPosition_ = columnDataPosition;            columnDataComputedLength_ = columnDataComputedLength;            isNull_ = columnDataIsNull;            if (!allRowsReceivedFromServer_) {                calculateLobColumnPositionsForRow();                // Flow another CNTQRY if we are blocking, are using rtnextrow, and expect                // non-trivial EXTDTAs for forward only cursors.  Note we do not support                // EXTDTA retrieval for scrollable cursors.                // if qryrowset was sent on excsqlstt for a sp call, which is only the case                if (blocking_ && rtnextrow_ &&                        extdtaPositions_.size() > 0 && !netResultSet_.scrollable_) {                    if (!extdtaPositions_.isEmpty()) {                        netResultSet_.flowFetch();                    }                }            }        }        // Else if this row is null, only add to the isRowNullCache_ if the cursor is scrollable.        else {            if (netResultSet_ != null && netResultSet_.scrollable_) {                setIsUpdataDeleteHole(rowIndex, true);            }        }        // If blocking protocol is used, we could have already received an ENDQRYRM,        // which sets allRowsReceivedFromServer_ to true.  It's safe to assume that all of        // our QRYDTA's have been successfully copied to the dataBuffer.  And even though        // the flag for allRowsReceivedFromServer_ is set, we still want to continue to parse through        // the data in the dataBuffer.        // But in the case where fixed row protocol is used,        if (!blocking_ && allRowsReceivedFromServer_ && daNullIndicator == 0xFF) {            return false;        } else {            return true;        }    }    protected boolean isDataBufferNull() {        if (dataBuffer_ == null) {            return true;        } else {            return false;        }    }    protected void allocateDataBuffer() {        int length;        if (maximumRowSize_ > DssConstants.MAX_DSS_LEN) {            length = maximumRowSize_;        } else {            length = DssConstants.MAX_DSS_LEN;        }        dataBuffer_ = new byte[length];        position_ = 0;        lastValidBytePosition_ = 0;    }    protected void allocateDataBuffer(int length) {        dataBuffer_ = new byte[length];    }    private int readFdocaInt() throws org.apache.derby.client.am.DisconnectException, SqlException {        if ((position_ + 4) > lastValidBytePosition_) {            // Check for ENDQRYRM, throw SqlException if already received one.            checkAndThrowReceivedEndqryrm();            // Send CNTQRY to complete the row/rowset.            int lastValidByteBeforeFetch = completeSplitRow();            // if lastValidBytePosition_ has not changed, and an ENDQRYRM was received,            // throw a SqlException for the ENDQRYRM.            checkAndThrowReceivedEndqryrm(lastValidByteBeforeFetch);        }        int i = SignedBinary.getInt(dataBuffer_, position_);        position_ += 4;        return i;    }    // Reads 1-byte from the dataBuffer from the current position.    // If position is already at the end of the buffer, send CNTQRY to get more data.    private int readFdocaOneByte() throws org.apache.derby.client.am.DisconnectException, SqlException {        // For singleton select, the complete row always comes back, even if multiple query blocks are required,

⌨️ 快捷键说明

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