10133 lines · 431.3 KB · Java
RawDownload
            } else if (cursorPos == numRows) {                // increment to after last                ++cursorPos;                ret = false;                break;            }        } while ((getShowDeleted() == false) && (rowDeleted() == true));         /* each call to internalNext may increment cursorPos multiple         * times however, the absolutePos only increments once per call.         */        if (ret == true)            absolutePos++;        else            absolutePos = 0;         return ret;    }     /**     * Closes this <code>CachedRowSetImpl</code> objecy and releases any resources     * it was using.     *     * @throws SQLException if an error occurs when releasing any resources in use     * by this <code>CachedRowSetImpl</code> object     */    public void close() throws SQLException {         // close all data structures holding        // the disconnected rowset         cursorPos = 0;        absolutePos = 0;        numRows = 0;        numDeleted = 0;         // set all insert(s), update(s) & delete(s),        // if at all, to their initial values.        initProperties();         // clear the vector of it's present contents        rvh.clear();         // this will make it eligible for gc        // rvh = null;    }     /**     * Reports whether the last column read was SQL <code>NULL</code>.     * Note that you must first call the method <code>getXXX</code>     * on a column to try to read its value and then call the method     * <code>wasNull</code> to determine whether the value was     * SQL <code>NULL</code>.     *     * @return <code>true</code> if the value in the last column read     *         was SQL <code>NULL</code>; <code>false</code> otherwise     * @throws SQLException if an error occurs     */    public boolean wasNull() throws SQLException {        return lastValueNull;    }     /**     * Sets the field <code>lastValueNull</code> to the given     * <code>boolean</code> value.     *     * @param value <code>true</code> to indicate that the value of     *        the last column read was SQL <code>NULL</code>;     *        <code>false</code> to indicate that it was not     */    private void setLastValueNull(boolean value) {        lastValueNull = value;    }     // Methods for accessing results by column index     /**     * Checks to see whether the given index is a valid column number     * in this <code>CachedRowSetImpl</code> object and throws     * an <code>SQLException</code> if it is not. The index is out of bounds     * if it is less than <code>1</code> or greater than the number of     * columns in this rowset.     * <P>     * This method is called internally by the <code>getXXX</code> and     * <code>updateXXX</code> methods.     *     * @param idx the number of a column in this <code>CachedRowSetImpl</code>     *            object; must be between <code>1</code> and the number of     *            rows in this rowset     * @throws SQLException if the given index is out of bounds     */    private void checkIndex(int idx) throws SQLException {        if (idx < 1 || idx > RowSetMD.getColumnCount()) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcol").toString());        }    }     /**     * Checks to see whether the cursor for this <code>CachedRowSetImpl</code>     * object is on a row in the rowset and throws an     * <code>SQLException</code> if it is not.     * <P>     * This method is called internally by <code>getXXX</code> methods, by     * <code>updateXXX</code> methods, and by methods that update, insert,     * or delete a row or that cancel a row update, insert, or delete.     *     * @throws SQLException if the cursor for this <code>CachedRowSetImpl</code>     *         object is not on a valid row     */    private void checkCursor() throws SQLException {        if (isAfterLast() == true || isBeforeFirst() == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcp").toString());        }    }     /**     * Returns the column number of the column with the given name in this     * <code>CachedRowSetImpl</code> object.  This method throws an     * <code>SQLException</code> if the given name is not the name of     * one of the columns in this rowset.     *     * @param name a <code>String</code> object that is the name of a column in     *              this <code>CachedRowSetImpl</code> object     * @throws SQLException if the given name does not match the name of one of     *         the columns in this rowset     */    private int getColIdxByName(String name) throws SQLException {        RowSetMD = (RowSetMetaDataImpl)this.getMetaData();        int cols = RowSetMD.getColumnCount();         for (int i=1; i <= cols; ++i) {            String colName = RowSetMD.getColumnName(i);            if (colName != null)                if (name.equalsIgnoreCase(colName))                    return (i);                else                    continue;        }        throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalcolnm").toString());     }     /**     * Returns the insert row or the current row of this     * <code>CachedRowSetImpl</code>object.     *     * @return the <code>Row</code> object on which this <code>CachedRowSetImpl</code>     * objects's cursor is positioned     */    protected BaseRow getCurrentRow() {        if (onInsertRow == true) {            return (BaseRow)insertRow;        } else {            return (BaseRow)(rvh.get(cursorPos - 1));        }    }     /**     * Removes the row on which the cursor is positioned.     * <p>     * This is a implementation only method and is not required as a standard     * implementation of the <code>CachedRowSet</code> interface.     *     * @throws SQLException if the cursor is positioned on the insert     *            row     */    protected void removeCurrentRow() {        ((Row)getCurrentRow()).setDeleted();        rvh.remove(cursorPos - 1);        --numRows;    }      /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>String</code> object.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>null</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, SMALLINT, INTEGER, BIGINT, REAL,     * FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, <b>CHAR</b>, <b>VARCHAR</b></code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     */    public String getString(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return null;        }         return value.toString();    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>boolean</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value as a <code>boolean</code> in the Java progamming language;     *        if the value is SQL <code>NULL</code>, the result is <code>false</code>     * @throws SQLException if (1) the given column index is out of bounds,     *            (2) the cursor is not on one of this rowset's rows or its     *            insert row, or (3) the designated column does not store an     *            SQL <code>BOOLEAN</code> value     * @see #getBoolean(String)     */    public boolean getBoolean(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return false;        }         // check for Boolean...        if (value instanceof Boolean) {            return ((Boolean)value).booleanValue();        }         // convert to a Double and compare to zero        try {            Double d = new Double(value.toString());            if (d.compareTo(new Double((double)0)) == 0) {                return false;            } else {                return true;            }        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.boolfail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>byte</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value as a <code>byte</code> in the Java programming     * language; if the value is SQL <code>NULL</code>, the result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     *            (2) the cursor is not on one of this rowset's rows or its     *            insert row, or (3) the designated column does not store an     *            SQL <code><b>TINYINT</b>, SMALLINT, INTEGER, BIGINT, REAL,     *            FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     *            or <code>LONGVARCHAR</code> value. The bold SQL type     *            designates the recommended return type.     * @see #getByte(String)     */    public byte getByte(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return (byte)0;        }        try {            return ((Byte.valueOf(value.toString())).byteValue());        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.bytefail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>short</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, <b>SMALLINT</b>, INTEGER, BIGINT, REAL     * FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     * @see #getShort(String)     */    public short getShort(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return (short)0;        }         try {            return ((Short.valueOf(value.toString().trim())).shortValue());        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.shortfail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as an     * <code>int</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, SMALLINT, <b>INTEGER</b>, BIGINT, REAL     * FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     */    public int getInt(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return (int)0;        }         try {            return ((Integer.valueOf(value.toString().trim())).intValue());        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.intfail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>long</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, SMALLINT, INTEGER, <b>BIGINT</b>, REAL     * FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     * @see #getLong(String)     */    public long getLong(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return (long)0;        }        try {            return ((Long.valueOf(value.toString().trim())).longValue());        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.longfail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>float</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, SMALLINT, INTEGER, BIGINT, <b>REAL</b>,     * FLOAT, DOUBLE, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     * @see #getFloat(String)     */    public float getFloat(int columnIndex) throws SQLException {        Object value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         setLastValueNull(false);        value = getCurrentRow().getColumnObject(columnIndex);         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return (float)0;        }        try {            return ((new Float(value.toString())).floatValue());        } catch (NumberFormatException ex) {            throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.floatfail").toString(),                  new Object[] {value.toString().trim(), columnIndex}));        }    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a     * <code>double</code> value.     *     * @param columnIndex the first column is <code>1</code>, the second     *        is <code>2</code>, and so on; must be <code>1</code> or larger     *        and equal to or less than the number of columns in the rowset     * @return the column value; if the value is SQL <code>NULL</code>, the     *         result is <code>0</code>     * @throws SQLException if (1) the given column index is out of bounds,     * (2) the cursor is not on one of this rowset's rows or its     * insert row, or (3) the designated column does not store an     * SQL <code>TINYINT, SMALLINT, INTEGER, BIGINT, REAL,     * <b>FLOAT</b>, <b>DOUBLE</b>, DECIMAL, NUMERIC, BIT, CHAR, VARCHAR</code>     * or <code>LONGVARCHAR</code> value. The bold SQL type designates the     * recommended return type.     * @see #getDouble(String)     *     */    public double getDouble(int columnIndex) throws SQLException {

Lines 1501–2000 of 10133. Previous lines