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

📄 tdsresultset.java

📁 Java写的TDS协议(JDBC/ODBC)实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     *  next()</code> because is makes sense to call <code>next()</code> when
     *  there is no current row, for example, when the cursor is positioned
     *  before the first row or after the last row of the result set.
     *
     *@param  rows
     *@return                   true if the cursor is on a row; false otherwise
     *@exception  SQLException  if a database access error occurs, there is no
     *      current row, or the result set type is TYPE_FORWARD_ONLY
     */
    public boolean relative(int rows) throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 <p>
     *
     *  Moves the cursor to the previous row in the result set. <p>
     *
     *  Note: <code>previous()</code> is not the same as <code>relative(-1)
     *  </code>because it makes sense to call</code> previous()</code> when
     *  there is no current row.
     *
     *@return                   true if the cursor is on a valid row; false if
     *      it is off the result set
     *@exception  SQLException  if a database access error occurs or the result
     *      set type is TYPE_FORWARD_ONLY
     */
    public boolean previous() throws SQLException
    {
        throw new SQLException("The result set type is TYPE_FORWARD_ONLY");
    }

    /**
     *  JDBC 2.0 Indicates whether the current row has been updated. The value
     *  returned depends on whether or not the result set can detect updates.
     *
     *@return                   true if the row has been visibly updated by the
     *      owner or another, and updates are detected
     *@exception  SQLException  if a database access error occurs
     *@see                      DatabaseMetaData#updatesAreDetected
     */
    public boolean rowUpdated() throws SQLException
    {
        checkClosed();
        return false;
    }

    /**
     *  JDBC 2.0 Indicates whether the current row has had an insertion. The
     *  value returned depends on whether or not the result set can detect
     *  visible inserts.
     *
     *@return                   true if a row has had an insertion and
     *      insertions are detected
     *@exception  SQLException  if a database access error occurs
     *@see                      DatabaseMetaData#insertsAreDetected
     */
    public boolean rowInserted() throws SQLException
    {
        checkClosed();
        return false;
    }

    /**
     *  JDBC 2.0 Indicates whether a row has been deleted. A deleted row may
     *  leave a visible "hole" in a result set. This method can be used to
     *  detect holes in a result set. The value returned depends on whether or
     *  not the result set can detect deletions.
     *
     *@return                   true if a row was deleted and deletions are
     *      detected
     *@exception  SQLException  if a database access error occurs
     *@see                      DatabaseMetaData#deletesAreDetected
     */
    public boolean rowDeleted() throws SQLException
    {
        checkClosed();
        return false;
    }

    /**
     *  JDBC 2.0 Inserts the contents of the insert row into the result set and
     *  the database. Must be on the insert row when this method is called.
     *
     *@exception  SQLException  if a database access error occurs, if called
     *      when not on the insert row, or if not all of non-nullable columns in
     *      the insert row have been given a value
     */
    public void insertRow() throws SQLException
    {
        throw new SQLException("ResultSet is not updateable");
    }

    /**
     *  JDBC 2.0 Updates the underlying database with the new contents of the
     *  current row. Cannot be called when on the insert row.
     *
     *@exception  SQLException  if a database access error occurs or if called
     *      when on the insert row
     */
    public void updateRow() throws SQLException
    {
        throw new SQLException("ResultSet is not updateable");
    }

    /**
     *  JDBC 2.0 Deletes the current row from the result set and the underlying
     *  database. Cannot be called when on the insert row.
     *
     *@exception  SQLException  if a database access error occurs or if called
     *      when on the insert row.
     */
    public void deleteRow() throws SQLException
    {
        throw new SQLException("ResultSet is not updateable");
    }

    /**
     *  JDBC 2.0 Refreshes the current row with its most recent value in the
     *  database. Cannot be called when on the insert row. The <code>refreshRow
     *  </code>method provides a way for an application to explicitly tell the
     *  JDBC driver to refetch a row(s) from the database. An application may
     *  want to call <code>refreshRow</code> when caching or prefetching is
     *  being done by the JDBC driver to fetch the latest value of a row from
     *  the database. The JDBC driver may actually refresh multiple rows at once
     *  if the fetch size is greater than one. All values are refetched subject
     *  to the transaction isolation level and cursor sensitivity. If <code>
     *  refreshRow</code> is called after calling <code>updateXXX</code> , but
     *  before calling <code>updateRow</code> , then the updates made to the row
     *  are lost. Calling the method <code>refreshRow</code> frequently will
     *  likely slow performance.
     *
     *@exception  SQLException  if a database access error occurs or if called
     *      when on the insert row
     */
    public void refreshRow() throws SQLException
    {
        //No effect
        checkClosed();
    }

    /**
     *  JDBC 2.0 Cancels the updates made to a row. This method may be called
     *  after calling an <code>updateXXX</code> method(s) and before calling
     *  <code>updateRow</code> to rollback the updates made to a row. If no
     *  updates have been made or <code>updateRow</code> has already been
     *  called, then this method has no effect.
     *
     *@exception  SQLException  if a database access error occurs or if called
     *      when on the insert row
     */
    public void cancelRowUpdates() throws SQLException
    {
        //No effect
        checkClosed();
    }

    /**
     *  JDBC 2.0 Moves the cursor to the insert row. The current cursor position
     *  is remembered while the cursor is positioned on the insert row. The
     *  insert row is a special row associated with an updatable result set. It
     *  is essentially a buffer where a new row may be constructed by calling
     *  the <code>updateXXX</code> methods prior to inserting the row into the
     *  result set. Only the <code>updateXXX</code> , <code>getXXX</code> , and
     *  <code>insertRow</code> methods may be called when the cursor is on the
     *  insert row. All of the columns in a result set must be given a value
     *  each time this method is called before calling <code>insertRow</code> .
     *  The method <code>updateXXX</code> must be called before a <code>getXXX
     *  </code>method can be called on a column value.
     *
     *@exception  SQLException  if a database access error occurs or the result
     *      set is not updatable
     */
    public void moveToInsertRow() throws SQLException
    {
        throw new SQLException("ResultSet is not updateable");
    }

    /**
     *  JDBC 2.0 Moves the cursor to the remembered cursor position, usually the
     *  current row. This method has no effect if the cursor is not on the
     *  insert row.
     *
     *@exception  SQLException  if a database access error occurs or the result
     *      set is not updatable
     */
    public void moveToCurrentRow() throws SQLException
    {
        throw new SQLException("ResultSet is not updateable");
    }

    public synchronized PacketRowResult currentRow() throws SQLException
    {
        checkClosed();

        if( rowIndex < 0 )
            throw new SQLException("No current row in the ResultSet");
        else if( rowIndex >= rowCount )
            throw new SQLException("No more results in ResultSet");

        return rowCache[rowIndex];
    }

    /**
     * Checks whether there are more results in the cache or, if the cache is
     * empty, gets the next batch of results.
     */
    private boolean haveMoreResults() throws SQLException
    {
        if( rowCount>0 && rowIndex<rowCount-1 )
            return true;

        if( hitEndOfData )
        {
            rowCount = 0;
            return false;
        }

        // Get next batch of results
        return internalFetchRows() > 0;
    }

    /**
     * Caches the next lot of rows, and returns the number of rows cached.
     * The current row is lost! Use with care!
     *
     * @return    the number of rows cached
     * @exception SQLException if an SQL error occurs
     */
    private int internalFetchRows() throws SQLException
    {
        rowCount = 0;

        do
        {
            PacketRowResult row = fetchNextRow();
            if( hitEndOfData )
                break;

            rowCache[rowCount] = row;
            rowCount++;
            // SAfe Need to set this so that next() will set it to 0
            // Not very efficient, but this should be set only if we got a row
            rowIndex = -1;
        } while (rowCount < fetchSize);

        return rowCount;
    }

    /**
     * Increases the size of the internal cache (keeping its contents).
     */
    private void reallocCache()
    {
        if( rowCache.length == fetchSize )
        {
            PacketRowResult[] newCache = new PacketRowResult[fetchSize*2];
            System.arraycopy(rowCache, 0, newCache, 0, rowCache.length);
            rowCache = newCache;
            fetchSize *= 2;
        }
        else
            // Make it as large as possible, it doesn't matter since we only do
            // this when fetching all rows into the cache.
            fetchSize = rowCache.length;
    }

    /**
     * Caches all unread rows into the internal cache, enlarging it as
     * necessary. Can be quite memory-consuming, depending on result size.
     */
    synchronized void fetchIntoCache() throws SQLException
    {
        checkClosed();

        if( rowCount == 0 )
            internalFetchRows();

        if( hitEndOfData )
            return;

        if( rowIndex>0 && rowIndex<rowCount)
        {
            System.arraycopy(rowCache,rowIndex,rowCache,0,rowCount-rowIndex);
            rowCount -= rowIndex;
            rowIndex = 0;
        }
        // Only if the cache is full
        else if( rowIndex<=0 && rowCount==fetchSize )
            reallocCache();

        while (!hitEndOfData)
        {
            do
            {
                PacketRowResult row = fetchNextRow();
                if( hitEndOfData )
                    break;

                rowCache[rowCount] = row;
                rowCount++;
            } while( rowCount < fetchSize );

            if( !hitEndOfData )
                reallocCache();
        }
    }

    private void checkClosed() throws SQLException
    {
        if( isClosed )
            throw new SQLException("Invalid state: ResultSet closed.");
    }
}

⌨️ 快捷键说明

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