com.sun.rowset.internal
Class CachedRowSetReader

java.lang.Object
  extended bycom.sun.rowset.internal.CachedRowSetReader
All Implemented Interfaces:
javax.sql.RowSetReader, java.io.Serializable

public class CachedRowSetReader
extends java.lang.Object
implements javax.sql.RowSetReader, java.io.Serializable

The facility called by the RIOptimisticProvider object internally to read data into it. The calling RowSet object must have implemented the RowSetInternal interface and have the standard CachedRowSetReader object set as its reader.

This implementation always reads all rows of the data source, and it assumes that the command property for the caller is set with a query that is appropriate for execution by a PreparedStatement object.

Typically the SyncFactory manages the RowSetReader and the RowSetWriter implementations using SyncProvider objects. Standard JDBC RowSet implementations provide an object instance of this reader by invoking the SyncProvider.getRowSetReader() method.

Version:
0.2
Author:
Jonathan Bruce
See Also:
SyncProvider, SyncFactory, SyncFactoryException, Serialized Form

Constructor Summary
CachedRowSetReader()
           
 
Method Summary
 java.sql.Connection connect(javax.sql.RowSetInternal caller)
          Establishes a connection with the data source for the given RowSet object.
protected  boolean getCloseConnection()
          Assists in determining whether the current connection was created by this CachedRowSet to ensure incorrect connections are not prematurely terminated.
 void readData(javax.sql.RowSetInternal caller)
          Reads data from a data source and populates the given RowSet object with that data.
 boolean reset()
          Checks to see if the writer associated with this reader needs to reset its state.
 void setStartPosition(int pos)
          This sets the start position in the ResultSet from where to begin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedRowSetReader

public CachedRowSetReader()
Method Detail

readData

public void readData(javax.sql.RowSetInternal caller)
              throws java.sql.SQLException
Reads data from a data source and populates the given RowSet object with that data. This method is called by the rowset internally when the application invokes the method execute to read a new set of rows.

After clearing the rowset of its contents, if any, and setting the number of writer calls to 0, this reader calls its connect method to make a connection to the rowset's data source. Depending on which of the rowset's properties have been set, the connect method will use a DataSource object or the DriverManager facility to make a connection to the data source.

Once the connection to the data source is made, this reader executes the query in the calling CachedRowSet object's command property. Then it calls the rowset's populate method, which reads data from the ResultSet object produced by executing the rowset's command. The rowset is then populated with this data.

This method's final act is to close the connection it made, thus leaving the rowset disconnected from its data source.

Specified by:
readData in interface javax.sql.RowSetReader
Parameters:
caller - a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader
Throws:
java.sql.SQLException - if there is a database access error, there is a problem making the connection, or the command property has not been set

reset

public boolean reset()
              throws java.sql.SQLException
Checks to see if the writer associated with this reader needs to reset its state. The writer will need to initialize its state if new contents have been read since the writer was last called. This method is called by the writer that was registered with this reader when components were being wired together.

Returns:
true if writer associated with this reader needs to reset the values of its fields; false otherwise
Throws:
java.sql.SQLException - if an access error occurs

connect

public java.sql.Connection connect(javax.sql.RowSetInternal caller)
                            throws java.sql.SQLException
Establishes a connection with the data source for the given RowSet object. If the rowset's dataSourceName property has been set, this method uses the JNDI API to retrieve the DataSource object that it can use to make the connection. If the url, username, and password properties have been set, this method uses the DriverManager.getConnection method to make the connection.

This method is used internally by the reader and writer associated with the calling RowSet object; an application never calls it directly.

Parameters:
caller - a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader
Returns:
a Connection object that represents a connection to the caller's data source
Throws:
java.sql.SQLException - if an access error occurs

getCloseConnection

protected boolean getCloseConnection()
Assists in determining whether the current connection was created by this CachedRowSet to ensure incorrect connections are not prematurely terminated.


setStartPosition

public void setStartPosition(int pos)
This sets the start position in the ResultSet from where to begin. This is called by the Reader in the CachedRowSetImpl to set the position on the page to begin populating from.

Parameters:
pos - integer indicating the position in the ResultSet to begin populating from.