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

📄 cursor.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*   Derby - Class org.apache.derby.client.am.Cursor   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.am;import java.io.UnsupportedEncodingException;// When we calculate column offsets make sure we calculate the correct offsets for double byte charactr5er data// length from server is number of chars, not bytes// Direct byte-level converters are called directly by this class, cross converters are deferred to the CrossConverters class.public abstract class Cursor {    protected Agent agent_;    //-----------------------------varchar representations------------------------    public final static int STRING = 0;    public final static int VARIABLE_STRING = 2;       // uses a 2-byte length indicator    public final static int VARIABLE_SHORT_STRING = 1; // aka Pascal L; uses a 1-byte length indicator    public final static int NULL_TERMINATED_STRING = 3;    public final static int BYTES = 4;    public final static int VARIABLE_BYTES = 5;    public final static int VARIABLE_SHORT_BYTES = 6;    public final static int NULL_TERMINATED_BYTES = 7;    public final static int SBCS_CLOB = 8;    public final static int MBCS_CLOB = 9;    public final static int DBCS_CLOB = 10;    //-----------------------------internal state---------------------------------    //-------------Structures for holding and scrolling the data -----------------    public byte[] dataBuffer_;    public java.io.ByteArrayOutputStream dataBufferStream_;    public int position_; // This is the read head    public int lastValidBytePosition_;    public boolean hasLobs_; // is there at least one LOB column?    // Current row positioning    protected int currentRowPosition_;    private int nextRowPosition_;    // Let's new up a 2-dimensional array based on fetch-size and reuse so that    protected int[] columnDataPosition_;    // This is the actual, computed lengths of varchar fields, not the max length from query descriptor or DA    protected int[] columnDataComputedLength_;    // populate this for    // All the data is in the buffers, but user may not have necessarily stepped to the last row yet.    // This flag indicates that the server has returned all the rows, and is positioned    // after last, for both scrollable and forward-only cursors.    // For singleton cursors, this memeber will be set to true as soon as next is called.    public boolean allRowsReceivedFromServer_;    // Total number of rows read so far.    // This should never exceed this.statement.maxRows    int rowsRead_;    // Maximum column size limit in bytes.    int maxFieldSize_ = 0;    // Row positioning for all cached rows    // For scrollable result sets, these lists hold the offsets into the cached rowset buffer for each row of data.    protected java.util.ArrayList columnDataPositionCache_ = new java.util.ArrayList();    protected java.util.ArrayList columnDataLengthCache_ = new java.util.ArrayList();    protected java.util.ArrayList columnDataIsNullCache_ = new java.util.ArrayList();    public java.util.ArrayList isUpdateDeleteHoleCache_ = new java.util.ArrayList();    public boolean isUpdateDeleteHole_;    final static public java.lang.Boolean ROW_IS_NULL = new Boolean(true);    final static public java.lang.Boolean ROW_IS_NOT_NULL = new Boolean(false);    java.sql.Date recyclableDate_ = null;    java.sql.Time recyclableTime_ = null;    java.sql.Timestamp recyclableTimestamp_ = null;    // For the net, this data comes from the query descriptor.    public int[] jdbcTypes_;    public int columns_;    public boolean[] nullable_;    public String[] charsetName_;    public boolean[] isNull_;    public int[] fdocaLength_; // this is the max length for    //----------------------------------------------------------------------------    public int[] ccsid_;    char[] charBuffer_;    //---------------------constructors/finalizer---------------------------------    public Cursor(Agent agent) {        agent_ = agent;        dataBufferStream_ = new java.io.ByteArrayOutputStream();    }    public Cursor(Agent agent, byte[] dataBuffer) {        this(agent);        dataBuffer_ = dataBuffer;        allRowsReceivedFromServer_ = false;    }    public void setNumberOfColumns(int numberOfColumns) {        columnDataPosition_ = new int[numberOfColumns];        columnDataComputedLength_ = new int[numberOfColumns];        columns_ = numberOfColumns;        nullable_ = new boolean[numberOfColumns];        charsetName_ = new String[numberOfColumns];        ccsid_ = new int[numberOfColumns];        isNull_ = new boolean[numberOfColumns];        jdbcTypes_ = new int[numberOfColumns];    }    // Makes the next row the current row.    // Returns true if the current row position is a valid row position.    public boolean next() throws SqlException {        // local variable usd to hold the returned value from calculateColumnOffsetsForRow()        boolean rowPositionIsValid = true;        // reset lob data        // clears out Cursor.lobs_ calculated for the current row when cursor is moved.        clearLobData_();        // mark the start of a new row.        makeNextRowPositionCurrent();        // Drive the CNTQRY outside of calculateColumnOffsetsForRow() if the dataBuffer_        // contains no data since it has no abilities to handle replies other than        // the QRYDTA, i.e. ENDQRYRM when the result set contains no more rows.        while (!dataBufferHasUnprocessedData()) {            if (allRowsReceivedFromServer_) {                return false;            }            getMoreData_();        }        // The parameter passed in here is used as an index into the cached rowset for        // scrollable cursors, for the arrays to be reused.  It is not used for forward-only        // cursors, so just pass in 0.        rowPositionIsValid = calculateColumnOffsetsForRow_(0);  // readFetchedRows()        markNextRowPosition();        return rowPositionIsValid;    }    //--------------------------reseting cursor state-----------------------------    public final void setAllRowsReceivedFromServer(boolean b) {        allRowsReceivedFromServer_ = b;    }    public final boolean currentRowPositionIsEqualToNextRowPosition() {        return (currentRowPosition_ == nextRowPosition_);    }    // reset the beginning and ending position in the data buffer to 0    // reset the currentRowPosition and nextRowPosition to 0    // reset lastRowReached and sqlcode100Received to false    // clear the column data offsets cache    public final void resetDataBuffer() {        position_ = 0;        lastValidBytePosition_ = 0;        currentRowPosition_ = 0;        nextRowPosition_ = 0;        allRowsReceivedFromServer_ = false;        dataBufferStream_.reset();    }    public final boolean dataBufferHasUnprocessedData() {        return (lastValidBytePosition_ - position_) > 0;    }    protected abstract boolean calculateColumnOffsetsForRow_(int row) throws SqlException, DisconnectException;    protected abstract void clearLobData_();    protected abstract void getMoreData_() throws SqlException;    // Associate a new underlying COM or SQLDA output data buffer for this converter.    public final void setBuffer(byte[] dataBuffer) {        dataBuffer_ = dataBuffer;    }    public final void setIsUpdataDeleteHole(int row, boolean isRowNull) {        isUpdateDeleteHole_ = isRowNull;        Boolean nullIndicator = (isUpdateDeleteHole_ == true) ? ROW_IS_NULL : ROW_IS_NOT_NULL;        if (isUpdateDeleteHoleCache_.size() == row) {            isUpdateDeleteHoleCache_.add(nullIndicator);        } else {            isUpdateDeleteHoleCache_.set(row, nullIndicator);        }    }    //---------------------------cursor positioning-------------------------------    final int getPosition() {        return position_;    }    final void setPosition(int newPosition) {        position_ = newPosition;    }    public final void markCurrentRowPosition() {        currentRowPosition_ = position_;    }    public final void markNextRowPosition() {        nextRowPosition_ = position_;    }    public final void makeNextRowPositionCurrent() {        currentRowPosition_ = nextRowPosition_;    }    final void repositionCursorToCurrentRow() {        position_ = currentRowPosition_;    }    final void repositionCursorToNextRow() {        position_ = nextRowPosition_;    }    public final byte[] getDataBuffer() {        return dataBuffer_;    }    public final int getDataBufferLength() {        return dataBuffer_.length;    }    public final int getLastValidBytePosition() {        return lastValidBytePosition_;    }    // This tracks the total number of rows read into the client side buffer for    // this result set, irregardless of scrolling.    // Per jdbc semantics, this should never exceed statement.maxRows.    // This event should be generated in the materialized cursor's implementation    // of calculateColumnOffsetsForRow().    public final void incrementRowsReadEvent() {        rowsRead_++;    }    //------- the following getters are called on known column types -------------    // Direct conversions only, cross conversions are handled by another set of getters.    // Build a Java short from a 2-byte signed binary representation.    private final short get_SMALLINT(int column) {        return org.apache.derby.client.am.SignedBinary.getShort(dataBuffer_,                columnDataPosition_[column - 1]);    }    // Build a Java int from a 4-byte signed binary representation.    private final int get_INTEGER(int column) {        return org.apache.derby.client.am.SignedBinary.getInt(dataBuffer_,                columnDataPosition_[column - 1]);    }    // Build a Java long from an 8-byte signed binary representation.    private final long get_BIGINT(int column) {

⌨️ 快捷键说明

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