Top Description Fields Constructors Methods
com.sun.rowset.internal

public Class CachedRowSetReader

extends Object
implements RowSetReader, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, javax.sql.RowSetReader
Imports
java.sql.*, javax.sql.*, javax.naming.*, java.io.*, java.lang.reflect.*, com.sun.rowset.*, javax.sql.rowset.*, javax.sql.rowset.spi.*

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.

Author
Jonathan Bruce
See Also
javax.sql.rowset.spi.SyncProvider, javax.sql.rowset.spi.SyncFactory, javax.sql.rowset.spi.SyncFactoryException

Field Summary

Modifier and TypeField and Description
private JdbcRowSetResourceBundle
pack-priv static final long
private int
private boolean
private int
writerCalls

The field that keeps track of whether the writer associated with this CachedRowSetReader object's rowset has been called since the rowset was populated.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Connection

Returns:

a Connection object that represents a connection to the caller's data source
connect
(RowSetInternal
a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader
caller
)

Establishes a connection with the data source for the given RowSet object.

private void
decodeParams(Object[]
an array of parameters to be used with the given PreparedStatement object
params
,
PreparedStatement
the PreparedStatement object that is the command for the calling rowset and into which the given parameters are to be set
pstmt
)

Sets the parameter placeholders in the rowset's command (the given PreparedStatement object) with the parameters in the given array.

protected boolean

Returns:

a boolean giving the status of whether the connection has been closed.
getCloseConnection
()

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

public void
readData(RowSetInternal
a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader
caller
)

Implements javax.sql.RowSetReader.readData.

Reads data from a data source and populates the given RowSet object with that data.
private void
public boolean

Returns:

true if writer associated with this reader needs to reset the values of its fields; false otherwise
reset
()

Checks to see if the writer associated with this reader needs to reset its state.

public void
setStartPosition(int
integer indicating the position in the ResultSet to begin populating from.
pos
)

This sets the start position in the ResultSet from where to begin.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resBundleback to summary
private JdbcRowSetResourceBundle resBundle
serialVersionUIDback to summary
pack-priv static final long serialVersionUID
startPositionback to summary
private int startPosition
userConback to summary
private boolean userCon
writerCallsback to summary
private int writerCalls

The field that keeps track of whether the writer associated with this CachedRowSetReader object's rowset has been called since the rowset was populated.

When this CachedRowSetReader object reads data into its rowset, it sets the field writerCalls to 0. When the writer associated with the rowset is called to write data back to the underlying data source, its writeData method calls the method CachedRowSetReader.reset, which increments writerCalls and returns true if writerCalls is 1. Thus, writerCalls equals 1 after the first call to writeData that occurs after the rowset has had data read into it.

Constructor Detail

CachedRowSetReaderback to summary
public CachedRowSetReader()

Method Detail

connectback to summary
public Connection connect(RowSetInternal caller) throws 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:RowSetInternal

a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader

Returns:Connection

a Connection object that represents a connection to the caller's data source

Exceptions
SQLException:
if an access error occurs
decodeParamsback to summary
private void decodeParams(Object[] params, PreparedStatement pstmt) throws SQLException

Sets the parameter placeholders in the rowset's command (the given PreparedStatement object) with the parameters in the given array. This method, called internally by the method CachedRowSetReader.readData, reads each parameter, and based on its type, determines the correct PreparedStatement.setXXX method to use for setting that parameter.

Parameters
params:Object[]

an array of parameters to be used with the given PreparedStatement object

pstmt:PreparedStatement

the PreparedStatement object that is the command for the calling rowset and into which the given parameters are to be set

Annotations
@SuppressWarnings:deprecation
Exceptions
SQLException:
if an access error occurs
getCloseConnectionback to summary
protected boolean getCloseConnection()

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

Returns:boolean

a boolean giving the status of whether the connection has been closed.

readDataback to summary
public void readData(RowSetInternal caller) throws SQLException

Implements javax.sql.RowSetReader.readData.

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.

Parameters
caller:RowSetInternal

a RowSet object that has implemented the RowSetInternal interface and had this CachedRowSetReader object set as its reader

Exceptions
SQLException:
if there is a database access error, there is a problem making the connection, or the command property has not been set
readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
resetback to summary
public boolean reset() throws 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:boolean

true if writer associated with this reader needs to reset the values of its fields; false otherwise

Exceptions
SQLException:
if an access error occurs
setStartPositionback to summary
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:int

integer indicating the position in the ResultSet to begin populating from.