2740N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * The interface that all standard implementations of 0N/A * <code>CachedRowSet</code> must implement. 0N/A * The reference implementation of the <code>CachedRowSet</code> interface provided 2802N/A * by Oracle Corporation is a standard implementation. Developers may use this implementation 0N/A * just as it is, they may extend it, or they may choose to write their own implementations 0N/A * of this interface. 0N/A * A <code>CachedRowSet</code> object is a container for rows of data 0N/A * that caches its rows in memory, which makes it possible to operate without always being 0N/A * connected to its data source. Further, it is a 0N/A * JavaBeans<sup><font size=-2>TM</font></sup> component and is scrollable, 0N/A * updatable, and serializable. A <code>CachedRowSet</code> object typically 0N/A * contains rows from a result set, but it can also contain rows from any file 0N/A * with a tabular format, such as a spread sheet. The reference implementation 0N/A * supports getting data only from a <code>ResultSet</code> object, but 0N/A * developers can extend the <code>SyncProvider</code> implementations to provide 0N/A * access to other tabular data sources. 0N/A * An application can modify the data in a <code>CachedRowSet</code> object, and 0N/A * those modifications can then be propagated back to the source of the data. 0N/A * A <code>CachedRowSet</code> object is a <i>disconnected</i> rowset, which means 0N/A * that it makes use of a connection to its data source only briefly. It connects to its 0N/A * data source while it is reading data to populate itself with rows and again 0N/A * while it is propagating changes back to its underlying data source. The rest 0N/A * of the time, a <code>CachedRowSet</code> object is disconnected, including 0N/A * while its data is being modified. Being disconnected makes a <code>RowSet</code> 0N/A * object much leaner and therefore much easier to pass to another component. For 0N/A * example, a disconnected <code>RowSet</code> object can be serialized and passed 0N/A * over the wire to a thin client such as a personal digital assistant (PDA). 0N/A * <h3>1.0 Creating a <code>CachedRowSet</code> Object</h3> 0N/A * The following line of code uses the default constructor for 0N/A * <code>CachedRowSet</code> 0N/A * supplied in the reference implementation (RI) to create a default 0N/A * <code>CachedRowSet</code> object. 0N/A * CachedRowSetImpl crs = new CachedRowSetImpl(); 0N/A * This new <code>CachedRowSet</code> object will have its properties set to the 0N/A * default properties of a <code>BaseRowSet</code> object, and, in addition, it will 0N/A * have an <code>RIOptimisticProvider</code> object as its synchronization provider. 0N/A * <code>RIOptimisticProvider</code>, one of two <code>SyncProvider</code> 0N/A * implementations included in the RI, is the default provider that the 0N/A * <code>SyncFactory</code> singleton will supply when no synchronization 0N/A * provider is specified. 0N/A * A <code>SyncProvider</code> object provides a <code>CachedRowSet</code> object 0N/A * with a reader (a <code>RowSetReader</code> object) for reading data from a 0N/A * data source to populate itself with data. A reader can be implemented to read 0N/A * data from a <code>ResultSet</code> object or from a file with a tabular format. 0N/A * A <code>SyncProvider</code> object also provides 0N/A * a writer (a <code>RowSetWriter</code> object) for synchronizing any 0N/A * modifications to the <code>CachedRowSet</code> object's data made while it was 0N/A * disconnected with the data in the underlying data source. 0N/A * A writer can be implemented to exercise various degrees of care in checking 0N/A * for conflicts and in avoiding them. 0N/A * (A conflict occurs when a value in the data source has been changed after 0N/A * the rowset populated itself with that value.) 0N/A * The <code>RIOptimisticProvider</code> implementation assumes there will be 0N/A * few or no conflicts and therefore sets no locks. It updates the data source 0N/A * with values from the <code>CachedRowSet</code> object only if there are no 0N/A * Other writers can be implemented so that they always write modified data to 0N/A * the data source, which can be accomplished either by not checking for conflicts 0N/A * or, on the other end of the spectrum, by setting locks sufficient to prevent data 0N/A * in the data source from being changed. Still other writer implementations can be 0N/A * somewhere in between. 0N/A * A <code>CachedRowSet</code> object may use any 0N/A * <code>SyncProvider</code> implementation that has been registered 0N/A * with the <code>SyncFactory</code> singleton. An application 0N/A * can find out which <code>SyncProvider</code> implementations have been 0N/A * registered by calling the following line of code. 0N/A * java.util.Enumeration providers = SyncFactory.getRegisteredProviders(); 0N/A * There are two ways for a <code>CachedRowSet</code> object to specify which 0N/A * <code>SyncProvider</code> object it will use. 0N/A * <LI>Supplying the name of the implementation to the constructor<BR> 0N/A * The following line of code creates the <code>CachedRowSet</code> 0N/A * object <i>crs2</i> that is initialized with default values except that its 0N/A * <code>SyncProvider</code> object is the one specified. 0N/A * CachedRowSetImpl crs2 = new CachedRowSetImpl( 0N/A * "com.fred.providers.HighAvailabilityProvider"); 0N/A * <LI>Setting the <code>SyncProvider</code> using the <code>CachedRowSet</code> 0N/A * method <code>setSyncProvider</code><BR> 0N/A * The following line of code resets the <code>SyncProvider</code> object 0N/A * for <i>crs</i>, the <code>CachedRowSet</code> object created with the 0N/A * default constructor. 0N/A * crs.setSyncProvider("com.fred.providers.HighAvailabilityProvider"); 0N/A * See the comments for <code>SyncFactory</code> and <code>SyncProvider</code> for 0N/A * <h3>2.0 Retrieving Data from a <code>CachedRowSet</code> Object</h3> 0N/A * Data is retrieved from a <code>CachedRowSet</code> object by using the 0N/A * getter methods inherited from the <code>ResultSet</code> 0N/A * interface. The following examples, in which <code>crs</code> is a 0N/A * <code>CachedRowSet</code> 0N/A * object, demonstrate how to iterate through the rows, retrieving the column 0N/A * values in each row. The first example uses the version of the 0N/A * getter methods that take a column number; the second example 0N/A * uses the version that takes a column name. Column numbers are generally 0N/A * used when the <code>RowSet</code> object's command 0N/A * is of the form <code>SELECT * FROM TABLENAME</code>; column names are most 0N/A * commonly used when the command specifies columns by name. 0N/A * while (crs.next()) { 0N/A * String name = crs.getString(1); 0N/A * int id = crs.getInt(2); 0N/A * Clob comment = crs.getClob(3); 0N/A * short dept = crs.getShort(4); 0N/A * System.out.println(name + " " + id + " " + comment + " " + dept); 0N/A * while (crs.next()) { 0N/A * String name = crs.getString("NAME"); 0N/A * int id = crs.getInt("ID"); 0N/A * Clob comment = crs.getClob("COM"); 0N/A * short dept = crs.getShort("DEPT"); 0N/A * System.out.println(name + " " + id + " " + comment + " " + dept); 0N/A * <h4>2.1 Retrieving <code>RowSetMetaData</code></h4> 0N/A * An application can get information about the columns in a <code>CachedRowSet</code> 0N/A * object by calling <code>ResultSetMetaData</code> and <code>RowSetMetaData</code> 0N/A * methods on a <code>RowSetMetaData</code> object. The following code fragment, 0N/A * in which <i>crs</i> is a <code>CachedRowSet</code> object, illustrates the process. 0N/A * The first line creates a <code>RowSetMetaData</code> object with information 0N/A * about the columns in <i>crs</i>. The method <code>getMetaData</code>, 0N/A * inherited from the <code>ResultSet</code> interface, returns a 0N/A * <code>ResultSetMetaData</code> object, which is cast to a 0N/A * <code>RowSetMetaData</code> object before being assigned to the variable 0N/A * <i>rsmd</i>. The second line finds out how many columns <i>jrs</i> has, and 0N/A * the third line gets the JDBC type of values stored in the second column of 0N/A * RowSetMetaData rsmd = (RowSetMetaData)crs.getMetaData(); 0N/A * int count = rsmd.getColumnCount(); 0N/A * int type = rsmd.getColumnType(2); 0N/A * The <code>RowSetMetaData</code> interface differs from the 0N/A * <code>ResultSetMetaData</code> interface in two ways. 0N/A * <LI><i>It includes <code>setter</code> methods:</i> A <code>RowSet</code> 0N/A * object uses these methods internally when it is populated with data from a 0N/A * different <code>ResultSet</code> object. 0N/A * <LI><i>It contains fewer <code>getter</code> methods:</i> Some 0N/A * <code>ResultSetMetaData</code> methods to not apply to a <code>RowSet</code> 0N/A * object. For example, methods retrieving whether a column value is writable 0N/A * or read only do not apply because all of a <code>RowSet</code> object's 0N/A * columns will be writable or read only, depending on whether the rowset is 0N/A * NOTE: In order to return a <code>RowSetMetaData</code> object, implementations must 0N/A * override the <code>getMetaData()</code> method defined in 0N/A * <code>java.sql.ResultSet</code> and return a <code>RowSetMetaData</code> object. 0N/A * <h3>3.0 Updating a <code>CachedRowSet</code> Object</h3> 0N/A * Updating a <code>CachedRowSet</code> object is similar to updating a 0N/A * <code>ResultSet</code> object, but because the rowset is not connected to 0N/A * its data source while it is being updated, it must take an additional step 0N/A * to effect changes in its underlying data source. After calling the method 0N/A * <code>updateRow</code> or <code>insertRow</code>, a 0N/A * <code>CachedRowSet</code> 0N/A * object must also call the method <code>acceptChanges</code> to have updates 0N/A * written to the data source. The following example, in which the cursor is 0N/A * on a row in the <code>CachedRowSet</code> object <i>crs</i>, shows 0N/A * the code required to update two column values in the current row and also 0N/A * update the <code>RowSet</code> object's underlying data source. 0N/A * crs.updateShort(3, 58); 0N/A * crs.updateInt(4, 150000); 0N/A * crs.acceptChanges(); 0N/A * The next example demonstrates moving to the insert row, building a new 0N/A * row on the insert row, inserting it into the rowset, and then calling the 0N/A * method <code>acceptChanges</code> to add the new row to the underlying data 0N/A * source. Note that as with the getter methods, the updater methods may take 0N/A * either a column index or a column name to designate the column being acted upon. 0N/A * crs.moveToInsertRow(); 0N/A * crs.updateString("Name", "Shakespeare"); 0N/A * crs.updateInt("ID", 10098347); 0N/A * crs.updateShort("Age", 58); 0N/A * crs.updateInt("Sal", 150000); 0N/A * crs.moveToCurrentRow(); 0N/A * crs.acceptChanges(); 0N/A * NOTE: Where the <code>insertRow()</code> method inserts the contents of a 0N/A * <code>CachedRowSet</code> object's insert row is implementation-defined. 0N/A * The reference implementation for the <code>CachedRowSet</code> interface 0N/A * inserts a new row immediately following the current row, but it could be 0N/A * implemented to insert new rows in any number of other places. 0N/A * Another thing to note about these examples is how they use the method 0N/A * <code>acceptChanges</code>. It is this method that propagates changes in 0N/A * a <code>CachedRowSet</code> object back to the underlying data source, 0N/A * calling on the <code>RowSet</code> object's writer internally to write 0N/A * changes to the data source. To do this, the writer has to incur the expense 0N/A * of establishing a connection with that data source. The 0N/A * preceding two code fragments call the method <code>acceptChanges</code> 0N/A * immediately after calling <code>updateRow</code> or <code>insertRow</code>. 0N/A * However, when there are multiple rows being changed, it is more efficient to call 0N/A * <code>acceptChanges</code> after all calls to <code>updateRow</code> 0N/A * and <code>insertRow</code> have been made. If <code>acceptChanges</code> 0N/A * is called only once, only one connection needs to be established. 0N/A * <h3>4.0 Updating the Underlying Data Source</h3> 0N/A * When the method <code>acceptChanges</code> is executed, the 0N/A * <code>CachedRowSet</code> object's writer, a <code>RowSetWriterImpl</code> 0N/A * object, is called behind the scenes to write the changes made to the 0N/A * rowset to the underlying data source. The writer is implemented to make a 0N/A * connection to the data source and write updates to it. 0N/A * A writer is made available through an implementation of the 0N/A * <code>SyncProvider</code> interface, as discussed in section 1, 0N/A * "Creating a <code>CachedRowSet</code> Object." 0N/A * The default reference implementation provider, <code>RIOptimisticProvider</code>, 0N/A * has its writer implemented to use an optimistic concurrency control 0N/A * mechanism. That is, it maintains no locks in the underlying database while 0N/A * the rowset is disconnected from the database and simply checks to see if there 0N/A * are any conflicts before writing data to the data source. If there are any 0N/A * conflicts, it does not write anything to the data source. 0N/A * provided by the <code>SyncProvider</code> class is pluggable, allowing for the 0N/A * customization of data retrieval and updating. If a different concurrency 0N/A * control mechanism is desired, a different implementation of 0N/A * <code>SyncProvider</code> can be plugged in using the method 0N/A * <code>setSyncProvider</code>. 0N/A * In order to use the optimistic concurrency control routine, the 0N/A * <code>RIOptismisticProvider</code> maintains both its current 0N/A * value and its original value (the value it had immediately preceding the 0N/A * current value). Note that if no changes have been made to the data in a 0N/A * <code>RowSet</code> object, its current values and its original values are the same, 0N/A * both being the values with which the <code>RowSet</code> object was initially 0N/A * populated. However, once any values in the <code>RowSet</code> object have been 0N/A * changed, the current values and the original values will be different, though at 0N/A * this stage, the original values are still the initial values. With any subsequent 0N/A * changes to data in a <code>RowSet</code> object, its original values and current 0N/A * values will still differ, but its original values will be the values that 0N/A * were previously the current values. 0N/A * Keeping track of original values allows the writer to compare the <code>RowSet</code> 0N/A * object's original value with the value in the database. If the values in 0N/A * the database differ from the <code>RowSet</code> object's original values, which means that 0N/A * the values in the database have been changed, there is a conflict. 0N/A * Whether a writer checks for conflicts, what degree of checking it does, and how 0N/A * it handles conflicts all depend on how it is implemented. 0N/A * <h3>5.0 Registering and Notifying Listeners</h3> 0N/A * Being JavaBeans components, all rowsets participate in the JavaBeans event 0N/A * model, inheriting methods for registering listeners and notifying them of 0N/A * changes from the <code>BaseRowSet</code> class. A listener for a 0N/A * <code>CachedRowSet</code> object is a component that wants to be notified 0N/A * whenever there is a change in the rowset. For example, if a 0N/A * <code>CachedRowSet</code> object contains the results of a query and 0N/A * results are being displayed in, say, a table and a bar graph, the table and 0N/A * bar graph could be registered as listeners with the rowset so that they can 0N/A * update themselves to reflect changes. To become listeners, the table and 0N/A * bar graph classes must implement the <code>RowSetListener</code> interface. 0N/A * Then they can be added to the <Code>CachedRowSet</code> object's list of 0N/A * listeners, as is illustrated in the following lines of code. 0N/A * crs.addRowSetListener(table); 0N/A * crs.addRowSetListener(barGraph); 0N/A * Each <code>CachedRowSet</code> method that moves the cursor or changes 0N/A * data also notifies registered listeners of the changes, so 0N/A * <code>table</code> and <code>barGraph</code> will be notified when there is 0N/A * a change in <code>crs</code>. 0N/A * <h3>6.0 Passing Data to Thin Clients</h3> 0N/A * One of the main reasons to use a <code>CachedRowSet</code> object is to 0N/A * pass data between different components of an application. Because it is 0N/A * serializable, a <code>CachedRowSet</code> object can be used, for example, 0N/A * to send the result of a query executed by an enterprise JavaBeans component 0N/A * running in a server environment over a network to a client running in a 0N/A * While a <code>CachedRowSet</code> object is disconnected, it can be much 0N/A * leaner than a <code>ResultSet</code> object with the same data. 0N/A * As a result, it can be especially suitable for sending data to a thin client 0N/A * such as a PDA, where it would be inappropriate to use a JDBC driver 0N/A * due to resource limitations or security considerations. 0N/A * Thus, a <code>CachedRowSet</code> object provides a means to "get rows in" 0N/A * without the need to implement the full JDBC API. 0N/A * <h3>7.0 Scrolling and Updating</h3> 0N/A * A second major use for <code>CachedRowSet</code> objects is to provide 0N/A * scrolling and updating for <code>ResultSet</code> objects that 0N/A * do not provide these capabilities themselves. In other words, a 0N/A * <code>CachedRowSet</code> object can be used to augment the 0N/A * capabilities of a JDBC technology-enabled driver (hereafter called a 0N/A * "JDBC driver") when the DBMS does not provide full support for scrolling and 0N/A * updating. To achieve the effect of making a non-scrollble and read-only 0N/A * <code>ResultSet</code> object scrollable and updatable, a programmer 0N/A * simply needs to create a <code>CachedRowSet</code> object populated 0N/A * with that <code>ResultSet</code> object's data. This is demonstrated 0N/A * in the following code fragment, where <code>stmt</code> is a 0N/A * <code>Statement</code> object. 0N/A * ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEES"); 0N/A * CachedRowSetImpl crs = new CachedRowSetImpl(); 0N/A * The object <code>crs</code> now contains the data from the table 0N/A * <code>EMPLOYEES</code>, just as the object <code>rs</code> does. 0N/A * The difference is that the cursor for <code>crs</code> can be moved 0N/A * forward, backward, or to a particular row even if the cursor for 0N/A * <code>rs</code> can move only forward. In addition, <code>crs</code> is 0N/A * updatable even if <code>rs</code> is not because by default, a 0N/A * <code>CachedRowSet</code> object is both scrollable and updatable. 0N/A * In summary, a <code>CachedRowSet</code> object can be thought of as simply 0N/A * a disconnected set of rows that are being cached outside of a data source. 0N/A * Being thin and serializable, it can easily be sent across a wire, 0N/A * and it is well suited to sending data to a thin client. However, a 0N/A * <code>CachedRowSet</code> object does have a limitation: It is limited in 0N/A * size by the amount of data it can store in memory at one time. 0N/A * <h3>8.0 Getting Universal Data Access</h3> 0N/A * Another advantage of the <code>CachedRowSet</code> class is that it makes it 0N/A * possible to retrieve and store data from sources other than a relational 0N/A * database. The reader for a rowset can be implemented to read and populate 0N/A * its rowset with data from any tabular data source, including a spreadsheet 0N/A * Because both a <code>CachedRowSet</code> object and its metadata can be 0N/A * created from scratch, a component that acts as a factory for rowsets 0N/A * can use this capability to create a rowset containing data from 0N/A * non-SQL data sources. Nevertheless, it is expected that most of the time, 0N/A * <code>CachedRowSet</code> objects will contain data that was fetched 0N/A * from an SQL database using the JDBC API. 0N/A * <h3>9.0 Setting Properties</h3> 0N/A * All rowsets maintain a set of properties, which will usually be set using 0N/A * a tool. The number and kinds of properties a rowset has will vary, 0N/A * depending on what the rowset does and how it gets its data. For example, 0N/A * rowsets that get their data from a <code>ResultSet</code> object need to 0N/A * set the properties that are required for making a database connection. 0N/A * If a rowset uses the <code>DriverManager</code> facility to make a 0N/A * connection, it needs to set a property for the JDBC URL that identifies 0N/A * the appropriate driver, and it needs to set the properties that give the 0N/A * user name and password. 0N/A * If, on the other hand, the rowset uses a <code>DataSource</code> object 0N/A * to make the connection, which is the preferred method, it does not need to 0N/A * set the property for the JDBC URL. Instead, it needs to set 0N/A * properties for the logical name of the data source, for the user name, 0N/A * and for the password. 0N/A * NOTE: In order to use a <code>DataSource</code> object for making a 0N/A * connection, the <code>DataSource</code> object must have been registered 0N/A * with a naming service that uses the Java Naming and Directory 0N/A * Interface<sup><font size=-2>TM</font></sup> (JNDI) API. This registration 0N/A * is usually done by a person acting in the capacity of a system 0N/A * In order to be able to populate itself with data from a database, a rowset 0N/A * needs to set a command property. This property is a query that is a 0N/A * <code>PreparedStatement</code> object, which allows the query to have 0N/A * parameter placeholders that are set at run time, as opposed to design time. 0N/A * To set these placeholder parameters with values, a rowset provides 0N/A * setter methods for setting values of each data type, 0N/A * similar to the setter methods provided by the <code>PreparedStatement</code> 0N/A * The following code fragment illustrates how the <code>CachedRowSet</code> 0N/A * object <code>crs</code> might have its command property set. Note that if a 0N/A * tool is used to set properties, this is the code that the tool would use. 0N/A * crs.setCommand("SELECT FIRST_NAME, LAST_NAME, ADDRESS FROM CUSTOMERS " + 0N/A * "WHERE CREDIT_LIMIT > ? AND REGION = ?"); 0N/A * The values that will be used to set the command's placeholder parameters are 0N/A * contained in the <code>RowSet</code> object's <code>params</code> field, which is a 0N/A * <code>Vector</code> object. 0N/A * The <code>CachedRowSet</code> class provides a set of setter 0N/A * methods for setting the elements in its <code>params</code> field. The 0N/A * following code fragment demonstrates setting the two parameters in the 0N/A * query from the previous example. 0N/A * crs.setInt(1, 5000); 0N/A * crs.setString(2, "West"); 0N/A * The <code>params</code> field now contains two elements, each of which is 0N/A * an array two elements long. The first element is the parameter number; 0N/A * the second is the value to be set. 0N/A * In this case, the first element of <code>params</code> is 0N/A * <code>1</code>, <code>5000</code>, and the second element is <code>2</code>, 0N/A * <code>"West"</code>. When an application calls the method 0N/A * <code>execute</code>, it will in turn call on this <code>RowSet</code> object's reader, 0N/A * which will in turn invoke its <code>readData</code> method. As part of 0N/A * its implementation, <code>readData</code> will get the values in 0N/A * <code>params</code> and use them to set the command's placeholder 0N/A * The following code fragment gives an idea of how the reader 0N/A * does this, after obtaining the <code>Connection</code> object 0N/A * PreparedStatement pstmt = con.prepareStatement(crs.getCommand()); 0N/A * reader.decodeParams(); 0N/A * // decodeParams figures out which setter methods to use and does something 0N/A * // like the following: 0N/A * // for (i = 0; i < params.length; i++) { 0N/A * // pstmt.setObject(i + 1, params[i]); 0N/A * At this point, the command for <code>crs</code> is the query <code>"SELECT 0N/A * FIRST_NAME, LAST_NAME, ADDRESS FROM CUSTOMERS WHERE CREDIT_LIMIT > 5000 0N/A * AND REGION = "West"</code>. After the <code>readData</code> method executes 0N/A * this command with the following line of code, it will have the data from 0N/A * <code>rs</code> with which to populate <code>crs</code>. 0N/A * ResultSet rs = pstmt.executeQuery(); 0N/A * The preceding code fragments give an idea of what goes on behind the 0N/A * scenes; they would not appear in an application, which would not invoke 0N/A * methods like <code>readData</code> and <code>decodeParams</code>. 0N/A * In contrast, the following code fragment shows what an application might do. 0N/A * It sets the rowset's command, sets the command's parameters, and executes 0N/A * the command. Simply by calling the <code>execute</code> method, 0N/A * <code>crs</code> populates itself with the requested data from the 0N/A * table <code>CUSTOMERS</code>. 0N/A * crs.setCommand("SELECT FIRST_NAME, LAST_NAME, ADDRESS FROM CUSTOMERS" + 0N/A * "WHERE CREDIT_LIMIT > ? AND REGION = ?"); 0N/A * crs.setInt(1, 5000); 0N/A * crs.setString(2, "West"); 0N/A * <h3>10.0 Paging Data</h3> 0N/A * Because a <code>CachedRowSet</code> object stores data in memory, 0N/A * the amount of data that it can contain at any one 0N/A * time is determined by the amount of memory available. To get around this limitation, 0N/A * a <code>CachedRowSet</code> object can retrieve data from a <code>ResultSet</code> 0N/A * object in chunks of data, called <i>pages</i>. To take advantage of this mechanism, 0N/A * an application sets the number of rows to be included in a page using the method 0N/A * <code>setPageSize</code>. In other words, if the page size is set to five, a chunk 0N/A * data will be fetched from the data source at one time. An application can also 0N/A * optionally set the maximum number of rows that may be fetched at one time. If the 0N/A * maximum number of rows is set to zero, or no maximum number of rows is set, there is 0N/A * no limit to the number of rows that may be fetched at a time. 0N/A * After properties have been set, 0N/A * the <code>CachedRowSet</code> object must be populated with data 0N/A * using either the method <code>populate</code> or the method <code>execute</code>. 0N/A * The following lines of code demonstrate using the method <code>populate</code>. 0N/A * Note that this version of the method takes two parameters, a <code>ResultSet</code> 0N/A * handle and the row in the <code>ResultSet</code> object from which to start 0N/A * CachedRowSet crs = new CachedRowSetImpl(); 0N/A * crs.setMaxRows(20); 0N/A * crs.setPageSize(4); 0N/A * crs.populate(rsHandle, 10); 0N/A * When this code runs, <i>crs</i> will be populated with four rows from 0N/A * <i>rsHandle</i> starting with the tenth row. 0N/A * The next code fragment shows populating a <code>CachedRowSet</code> object using the 0N/A * method <code>execute</code>, which may or may not take a <code>Connection</code> 0N/A * object as a parameter. This code passes <code>execute</code> the <code>Connection</code> 0N/A * object <i>conHandle</i>. 0N/A * Note that there are two differences between the following code 0N/A * fragment and the previous one. First, the method <code>setMaxRows</code> is not 0N/A * called, so there is no limit set for the number of rows that <i>crs</i> may contain. 0N/A * (Remember that <i>crs</i> always has the overriding limit of how much data it can 0N/A * store in memory.) The second difference is that the you cannot pass the method 0N/A * <code>execute</code> the number of the row in the <code>ResultSet</code> object 0N/A * from which to start retrieving rows. This method always starts with the first row. 0N/A * CachedRowSet crs = new CachedRowSetImpl(); 0N/A * crs.setPageSize(5); 0N/A * crs.execute(conHandle); 0N/A * After this code has run, <i>crs</i> will contain five rows of data from the 0N/A * <code>ResultSet</code> object produced by the command for <i>crs</i>. The writer 0N/A * for <i>crs</i> will use <i>conHandle</i> to connect to the data source and 0N/A * execute the command for <i>crs</i>. An application is then able to operate on the 0N/A * data in <i>crs</i> in the same way that it would operate on data in any other 0N/A * <code>CachedRowSet</code> object. 0N/A * To access the next page (chunk of data), an application calls the method 0N/A * <code>nextPage</code>. This method creates a new <code>CachedRowSet</code> object 0N/A * and fills it with the next page of data. For example, assume that the 0N/A * <code>CachedRowSet</code> object's command returns a <code>ResultSet</code> object 0N/A * <i>rs</i> with 1000 rows of data. If the page size has been set to 100, the first 0N/A * call to the method <code>nextPage</code> will create a <code>CachedRowSet</code> object 0N/A * containing the first 100 rows of <i>rs</i>. After doing what it needs to do with the 0N/A * data in these first 100 rows, the application can again call the method 0N/A * <code>nextPage</code> to create another <code>CachedRowSet</code> object 0N/A * with the second 100 rows from <i>rs</i>. The data from the first <code>CachedRowSet</code> 0N/A * object will no longer be in memory because it is replaced with the data from the 0N/A * second <code>CachedRowSet</code> object. After the tenth call to the method <code>nextPage</code>, 0N/A * the tenth <code>CachedRowSet</code> object will contain the last 100 rows of data from 0N/A * <i>rs</i>, which are stored in memory. At any given time, the data from only one 0N/A * <code>CachedRowSet</code> object is stored in memory. 0N/A * The method <code>nextPage</code> returns <code>true</code> as long as the current 0N/A * page is not the last page of rows and <code>false</code> when there are no more pages. 0N/A * It can therefore be used in a <code>while</code> loop to retrieve all of the pages, 0N/A * as is demonstrated in the following lines of code. 0N/A * CachedRowSet crs = CachedRowSetImpl(); 0N/A * crs.setPageSize(100); 0N/A * crs.execute(conHandle); 0N/A * while(crs.nextPage()) { 0N/A * while(crs.next()) { 0N/A * . . . // operate on chunks (of 100 rows each) in crs, 0N/A * After this code fragment has been run, the application will have traversed all 0N/A * 1000 rows, but it will have had no more than 100 rows in memory at a time. 0N/A * The <code>CachedRowSet</code> interface also defines the method <code>previousPage</code>. 0N/A * Just as the method <code>nextPage</code> is analogous to the <code>ResultSet</code> 0N/A * method <code>next</code>, the method <code>previousPage</code> is analogous to 0N/A * the <code>ResultSet</code> method <code>previous</code>. Similar to the method 0N/A * <code>nextPage</code>, <code>previousPage</code> creates a <code>CachedRowSet</code> 0N/A * object containing the number of rows set as the page size. So, for instance, the 0N/A * method <code>previousPage</code> could be used in a <code>while</code> loop at 0N/A * the end of the preceding code fragment to navigate back through the pages from the last 0N/A * page to the first page. 0N/A * The method <code>previousPage</code> is also similar to <code>nextPage</code> 0N/A * in that it can be used in a <code>while</code> 0N/A * loop, except that it returns <code>true</code> as long as there is another page 0N/A * preceding it and <code>false</code> when there are no more pages ahead of it. 0N/A * By positioning the cursor after the last row for each page, 0N/A * as is done in the following code fragment, the method <code>previous</code> 0N/A * navigates from the last row to the first row in each page. 0N/A * The code could also have left the cursor before the first row on each page and then 0N/A * used the method <code>next</code> in a <code>while</code> loop to navigate each page 0N/A * from the first row to the last row. 0N/A * The following code fragment assumes a continuation from the previous code fragment, 0N/A * meaning that the cursor for the tenth <code>CachedRowSet</code> object is on the 0N/A * last row. The code moves the cursor to after the last row so that the first 0N/A * call to the method <code>previous</code> will put the cursor back on the last row. 0N/A * After going through all of the rows in the last page (the <code>CachedRowSet</code> 0N/A * object <i>crs</i>), the code then enters 0N/A * the <code>while</code> loop to get to the ninth page, go through the rows backwards, 0N/A * go to the eighth page, go through the rows backwards, and so on to the first row 0N/A * of the first page. 0N/A * while(crs.previous()) { 0N/A * . . . // navigate through the rows, last to first 0N/A * while(crs.previousPage()) { 0N/A * while(crs.previous()) { 0N/A * . . . // go from the last row to the first row of each page 0N/A * @author Jonathan Bruce 0N/A * Populates this <code>CachedRowSet</code> object with data from 0N/A * the given <code>ResultSet</code> object. 0N/A * This method can be used as an alternative to the <code>execute</code> method when an 0N/A * application has a connection to an open <code>ResultSet</code> object. 0N/A * Using the method <code>populate</code> can be more efficient than using 0N/A * the version of the <code>execute</code> method that takes no parameters 0N/A * because it does not open a new connection and re-execute this 0N/A * <code>CachedRowSet</code> object's command. Using the <code>populate</code> 0N/A * method is more a matter of convenience when compared to using the version 0N/A * of <code>execute</code> that takes a <code>ResultSet</code> object. 0N/A * @param data the <code>ResultSet</code> object containing the data 2740N/A * to be read into this <code>CachedRowSet</code> object 0N/A * @throws SQLException if a null <code>ResultSet</code> object is supplied 2740N/A * or this <code>CachedRowSet</code> object cannot 2740N/A * retrieve the associated <code>ResultSetMetaData</code> object 0N/A * @see java.sql.ResultSet 0N/A * @see java.sql.ResultSetMetaData 0N/A * Populates this <code>CachedRowSet</code> object with data, using the 0N/A * given connection to produce the result set from which the data will be read. 0N/A * This method should close any database connections that it creates to 0N/A * ensure that this <code>CachedRowSet</code> object is disconnected except when 0N/A * it is reading data from its data source or writing data to its data source. 0N/A * The reader for this <code>CachedRowSet</code> object 0N/A * will use <i>conn</i> to establish a connection to the data source 0N/A * so that it can execute the rowset's command and read data from the 0N/A * the resulting <code>ResultSet</code> object into this 0N/A * <code>CachedRowSet</code> object. This method also closes <i>conn</i> 0N/A * after it has populated this <code>CachedRowSet</code> object. 0N/A * If this method is called when an implementation has already been 0N/A * populated, the contents and the metadata are (re)set. Also, if this method is 0N/A * called before the method <code>acceptChanges</code> has been called 0N/A * to commit outstanding updates, those updates are lost. 0N/A * @param conn a standard JDBC <code>Connection</code> object with valid 0N/A * @throws SQLException if an invalid <code>Connection</code> object is supplied 2740N/A * or an error occurs in establishing the connection to the 0N/A * @see java.sql.Connection 0N/A * Propagates row update, insert and delete changes made to this 0N/A * <code>CachedRowSet</code> object to the underlying data source. 0N/A * This method calls on this <code>CachedRowSet</code> object's writer 0N/A * to do the work behind the scenes. 0N/A * Standard <code>CachedRowSet</code> implementations should use the 0N/A * <code>SyncFactory</code> singleton 0N/A * to obtain a <code>SyncProvider</code> instance providing a 0N/A * <code>RowSetWriter</code> object (writer). The writer will attempt 0N/A * to propagate changes made in this <code>CachedRowSet</code> object 0N/A * back to the data source. 0N/A * When the method <code>acceptChanges</code> executes successfully, in 0N/A * addition to writing changes to the data source, it 0N/A * makes the values in the current row be the values in the original row. 0N/A * Depending on the synchronization level of the <code>SyncProvider</code> 0N/A * implementation being used, the writer will compare the original values 0N/A * with those in the data source to check for conflicts. When there is a conflict, 0N/A * the <code>RIOptimisticProvider</code> implementation, for example, throws a 0N/A * <code>SyncProviderException</code> and does not write anything to the 0N/A * An application may choose to catch the <code>SyncProviderException</code> 0N/A * object and retrieve the <code>SyncResolver</code> object it contains. 0N/A * The <code>SyncResolver</code> object lists the conflicts row by row and 0N/A * sets a lock on the data source to avoid further conflicts while the 0N/A * current conflicts are being resolved. 0N/A * Further, for each conflict, it provides methods for examining the conflict 0N/A * and setting the value that should be persisted in the data source. 0N/A * After all conflicts have been resolved, an application must call the 0N/A * <code>acceptChanges</code> method again to write resolved values to the 0N/A * data source. If all of the values in the data source are already the 0N/A * values to be persisted, the method <code>acceptChanges</code> does nothing. 0N/A * Some provider implementations may use locks to ensure that there are no 0N/A * conflicts. In such cases, it is guaranteed that the writer will succeed in 0N/A * writing changes to the data source when the method <code>acceptChanges</code> 0N/A * is called. This method may be called immediately after the methods 0N/A * <code>updateRow</code>, <code>insertRow</code>, or <code>deleteRow</code> 0N/A * have been called, but it is more efficient to call it only once after 0N/A * all changes have been made so that only one connection needs to be 0N/A * Note: The <code>acceptChanges()</code> method will determine if the 0N/A * <code>COMMIT_ON_ACCEPT_CHANGES</code> is set to true or not. If it is set 0N/A * to true, all updates in the synchronization are committed to the data 0N/A * source. Otherwise, the application <b>must</b> explicity call the 0N/A * <code>commit()</code> or <code>rollback()</code> methods as appropriate. 0N/A * @throws SQLException if the cursor is on the insert row 0N/A * @throws SyncProviderException if the underlying 2740N/A * synchronization provider's writer fails to write the updates 0N/A * @see #acceptChanges(java.sql.Connection) 0N/A * @see javax.sql.RowSetWriter 0N/A * @see javax.sql.rowset.spi.SyncFactory 0N/A * @see javax.sql.rowset.spi.SyncProvider 0N/A * @see javax.sql.rowset.spi.SyncProviderException 0N/A * @see javax.sql.rowset.spi.SyncResolver 0N/A * Propagates all row update, insert and delete changes to the 0N/A * data source backing this <code>CachedRowSet</code> object 0N/A * using the specified <code>Connection</code> object to establish a 0N/A * connection to the data source. 0N/A * The other version of the <code>acceptChanges</code> method is not passed 0N/A * a connection because it uses 0N/A * the <code>Connection</code> object already defined within the <code>RowSet</code> 0N/A * object, which is the connection used for populating it initially. 0N/A * This form of the method <code>acceptChanges</code> is similar to the 0N/A * form that takes no arguments; however, unlike the other form, this form 0N/A * can be used only when the underlying data source is a JDBC data source. 0N/A * The updated <code>Connection</code> properties must be used by the 0N/A * <code>SyncProvider</code> to reset the <code>RowSetWriter</code> 0N/A * configuration to ensure that the contents of the <code>CachedRowSet</code> 0N/A * object are synchronized correctly. 0N/A * When the method <code>acceptChanges</code> executes successfully, in 0N/A * addition to writing changes to the data source, it 0N/A * makes the values in the current row be the values in the original row. 0N/A * Depending on the synchronization level of the <code>SyncProvider</code> 0N/A * implementation being used, the writer will compare the original values 0N/A * with those in the data source to check for conflicts. When there is a conflict, 0N/A * the <code>RIOptimisticProvider</code> implementation, for example, throws a 0N/A * <code>SyncProviderException</code> and does not write anything to the 0N/A * An application may choose to catch the <code>SyncProviderException</code> 0N/A * object and retrieve the <code>SyncResolver</code> object it contains. 0N/A * The <code>SyncResolver</code> object lists the conflicts row by row and 0N/A * sets a lock on the data source to avoid further conflicts while the 0N/A * current conflicts are being resolved. 0N/A * Further, for each conflict, it provides methods for examining the conflict 0N/A * and setting the value that should be persisted in the data source. 0N/A * After all conflicts have been resolved, an application must call the 0N/A * <code>acceptChanges</code> method again to write resolved values to the 0N/A * data source. If all of the values in the data source are already the 0N/A * values to be persisted, the method <code>acceptChanges</code> does nothing. 0N/A * Some provider implementations may use locks to ensure that there are no 0N/A * conflicts. In such cases, it is guaranteed that the writer will succeed in 0N/A * writing changes to the data source when the method <code>acceptChanges</code> 0N/A * is called. This method may be called immediately after the methods 0N/A * <code>updateRow</code>, <code>insertRow</code>, or <code>deleteRow</code> 0N/A * have been called, but it is more efficient to call it only once after 0N/A * all changes have been made so that only one connection needs to be 0N/A * Note: The <code>acceptChanges()</code> method will determine if the 0N/A * <code>COMMIT_ON_ACCEPT_CHANGES</code> is set to true or not. If it is set 0N/A * to true, all updates in the synchronization are committed to the data 0N/A * source. Otherwise, the application <b>must</b> explicity call the 0N/A * <code>commit</code> or <code>rollback</code> methods as appropriate. 0N/A * @param con a standard JDBC <code>Connection</code> object 0N/A * @throws SQLException if the cursor is on the insert row 0N/A * @throws SyncProviderException if the underlying 2740N/A * synchronization provider's writer fails to write the updates 0N/A * @see #acceptChanges() 0N/A * @see javax.sql.RowSetWriter 0N/A * @see javax.sql.rowset.spi.SyncFactory 0N/A * @see javax.sql.rowset.spi.SyncProvider 0N/A * @see javax.sql.rowset.spi.SyncProviderException 0N/A * @see javax.sql.rowset.spi.SyncResolver 0N/A * Restores this <code>CachedRowSet</code> object to its original 0N/A * value, that is, its value before the last set of changes. If there 0N/A * have been no changes to the rowset or only one set of changes, 0N/A * the original value is the value with which this <code>CachedRowSet</code> object 0N/A * was populated; otherwise, the original value is 0N/A * the value it had immediately before its current value. 0N/A * When this method is called, a <code>CachedRowSet</code> implementation 0N/A * must ensure that all updates, inserts, and deletes to the current 0N/A * rowset instance are replaced by the previous values. In addition, 0N/A * the cursor should be 0N/A * reset to the first row and a <code>rowSetChanged</code> event 0N/A * should be fired to notify all registered listeners. 0N/A * @throws SQLException if an error occurs rolling back the current value of 0N/A * this <code>CachedRowSet</code> object to its previous value 0N/A * @see javax.sql.RowSetListener#rowSetChanged 0N/A * Releases the current contents of this <code>CachedRowSet</code> 0N/A * object and sends a <code>rowSetChanged</code> event to all 0N/A * registered listeners. Any outstanding updates are discarded and 0N/A * the rowset contains no rows after this method is called. There 0N/A * are no interactions with the underlying data source, and any rowset 0N/A * content, metadata, and content updates should be non-recoverable. 0N/A * This <code>CachedRowSet</code> object should lock until its contents and 0N/A * associated updates are fully cleared, thus preventing 'dirty' reads by 0N/A * other components that hold a reference to this <code>RowSet</code> object. 0N/A * In addition, the contents cannot be released 0N/A * until all all components reading this <code>CachedRowSet</code> object 0N/A * have completed their reads. This <code>CachedRowSet</code> object 0N/A * should be returned to normal behavior after firing the 0N/A * <code>rowSetChanged</code> event. 0N/A * The metadata, including JDBC properties and Synchronization SPI 0N/A * properties, are maintained for future use. It is important that 0N/A * properties such as the <code>command</code> property be 0N/A * relevant to the originating data source from which this <code>CachedRowSet</code> 0N/A * object was originally established. 0N/A * This method empties a rowset, as opposed to the <code>close</code> method, 0N/A * which marks the entire rowset as recoverable to allow the garbage collector 0N/A * the rowset's Java VM resources. 0N/A * @throws SQLException if an error occurs flushing the contents of this 2740N/A * <code>CachedRowSet</code> object 0N/A * @see javax.sql.RowSetListener#rowSetChanged 0N/A * @see java.sql.ResultSet#close 0N/A * Cancels the deletion of the current row and notifies listeners that 0N/A * a row has changed. After this method is called, the current row is 0N/A * no longer marked for deletion. This method can be called at any 0N/A * time during the lifetime of the rowset. 0N/A * In addition, multiple cancellations of row deletions can be made 0N/A * by adjusting the position of the cursor using any of the cursor 0N/A * position control methods such as: 0N/A * <li><code>CachedRowSet.absolute</code> 0N/A * <li><code>CachedRowSet.first</code> 0N/A * <li><code>CachedRowSet.last</code> 0N/A * @throws SQLException if (1) the current row has not been deleted or 0N/A * (2) the cursor is on the insert row, before the first row, or 0N/A * after the last row 0N/A * @see javax.sql.rowset.CachedRowSet#undoInsert 0N/A * @see java.sql.ResultSet#cancelRowUpdates 0N/A * Immediately removes the current row from this <code>CachedRowSet</code> 0N/A * object if the row has been inserted, and also notifies listeners that a 0N/A * row has changed. This method can be called at any time during the 0N/A * lifetime of a rowset and assuming the current row is within 0N/A * the exception limitations (see below), it cancels the row insertion 0N/A * of the current row. 0N/A * In addition, multiple cancellations of row insertions can be made 0N/A * by adjusting the position of the cursor using any of the cursor 0N/A * position control methods such as: 0N/A * <li><code>CachedRowSet.absolute</code> 0N/A * <li><code>CachedRowSet.first</code> 0N/A * <li><code>CachedRowSet.last</code> 0N/A * @throws SQLException if (1) the current row has not been inserted or (2) 0N/A * the cursor is before the first row, after the last row, or on the 0N/A * @see javax.sql.rowset.CachedRowSet#undoDelete 0N/A * @see java.sql.ResultSet#cancelRowUpdates 0N/A * Immediately reverses the last update operation if the 0N/A * row has been modified. This method can be 0N/A * called to reverse updates on all columns until all updates in a row have 0N/A * been rolled back to their state just prior to the last synchronization 0N/A * (<code>acceptChanges</code>) or population. This method may also be called 0N/A * while performing updates to the insert row. 0N/A * <code>undoUpdate</code> may be called at any time during the lifetime of a 0N/A * rowset; however, after a synchronization has occurred, this method has no 0N/A * effect until further modification to the rowset data has occurred. 0N/A * @throws SQLException if the cursor is before the first row or after the last 0N/A * row in in this <code>CachedRowSet</code> object 0N/A * @see java.sql.ResultSet#cancelRowUpdates 0N/A * Indicates whether the designated column in the current row of this 0N/A * <code>CachedRowSet</code> object has been updated. 0N/A * @param idx an <code>int</code> identifying the column to be checked for updates 0N/A * @return <code>true</code> if the designated column has been visibly updated; 2740N/A * <code>false</code> otherwise 0N/A * @throws SQLException if the cursor is on the insert row, before the first row, 0N/A * @see java.sql.DatabaseMetaData#updatesAreDetected 0N/A * Indicates whether the designated column in the current row of this 0N/A * <code>CachedRowSet</code> object has been updated. 0N/A * @param columnName a <code>String</code> object giving the name of the 0N/A * column to be checked for updates 0N/A * @return <code>true</code> if the column has been visibly updated; 2740N/A * <code>false</code> otherwise 0N/A * @throws SQLException if the cursor is on the insert row, before the first row, 0N/A * @see java.sql.DatabaseMetaData#updatesAreDetected 0N/A * Converts this <code>CachedRowSet</code> object to a <code>Collection</code> 0N/A * object that contains all of this <code>CachedRowSet</code> object's data. 0N/A * Implementations have some latitude in 0N/A * how they can represent this <code>Collection</code> object because of the 0N/A * abstract nature of the <code>Collection</code> framework. 0N/A * Each row must be fully represented in either a 0N/A * general purpose <code>Collection</code> implementation or a specialized 0N/A * <code>Collection</code> implementation, such as a <code>TreeMap</code> 0N/A * object or a <code>Vector</code> object. 0N/A * An SQL <code>NULL</code> column value must be represented as a <code>null</code> 0N/A * in the Java programming language. 0N/A * The standard reference implementation for the <code>CachedRowSet</code> 0N/A * interface uses a <code>TreeMap</code> object for the rowset, with the 0N/A * values in each row being contained in <code>Vector</code> objects. It is 0N/A * expected that most implementations will do the same. 0N/A * The <code>TreeMap</code> type of collection guarantees that the map will be in 0N/A * ascending key order, sorted according to the natural order for the 0N/A * Each key references a <code>Vector</code> object that corresponds to one 0N/A * row of a <code>RowSet</code> object. Therefore, the size of each 0N/A * <code>Vector</code> object must be exactly equal to the number of 0N/A * columns in the <code>RowSet</code> object. 0N/A * The key used by the <code>TreeMap</code> collection is determined by the 0N/A * implementation, which may choose to leverage a set key that is 0N/A * available within the internal <code>RowSet</code> tabular structure by 0N/A * virtue of a key already set either on the <code>RowSet</code> object 0N/A * itself or on the underlying SQL data. 0N/A * @return a <code>Collection</code> object that contains the values in 2740N/A * each row in this <code>CachedRowSet</code> object 0N/A * @throws SQLException if an error occurs generating the collection 0N/A * @see #toCollection(int) 0N/A * @see #toCollection(String) 0N/A * Converts the designated column in this <code>CachedRowSet</code> object 0N/A * to a <code>Collection</code> object. Implementations have some latitude in 0N/A * how they can represent this <code>Collection</code> object because of the 0N/A * abstract nature of the <code>Collection</code> framework. 0N/A * Each column value should be fully represented in either a 0N/A * general purpose <code>Collection</code> implementation or a specialized 0N/A * <code>Collection</code> implementation, such as a <code>Vector</code> object. 0N/A * An SQL <code>NULL</code> column value must be represented as a <code>null</code> 0N/A * in the Java programming language. 0N/A * The standard reference implementation uses a <code>Vector</code> object 0N/A * to contain the column values, and it is expected 0N/A * that most implementations will do the same. If a <code>Vector</code> object 0N/A * is used, it size must be exactly equal to the number of rows 0N/A * in this <code>CachedRowSet</code> object. 0N/A * @param column an <code>int</code> indicating the column whose values 0N/A * are to be represented in a <code>Collection</code> object 0N/A * @return a <code>Collection</code> object that contains the values 2740N/A * stored in the specified column of this <code>CachedRowSet</code> 0N/A * @throws SQLException if an error occurs generating the collection or 2740N/A * an invalid column id is provided 0N/A * @see #toCollection 0N/A * @see #toCollection(String) 0N/A * Converts the designated column in this <code>CachedRowSet</code> object 0N/A * to a <code>Collection</code> object. Implementations have some latitude in 0N/A * how they can represent this <code>Collection</code> object because of the 0N/A * abstract nature of the <code>Collection</code> framework. 0N/A * Each column value should be fully represented in either a 0N/A * general purpose <code>Collection</code> implementation or a specialized 0N/A * <code>Collection</code> implementation, such as a <code>Vector</code> object. 0N/A * An SQL <code>NULL</code> column value must be represented as a <code>null</code> 0N/A * in the Java programming language. 0N/A * The standard reference implementation uses a <code>Vector</code> object 0N/A * to contain the column values, and it is expected 0N/A * that most implementations will do the same. If a <code>Vector</code> object 0N/A * is used, it size must be exactly equal to the number of rows 0N/A * in this <code>CachedRowSet</code> object. 0N/A * @param column a <code>String</code> object giving the name of the 0N/A * column whose values are to be represented in a collection 0N/A * @return a <code>Collection</code> object that contains the values 2740N/A * stored in the specified column of this <code>CachedRowSet</code> 0N/A * @throws SQLException if an error occurs generating the collection or 2740N/A * an invalid column id is provided 0N/A * @see #toCollection 0N/A * @see #toCollection(int) 0N/A * Retrieves the <code>SyncProvider</code> implementation for this 0N/A * <code>CachedRowSet</code> object. Internally, this method is used by a rowset 0N/A * to trigger read or write actions between the rowset 0N/A * and the data source. For example, a rowset may need to get a handle 0N/A * on the the rowset reader (<code>RowSetReader</code> object) from the 0N/A * <code>SyncProvider</code> to allow the rowset to be populated. 0N/A * RowSetReader rowsetReader = null; 0N/A * SyncProvider provider = 0N/A * SyncFactory.getInstance("javax.sql.rowset.provider.RIOptimisticProvider"); 0N/A * if (provider instanceof RIOptimisticProvider) { 0N/A * rowsetReader = provider.getRowSetReader(); 0N/A * Assuming <i>rowsetReader</i> is a private, accessible field within 0N/A * the rowset implementation, when an application calls the <code>execute</code> 0N/A * method, it in turn calls on the reader's <code>readData</code> method 0N/A * to populate the <code>RowSet</code> object. 0N/A * rowsetReader.readData((RowSetInternal)this); 0N/A * In addition, an application can use the <code>SyncProvider</code> object 0N/A * returned by this method to call methods that return information about the 0N/A * <code>SyncProvider</code> object, including information about the 0N/A * vendor, version, provider identification, synchronization grade, and locks 0N/A * it currently has set. 0N/A * @return the <code>SyncProvider</code> object that was set when the rowset 0N/A * was instantiated, or if none was was set, the default provider 0N/A * @throws SQLException if an error occurs while returning the 2740N/A * <code>SyncProvider</code> object 0N/A * @see #setSyncProvider 0N/A * Sets the <code>SyncProvider</code> objec for this <code>CachedRowSet</code> 0N/A * object to the one specified. This method 0N/A * allows the <code>SyncProvider</code> object to be reset. 0N/A * A <code>CachedRowSet</code> implementation should always be instantiated 0N/A * with an available <code>SyncProvider</code> mechanism, but there are 0N/A * cases where resetting the <code>SyncProvider</code> object is desirable 0N/A * or necessary. For example, an application might want to use the default 0N/A * <code>SyncProvider</code> object for a time and then choose to use a provider 0N/A * that has more recently become available and better fits its needs. 0N/A * Resetting the <code>SyncProvider</code> object causes the 0N/A * <code>RowSet</code> object to request a new <code>SyncProvider</code> implementation 0N/A * from the <code>SyncFactory</code>. This has the effect of resetting 0N/A * all previous connections and relationships with the originating 0N/A * data source and can potentially drastically change the synchronization 0N/A * behavior of a disconnected rowset. 0N/A * @param provider a <code>String</code> object giving the fully qualified class 0N/A * name of a <code>SyncProvider</code> implementation 0N/A * @throws SQLException if an error occurs while attempting to reset the 2740N/A * <code>SyncProvider</code> implementation 0N/A * @see #getSyncProvider 0N/A * Returns the number of rows in this <code>CachedRowSet</code> 0N/A * @return number of rows in the rowset 0N/A * Sets the metadata for this <code>CachedRowSet</code> object with 0N/A * the given <code>RowSetMetaData</code> object. When a 0N/A * <code>RowSetReader</code> object is reading the contents of a rowset, 0N/A * it creates a <code>RowSetMetaData</code> object and initializes 0N/A * it using the methods in the <code>RowSetMetaData</code> implementation. 0N/A * The reference implementation uses the <code>RowSetMetaDataImpl</code> 0N/A * class. When the reader has completed reading the rowset contents, 0N/A * this method is called internally to pass the <code>RowSetMetaData</code> 0N/A * object to the rowset. 0N/A * @param md a <code>RowSetMetaData</code> object containing 2740N/A * metadata about the columns in this <code>CachedRowSet</code> object 0N/A * @throws SQLException if invalid metadata is supplied to the 0N/A * Returns a <code>ResultSet</code> object containing the original value of this 0N/A * <code>CachedRowSet</code> object. 0N/A * The cursor for the <code>ResultSet</code> 0N/A * object should be positioned before the first row. 0N/A * In addition, the returned <code>ResultSet</code> object should have the following 0N/A * <LI>ResultSet.TYPE_SCROLL_INSENSITIVE 0N/A * <LI>ResultSet.CONCUR_UPDATABLE 0N/A * The original value for a <code>RowSet</code> object is the value it had before 0N/A * the last synchronization with the underlying data source. If there have been 0N/A * no synchronizations, the original value will be the value with which the 0N/A * <code>RowSet</code> object was populated. This method is called internally 0N/A * when an aplication calls the method <code>acceptChanges</code> and the 0N/A * <code>SyncProvider</code> object has been implemented to check for conflicts. 0N/A * If this is the case, the writer compares the original value with the value 0N/A * currently in the data source to check for conflicts. 0N/A * @return a <code>ResultSet</code> object that contains the original value for 0N/A * this <code>CachedRowSet</code> object 0N/A * @throws SQLException if an error occurs producing the 2740N/A * <code>ResultSet</code> object 0N/A * Returns a <code>ResultSet</code> object containing the original value for the 0N/A * current row only of this <code>CachedRowSet</code> object. 0N/A * The cursor for the <code>ResultSet</code> 0N/A * object should be positioned before the first row. 0N/A * In addition, the returned <code>ResultSet</code> object should have the following 0N/A * <LI>ResultSet.TYPE_SCROLL_INSENSITIVE 0N/A * <LI>ResultSet.CONCUR_UPDATABLE 0N/A * @return the original result set of the row 0N/A * @throws SQLException if there is no current row 0N/A * @see #setOriginalRow 0N/A * Sets the current row in this <code>CachedRowSet</code> object as the original 0N/A * This method is called internally after the any modified values in the current 0N/A * row have been synchronized with the data source. The current row must be tagged 0N/A * as no longer inserted, deleted or updated. 0N/A * A call to <code>setOriginalRow</code> is irreversible. 0N/A * @throws SQLException if there is no current row or an error is 2740N/A * encountered resetting the contents of the original row 0N/A * @see #getOriginalRow 0N/A * Returns an identifier for the object (table) that was used to 0N/A * create this <code>CachedRowSet</code> object. This name may be set on multiple occasions, 0N/A * and the specification imposes no limits on how many times this 0N/A * may occur or whether standard implementations should keep track 0N/A * of previous table names. 0N/A * @return a <code>String</code> object giving the name of the table that is the 0N/A * source of data for this <code>CachedRowSet</code> object or <code>null</code> 0N/A * if no name has been set for the table 0N/A * @throws SQLException if an error is encountered returning the table name 0N/A * @see javax.sql.RowSetMetaData#getTableName 0N/A * Sets the identifier for the table from which this <code>CachedRowSet</code> 0N/A * object was derived to the given table name. The writer uses this name to 0N/A * determine which table to use when comparing the values in the data source with the 0N/A * <code>CachedRowSet</code> object's values during a synchronization attempt. 0N/A * The table identifier also indicates where modified values from this 0N/A * <code>CachedRowSet</code> object should be written. 0N/A * The implementation of this <code>CachedRowSet</code> object may obtain the 0N/A * the name internally from the <code>RowSetMetaDataImpl</code> object. 0N/A * @param tabName a <code>String</code> object identifying the table from which this 0N/A <code>CachedRowSet</code> object was derived; cannot be <code>null</code> 0N/A * but may be an empty string 0N/A * @throws SQLException if an error is encountered naming the table or 0N/A * <i>tabName</i> is <code>null</code> 0N/A * @see javax.sql.RowSetMetaData#setTableName 0N/A * @see javax.sql.RowSetWriter 0N/A * @see javax.sql.rowset.spi.SyncProvider 0N/A * Returns an array containing one or more column numbers indicating the columns 0N/A * that form a key that uniquely 0N/A * identifies a row in this <code>CachedRowSet</code> object. 0N/A * @return an array containing the column number or numbers that indicate which columns 0N/A * constitute a primary key 0N/A * for a row in this <code>CachedRowSet</code> object. This array should be 0N/A * empty if no columns are representative of a primary key. 0N/A * @throws SQLException if this <code>CachedRowSet</code> object is empty 0N/A * @see #setKeyColumns 0N/A * @see Joinable#getMatchColumnIndexes 0N/A * @see Joinable#getMatchColumnNames 0N/A * Sets this <code>CachedRowSet</code> object's <code>keyCols</code> 0N/A * field with the given array of column numbers, which forms a key 0N/A * for uniquely identifying a row in this <code>CachedRowSet</code> object. 0N/A * If a <code>CachedRowSet</code> object becomes part of a <code>JoinRowSet</code> 0N/A * object, the keys defined by this method and the resulting constraints are 0N/A * maintained if the columns designated as key columns also become match 0N/A * @param keys an array of <code>int</code> indicating the columns that form 0N/A * a primary key for this <code>CachedRowSet</code> object; every 0N/A * element in the array must be greater than <code>0</code> and 0N/A * less than or equal to the number of columns in this rowset 0N/A * @throws SQLException if any of the numbers in the given array 0N/A * are not valid for this rowset 0N/A * @see #getKeyColumns 0N/A * @see Joinable#setMatchColumn(String) 0N/A * @see Joinable#setMatchColumn(int) 0N/A * Returns a new <code>RowSet</code> object backed by the same data as 0N/A * that of this <code>CachedRowSet</code> object. In effect, both 0N/A * <code>CachedRowSet</code> objects have a cursor over the same data. 0N/A * As a result, any changes made by a duplicate are visible to the original 0N/A * and to any other duplicates, just as a change made by the original is visible 0N/A * to all of its duplicates. If a duplicate calls a method that changes the 0N/A * underlying data, the method it calls notifies all registered listeners 0N/A * just as it would when it is called by the original <code>CachedRowSet</code> 0N/A * In addition, any <code>RowSet</code> object 0N/A * created by this method will have the same properties as this 0N/A * <code>CachedRowSet</code> object. For example, if this <code>CachedRowSet</code> 0N/A * object is read-only, all of its duplicates will also be read-only. If it is 0N/A * changed to be updatable, the duplicates also become updatable. 0N/A * NOTE: If multiple threads access <code>RowSet</code> objects created from 0N/A * the <code>createShared()</code> method, the following behavior is specified 0N/A * to preserve shared data integrity: reads and writes of all 0N/A * shared <code>RowSet</code> objects should be made serially between each 0N/A * object and the single underlying tabular structure. 0N/A * @return a new shared <code>RowSet</code> object that has the same properties 0N/A * as this <code>CachedRowSet</code> object and that has a cursor over 0N/A * @throws SQLException if an error occurs or cloning is not 2740N/A * supported in the underlying platform 0N/A * @see javax.sql.RowSetEvent 0N/A * @see javax.sql.RowSetListener 0N/A * Creates a <code>RowSet</code> object that is a deep copy of the data in 0N/A * this <code>CachedRowSet</code> object. In contrast to 0N/A * the <code>RowSet</code> object generated from a <code>createShared</code> 0N/A * call, updates made to the copy of the original <code>RowSet</code> object 0N/A * must not be visible to the original <code>RowSet</code> object. Also, any 0N/A * event listeners that are registered with the original 0N/A * <code>RowSet</code> must not have scope over the new 0N/A * <code>RowSet</code> copies. In addition, any constraint restrictions 0N/A * established must be maintained. 0N/A * @return a new <code>RowSet</code> object that is a deep copy 2740N/A * of this <code>CachedRowSet</code> object and is 2740N/A * completely independent of this <code>CachedRowSet</code> object 0N/A * @throws SQLException if an error occurs in generating the copy of 2740N/A * the of this <code>CachedRowSet</code> object 0N/A * @see #createShared 0N/A * @see #createCopySchema 0N/A * @see #createCopyNoConstraints 0N/A * @see javax.sql.RowSetEvent 0N/A * @see javax.sql.RowSetListener 0N/A * Creates a <code>CachedRowSet</code> object that is an empty copy of this 0N/A * <code>CachedRowSet</code> object. The copy 0N/A * must not contain any contents but only represent the table 0N/A * structure of the original <code>CachedRowSet</code> object. In addition, primary 0N/A * or foreign key constraints set in the originating <code>CachedRowSet</code> object must 0N/A * be equally enforced in the new empty <code>CachedRowSet</code> object. 0N/A * the <code>RowSet</code> object generated from a <code>createShared</code> method 0N/A * call, updates made to a copy of this <code>CachedRowSet</code> object with the 0N/A * <code>createCopySchema</code> method must not be visible to it. 0N/A * Applications can form a <code>WebRowSet</code> object from the <code>CachedRowSet</code> 0N/A * object returned by this method in order 0N/A * to export the <code>RowSet</code> schema definition to XML for future use. 0N/A * @throws SQLException if an error occurs in cloning the structure of this 0N/A * <code>CachedRowSet</code> object 0N/A * @see #createShared 0N/A * @see #createCopySchema 0N/A * @see #createCopyNoConstraints 0N/A * @see javax.sql.RowSetEvent 0N/A * @see javax.sql.RowSetListener 0N/A * Creates a <code>CachedRowSet</code> object that is a deep copy of 0N/A * this <code>CachedRowSet</code> object's data but is independent of it. 0N/A * the <code>RowSet</code> object generated from a <code>createShared</code> 0N/A * method call, updates made to a copy of this <code>CachedRowSet</code> object 0N/A * must not be visible to it. Also, any 0N/A * event listeners that are registered with this 0N/A * <code>CachedRowSet</code> object must not have scope over the new 0N/A * <code>RowSet</code> object. In addition, any constraint restrictions 0N/A * established for this <code>CachedRowSet</code> object must <b>not</b> be maintained 0N/A * @return a new <code>CachedRowSet</code> object that is a deep copy 2740N/A * of this <code>CachedRowSet</code> object and is 2740N/A * completely independent of this <code>CachedRowSet</code> object 0N/A * @throws SQLException if an error occurs in generating the copy of 2740N/A * the of this <code>CachedRowSet</code> object 0N/A * @see #createShared 0N/A * @see #createCopySchema 0N/A * @see javax.sql.RowSetEvent 0N/A * @see javax.sql.RowSetListener 0N/A * Retrieves the first warning reported by calls on this <code>RowSet</code> object. 0N/A * Subsequent warnings on this <code>RowSet</code> object will be chained to the 0N/A * <code>RowSetWarning</code> object that this method returns. 0N/A * The warning chain is automatically cleared each time a new row is read. 0N/A * This method may not be called on a RowSet object that has been closed; 0N/A * doing so will cause a <code>SQLException</code> to be thrown. 0N/A * @return RowSetWarning the first <code>RowSetWarning</code> 0N/A * object reported or null if there are none 0N/A * @throws SQLException if this method is called on a closed RowSet 0N/A * @see RowSetWarning 0N/A * Retrieves a <code>boolean</code> indicating whether rows marked 0N/A * for deletion appear in the set of current rows. If <code>true</code> is 0N/A * returned, deleted rows are visible with the current rows. If 0N/A * <code>false</code> is returned, rows are not visible with the set of 0N/A * current rows. The default value is <code>false</code>. 0N/A * Standard rowset implementations may choose to restrict this behavior 0N/A * due to security considerations or to better fit certain deployment 0N/A * scenarios. This is left as implementation defined and does not 0N/A * represent standard behavior. 0N/A * Note: Allowing deleted rows to remain visible complicates the behavior 0N/A * of some standard JDBC <code>RowSet</code> Implementations methods. 0N/A * However, most rowset users can simply ignore this extra detail because 0N/A * only very specialized applications will likely want to take advantage of 0N/A * @return <code>true</code> if deleted rows are visible; 0N/A * <code>false</code> otherwise 0N/A * @throws SQLException if a rowset implementation is unable to 2740N/A * to determine whether rows marked for deletion are visible 0N/A * @see #setShowDeleted 0N/A * Sets the property <code>showDeleted</code> to the given 0N/A * <code>boolean</code> value, which determines whether 0N/A * rows marked for deletion appear in the set of current rows. 0N/A * If the value is set to <code>true</code>, deleted rows are immediately 0N/A * visible with the set of current rows. If the value is set to 0N/A * <code>false</code>, the deleted rows are set as invisible with the 0N/A * current set of rows. 0N/A * Standard rowset implementations may choose to restrict this behavior 0N/A * due to security considerations or to better fit certain deployment 0N/A * scenarios. This is left as implementations defined and does not 0N/A * represent standard behavior. 0N/A * @param b <code>true</code> if deleted rows should be shown; 0N/A * <code>false</code> otherwise 0N/A * @exception SQLException if a rowset implementation is unable to 2740N/A * to reset whether deleted rows should be visible 0N/A * @see #getShowDeleted 0N/A * Each <code>CachedRowSet</code> object's <code>SyncProvider</code> contains 0N/A * a <code>Connection</code> object from the <code>ResultSet</code> or JDBC 0N/A * properties passed to it's constructors. This method wraps the 0N/A * <code>Connection</code> commit method to allow flexible 0N/A * auto commit or non auto commit transactional control support. 0N/A * Makes all changes that are performed by the <code>acceptChanges()</code> 0N/A * be used only when auto-commit mode has been disabled. 0N/A * @throws SQLException if a database access error occurs or this 0N/A * Connection object within this <code>CachedRowSet</code> is in auto-commit mode 0N/A * @see java.sql.Connection#setAutoCommit 0N/A * Each <code>CachedRowSet</code> object's <code>SyncProvider</code> contains 0N/A * a <code>Connection</code> object from the original <code>ResultSet</code> 0N/A * or JDBC properties passed to it. 0N/A * Undoes all changes made in the current transaction. This method 0N/A * should be used only when auto-commit mode has been disabled. 0N/A * @throws SQLException if a database access error occurs or this Connection 0N/A * object within this <code>CachedRowSet</code> is in auto-commit mode. 0N/A * Each <code>CachedRowSet</code> object's <code>SyncProvider</code> contains 0N/A * a <code>Connection</code> object from the original <code>ResultSet</code> 0N/A * or JDBC properties passed to it. 0N/A * Undoes all changes made in the current transaction back to the last 0N/A * <code>Savepoint</code> transaction marker. This method should be used only 0N/A * when auto-commit mode has been disabled. 0N/A * @param s A <code>Savepoint</code> transaction marker 0N/A * @throws SQLException if a database access error occurs or this Connection 0N/A * object within this <code>CachedRowSet</code> is in auto-commit mode. 0N/A * Causes the <code>CachedRowSet</code> object's <code>SyncProvider</code> 0N/A * to commit the changes when <code>acceptChanges()</code> is called. If 0N/A * set to false, the changes will <b>not</b> be committed until one of the 0N/A * <code>CachedRowSet</code> interface transaction methods is called. 2740N/A * @deprecated Because this field is final (it is part of an interface), 2740N/A * its value cannot be changed. 0N/A * Notifies registered listeners that a RowSet object in the given RowSetEvent 0N/A * object has populated a number of additional rows. The <code>numRows</code> parameter 0N/A * ensures that this event will only be fired every <code>numRow</code>. 0N/A * The source of the event can be retrieved with the method event.getSource. 0N/A * @param event a <code>RowSetEvent</code> object that contains the 0N/A * <code>RowSet</code> object that is the source of the events 0N/A * @param numRows when populating, the number of rows interval on which the 0N/A * <code>CachedRowSet</code> populated should fire; the default value 0N/A * is zero; cannot be less than <code>fetchSize</code> or zero 0N/A * Populates this <code>CachedRowSet</code> object with data from 0N/A * the given <code>ResultSet</code> object. While related to the <code>populate(ResultSet)</code> 0N/A * method, an additional parameter is provided to allow starting position within 0N/A * the <code>ResultSet</code> from where to populate the CachedRowSet 0N/A * This method can be used as an alternative to the <code>execute</code> method when an 0N/A * application has a connection to an open <code>ResultSet</code> object. 0N/A * Using the method <code>populate</code> can be more efficient than using 0N/A * the version of the <code>execute</code> method that takes no parameters 0N/A * because it does not open a new connection and re-execute this 0N/A * <code>CachedRowSet</code> object's command. Using the <code>populate</code> 0N/A * method is more a matter of convenience when compared to using the version 0N/A * of <code>execute</code> that takes a <code>ResultSet</code> object. 0N/A * @param startRow the position in the <code>ResultSet</code> from where to start 0N/A * populating the records in this <code>CachedRowSet</code> 0N/A * @param rs the <code>ResultSet</code> object containing the data 2740N/A * to be read into this <code>CachedRowSet</code> object 0N/A * @throws SQLException if a null <code>ResultSet</code> object is supplied 2740N/A * or this <code>CachedRowSet</code> object cannot 2740N/A * retrieve the associated <code>ResultSetMetaData</code> object 0N/A * @see #populate(ResultSet) 0N/A * @see java.sql.ResultSet 0N/A * @see java.sql.ResultSetMetaData 0N/A * Sets the <code>CachedRowSet</code> object's page-size. A <code>CachedRowSet</code> 0N/A * may be configured to populate itself in page-size sized batches of rows. When 0N/A * either <code>populate()</code> or <code>execute()</code> are called, the 0N/A * <code>CachedRowSet</code> fetches an additional page according to the 0N/A * original SQL query used to populate the RowSet. 0N/A * @param size the page-size of the <code>CachedRowSet</code> 0N/A * @throws SQLException if an error occurs setting the <code>CachedRowSet</code> 0N/A * page size or if the page size is less than 0. 0N/A * Returns the page-size for the <code>CachedRowSet</code> object 0N/A * @return an <code>int</code> page size 0N/A * Increments the current page of the <code>CachedRowSet</code>. This causes 0N/A * the <code>CachedRowSet</code> implementation to fetch the next page-size 0N/A * rows and populate the RowSet, if remaining rows remain within scope of the 0N/A * original SQL query used to populated the RowSet. 0N/A * @return true if more pages exist; false if this is the last page 0N/A * @throws SQLException if an error occurs fetching the next page, or if this 0N/A * method is called prematurely before populate or execute. 0N/A * Decrements the current page of the <code>CachedRowSet</code>. This causes 0N/A * the <code>CachedRowSet</code> implementation to fetch the previous page-size 0N/A * rows and populate the RowSet. The amount of rows returned in the previous 0N/A * page must always remain within scope of the original SQL query used to 0N/A * populate the RowSet. 0N/A * @return true if the previous page is successfully retrieved; false if this 0N/A * is the first page. 0N/A * @throws SQLException if an error occurs fetching the previous page, or if 0N/A * this method is called prematurely before populate or execute.