BaseRowSet (Java SE 15 & JDK 15) (original) (raw)

All Implemented Interfaces:

[Serializable](../../../../java.base/java/io/Serializable.html "interface in java.io"), [Cloneable](../../../../java.base/java/lang/Cloneable.html "interface in java.lang")


public abstract class BaseRowSet extends Object implements Serializable, Cloneable

An abstract class providing a RowSet object with its basic functionality. The basic functions include having properties and sending event notifications, which all JavaBeans components must implement.

1.0 Overview

The BaseRowSet class provides the core functionality for all RowSet implementations, and all standard implementations may use this class in combination with one or more RowSet interfaces in order to provide a standard vendor-specific implementation. To clarify, all implementations must implement at least one of the RowSet interfaces (JdbcRowSet,CachedRowSet, JoinRowSet, FilteredRowSet, or WebRowSet). This means that any implementation that extends the BaseRowSet class must also implement one of the RowSet interfaces.

The BaseRowSet class provides the following:

2.0 Setting Properties

All rowsets maintain a set of properties, which will usually be set using a tool. The number and kinds of properties a rowset has will vary, depending on what the RowSet implementation does and how it gets its data. For example, rowsets that get their data from a ResultSet object need to set the properties that are required for making a database connection. If a RowSet object uses the DriverManager facility to make a connection, it needs to set a property for the JDBC URL that identifies the appropriate driver, and it needs to set the properties that give the user name and password. If, on the other hand, the rowset uses a DataSource object to make the connection, which is the preferred method, it does not need to set the property for the JDBC URL. Instead, it needs to set the property for the logical name of the data source along with the properties for the user name and password.

NOTE: In order to use a DataSource object for making a connection, the DataSource object must have been registered with a naming service that uses the Java Naming and Directory Interface (JNDI) API. This registration is usually done by a person acting in the capacity of a system administrator.

3.0 Setting the Command and Its Parameters

When a rowset gets its data from a relational database, it executes a command (a query) that produces a ResultSet object. This query is the command that is set for the RowSet object's command property. The rowset populates itself with data by reading the data from the ResultSet object into itself. If the query contains placeholders for values to be set, the BaseRowSet setter methods are used to set these values. All setter methods allow these values to be set to null if required.

The following code fragment illustrates how theCachedRowSet object crs might have its command property set. Note that if a tool is used to set properties, this is the code that the tool would use.


    crs.setCommand("SELECT FIRST_NAME, LAST_NAME, ADDRESS FROM CUSTOMERS" +
                   "WHERE CREDIT_LIMIT > ? AND REGION = ?");
 

In this example, the values for CREDIT_LIMIT andREGION are placeholder parameters, which are indicated with a question mark (?). The first question mark is placeholder parameter number1, the second question mark is placeholder parameter number2, and so on. Any placeholder parameters must be set with values before the query can be executed. To set these placeholder parameters, the BaseRowSet class provides a set of setter methods, similar to those provided by the PreparedStatement interface, for setting values of each data type. A RowSet object stores the parameter values internally, and its execute method uses them internally to set values for the placeholder parameters before it sends the command to the DBMS to be executed.

The following code fragment demonstrates setting the two parameters in the query from the previous example.


    crs.setInt(1, 5000);
    crs.setString(2, "West");
 

If the execute method is called at this point, the query sent to the DBMS will be:


    "SELECT FIRST_NAME, LAST_NAME, ADDRESS FROM CUSTOMERS" +
                   "WHERE CREDIT_LIMIT > 5000 AND REGION = 'West'"
 

NOTE: Setting Array, Clob, Blob andRef objects as a command parameter, stores these values asSerialArray, SerialClob, SerialBlob and SerialRef objects respectively.

4.0 Handling of Parameters Behind the Scenes

NOTE: The BaseRowSet class provides two kinds of setter methods, those that set properties and those that set placeholder parameters. The setter methods discussed in this section are those that set placeholder parameters.

