* as an array of <code>Object</code> values. This method also custom * maps SQL user-defined types to classes * in the Java programming language. When the specified column contains * a structured or distinct value, the behavior of this method is as * if it were a call to the method <code>getObject(columnIndex, * this.getStatement().getConnection().getTypeMap())</code>. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return a <code>java.lang.Object</code> holding the column value; * if the value is SQL <code>NULL</code>, the result is <code>null</code> * @throws SQLException if (1) the given column name does not match one of * this rowset's column names, (2) the cursor is not * on a valid row, or (3) there is a problem getting * the <code>Class</code> object for a custom mapping * @see #getObject(int) */ public Object getObject(String columnName) throws SQLException { return getObject(getColIdxByName(columnName)); } //---------------------------------------------------------------- /** * Maps the given column name for one of this <code>CachedRowSetImpl</code> * object's columns to its column number. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return the column index of the given column name * @throws SQLException if the given column name does not match one * of this rowset's column names */ public int findColumn(String columnName) throws SQLException { return getColIdxByName(columnName); } //--------------------------JDBC 2.0----------------------------------- //--------------------------------------------------------------------- // Getter's and Setter's //--------------------------------------------------------------------- /** * Retrieves the value stored in the designated column * of the current row as a <code>java.io.Reader</code> object. * * <P><B>Note:</B> All the data in the returned stream must * be read prior to getting the value of any other column. The * next call to a <code>getXXX</code> method implicitly closes the stream. * * @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 a Java character stream that delivers the database column value * as a stream of two-byte unicode characters in a * <code>java.io.Reader</code> object. 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>CHAR, VARCHAR, <b>LONGVARCHAR</b>, BINARY, VARBINARY</code> or * <code>LONGVARBINARY</code> value. * The bold SQL type designates the recommended return type. * @see #getCharacterStream(String) */ public java.io.Reader getCharacterStream(int columnIndex) throws SQLException{ // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); if (isBinary(RowSetMD.getColumnType(columnIndex))) { Object value = getCurrentRow().getColumnObject(columnIndex); if (value == null) { lastValueNull = true; return null; } charStream = new InputStreamReader (new ByteArrayInputStream((byte[])value)); } else if (isString(RowSetMD.getColumnType(columnIndex))) { Object value = getCurrentRow().getColumnObject(columnIndex); if (value == null) { lastValueNull = true; return null; } charStream = new StringReader(value.toString()); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } return (java.io.Reader)charStream; } /** * Retrieves the value stored in the designated column * of the current row as a <code>java.io.Reader</code> object. * * <P><B>Note:</B> All the data in the returned stream must * be read prior to getting the value of any other column. The * next call to a <code>getXXX</code> method implicitly closes the stream. * * @param columnName a <code>String</code> object giving the SQL name of * a column in this <code>CachedRowSetImpl</code> object * @return a Java input stream that delivers the database column value * as a stream of two-byte Unicode characters. If the value is * SQL <code>NULL</code>, the result is <code>null</code>. * @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>CHAR, VARCHAR, <b>LONGVARCHAR</b>, * BINARY, VARYBINARY</code> or <code>LONGVARBINARY</code> value. * The bold SQL type designates the recommended return type. */ public java.io.Reader getCharacterStream(String columnName) throws SQLException { return getCharacterStream(getColIdxByName(columnName)); } /** * Retrieves the value of the designated column in the current row * of this <code>CachedRowSetImpl</code> object as a * <code>java.math.BigDecimal</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 a <code>java.math.BigDecimal</code> value with full precision; * 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, <b>DECIMAL</b>, <b>NUMERIC</b>, BIT, CHAR, VARCHAR</code> * or <code>LONGVARCHAR</code> value. The bold SQL type designates the * recommended return types that this method is used to retrieve. * @see #getBigDecimal(String) */ public BigDecimal getBigDecimal(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; } try { return (new BigDecimal(value.toString().trim())); } catch (NumberFormatException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.doublefail").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>java.math.BigDecimal</code> object. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return a <code>java.math.BigDecimal</code> value with full precision; * if the value is SQL <code>NULL</code>, the result is <code>null</code> * @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>TINYINT, SMALLINT, INTEGER * BIGINT, REAL, FLOAT, DOUBLE, <b>DECIMAL</b>, <b>NUMERIC</b>, BIT CHAR, * VARCHAR</code> or <code>LONGVARCHAR</code> value. The bold SQL type * designates the recommended return type that this method is used to * retrieve * @see #getBigDecimal(int) */ public BigDecimal getBigDecimal(String columnName) throws SQLException { return getBigDecimal(getColIdxByName(columnName)); } //--------------------------------------------------------------------- // Traversal/Positioning //--------------------------------------------------------------------- /** * Returns the number of rows in this <code>CachedRowSetImpl</code> object. * * @return number of rows in the rowset */ public int size() { return numRows; } /** * Indicates whether the cursor is before the first row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is before the first row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isBeforeFirst() throws SQLException { if (cursorPos == 0 && numRows > 0) { return true; } else { return false; } } /** * Indicates whether the cursor is after the last row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is after the last row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isAfterLast() throws SQLException { if (cursorPos == numRows+1 && numRows > 0) { return true; } else { return false; } } /** * Indicates whether the cursor is on the first row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is on the first row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isFirst() throws SQLException { // this becomes nasty because of deletes. int saveCursorPos = cursorPos; int saveAbsoluteCursorPos = absolutePos; internalFirst(); if (cursorPos == saveCursorPos) { return true; } else { cursorPos = saveCursorPos; absolutePos = saveAbsoluteCursorPos; return false; } } /** * Indicates whether the cursor is on the last row in this * <code>CachedRowSetImpl</code> object. * <P> * Note: Calling the method <code>isLast</code> may be expensive * because the JDBC driver might need to fetch ahead one row in order * to determine whether the current row is the last row in this rowset. * * @return <code>true</code> if the cursor is on the last row; * <code>false</code> otherwise or if this rowset contains no rows * @throws SQLException if an error occurs */ public boolean isLast() throws SQLException { int saveCursorPos = cursorPos; int saveAbsoluteCursorPos = absolutePos; boolean saveShowDeleted = getShowDeleted(); setShowDeleted(true); internalLast(); if (cursorPos == saveCursorPos) { setShowDeleted(saveShowDeleted); return true; } else { setShowDeleted(saveShowDeleted); cursorPos = saveCursorPos; absolutePos = saveAbsoluteCursorPos; return false; } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the front of * the rowset, just before the first row. This method has no effect if * this rowset contains no rows. * * @throws SQLException if an error occurs or the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public void beforeFirst() throws SQLException { if (getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.beforefirst").toString()); } cursorPos = 0; absolutePos = 0; notifyCursorMoved(); } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the end of * the rowset, just after the last row. This method has no effect if * this rowset contains no rows. * * @throws SQLException if an error occurs */ public void afterLast() throws SQLException { if (numRows > 0) { cursorPos = numRows + 1; absolutePos = 0; notifyCursorMoved(); } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the first row * and returns <code>true</code> if the operation was successful. This * method also notifies registered listeners that the cursor has moved. * * @return <code>true</code> if the cursor is on a valid row; * <code>false</code> otherwise or if there are no rows in this * <code>CachedRowSetImpl</code> object * @throws SQLException if the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public boolean first() throws SQLException { if(getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.first").toString()); } // move and notify boolean ret = this.internalFirst(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the first * row and returns <code>true</code> if the operation is successful. * <P> * This method is called internally by the methods <code>first</code>, * <code>isFirst</code>, and <code>absolute</code>. * It in turn calls the method <code>internalNext</code> in order to * handle the case where the first row is a deleted row that is not visible. * <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 moved to the first row; * <code>false</code> otherwise * @throws SQLException if an error occurs */ protected boolean internalFirst() throws SQLException { boolean ret = false; if (numRows > 0) { cursorPos = 1; if ((getShowDeleted() == false) && (rowDeleted() == true)) { ret = internalNext(); } else { ret = true; } } if (ret == true) absolutePos = 1; else absolutePos = 0; return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the last row * and returns <code>true</code> if the operation was successful. This * method also notifies registered listeners that the cursor has moved. * * @return <code>true</code> if the cursor is on a valid row; * <code>false</code> otherwise or if there are no rows in this * <code>CachedRowSetImpl</code> object * @throws SQLException if the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public boolean last() throws SQLException { if (getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.last").toString()); } // move and notify boolean ret = this.internalLast(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the last * row and returns <code>true</code> if the operation is successful. * <P> * This method is called internally by the method <code>last</code> * when rows have been deleted and the deletions are not visible. * The method <code>internalLast</code> handles the case where the * last row is a deleted row that is not visible by in turn calling * the method <code>internalPrevious</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 moved to the last row; * <code>false</code> otherwise * @throws SQLException if an error occurs */ protected boolean internalLast() throws SQLException { boolean ret = false; if (numRows > 0) { cursorPos = numRows; if ((getShowDeleted() == false) && (rowDeleted() == true)) { ret = internalPrevious(); } else { ret = true; } } if (ret == true) absolutePos = numRows - numDeleted; else absolutePos = 0; return ret; } /** * Returns the number of the current row in this <code>CachedRowSetImpl</code> * object. The first row is number 1, the second number 2, and so on. * * @return the number of the current row; <code>0</code> if there is no * current row * @throws SQLException if an error occurs; or if the <code>CacheRowSetImpl</code> * is empty */ public int getRow() throws SQLException { // are we on a valid row? Valid rows are between first and last if (numRows > 0 && cursorPos > 0 && cursorPos < (numRows + 1) && (getShowDeleted() == false && rowDeleted() == false)) { return absolutePos; } else if (getShowDeleted() == true) { return cursorPos; } else { return 0; } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the row number * specified. * * <p>If the number is positive, the cursor moves to an absolute row with * respect to the beginning of the rowset. The first row is row 1, the second * is row 2, and so on. For example, the following command, in which * <code>crs</code> is a <code>CachedRowSetImpl</code> object, moves the cursor * to the fourth row, starting from the beginning of the rowset. * <PRE><code> * * crs.absolute(4); * * </code> </PRE> * <P> * If the number is negative, the cursor moves to an absolute row position * with respect to the end of the rowset. For example, calling * <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, counting * 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. * <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>. * * @param row a positive number to indicate the row, starting row numbering from * the first row, which is <code>1</code>; a negative number to indicate * the row, starting row numbering from the last row, which is * <code>-1</code>; it must not be <code>0</code> * @return <code>true</code> if the cursor is on the rowset; <code>false</code> * otherwise * @throws SQLException if the given cursor position is <code>0</code> or the * type of this rowset is <code>ResultSet.TYPE_FORWARD_ONLY</code>Lines 3001–3500 of 10133. Previous lines Load more
* as an array of <code>Object</code> values. This method also custom * maps SQL user-defined types to classes * in the Java programming language. When the specified column contains * a structured or distinct value, the behavior of this method is as * if it were a call to the method <code>getObject(columnIndex, * this.getStatement().getConnection().getTypeMap())</code>. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return a <code>java.lang.Object</code> holding the column value; * if the value is SQL <code>NULL</code>, the result is <code>null</code> * @throws SQLException if (1) the given column name does not match one of * this rowset's column names, (2) the cursor is not * on a valid row, or (3) there is a problem getting * the <code>Class</code> object for a custom mapping * @see #getObject(int) */ public Object getObject(String columnName) throws SQLException { return getObject(getColIdxByName(columnName)); } //---------------------------------------------------------------- /** * Maps the given column name for one of this <code>CachedRowSetImpl</code> * object's columns to its column number. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return the column index of the given column name * @throws SQLException if the given column name does not match one * of this rowset's column names */ public int findColumn(String columnName) throws SQLException { return getColIdxByName(columnName); } //--------------------------JDBC 2.0----------------------------------- //--------------------------------------------------------------------- // Getter's and Setter's //--------------------------------------------------------------------- /** * Retrieves the value stored in the designated column * of the current row as a <code>java.io.Reader</code> object. * * <P><B>Note:</B> All the data in the returned stream must * be read prior to getting the value of any other column. The * next call to a <code>getXXX</code> method implicitly closes the stream. * * @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 a Java character stream that delivers the database column value * as a stream of two-byte unicode characters in a * <code>java.io.Reader</code> object. 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>CHAR, VARCHAR, <b>LONGVARCHAR</b>, BINARY, VARBINARY</code> or * <code>LONGVARBINARY</code> value. * The bold SQL type designates the recommended return type. * @see #getCharacterStream(String) */ public java.io.Reader getCharacterStream(int columnIndex) throws SQLException{ // sanity check. checkIndex(columnIndex); // make sure the cursor is on a valid row checkCursor(); if (isBinary(RowSetMD.getColumnType(columnIndex))) { Object value = getCurrentRow().getColumnObject(columnIndex); if (value == null) { lastValueNull = true; return null; } charStream = new InputStreamReader (new ByteArrayInputStream((byte[])value)); } else if (isString(RowSetMD.getColumnType(columnIndex))) { Object value = getCurrentRow().getColumnObject(columnIndex); if (value == null) { lastValueNull = true; return null; } charStream = new StringReader(value.toString()); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.dtypemismt").toString()); } return (java.io.Reader)charStream; } /** * Retrieves the value stored in the designated column * of the current row as a <code>java.io.Reader</code> object. * * <P><B>Note:</B> All the data in the returned stream must * be read prior to getting the value of any other column. The * next call to a <code>getXXX</code> method implicitly closes the stream. * * @param columnName a <code>String</code> object giving the SQL name of * a column in this <code>CachedRowSetImpl</code> object * @return a Java input stream that delivers the database column value * as a stream of two-byte Unicode characters. If the value is * SQL <code>NULL</code>, the result is <code>null</code>. * @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>CHAR, VARCHAR, <b>LONGVARCHAR</b>, * BINARY, VARYBINARY</code> or <code>LONGVARBINARY</code> value. * The bold SQL type designates the recommended return type. */ public java.io.Reader getCharacterStream(String columnName) throws SQLException { return getCharacterStream(getColIdxByName(columnName)); } /** * Retrieves the value of the designated column in the current row * of this <code>CachedRowSetImpl</code> object as a * <code>java.math.BigDecimal</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 a <code>java.math.BigDecimal</code> value with full precision; * 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, <b>DECIMAL</b>, <b>NUMERIC</b>, BIT, CHAR, VARCHAR</code> * or <code>LONGVARCHAR</code> value. The bold SQL type designates the * recommended return types that this method is used to retrieve. * @see #getBigDecimal(String) */ public BigDecimal getBigDecimal(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; } try { return (new BigDecimal(value.toString().trim())); } catch (NumberFormatException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.doublefail").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>java.math.BigDecimal</code> object. * * @param columnName a <code>String</code> object that must match the * SQL name of a column in this rowset, ignoring case * @return a <code>java.math.BigDecimal</code> value with full precision; * if the value is SQL <code>NULL</code>, the result is <code>null</code> * @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>TINYINT, SMALLINT, INTEGER * BIGINT, REAL, FLOAT, DOUBLE, <b>DECIMAL</b>, <b>NUMERIC</b>, BIT CHAR, * VARCHAR</code> or <code>LONGVARCHAR</code> value. The bold SQL type * designates the recommended return type that this method is used to * retrieve * @see #getBigDecimal(int) */ public BigDecimal getBigDecimal(String columnName) throws SQLException { return getBigDecimal(getColIdxByName(columnName)); } //--------------------------------------------------------------------- // Traversal/Positioning //--------------------------------------------------------------------- /** * Returns the number of rows in this <code>CachedRowSetImpl</code> object. * * @return number of rows in the rowset */ public int size() { return numRows; } /** * Indicates whether the cursor is before the first row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is before the first row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isBeforeFirst() throws SQLException { if (cursorPos == 0 && numRows > 0) { return true; } else { return false; } } /** * Indicates whether the cursor is after the last row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is after the last row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isAfterLast() throws SQLException { if (cursorPos == numRows+1 && numRows > 0) { return true; } else { return false; } } /** * Indicates whether the cursor is on the first row in this * <code>CachedRowSetImpl</code> object. * * @return <code>true</code> if the cursor is on the first row; * <code>false</code> otherwise or if the rowset contains no rows * @throws SQLException if an error occurs */ public boolean isFirst() throws SQLException { // this becomes nasty because of deletes. int saveCursorPos = cursorPos; int saveAbsoluteCursorPos = absolutePos; internalFirst(); if (cursorPos == saveCursorPos) { return true; } else { cursorPos = saveCursorPos; absolutePos = saveAbsoluteCursorPos; return false; } } /** * Indicates whether the cursor is on the last row in this * <code>CachedRowSetImpl</code> object. * <P> * Note: Calling the method <code>isLast</code> may be expensive * because the JDBC driver might need to fetch ahead one row in order * to determine whether the current row is the last row in this rowset. * * @return <code>true</code> if the cursor is on the last row; * <code>false</code> otherwise or if this rowset contains no rows * @throws SQLException if an error occurs */ public boolean isLast() throws SQLException { int saveCursorPos = cursorPos; int saveAbsoluteCursorPos = absolutePos; boolean saveShowDeleted = getShowDeleted(); setShowDeleted(true); internalLast(); if (cursorPos == saveCursorPos) { setShowDeleted(saveShowDeleted); return true; } else { setShowDeleted(saveShowDeleted); cursorPos = saveCursorPos; absolutePos = saveAbsoluteCursorPos; return false; } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the front of * the rowset, just before the first row. This method has no effect if * this rowset contains no rows. * * @throws SQLException if an error occurs or the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public void beforeFirst() throws SQLException { if (getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.beforefirst").toString()); } cursorPos = 0; absolutePos = 0; notifyCursorMoved(); } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the end of * the rowset, just after the last row. This method has no effect if * this rowset contains no rows. * * @throws SQLException if an error occurs */ public void afterLast() throws SQLException { if (numRows > 0) { cursorPos = numRows + 1; absolutePos = 0; notifyCursorMoved(); } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the first row * and returns <code>true</code> if the operation was successful. This * method also notifies registered listeners that the cursor has moved. * * @return <code>true</code> if the cursor is on a valid row; * <code>false</code> otherwise or if there are no rows in this * <code>CachedRowSetImpl</code> object * @throws SQLException if the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public boolean first() throws SQLException { if(getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.first").toString()); } // move and notify boolean ret = this.internalFirst(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the first * row and returns <code>true</code> if the operation is successful. * <P> * This method is called internally by the methods <code>first</code>, * <code>isFirst</code>, and <code>absolute</code>. * It in turn calls the method <code>internalNext</code> in order to * handle the case where the first row is a deleted row that is not visible. * <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 moved to the first row; * <code>false</code> otherwise * @throws SQLException if an error occurs */ protected boolean internalFirst() throws SQLException { boolean ret = false; if (numRows > 0) { cursorPos = 1; if ((getShowDeleted() == false) && (rowDeleted() == true)) { ret = internalNext(); } else { ret = true; } } if (ret == true) absolutePos = 1; else absolutePos = 0; return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the last row * and returns <code>true</code> if the operation was successful. This * method also notifies registered listeners that the cursor has moved. * * @return <code>true</code> if the cursor is on a valid row; * <code>false</code> otherwise or if there are no rows in this * <code>CachedRowSetImpl</code> object * @throws SQLException if the type of this rowset * is <code>ResultSet.TYPE_FORWARD_ONLY</code> */ public boolean last() throws SQLException { if (getType() == ResultSet.TYPE_FORWARD_ONLY) { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.last").toString()); } // move and notify boolean ret = this.internalLast(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the last * row and returns <code>true</code> if the operation is successful. * <P> * This method is called internally by the method <code>last</code> * when rows have been deleted and the deletions are not visible. * The method <code>internalLast</code> handles the case where the * last row is a deleted row that is not visible by in turn calling * the method <code>internalPrevious</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 moved to the last row; * <code>false</code> otherwise * @throws SQLException if an error occurs */ protected boolean internalLast() throws SQLException { boolean ret = false; if (numRows > 0) { cursorPos = numRows; if ((getShowDeleted() == false) && (rowDeleted() == true)) { ret = internalPrevious(); } else { ret = true; } } if (ret == true) absolutePos = numRows - numDeleted; else absolutePos = 0; return ret; } /** * Returns the number of the current row in this <code>CachedRowSetImpl</code> * object. The first row is number 1, the second number 2, and so on. * * @return the number of the current row; <code>0</code> if there is no * current row * @throws SQLException if an error occurs; or if the <code>CacheRowSetImpl</code> * is empty */ public int getRow() throws SQLException { // are we on a valid row? Valid rows are between first and last if (numRows > 0 && cursorPos > 0 && cursorPos < (numRows + 1) && (getShowDeleted() == false && rowDeleted() == false)) { return absolutePos; } else if (getShowDeleted() == true) { return cursorPos; } else { return 0; } } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the row number * specified. * * <p>If the number is positive, the cursor moves to an absolute row with * respect to the beginning of the rowset. The first row is row 1, the second * is row 2, and so on. For example, the following command, in which * <code>crs</code> is a <code>CachedRowSetImpl</code> object, moves the cursor * to the fourth row, starting from the beginning of the rowset. * <PRE><code> * * crs.absolute(4); * * </code> </PRE> * <P> * If the number is negative, the cursor moves to an absolute row position * with respect to the end of the rowset. For example, calling * <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, counting * 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. * <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>. * * @param row a positive number to indicate the row, starting row numbering from * the first row, which is <code>1</code>; a negative number to indicate * the row, starting row numbering from the last row, which is * <code>-1</code>; it must not be <code>0</code> * @return <code>true</code> if the cursor is on the rowset; <code>false</code> * otherwise * @throws SQLException if the given cursor position is <code>0</code> or the * type of this rowset is <code>ResultSet.TYPE_FORWARD_ONLY</code>