10133 lines · 431.3 KB · Java
RawDownload
     */    public boolean absolute( int row ) throws SQLException {        if (row == 0 || getType() == ResultSet.TYPE_FORWARD_ONLY) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.absolute").toString());        }         if (row > 0) { // we are moving foward            if (row > numRows) {                // fell off the end                afterLast();                return false;            } else {                if (absolutePos <= 0)                    internalFirst();            }        } else { // we are moving backward            if (cursorPos + row < 0) {                // fell off the front                beforeFirst();                return false;            } else {                if (absolutePos >= 0)                    internalLast();            }        }         // Now move towards the absolute row that we're looking for        while (absolutePos != row) {            if (absolutePos < row) {                if (!internalNext())                    break;            }            else {                if (!internalPrevious())                    break;            }        }         notifyCursorMoved();         if (isAfterLast() || isBeforeFirst()) {            return false;        } else {            return true;        }    }     /**     * Moves the cursor the specified number of rows from the current     * position, with a positive number moving it forward and a     * negative number moving it backward.     * <P>     * If the number is positive, the cursor moves the specified number of     * rows toward the end of the rowset, starting at the current row.     * For example, the following command, in which     * <code>crs</code> is a <code>CachedRowSetImpl</code> object with 100 rows,     * moves the cursor forward four rows from the current row.  If the     * current row is 50, the cursor would move to row 54.     * <PRE><code>     *     *    crs.relative(4);     *     * </code> </PRE>     * <P>     * If the number is negative, the cursor moves back toward the beginning     * the specified number of rows, starting at the current row.     * For example, calling the method     * <code>absolute(-1)</code> positions the cursor on the last row,     * <code>absolute(-2)</code> moves it on the next-to-last row, and so on.     * If the <code>CachedRowSetImpl</code> object <code>crs</code> has five rows,     * the following command moves the cursor to the fourth-to-last row, which     * in the case of a  rowset with five rows, is also the second row     * from the beginning.     * <PRE><code>     *     *    crs.absolute(-4);     *     * </code> </PRE>     *     * If the number specified is larger than the number of rows, the cursor     * will move to the position after the last row. If the number specified     * would move the cursor one or more rows before the first row, the cursor     * moves to the position before the first row. In both cases, this method     * throws an <code>SQLException</code>.     * <P>     * Note: Calling <code>absolute(1)</code> is the same as calling the     * method <code>first()</code>.  Calling <code>absolute(-1)</code> is the     * same as calling <code>last()</code>.  Calling <code>relative(0)</code>     * is valid, but it does not change the cursor position.     *     * @param rows an <code>int</code> indicating the number of rows to move     *             the cursor, starting at the current row; a positive number     *             moves the cursor forward; a negative number moves the cursor     *             backward; must not move the cursor past the valid     *             rows     * @return <code>true</code> if the cursor is on a row in this     *         <code>CachedRowSetImpl</code> object; <code>false</code>     *         otherwise     * @throws SQLException if there are no rows in this rowset, the cursor is     *         positioned either before the first row or after the last row, or     *         the rowset is type <code>ResultSet.TYPE_FORWARD_ONLY</code>     */    public boolean relative(int rows) throws SQLException {        if (numRows == 0 || isBeforeFirst() ||        isAfterLast() || getType() == ResultSet.TYPE_FORWARD_ONLY) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.relative").toString());        }         if (rows == 0) {            return true;        }         if (rows > 0) { // we are moving forward            if (cursorPos + rows > numRows) {                // fell off the end                afterLast();            } else {                for (int i=0; i < rows; i++) {                    if (!internalNext())                        break;                }            }        } else { // we are moving backward            if (cursorPos + rows < 0) {                // fell off the front                beforeFirst();            } else {                for (int i=rows; i < 0; i++) {                    if (!internalPrevious())                        break;                }            }        }        notifyCursorMoved();         if (isAfterLast() || isBeforeFirst()) {            return false;        } else {            return true;        }    }     /**     * Moves this <code>CachedRowSetImpl</code> object's cursor to the     * previous row and returns <code>true</code> if the cursor is on     * a valid row or <code>false</code> if it is not.     * This method also notifies all listeners registered with this     * <code>CachedRowSetImpl</code> object that its cursor has moved.     * <P>     * Note: calling the method <code>previous()</code> is not the same     * as calling the method <code>relative(-1)</code>.  This is true     * because it is possible to call <code>previous()</code> from the insert     * row, from after the last row, or from the current row, whereas     * <code>relative</code> may only be called from the current row.     * <P>     * The method <code>previous</code> may used in a <code>while</code>     * loop to iterate through a rowset starting after the last row     * and moving toward the beginning. The loop ends when <code>previous</code>     * returns <code>false</code>, meaning that there are no more rows.     * For example, the following code fragment retrieves all the data in     * the <code>CachedRowSetImpl</code> object <code>crs</code>, which has     * three columns.  Note that the cursor must initially be positioned     * after the last row so that the first call to the method     * <code>previous</code> places the cursor on the last line.     * <PRE> <code>     *     *     crs.afterLast();     *     while (previous()) {     *         String name = crs.getString(1);     *         int age = crs.getInt(2);     *         short ssn = crs.getShort(3);     *         System.out.println(name + "   " + age + "   " + ssn);     *     }     *     * </code> </PRE>     * This method throws an <code>SQLException</code> if the cursor is not     * on a row in the rowset, before the first row, or after the last row.     *     * @return <code>true</code> if the cursor is on a valid row;     *         <code>false</code> if it is before the first row or after the     *         last row     * @throws SQLException if the cursor is not on a valid position or the     *           type of this rowset is <code>ResultSet.TYPE_FORWARD_ONLY</code>     */    public boolean previous() throws SQLException {        if (getType() == ResultSet.TYPE_FORWARD_ONLY) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.last").toString());        }        /*         * make sure things look sane. The cursor must be         * positioned in the rowset or before first (0) or         * after last (numRows + 1)         */        if (cursorPos < 0 || cursorPos > numRows + 1) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcp").toString());        }        // move and notify        boolean ret = this.internalPrevious();        notifyCursorMoved();         return ret;    }     /**     * Moves the cursor to the previous row in this <code>CachedRowSetImpl</code>     * object, skipping past deleted rows that are not visible; returns     * <code>true</code> if the cursor is on a row in this rowset and     * <code>false</code> when the cursor goes before the first row.     * <P>     * This method is called internally by the method <code>previous</code>.     * <P>     * This is a implementation only method and is not required as a standard     * implementation of the <code>CachedRowSet</code> interface.     *     * @return <code>true</code> if the cursor is on a row in this rowset;     *         <code>false</code> when the cursor reaches the position before     *         the first row     * @throws SQLException if an error occurs     */    protected boolean internalPrevious() throws SQLException {        boolean ret = false;         do {            if (cursorPos > 1) {                --cursorPos;                ret = true;            } else if (cursorPos == 1) {                // decrement to before first                --cursorPos;                ret = false;                break;            }        } while ((getShowDeleted() == false) && (rowDeleted() == true));         /*         * Each call to internalPrevious may move the cursor         * over multiple rows, the absolute postion moves one one row         */        if (ret == true)            --absolutePos;        else            absolutePos = 0;         return ret;    }      //---------------------------------------------------------------------    // Updates    //---------------------------------------------------------------------     /**     * Indicates whether the current row of this <code>CachedRowSetImpl</code>     * object has been updated.  The value returned     * depends on whether this rowset can detect updates: <code>false</code>     * will always be returned if it does not detect updates.     *     * @return <code>true</code> if the row has been visibly updated     *         by the owner or another and updates are detected;     *         <code>false</code> otherwise     * @throws SQLException if the cursor is on the insert row or not     *            not on a valid row     *     * @see DatabaseMetaData#updatesAreDetected     */    public boolean rowUpdated() throws SQLException {        // make sure the cursor is on a valid row        checkCursor();        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidop").toString());        }        return(((Row)getCurrentRow()).getUpdated());    }     /**     * Indicates whether the designated column of the current row of     * this <code>CachedRowSetImpl</code> object has been updated. The     * value returned depends on whether this rowset can detcted updates:     * <code>false</code> will always be returned if it does not detect updates.     *     * @param idx the index identifier of the column that may be have been updated.     * @return <code>true</code> is the designated column has been updated     * and the rowset detects updates; <code>false</code> if the rowset has not     * been updated or the rowset does not detect updates     * @throws SQLException if the cursor is on the insert row or not     *          on a valid row     * @see DatabaseMetaData#updatesAreDetected     */    public boolean columnUpdated(int idx) throws SQLException {        // make sure the cursor is on a valid row        checkCursor();        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidop").toString());        }        return (((Row)getCurrentRow()).getColUpdated(idx - 1));    }     /**     * Indicates whether the designated column of the current row of     * this <code>CachedRowSetImpl</code> object has been updated. The     * value returned depends on whether this rowset can detcted updates:     * <code>false</code> will always be returned if it does not detect updates.     *     * @param columnName the <code>String</code> column name column that may be have     * been updated.     * @return <code>true</code> is the designated column has been updated     * and the rowset detects updates; <code>false</code> if the rowset has not     * been updated or the rowset does not detect updates     * @throws SQLException if the cursor is on the insert row or not     *          on a valid row     * @see DatabaseMetaData#updatesAreDetected     */    public boolean columnUpdated(String columnName) throws SQLException {        return columnUpdated(getColIdxByName(columnName));    }     /**     * Indicates whether the current row has been inserted.  The value returned     * depends on whether or not the rowset can detect visible inserts.     *     * @return <code>true</code> if a row has been inserted and inserts are detected;     *         <code>false</code> otherwise     * @throws SQLException if the cursor is on the insert row or not     *            not on a valid row     *     * @see DatabaseMetaData#insertsAreDetected     */    public boolean rowInserted() throws SQLException {        // make sure the cursor is on a valid row        checkCursor();        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidop").toString());        }        return(((Row)getCurrentRow()).getInserted());    }     /**     * Indicates whether the current row has been deleted.  A deleted row     * may leave a visible "hole" in a rowset.  This method can be used to     * detect such holes if the rowset can detect deletions. This method     * will always return <code>false</code> if this rowset cannot detect     * deletions.     *     * @return <code>true</code> if (1)the current row is blank, indicating that     *         the row has been deleted, and (2)deletions are detected;     *         <code>false</code> otherwise     * @throws SQLException if the cursor is on a valid row in this rowset     * @see DatabaseMetaData#deletesAreDetected     */    public boolean rowDeleted() throws SQLException {        // make sure the cursor is on a valid row         if (isAfterLast() == true ||        isBeforeFirst() == true ||        onInsertRow == true) {             throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcp").toString());        }        return(((Row)getCurrentRow()).getDeleted());    }     /**     * Indicates whether the given SQL data type is a numberic type.     *     * @param type one of the constants from <code>java.sql.Types</code>     * @return <code>true</code> if the given type is <code>NUMERIC</code>,'     *         <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>,     *         <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>,     *         <code>REAL</code>, <code>DOUBLE</code>, or <code>FLOAT</code>;     *         <code>false</code> otherwise     */    private boolean isNumeric(int type) {        switch (type) {            case java.sql.Types.NUMERIC:            case java.sql.Types.DECIMAL:            case java.sql.Types.BIT:            case java.sql.Types.TINYINT:            case java.sql.Types.SMALLINT:            case java.sql.Types.INTEGER:            case java.sql.Types.BIGINT:            case java.sql.Types.REAL:            case java.sql.Types.DOUBLE:            case java.sql.Types.FLOAT:                return true;            default:                return false;        }    }     /**     * Indicates whether the given SQL data type is a string type.     *     * @param type one of the constants from <code>java.sql.Types</code>     * @return <code>true</code> if the given type is <code>CHAR</code>,'     *         <code>VARCHAR</code>, or <code>LONGVARCHAR</code>;     *         <code>false</code> otherwise     */    private boolean isString(int type) {        switch (type) {            case java.sql.Types.CHAR:            case java.sql.Types.VARCHAR:            case java.sql.Types.LONGVARCHAR:                return true;            default:                return false;        }    }     /**     * Indicates whether the given SQL data type is a binary type.     *     * @param type one of the constants from <code>java.sql.Types</code>     * @return <code>true</code> if the given type is <code>BINARY</code>,'     *         <code>VARBINARY</code>, or <code>LONGVARBINARY</code>;     *         <code>false</code> otherwise     */    private boolean isBinary(int type) {        switch (type) {            case java.sql.Types.BINARY:            case java.sql.Types.VARBINARY:            case java.sql.Types.LONGVARBINARY:                return true;            default:                return false;        }    }     /**     * Indicates whether the given SQL data type is a temporal type.     * This method is called internally by the conversion methods     * <code>convertNumeric</code> and <code>convertTemporal</code>.     *     * @param type one of the constants from <code>java.sql.Types</code>     * @return <code>true</code> if the given type is <code>DATE</code>,     *         <code>TIME</code>, or <code>TIMESTAMP</code>;     *         <code>false</code> otherwise     */    private boolean isTemporal(int type) {        switch (type) {            case java.sql.Types.DATE:            case java.sql.Types.TIME:            case java.sql.Types.TIMESTAMP:                return true;            default:                return false;        }    }     /**     * Indicates whether the given SQL data type is a boolean type.     * This method is called internally by the conversion methods     * <code>convertNumeric</code> and <code>convertBoolean</code>.     *     * @param type one of the constants from <code>java.sql.Types</code>     * @return <code>true</code> if the given type is <code>BIT</code>,     *         , or <code>BOOLEAN</code>;     *         <code>false</code> otherwise     */    private boolean isBoolean(int type) {        switch (type) {            case java.sql.Types.BIT:            case java.sql.Types.BOOLEAN:                return true;            default:                return false;        }    }      /**     * Converts the given <code>Object</code> in the Java programming language     * to the standard mapping for the specified SQL target data type.     * The conversion must be to a string or numeric type, but there are no     * restrictions on the type to be converted.  If the source type and target     * type are the same, the given object is simply returned.     *     * @param srcObj the <code>Object</code> in the Java programming language     *               that is to be converted to the target type     * @param srcType the data type that is the standard mapping in SQL of the     *                object to be converted; must be one of the constants in     *                <code>java.sql.Types</code>     * @param trgType the SQL data type to which to convert the given object;     *                must be one of the following constants in     *                <code>java.sql.Types</code>: <code>NUMERIC</code>,     *         <code>DECIMAL</code>, <code>BIT</code>, <code>TINYINT</code>,     *         <code>SMALLINT</code>, <code>INTEGER</code>, <code>BIGINT</code>,     *         <code>REAL</code>, <code>DOUBLE</code>, <code>FLOAT</code>,     *         <code>VARCHAR</code>, <code>LONGVARCHAR</code>, or <code>CHAR</code>     * @return an <code>Object</code> value.that is     *         the standard object mapping for the target SQL type     * @throws SQLException if the given target type is not one of the string or     *         numeric types in <code>java.sql.Types</code>     */    private Object convertNumeric(Object srcObj, int srcType,    int trgType) throws SQLException {         if (srcType == trgType) {            return srcObj;        } 

Lines 3501–4000 of 10133. Previous lines