The placeholder parameters set with the BaseRowSet setter methods are stored as objects in an internal Hashtable object. Primitives are stored as their Object type. For example, byte is stored as Byte object, and int is stored as an Integer object. When the method execute is called, the values in theHashtable object are substituted for the appropriate placeholder parameters in the command.

A call to the method getParams returns the values stored in theHashtable object as an array of Object instances. An element in this array may be a simple Object instance or an array (which is a type of Object). The particular setter method used determines whether an element in this array is an Object or an array.

The majority of methods for setting placeholder parameters take two parameters, with the first parameter indicating which placeholder parameter is to be set, and the second parameter giving the value to be set. Methods such as setInt,setString, setBoolean, and setLong fall into this category. After these methods have been called, a call to the methodgetParams will return an array with the values that have been set. Each element in the array is an Object instance representing the values that have been set. The order of these values in the array is determined by theint (the first parameter) passed to the setter method. The values in the array are the values (the second parameter) passed to the setter method. In other words, the first element in the array is the value to be set for the first placeholder parameter in the RowSet object's command. The second element is the value to be set for the second placeholder parameter, and so on.

Several setter methods send the driver and DBMS information beyond the value to be set. When the method getParams is called after one of these setter methods has been used, the elements in the array will themselves be arrays to accommodate the additional information. In this category, the method setNull is a special case because one version takes only two parameters (setNull(int parameterIndex, int SqlType)). Nevertheless, it requires an array to contain the information that will be passed to the driver and DBMS. The first element in this array is the value to be set, which is null, and the second element is the int supplied for sqlType, which indicates the type of SQL value that is being set to null. This information is needed by some DBMSs and is therefore required in order to ensure that applications are portable. The other version is intended to be used when the value to be set to null is a user-defined type. It takes three parameters (setNull(int parameterIndex, int sqlType, String typeName)) and also requires an array to contain the information to be passed to the driver and DBMS. The first two elements in this array are the same as for the first version ofsetNull. The third element, typeName, gives the SQL name of the user-defined type. As is true with the other setter methods, the number of the placeholder parameter to be set is indicated by an element's position in the array returned by getParams. So, for example, if the parameter supplied to setNull is 2, the second element in the array returned by getParams will be an array of two or three elements.

Some methods, such as setObject and setDate have versions that take more than two parameters, with the extra parameters giving information to the driver or the DBMS. For example, the methods setDate,setTime, and setTimestamp can take a Calendar object as their third parameter. If the DBMS does not store time zone information, the driver uses the Calendar object to construct the Date,Time, or Timestamp object being set. As is true with other methods that provide additional information, the element in the array returned by getParams is an array instead of a simple Object instance.

The methods setAsciiStream, setBinaryStream,setCharacterStream, and setUnicodeStream (which is deprecated, so applications should use getCharacterStream instead) take three parameters, so for them, the element in the array returned bygetParams is also an array. What is different about these setter methods is that in addition to the information provided by parameters, the array contains one of the BaseRowSet constants indicating the type of stream being set.

NOTE: The method getParams is called internally byRowSet implementations extending this class; it is not normally called by an application programmer directly.

5.0 Event Notification

The BaseRowSet class provides the event notification mechanism for rowsets. It contains the fieldlisteners, methods for adding and removing listeners, and methods for notifying listeners of changes.

A listener is an object that has implemented the RowSetListener interface. If it has been added to a RowSet object's list of listeners, it will be notified when an event occurs on that RowSet object. Each listener's implementation of the RowSetListener methods defines what that object will do when it is notified that an event has occurred.

There are three possible events for a RowSet object:

  1. the cursor moves
  2. an individual row is changed (updated, deleted, or inserted)
  3. the contents of the entire RowSet object are changed

The BaseRowSet method used for the notification indicates the type of event that has occurred. For example, the methodnotifyRowChanged indicates that a row has been updated, deleted, or inserted. Each of the notification methods creates aRowSetEvent object, which is supplied to the listener in order to identify the RowSet object on which the event occurred. What the listener does with this information, which may be nothing, depends on how it was implemented.

6.0 Default Behavior

