* * @throws SQLException if the cursor is not on a valid row */ public void undoDelete() throws SQLException { if (getShowDeleted() == false) { return; } // 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.getDeleted() == true) { currentRow.clearDeleted(); --numDeleted; notifyRowChanged(); } } /** * Immediately removes the current row from this * <code>CachedRowSetImpl</code> object if the row has been inserted, and * also notifies listeners the a row has changed. An exception is thrown * if the row is not a row that has been inserted or the cursor is before * the first row, after the last row, or on the insert row. * <P> * This operation cannot be undone. * * @throws SQLException if an error occurs, * the cursor is not on a valid row, * or the row has not been inserted */ public void undoInsert() 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.getInserted() == true) { rvh.remove(cursorPos-1); --numRows; notifyRowChanged(); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.illegalop").toString()); } } /** * Immediately reverses the last update operation if the * row has been modified. This method can be * called to reverse updates on a all columns until all updates in a row have * been rolled back to their originating state since the last synchronization * (<code>acceptChanges</code>) or population. This method may also be called * while performing updates to the insert row. * <P> * <code>undoUpdate</code may be called at any time during the life-time of a * rowset, however after a synchronization has occurs this method has no * affect until further modification to the RowSet data occurs. * * @throws SQLException if cursor is before the first row, after the last * row in rowset. * @see #undoDelete * @see #undoInsert * @see java.sql.ResultSet#cancelRowUpdates */ public void undoUpdate() throws SQLException { // if on insert row, cancel the insert row // make the insert row flag, // cursorPos back to the current row moveToCurrentRow(); // else if not on insert row // call undoUpdate or undoInsert undoDelete(); undoInsert(); } //-------------------------------------------------------------------- // Views //-------------------------------------------------------------------- /** * Returns a new <code>RowSet</code> object backed by the same data as * that of this <code>CachedRowSetImpl</code> object and sharing a set of cursors * with it. This allows cursors to interate over a shared set of rows, providing * multiple views of the underlying data. * * @return a <code>RowSet</code> object that is a copy of this <code>CachedRowSetImpl</code> * object and shares a set of cursors with it * @throws SQLException if an error occurs or cloning is * not supported * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public RowSet createShared() throws SQLException { RowSet clone; try { clone = (RowSet)clone(); } catch (CloneNotSupportedException ex) { throw new SQLException(ex.getMessage()); } return clone; } /** * Returns a new <code>RowSet</code> object containing by the same data * as this <code>CachedRowSetImpl</code> object. This method * differs from the method <code>createCopy</code> in that it throws a * <code>CloneNotSupportedException</code> object instead of an * <code>SQLException</code> object, as the method <code>createShared</code> * does. This <code>clone</code> * method is called internally by the method <code>createShared</code>, * which catches the <code>CloneNotSupportedException</code> object * and in turn throws a new <code>SQLException</code> object. * * @return a copy of this <code>CachedRowSetImpl</code> object * @throws CloneNotSupportedException if an error occurs when * attempting to clone this <code>CachedRowSetImpl</code> object * @see #createShared */ protected Object clone() throws CloneNotSupportedException { return (super.clone()); } /** * Creates a <code>RowSet</code> object that is a deep copy of * this <code>CachedRowSetImpl</code> object's data, including * constraints. Updates made * on a copy are not visible to the original rowset; * a copy of a rowset is completely independent from the original. * <P> * Making a copy saves the cost of creating an identical rowset * from first principles, which can be quite expensive. * For example, it can eliminate the need to query a * remote database server. * @return a new <code>CachedRowSet</code> object that is a deep copy * of this <code>CachedRowSet</code> object and is * completely independent from this <code>CachedRowSetImpl</code> * object. * @throws SQLException if an error occurs in generating the copy of this * of the <code>CachedRowSetImpl</code> * @see #createShared * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopy() throws SQLException { ObjectOutputStream out; ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { out = new ObjectOutputStream(bOut); out.writeObject(this); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } ObjectInputStream in; try { ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); in = new ObjectInputStream(bIn); } catch (StreamCorruptedException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } try { //return ((CachedRowSet)(in.readObject())); CachedRowSetImpl crsTemp = (CachedRowSetImpl)in.readObject(); crsTemp.resBundle = this.resBundle; return ((CachedRowSet)crsTemp); } catch (ClassNotFoundException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (OptionalDataException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } } /** * Creates a <code>RowSet</code> object that is a copy of * this <code>CachedRowSetImpl</code> object's table structure * and the constraints only. * There will be no data in the object being returned. * Updates made on a copy are not visible to the original rowset. * <P> * This helps in getting the underlying XML schema which can * be used as the basis for populating a <code>WebRowSet</code>. * * @return a new <code>CachedRowSet</code> object that is a copy * of this <code>CachedRowSetImpl</code> object's schema and * retains all the constraints on the original rowset but contains * no data * @throws SQLException if an error occurs in generating the copy * of the <code>CachedRowSet</code> object * @see #createShared * @see #createCopy * @see #createCopyNoConstraints * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopySchema() throws SQLException { // Copy everything except data i.e all constraints // Store the number of rows of "this" // and make numRows equals zero. // and make data also zero. int nRows = numRows; numRows = 0; CachedRowSet crs = this.createCopy(); // reset this object back to number of rows. numRows = nRows; return crs; } /** * Creates a <code>CachedRowSet</code> object that is a copy of * this <code>CachedRowSetImpl</code> object's data only. * All constraints set in this object will not be there * in the returning object. Updates made * on a copy are not visible to the original rowset. * * @return a new <code>CachedRowSet</code> object that is a deep copy * of this <code>CachedRowSetImpl</code> object and is * completely independent from this <code>CachedRowSetImpl</code> object * @throws SQLException if an error occurs in generating the copy of the * of the <code>CachedRowSet</code> * @see #createShared * @see #createCopy * @see #createCopySchema * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopyNoConstraints() throws SQLException { // Copy the whole data ONLY without any constraints. CachedRowSetImpl crs; crs = (CachedRowSetImpl)this.createCopy(); crs.initProperties(); try { crs.unsetMatchColumn(crs.getMatchColumnIndexes()); } catch(SQLException sqle) { //do nothing, if the setMatchColumn is not set. } try { crs.unsetMatchColumn(crs.getMatchColumnNames()); } catch(SQLException sqle) { //do nothing, if the setMatchColumn is not set. } return crs; } /** * Converts this <code>CachedRowSetImpl</code> object to a collection * of tables. The sample implementation utilitizes the <code>TreeMap</code> * collection type. * This class guarantees that the map will be in ascending key order, * sorted according to the natural order for the key's class. * * @return a <code>Collection</code> object consisting of tables, * each of which is a copy of a row in this * <code>CachedRowSetImpl</code> object * @throws SQLException if an error occurs in generating the collection * @see #toCollection(int) * @see #toCollection(String) * @see java.util.TreeMap */ public Collection<?> toCollection() throws SQLException { TreeMap<Integer, Object> tMap = new TreeMap<>(); for (int i = 0; i<numRows; i++) { tMap.put(Integer.valueOf(i), rvh.get(i)); } return (tMap.values()); } /** * Returns the specified column of this <code>CachedRowSetImpl</code> object * as a <code>Collection</code> object. This method makes a copy of the * column's data and utilitizes the <code>Vector</code> to establish the * collection. The <code>Vector</code> class implements a growable array * objects allowing the individual components to be accessed using an * an integer index similar to that of an array. * * @return a <code>Collection</code> object that contains the value(s) * stored in the specified column of this * <code>CachedRowSetImpl</code> * object * @throws SQLException if an error occurs generated the collection; or * an invalid column is provided. * @see #toCollection() * @see #toCollection(String) * @see java.util.Vector */ public Collection<?> toCollection(int column) throws SQLException { int nRows = numRows; Vector<Object> vec = new Vector<>(nRows); // create a copy CachedRowSetImpl crsTemp; crsTemp = (CachedRowSetImpl) this.createCopy(); while(nRows!=0) { crsTemp.next(); vec.add(crsTemp.getObject(column)); nRows--; } return (Collection)vec; } /** * Returns the specified column of this <code>CachedRowSetImpl</code> object * as a <code>Collection</code> object. This method makes a copy of the * column's data and utilitizes the <code>Vector</code> to establish the * collection. The <code>Vector</code> class implements a growable array * objects allowing the individual components to be accessed using an * an integer index similar to that of an array. * * @return a <code>Collection</code> object that contains the value(s) * stored in the specified column of this * <code>CachedRowSetImpl</code> * object * @throws SQLException if an error occurs generated the collection; or * an invalid column is provided. * @see #toCollection() * @see #toCollection(int) * @see java.util.Vector */ public Collection<?> toCollection(String column) throws SQLException { return toCollection(getColIdxByName(column)); } //-------------------------------------------------------------------- // Advanced features //-------------------------------------------------------------------- /** * Returns the <code>SyncProvider</code> implementation being used * with this <code>CachedRowSetImpl</code> implementation rowset. * * @return the SyncProvider used by the rowset. If not provider was * set when the rowset was instantiated, the reference * implementation (default) provider is returned. * @throws SQLException if error occurs while return the * <code>SyncProvider</code> instance. */ public SyncProvider getSyncProvider() throws SQLException { return provider; } /** * Sets the active <code>SyncProvider</code> and attempts to load * load the new provider using the <code>SyncFactory</code> SPI. * * @throws SQLException if an error occurs while resetting the * <code>SyncProvider</code>. */ public void setSyncProvider(String providerStr) throws SQLException { provider = (SyncProvider)SyncFactory.getInstance(providerStr); rowSetReader = provider.getRowSetReader(); rowSetWriter = provider.getRowSetWriter(); } //----------------- // methods inherited from RowSet //----------------- //--------------------------------------------------------------------- // Reading and writing data //--------------------------------------------------------------------- /** * Populates this <code>CachedRowSetImpl</code> object with data. * This form of the method uses the rowset's user, password, and url or * data source name properties to create a database * connection. If properties that are needed * have not been set, this method will throw an exception. * <P> * Another form of this method uses an existing JDBC <code>Connection</code> * object instead of creating a new one; therefore, it ignores the * properties used for establishing a new connection. * <P> * The query specified by the command property is executed to create a * <code>ResultSet</code> object from which to retrieve data. * The current contents of the rowset are discarded, and the * rowset's metadata is also (re)set. If there are outstanding updates, * they are also ignored. * <P> * The method <code>execute</code> closes any database connections that it * creates. * * @throws SQLException if an error occurs or the * necessary properties have not been set */ public void execute() throws SQLException { execute(null); } //----------------------------------- // Methods inherited from ResultSet //----------------------------------- /** * Moves the cursor down one row from its current position and * returns <code>true</code> if the new cursor position is a * valid row. * The cursor for a new <code>ResultSet</code> object is initially * positioned before the first row. The first call to the method * <code>next</code> moves the cursor to the first row, making it * the current row; the second call makes the second row the * current row, and so on. * * <P>If an input stream from the previous row is open, it is * implicitly closed. The <code>ResultSet</code> object's warning * chain is cleared when a new row is read. * * @return <code>true</code> if the new current row is valid; * <code>false</code> if there are no more rows * @throws SQLException if an error occurs or * the cursor is not positioned in the rowset, before * the first row, or after the last row */ public boolean next() throws SQLException { /* * 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()); } // now move and notify boolean ret = this.internalNext(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the next * row and returns <code>true</code> if the cursor is still in the rowset; * returns <code>false</code> if the cursor has moved to the position after * the last row. * <P> * This method handles the cases where the cursor moves to a row that * has been deleted. * If this rowset shows deleted rows and the cursor moves to a row * that has been deleted, this method moves the cursor to the next * row until the cursor is on a row that has not been deleted. * <P> * The method <code>internalNext</code> is called by methods such as * <code>next</code>, <code>absolute</code>, and <code>relative</code>, * and, as its name implies, is only called internally. * <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 valid row in this * rowset; <code>false</code> if it is after the last row * @throws SQLException if an error occurs */ protected boolean internalNext() throws SQLException { boolean ret = false; do { if (cursorPos < numRows) { ++cursorPos; ret = true;Lines 1001–1500 of 10133. Previous lines Load more
* * @throws SQLException if the cursor is not on a valid row */ public void undoDelete() throws SQLException { if (getShowDeleted() == false) { return; } // 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.getDeleted() == true) { currentRow.clearDeleted(); --numDeleted; notifyRowChanged(); } } /** * Immediately removes the current row from this * <code>CachedRowSetImpl</code> object if the row has been inserted, and * also notifies listeners the a row has changed. An exception is thrown * if the row is not a row that has been inserted or the cursor is before * the first row, after the last row, or on the insert row. * <P> * This operation cannot be undone. * * @throws SQLException if an error occurs, * the cursor is not on a valid row, * or the row has not been inserted */ public void undoInsert() 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.getInserted() == true) { rvh.remove(cursorPos-1); --numRows; notifyRowChanged(); } else { throw new SQLException(resBundle.handleGetObject("cachedrowsetimpl.illegalop").toString()); } } /** * Immediately reverses the last update operation if the * row has been modified. This method can be * called to reverse updates on a all columns until all updates in a row have * been rolled back to their originating state since the last synchronization * (<code>acceptChanges</code>) or population. This method may also be called * while performing updates to the insert row. * <P> * <code>undoUpdate</code may be called at any time during the life-time of a * rowset, however after a synchronization has occurs this method has no * affect until further modification to the RowSet data occurs. * * @throws SQLException if cursor is before the first row, after the last * row in rowset. * @see #undoDelete * @see #undoInsert * @see java.sql.ResultSet#cancelRowUpdates */ public void undoUpdate() throws SQLException { // if on insert row, cancel the insert row // make the insert row flag, // cursorPos back to the current row moveToCurrentRow(); // else if not on insert row // call undoUpdate or undoInsert undoDelete(); undoInsert(); } //-------------------------------------------------------------------- // Views //-------------------------------------------------------------------- /** * Returns a new <code>RowSet</code> object backed by the same data as * that of this <code>CachedRowSetImpl</code> object and sharing a set of cursors * with it. This allows cursors to interate over a shared set of rows, providing * multiple views of the underlying data. * * @return a <code>RowSet</code> object that is a copy of this <code>CachedRowSetImpl</code> * object and shares a set of cursors with it * @throws SQLException if an error occurs or cloning is * not supported * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public RowSet createShared() throws SQLException { RowSet clone; try { clone = (RowSet)clone(); } catch (CloneNotSupportedException ex) { throw new SQLException(ex.getMessage()); } return clone; } /** * Returns a new <code>RowSet</code> object containing by the same data * as this <code>CachedRowSetImpl</code> object. This method * differs from the method <code>createCopy</code> in that it throws a * <code>CloneNotSupportedException</code> object instead of an * <code>SQLException</code> object, as the method <code>createShared</code> * does. This <code>clone</code> * method is called internally by the method <code>createShared</code>, * which catches the <code>CloneNotSupportedException</code> object * and in turn throws a new <code>SQLException</code> object. * * @return a copy of this <code>CachedRowSetImpl</code> object * @throws CloneNotSupportedException if an error occurs when * attempting to clone this <code>CachedRowSetImpl</code> object * @see #createShared */ protected Object clone() throws CloneNotSupportedException { return (super.clone()); } /** * Creates a <code>RowSet</code> object that is a deep copy of * this <code>CachedRowSetImpl</code> object's data, including * constraints. Updates made * on a copy are not visible to the original rowset; * a copy of a rowset is completely independent from the original. * <P> * Making a copy saves the cost of creating an identical rowset * from first principles, which can be quite expensive. * For example, it can eliminate the need to query a * remote database server. * @return a new <code>CachedRowSet</code> object that is a deep copy * of this <code>CachedRowSet</code> object and is * completely independent from this <code>CachedRowSetImpl</code> * object. * @throws SQLException if an error occurs in generating the copy of this * of the <code>CachedRowSetImpl</code> * @see #createShared * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopy() throws SQLException { ObjectOutputStream out; ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { out = new ObjectOutputStream(bOut); out.writeObject(this); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } ObjectInputStream in; try { ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray()); in = new ObjectInputStream(bIn); } catch (StreamCorruptedException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } try { //return ((CachedRowSet)(in.readObject())); CachedRowSetImpl crsTemp = (CachedRowSetImpl)in.readObject(); crsTemp.resBundle = this.resBundle; return ((CachedRowSet)crsTemp); } catch (ClassNotFoundException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (OptionalDataException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } catch (IOException ex) { throw new SQLException(MessageFormat.format(resBundle.handleGetObject("cachedrowsetimpl.clonefail").toString() , ex.getMessage())); } } /** * Creates a <code>RowSet</code> object that is a copy of * this <code>CachedRowSetImpl</code> object's table structure * and the constraints only. * There will be no data in the object being returned. * Updates made on a copy are not visible to the original rowset. * <P> * This helps in getting the underlying XML schema which can * be used as the basis for populating a <code>WebRowSet</code>. * * @return a new <code>CachedRowSet</code> object that is a copy * of this <code>CachedRowSetImpl</code> object's schema and * retains all the constraints on the original rowset but contains * no data * @throws SQLException if an error occurs in generating the copy * of the <code>CachedRowSet</code> object * @see #createShared * @see #createCopy * @see #createCopyNoConstraints * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopySchema() throws SQLException { // Copy everything except data i.e all constraints // Store the number of rows of "this" // and make numRows equals zero. // and make data also zero. int nRows = numRows; numRows = 0; CachedRowSet crs = this.createCopy(); // reset this object back to number of rows. numRows = nRows; return crs; } /** * Creates a <code>CachedRowSet</code> object that is a copy of * this <code>CachedRowSetImpl</code> object's data only. * All constraints set in this object will not be there * in the returning object. Updates made * on a copy are not visible to the original rowset. * * @return a new <code>CachedRowSet</code> object that is a deep copy * of this <code>CachedRowSetImpl</code> object and is * completely independent from this <code>CachedRowSetImpl</code> object * @throws SQLException if an error occurs in generating the copy of the * of the <code>CachedRowSet</code> * @see #createShared * @see #createCopy * @see #createCopySchema * @see javax.sql.RowSetEvent * @see javax.sql.RowSetListener */ public CachedRowSet createCopyNoConstraints() throws SQLException { // Copy the whole data ONLY without any constraints. CachedRowSetImpl crs; crs = (CachedRowSetImpl)this.createCopy(); crs.initProperties(); try { crs.unsetMatchColumn(crs.getMatchColumnIndexes()); } catch(SQLException sqle) { //do nothing, if the setMatchColumn is not set. } try { crs.unsetMatchColumn(crs.getMatchColumnNames()); } catch(SQLException sqle) { //do nothing, if the setMatchColumn is not set. } return crs; } /** * Converts this <code>CachedRowSetImpl</code> object to a collection * of tables. The sample implementation utilitizes the <code>TreeMap</code> * collection type. * This class guarantees that the map will be in ascending key order, * sorted according to the natural order for the key's class. * * @return a <code>Collection</code> object consisting of tables, * each of which is a copy of a row in this * <code>CachedRowSetImpl</code> object * @throws SQLException if an error occurs in generating the collection * @see #toCollection(int) * @see #toCollection(String) * @see java.util.TreeMap */ public Collection<?> toCollection() throws SQLException { TreeMap<Integer, Object> tMap = new TreeMap<>(); for (int i = 0; i<numRows; i++) { tMap.put(Integer.valueOf(i), rvh.get(i)); } return (tMap.values()); } /** * Returns the specified column of this <code>CachedRowSetImpl</code> object * as a <code>Collection</code> object. This method makes a copy of the * column's data and utilitizes the <code>Vector</code> to establish the * collection. The <code>Vector</code> class implements a growable array * objects allowing the individual components to be accessed using an * an integer index similar to that of an array. * * @return a <code>Collection</code> object that contains the value(s) * stored in the specified column of this * <code>CachedRowSetImpl</code> * object * @throws SQLException if an error occurs generated the collection; or * an invalid column is provided. * @see #toCollection() * @see #toCollection(String) * @see java.util.Vector */ public Collection<?> toCollection(int column) throws SQLException { int nRows = numRows; Vector<Object> vec = new Vector<>(nRows); // create a copy CachedRowSetImpl crsTemp; crsTemp = (CachedRowSetImpl) this.createCopy(); while(nRows!=0) { crsTemp.next(); vec.add(crsTemp.getObject(column)); nRows--; } return (Collection)vec; } /** * Returns the specified column of this <code>CachedRowSetImpl</code> object * as a <code>Collection</code> object. This method makes a copy of the * column's data and utilitizes the <code>Vector</code> to establish the * collection. The <code>Vector</code> class implements a growable array * objects allowing the individual components to be accessed using an * an integer index similar to that of an array. * * @return a <code>Collection</code> object that contains the value(s) * stored in the specified column of this * <code>CachedRowSetImpl</code> * object * @throws SQLException if an error occurs generated the collection; or * an invalid column is provided. * @see #toCollection() * @see #toCollection(int) * @see java.util.Vector */ public Collection<?> toCollection(String column) throws SQLException { return toCollection(getColIdxByName(column)); } //-------------------------------------------------------------------- // Advanced features //-------------------------------------------------------------------- /** * Returns the <code>SyncProvider</code> implementation being used * with this <code>CachedRowSetImpl</code> implementation rowset. * * @return the SyncProvider used by the rowset. If not provider was * set when the rowset was instantiated, the reference * implementation (default) provider is returned. * @throws SQLException if error occurs while return the * <code>SyncProvider</code> instance. */ public SyncProvider getSyncProvider() throws SQLException { return provider; } /** * Sets the active <code>SyncProvider</code> and attempts to load * load the new provider using the <code>SyncFactory</code> SPI. * * @throws SQLException if an error occurs while resetting the * <code>SyncProvider</code>. */ public void setSyncProvider(String providerStr) throws SQLException { provider = (SyncProvider)SyncFactory.getInstance(providerStr); rowSetReader = provider.getRowSetReader(); rowSetWriter = provider.getRowSetWriter(); } //----------------- // methods inherited from RowSet //----------------- //--------------------------------------------------------------------- // Reading and writing data //--------------------------------------------------------------------- /** * Populates this <code>CachedRowSetImpl</code> object with data. * This form of the method uses the rowset's user, password, and url or * data source name properties to create a database * connection. If properties that are needed * have not been set, this method will throw an exception. * <P> * Another form of this method uses an existing JDBC <code>Connection</code> * object instead of creating a new one; therefore, it ignores the * properties used for establishing a new connection. * <P> * The query specified by the command property is executed to create a * <code>ResultSet</code> object from which to retrieve data. * The current contents of the rowset are discarded, and the * rowset's metadata is also (re)set. If there are outstanding updates, * they are also ignored. * <P> * The method <code>execute</code> closes any database connections that it * creates. * * @throws SQLException if an error occurs or the * necessary properties have not been set */ public void execute() throws SQLException { execute(null); } //----------------------------------- // Methods inherited from ResultSet //----------------------------------- /** * Moves the cursor down one row from its current position and * returns <code>true</code> if the new cursor position is a * valid row. * The cursor for a new <code>ResultSet</code> object is initially * positioned before the first row. The first call to the method * <code>next</code> moves the cursor to the first row, making it * the current row; the second call makes the second row the * current row, and so on. * * <P>If an input stream from the previous row is open, it is * implicitly closed. The <code>ResultSet</code> object's warning * chain is cleared when a new row is read. * * @return <code>true</code> if the new current row is valid; * <code>false</code> if there are no more rows * @throws SQLException if an error occurs or * the cursor is not positioned in the rowset, before * the first row, or after the last row */ public boolean next() throws SQLException { /* * 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()); } // now move and notify boolean ret = this.internalNext(); notifyCursorMoved(); return ret; } /** * Moves this <code>CachedRowSetImpl</code> object's cursor to the next * row and returns <code>true</code> if the cursor is still in the rowset; * returns <code>false</code> if the cursor has moved to the position after * the last row. * <P> * This method handles the cases where the cursor moves to a row that * has been deleted. * If this rowset shows deleted rows and the cursor moves to a row * that has been deleted, this method moves the cursor to the next * row until the cursor is on a row that has not been deleted. * <P> * The method <code>internalNext</code> is called by methods such as * <code>next</code>, <code>absolute</code>, and <code>relative</code>, * and, as its name implies, is only called internally. * <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 valid row in this * rowset; <code>false</code> if it is after the last row * @throws SQLException if an error occurs */ protected boolean internalNext() throws SQLException { boolean ret = false; do { if (cursorPos < numRows) { ++cursorPos; ret = true;