10133 lines · 431.3 KB · Java
RawDownload
     */    public void updateRow() throws SQLException {        // make sure we aren't on the insert row        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.updateins").toString());        }         ((Row)getCurrentRow()).setUpdated();         // notify the listeners that the row changed.        notifyRowChanged();    }     /**     * Deletes the current row from this <code>CachedRowSetImpl</code> object and     * notifies listeners registered with this rowset that a row has changed.     * This method cannot be called when the cursor is on the insert row.     * <P>     * This method marks the current row as deleted, but it does not delete     * the row from the underlying data source.  The method     * <code>acceptChanges</code> must be called to delete the row in     * the data source.     *     * @throws SQLException if (1) this method is called when the cursor     *            is on the insert row, before the first row, or after the     *            last row or (2) this rowset is     *            <code>ResultSet.CONCUR_READ_ONLY</code>     */    public void deleteRow() throws SQLException {        // make sure the cursor is on a valid row        checkCursor();         ((Row)getCurrentRow()).setDeleted();        ++numDeleted;         // notify the listeners that the row changed.        notifyRowChanged();    }     /**     * Sets the current row with its original value and marks the row as     * not updated, thus undoing any changes made to the row since the     * last call to the methods <code>updateRow</code> or <code>deleteRow</code>.     * This method should be called only when the cursor is on a row in     * this rowset.     *     * @throws SQLException if the cursor is on the insert row, before the     *            first row, or after the last row     */    public void refreshRow() throws SQLException {        // make sure we are on a row        checkCursor();         // don't want this to happen...        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcp").toString());        }         Row currentRow = (Row)getCurrentRow();        // just undo any changes made to this row.        currentRow.clearUpdated();     }     /**     * Rolls back any updates made to the current row of this     * <code>CachedRowSetImpl</code> object and notifies listeners that     * a row has changed.  To have an effect, this method     * must be called after an <code>updateXXX</code> method has been     * called and before the method <code>updateRow</code> has been called.     * If no updates have been made or the method <code>updateRow</code>     * has already been called, this method has no effect.     *     * @throws SQLException if the cursor is on the insert row, before the     *            first row, or after the last row     */    public void cancelRowUpdates() throws SQLException {        // make sure we are on a row        checkCursor();         // don't want this to happen...        if (onInsertRow == true) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.invalidcp").toString());        }         Row currentRow = (Row)getCurrentRow();        if (currentRow.getUpdated() == true) {            currentRow.clearUpdated();            notifyRowChanged();        }    }     /**     * Moves the cursor for this <code>CachedRowSetImpl</code> object     * to the insert row.  The current row in the rowset is remembered     * while the cursor is on the insert row.     * <P>     * The insert row is a special row associated with an updatable     * rowset.  It is essentially a buffer where a new row may     * be constructed by calling the appropriate <code>updateXXX</code>     * methods to assign a value to each column in the row.  A complete     * row must be constructed; that is, every column that is not nullable     * must be assigned a value.  In order for the new row to become part     * of this rowset, the method <code>insertRow</code> must be called     * before the cursor is moved back to the rowset.     * <P>     * Only certain methods may be invoked while the cursor is on the insert     * row; many methods throw an exception if they are called while the     * cursor is there.  In addition to the <code>updateXXX</code>     * and <code>insertRow</code> methods, only the <code>getXXX</code> methods     * may be called when the cursor is on the insert row.  A <code>getXXX</code>     * method should be called on a column only after an <code>updateXXX</code>     * method has been called on that column; otherwise, the value returned is     * undetermined.     *     * @throws SQLException if this <code>CachedRowSetImpl</code> object is     *            <code>ResultSet.CONCUR_READ_ONLY</code>     */    public void moveToInsertRow() throws SQLException {        if (getConcurrency() == ResultSet.CONCUR_READ_ONLY) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.movetoins").toString());        }        if (insertRow == null) {            if (RowSetMD == null)                throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.movetoins1").toString());            int numCols = RowSetMD.getColumnCount();            if (numCols > 0) {                insertRow = new InsertRow(numCols);            } else {                throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.movetoins2").toString());            }        }        onInsertRow = true;        // %%% setCurrentRow called in BaseRow         currentRow = cursorPos;        cursorPos = -1;         insertRow.initInsertRow();    }     /**     * Moves the cursor for this <code>CachedRowSetImpl</code> object to     * the current row.  The current row is the row the cursor was on     * when the method <code>moveToInsertRow</code> was called.     * <P>     * Calling this method has no effect unless it is called while the     * cursor is on the insert row.     *     * @throws SQLException if an error occurs     */    public void moveToCurrentRow() throws SQLException {        if (onInsertRow == false) {            return;        } else {            cursorPos = currentRow;            onInsertRow = false;        }    }     /**     * Returns <code>null</code>.     *     * @return <code>null</code>     * @throws SQLException if an error occurs     */    public Statement getStatement() throws SQLException {        return null;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as an <code>Object</code> in     * the Java programming language, using the given     * <code>java.util.Map</code> object to custom map the value if     * appropriate.     *     * @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 this rowset     * @param map a <code>java.util.Map</code> object showing the mapping     *            from SQL type names to classes in the Java programming     *            language     * @return an <code>Object</code> representing the SQL value     * @throws SQLException if the given column index is out of bounds or     *            the cursor is not on one of this rowset's rows or its     *            insert row     */     public Object getObject(int columnIndex,                             java.util.Map<String,Class<?>> map)         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;        }        if (value instanceof Struct) {            Struct s = (Struct)value;             // look up the class in the map            Class c = (Class)map.get(s.getSQLTypeName());            if (c != null) {                // create new instance of the class                SQLData obj = null;                try {                    obj = (SQLData)c.newInstance();                } catch (java.lang.InstantiationException ex) {                    throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(),                    ex.getMessage()));                } catch (java.lang.IllegalAccessException ex) {                    throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.unableins").toString(),                    ex.getMessage()));                }                // get the attributes from the struct                Object attribs[] = s.getAttributes(map);                // create the SQLInput "stream"                SQLInputImpl sqlInput = new SQLInputImpl(attribs, map);                // read the values...                obj.readSQL(sqlInput, s.getSQLTypeName());                return (Object)obj;            }        }        return value;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Ref</code> object     * in the Java programming language.     *     * @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 this rowset     * @return a <code>Ref</code> object representing an SQL<code> REF</code> value     * @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>REF</code> value     * @see #getRef(String)     */    public Ref getRef(int columnIndex) throws SQLException {        Ref value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         if (RowSetMD.getColumnType(columnIndex) != java.sql.Types.REF) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());        }         setLastValueNull(false);        value = (Ref)(getCurrentRow().getColumnObject(columnIndex));         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return null;        }         return value;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Blob</code> object     * in the Java programming language.     *     * @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 this rowset     * @return a <code>Blob</code> object representing an SQL <code>BLOB</code> value     * @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>BLOB</code> value     * @see #getBlob(String)     */    public Blob getBlob(int columnIndex) throws SQLException {        Blob value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         if (RowSetMD.getColumnType(columnIndex) != java.sql.Types.BLOB) {            System.out.println(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.type").toString(), RowSetMD.getColumnType(columnIndex)));            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());        }         setLastValueNull(false);        value = (Blob)(getCurrentRow().getColumnObject(columnIndex));         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return null;        }         return value;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Clob</code> object     * in the Java programming language.     *     * @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 this rowset     * @return a <code>Clob</code> object representing an SQL <code>CLOB</code> value     * @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>CLOB</code> value     * @see #getClob(String)     */    public Clob getClob(int columnIndex) throws SQLException {        Clob value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         if (RowSetMD.getColumnType(columnIndex) != java.sql.Types.CLOB) {            System.out.println(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.type").toString(), RowSetMD.getColumnType(columnIndex)));            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());        }         setLastValueNull(false);        value = (Clob)(getCurrentRow().getColumnObject(columnIndex));         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return null;        }         return value;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as an <code>Array</code> object     * in the Java programming language.     *     * @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 this rowset     * @return an <code>Array</code> object representing an SQL     *         <code>ARRAY</code> value     * @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>ARRAY</code> value     * @see #getArray(String)     */    public Array getArray(int columnIndex) throws SQLException {        java.sql.Array value;         // sanity check.        checkIndex(columnIndex);        // make sure the cursor is on a valid row        checkCursor();         if (RowSetMD.getColumnType(columnIndex) != java.sql.Types.ARRAY) {            throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString());        }         setLastValueNull(false);        value = (java.sql.Array)(getCurrentRow().getColumnObject(columnIndex));         // check for SQL NULL        if (value == null) {            setLastValueNull(true);            return null;        }         return value;    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as an <code>Object</code> in     * the Java programming language, using the given     * <code>java.util.Map</code> object to custom map the value if     * appropriate.     *     * @param columnName a <code>String</code> object that must match the     *        SQL name of a column in this rowset, ignoring case     * @param map a <code>java.util.Map</code> object showing the mapping     *        from SQL type names to classes in the Java programming     *        language     * @return an <code>Object</code> representing the SQL value     * @throws SQLException if the given column name is not the name of     *         a column in this rowset or the cursor is not on one of     *         this rowset's rows or its insert row     */    public Object getObject(String columnName,                            java.util.Map<String,Class<?>> map)    throws SQLException {        return getObject(getColIdxByName(columnName), map);    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Ref</code> object     * in the Java programming language.     *     * @param colName a <code>String</code> object that must match the     *        SQL name of a column in this rowset, ignoring case     * @return a <code>Ref</code> object representing an SQL<code> REF</code> value     * @throws SQLException  if (1) the given column name is not the name of     *            a column in this rowset, (2) the cursor is not on one of     *            this rowset's rows or its insert row, or (3) the column value     *            is not an SQL <code>REF</code> value     * @see #getRef(int)     */    public Ref getRef(String colName) throws SQLException {        return getRef(getColIdxByName(colName));    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Blob</code> object     * in the Java programming language.     *     * @param colName a <code>String</code> object that must match the     *        SQL name of a column in this rowset, ignoring case     * @return a <code>Blob</code> object representing an SQL <code>BLOB</code> value     * @throws SQLException if (1) the given column name is not the name of     *            a column in this rowset, (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>BLOB</code> value     * @see #getBlob(int)     */    public Blob getBlob(String colName) throws SQLException {        return getBlob(getColIdxByName(colName));    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as a <code>Clob</code> object     * in the Java programming language.     *     * @param colName a <code>String</code> object that must match the     *        SQL name of a column in this rowset, ignoring case     * @return a <code>Clob</code> object representing an SQL     *         <code>CLOB</code> value     * @throws SQLException if (1) the given column name is not the name of     *            a column in this rowset, (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>CLOB</code> value     * @see #getClob(int)     */    public Clob getClob(String colName) throws SQLException {        return getClob(getColIdxByName(colName));    }     /**     * Retrieves the value of the designated column in this     * <code>CachedRowSetImpl</code> object as an <code>Array</code> object     * in the Java programming langugage.     *     * @param colName a <code>String</code> object that must match the     *        SQL name of a column in this rowset, ignoring case     * @return an <code>Array</code> object representing an SQL     *         <code>ARRAY</code> value     * @throws SQLException if (1) the given column name is not the name of     *            a column in this rowset, (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>ARRAY</code> value     * @see #getArray(int)     */    public Array getArray(String colName) throws SQLException {        return getArray(getColIdxByName(colName));    }     /**     * Retrieves the value of the designated column in the current row     * of this <code>CachedRowSetImpl</code> object as a <code>java.sql.Date</code>     * object, using the given <code>Calendar</code> object to construct an     * appropriate millisecond value for the date.     *     * @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

Lines 5501–6000 of 10133. Previous lines