A default BaseRowSet object is initialized with many starting values. The following is true of a default RowSet instance that extends the BaseRowSet class:

If other values are desired, an application must set the property values explicitly. For example, the following line of code sets the maximum number of rows for the CachedRowSet object crs to 500.

crs.setMaxRows(500);

Methods implemented in extensions of this BaseRowSet class must throw anSQLException object for any violation of the defined assertions. Also, if the extending class overrides and reimplements any BaseRowSet method and encounters connectivity or underlying data source issues, that method may in addition throw anSQLException object for that reason.

Since:

1.5

See Also:

Serialized Form

Fields

Modifier and Type Field Description
static int ASCII_STREAM_PARAM A constant indicating to a RowSetReaderImpl object that a given parameter is an ASCII stream.
protected InputStream asciiStream The InputStream object that will be returned by the method getAsciiStream, which is specified in the ResultSet interface.
static int BINARY_STREAM_PARAM A constant indicating to a RowSetReaderImpl object that a given parameter is a binary stream.
protected InputStream binaryStream The InputStream object that will be returned by the method getBinaryStream, which is specified in the ResultSet interface.
protected Reader charStream The Reader object that will be returned by the method getCharacterStream, which is specified in the ResultSet interface.
static int UNICODE_STREAM_PARAM A constant indicating to a RowSetReaderImpl object that a given parameter is a Unicode stream.
protected InputStream unicodeStream The InputStream object that will be returned by the method getUnicodeStream, which is specified in the ResultSet interface.

Constructors

Constructor Description
BaseRowSet() Constructs a new BaseRowSet object initialized with a default Vector object for its listeners field.
Modifier and Type Method Description
void addRowSetListener​(RowSetListener listener) The listener will be notified whenever an event occurs on this RowSet object.
void clearParameters() Clears all of the current parameter values in this RowSet object's internal representation of the parameters to be set in this RowSet object's command when it is executed.
String getCommand() Retrieves the SQL query that is the command for thisRowSet object.
int getConcurrency() Returns the concurrency for this RowSet object.
String getDataSourceName() Returns the logical name that when supplied to a naming service that uses the Java Naming and Directory Interface (JNDI) API, will retrieve a javax.sql.DataSource object.
boolean getEscapeProcessing() Ascertains whether escape processing is enabled for thisRowSet object.
int getFetchDirection() Retrieves this RowSet object's current setting for the fetch direction.
int getFetchSize() Returns the fetch size for this RowSet object.
int getMaxFieldSize() Retrieves the maximum number of bytes that can be used for a column value in this RowSet object.
int getMaxRows() Retrieves the maximum number of rows that this RowSet object may contain.
Object[] getParams() Retrieves an array containing the parameter values (both Objects and primitives) that have been set for thisRowSet object's command and throws an SQLException object if all parameters have not been set.
String getPassword() Returns the password used to create a database connection for thisRowSet object.
int getQueryTimeout() Retrieves the maximum number of seconds the driver will wait for a query to execute.
boolean getShowDeleted() Retrieves a boolean indicating whether rows marked for deletion appear in the set of current rows.
int getTransactionIsolation() Returns the transaction isolation property for thisRowSet object's connection.
int getType() Returns the type of this RowSet object.
Map<String,​Class<?>> getTypeMap() Retrieves the type map associated with the Connection object for this RowSet object.
String getUrl() Retrieves the JDBC URL that this RowSet object'sjavax.sql.Reader object uses to make a connection with a relational database using a JDBC technology-enabled driver.
String getUsername() Returns the user name used to create a database connection.
protected void initParams() Performs the necessary internal configurations and initializations to allow any JDBC RowSet implementation to start using the standard facilities provided by a BaseRowSet instance.
boolean isReadOnly() Returns a boolean indicating whether thisRowSet object is read-only.
protected void notifyCursorMoved() Notifies all of the listeners registered with thisRowSet object that its cursor has moved.
protected void notifyRowChanged() Notifies all of the listeners registered with this RowSet object that one of its rows has changed.
protected void notifyRowSetChanged() Notifies all of the listeners registered with this RowSet object that its entire contents have changed.
void removeRowSetListener​(RowSetListener listener) Removes the designated object from this RowSet object's list of listeners.
void setArray​(int parameterIndex,Array array) Sets the designated parameter to an Array object in the Java programming language.
void setAsciiStream​(int parameterIndex,InputStream x) Sets the designated parameter in this RowSet object's command to the given input stream.
void setAsciiStream​(int parameterIndex,InputStream x, int length) Sets the designated parameter to the givenjava.io.InputStream object, which will have the specified number of bytes.
void setAsciiStream​(String parameterName,InputStream x) Sets the designated parameter to the given input stream.
void setAsciiStream​(String parameterName,InputStream x, int length) Sets the designated parameter to the given input stream, which will have the specified number of bytes.
void setBigDecimal​(int parameterIndex,BigDecimal x) Sets the designated parameter to the givenjava.lang.BigDecimal value.
void setBigDecimal​(String parameterName,BigDecimal x) Sets the designated parameter to the givenjava.math.BigDecimal value.
void setBinaryStream​(int parameterIndex,InputStream x) Sets the designated parameter in this RowSet object's command to the given input stream.
void setBinaryStream​(int parameterIndex,InputStream x, int length) Sets the designated parameter to the given java.io.InputStream object, which will have the specified number of bytes.
void setBinaryStream​(String parameterName,InputStream x) Sets the designated parameter to the given input stream.
void setBinaryStream​(String parameterName,InputStream x, int length) Sets the designated parameter to the given input stream, which will have the specified number of bytes.
void setBlob​(int parameterIndex,InputStream inputStream) Sets the designated parameter to a InputStream object.
void setBlob​(int parameterIndex,InputStream inputStream, long length) Sets the designated parameter to a InputStream object.
void setBlob​(int parameterIndex,Blob x) Sets the designated parameter to the given Blob object in the Java programming language.
void setBlob​(String parameterName,InputStream inputStream) Sets the designated parameter to a InputStream object.
void setBlob​(String parameterName,InputStream inputStream, long length) Sets the designated parameter to a InputStream object.
void setBlob​(String parameterName,Blob x) Sets the designated parameter to the given java.sql.Blob object.
void setBoolean​(int parameterIndex, boolean x) Sets the designated parameter to the given boolean in the Java programming language.
void setBoolean​(String parameterName, boolean x) Sets the designated parameter to the given Java boolean value.
void setByte​(int parameterIndex, byte x) Sets the designated parameter to the given byte in the Java programming language.
void setByte​(String parameterName, byte x) Sets the designated parameter to the given Java byte value.
void setBytes​(int parameterIndex, byte[] x) Sets the designated parameter to the given array of bytes.
void setBytes​(String parameterName, byte[] x) Sets the designated parameter to the given Java array of bytes.
void setCharacterStream​(int parameterIndex,Reader reader) Sets the designated parameter in this RowSet object's command to the given Reader object.
void setCharacterStream​(int parameterIndex,Reader reader, int length) Sets the designated parameter to the given java.io.Reader object, which will have the specified number of characters.
void setCharacterStream​(String parameterName,Reader reader) Sets the designated parameter to the given Reader object.
void setCharacterStream​(String parameterName,Reader reader, int length) Sets the designated parameter to the given Reader object, which is the given number of characters long.
void setClob​(int parameterIndex,Reader reader) Sets the designated parameter to a Reader object.
void setClob​(int parameterIndex,Reader reader, long length) Sets the designated parameter to a Reader object.
void setClob​(int parameterIndex,Clob x) Sets the designated parameter to the given Clob object in the Java programming language.
void setClob​(String parameterName,Reader reader) Sets the designated parameter to a Reader object.
void setClob​(String parameterName,Reader reader, long length) Sets the designated parameter to a Reader object.
void setClob​(String parameterName,Clob x) Sets the designated parameter to the given java.sql.Clob object.
void setCommand​(String cmd) Sets this RowSet object's command property to the given String object and clears the parameters, if any, that were set for the previous command.
void setConcurrency​(int concurrency) Sets the concurrency for this RowSet object to the specified concurrency.
void setDataSourceName​(String name) Sets the DataSource name property for this RowSet object to the given logical name and sets this RowSet object's Url property to null.
void setDate​(int parameterIndex,Date x) Sets the designated parameter to the given java.sql.Date value.
void setDate​(int parameterIndex,Date x,Calendar cal) Sets the designated parameter to the given java.sql.Date object.
void setDate​(String parameterName,Date x) Sets the designated parameter to the given java.sql.Date value using the default time zone of the virtual machine that is running the application.
void setDate​(String parameterName,Date x,Calendar cal) Sets the designated parameter to the given java.sql.Date value, using the given Calendar object.
void setDouble​(int parameterIndex, double x) Sets the designated parameter to the given double in the Java programming language.
void setDouble​(String parameterName, double x) Sets the designated parameter to the given Java double value.
void setEscapeProcessing​(boolean enable) Sets to the given boolean whether or not the driver will scan for escape syntax and do escape substitution before sending SQL statements to the database.
void setFetchDirection​(int direction) Gives the driver a performance hint as to the direction in which the rows in this RowSet object will be processed.
void setFetchSize​(int rows) Sets the fetch size for this RowSet object to the given number of rows.
void setFloat​(int parameterIndex, float x) Sets the designated parameter to the given float in the Java programming language.
void setFloat​(String parameterName, float x) Sets the designated parameter to the given Java float value.
void setInt​(int parameterIndex, int x) Sets the designated parameter to an int in the Java programming language.
void setInt​(String parameterName, int x) Sets the designated parameter to the given Java int value.
void setLong​(int parameterIndex, long x) Sets the designated parameter to the given long in the Java programming language.
void setLong​(String parameterName, long x) Sets the designated parameter to the given Java long value.
void setMaxFieldSize​(int max) Sets the maximum number of bytes that can be used for a column value in this RowSet object to the given number.
void setMaxRows​(int max) Sets the maximum number of rows that this RowSet object may contain to the given number.
void setNCharacterStream​(int parameterIndex,Reader value) Sets the designated parameter in this RowSet object's command to a Reader object.
void setNCharacterStream​(int parameterIndex,Reader value, long length) Sets the designated parameter to a Reader object.
void setNCharacterStream​(String parameterName,Reader value) Sets the designated parameter to a Reader object.
void setNCharacterStream​(String parameterName,Reader value, long length) Sets the designated parameter to a Reader object.
void setNClob​(int parameterIndex,Reader reader) Sets the designated parameter to a Reader object.
void setNClob​(int parameterIndex,Reader reader, long length) Sets the designated parameter to a Reader object.
void setNClob​(int parameterIndex,NClob value) Sets the designated parameter to a java.sql.NClob object.
void setNClob​(String parameterName,Reader reader) Sets the designated parameter to a Reader object.
void setNClob​(String parameterName,Reader reader, long length) Sets the designated parameter to a Reader object.
void setNClob​(String parameterName,NClob value) Sets the designated parameter to a java.sql.NClob object.
void setNString​(int parameterIndex,String value) Sets the designated parameter to the given String object.
void setNString​(String parameterName,String value) Sets the designated parameter to the given String object.
void setNull​(int parameterIndex, int sqlType) Sets the designated parameter to SQL NULL.
void setNull​(int parameterIndex, int sqlType,String typeName) Sets the designated parameter to SQL NULL.
void setNull​(String parameterName, int sqlType) Sets the designated parameter to SQL NULL.
void setNull​(String parameterName, int sqlType,String typeName) Sets the designated parameter to SQL NULL.
void setObject​(int parameterIndex,Object x) Sets the designated parameter to an Object in the Java programming language.
void setObject​(int parameterIndex,Object x, int targetSqlType) Sets the value of the designated parameter with the givenObject value.
void setObject​(int parameterIndex,Object x, int targetSqlType, int scale) Sets the designated parameter to an Object in the Java programming language.
void setObject​(String parameterName,Object x) Sets the value of the designated parameter with the given object.
void setObject​(String parameterName,Object x, int targetSqlType) Sets the value of the designated parameter with the given object.
void setObject​(String parameterName,Object x, int targetSqlType, int scale) Sets the value of the designated parameter with the given object.
void setPassword​(String pass) Sets the password used to create a database connection for thisRowSet object to the given String object.
void setQueryTimeout​(int seconds) Sets to the given number the maximum number of seconds the driver will wait for a query to execute.
void setReadOnly​(boolean value) Sets this RowSet object's readOnly property to the given boolean.
void setRef​(int parameterIndex,Ref ref) Sets the designated parameter to the given Ref object in the Java programming language.
void setRowId​(int parameterIndex,RowId x) Sets the designated parameter to the given java.sql.RowId object.
void setRowId​(String parameterName,RowId x) Sets the designated parameter to the given java.sql.RowId object.
void setShort​(int parameterIndex, short x) Sets the designated parameter to the given short in the Java programming language.
void setShort​(String parameterName, short x) Sets the designated parameter to the given Java short value.
void setShowDeleted​(boolean value) Sets the property showDeleted to the givenboolean value, which determines whether rows marked for deletion appear in the set of current rows.
void setSQLXML​(int parameterIndex,SQLXML xmlObject) Sets the designated parameter to the given java.sql.SQLXML object.
void setSQLXML​(String parameterName,SQLXML xmlObject) Sets the designated parameter to the given java.sql.SQLXML object.
void setString​(int parameterIndex,String x) Sets the designated parameter to the given String value.
void setString​(String parameterName,String x) Sets the designated parameter to the given Java String value.
void setTime​(int parameterIndex,Time x) Sets the designated parameter to the given java.sql.Time value.
void setTime​(int parameterIndex,Time x,Calendar cal) Sets the designated parameter to the given java.sql.Time object.
void setTime​(String parameterName,Time x) Sets the designated parameter to the given java.sql.Time value.
void setTime​(String parameterName,Time x,Calendar cal) Sets the designated parameter to the given java.sql.Time value, using the given Calendar object.
void setTimestamp​(int parameterIndex,Timestamp x) Sets the designated parameter to the givenjava.sql.Timestamp value.
void setTimestamp​(int parameterIndex,Timestamp x,Calendar cal) Sets the designated parameter to the givenjava.sql.Timestamp object.
void setTimestamp​(String parameterName,Timestamp x) Sets the designated parameter to the given java.sql.Timestamp value.
void setTimestamp​(String parameterName,Timestamp x,Calendar cal) Sets the designated parameter to the given java.sql.Timestamp value, using the given Calendar object.
void setTransactionIsolation​(int level) Sets the transaction isolation property for this JDBC RowSet object to the given constant.
void setType​(int type) Sets the type for this RowSet object to the specified type.
void setTypeMap​(Map<String,​Class<?>> map) Installs the given java.util.Map object as the type map associated with the Connection object for thisRowSet object.
void setUnicodeStream​(int parameterIndex,InputStream x, int length) Deprecated.
void setUrl​(String url) Sets the Url property for this RowSet object to the given String object and sets the dataSource name property to null.
void setURL​(int parameterIndex,URL x) Sets the designated parameter to the given java.net.URL value.
void setUsername​(String name) Sets the username property for this RowSet object to the given user name.

Methods declared in class java.lang.Object

[clone](../../../../java.base/java/lang/Object.html#clone%28%29), [equals](../../../../java.base/java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../../java.base/java/lang/Object.html#finalize%28%29), [getClass](../../../../java.base/java/lang/Object.html#getClass%28%29), [hashCode](../../../../java.base/java/lang/Object.html#hashCode%28%29), [notify](../../../../java.base/java/lang/Object.html#notify%28%29), [notifyAll](../../../../java.base/java/lang/Object.html#notifyAll%28%29), [toString](../../../../java.base/java/lang/Object.html#toString%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long%29), [wait](../../../../java.base/java/lang/Object.html#wait%28long,int%29)