Previous Next Contents Index


DBRowSet class

When you generate JSPs with Netscape Application Builder (NAB), the resulting JSPs use declarative tags, which support a result-set-oriented view of data rather than a bean-oriented view. To support standard RowSet objects in NAB-generated JSPs, NAS provides the DBRowSet class.

DBRowSet is a declarative-tag-aware extension to the NASRowSet class. Use the methods of DBRowSet in any JSP you have generated with NAB. NAB programmers can extend DBRowSet to display formatted, columnar data in a JSP.

DBRowSet can either load queries from a query file or use queries set up by the user. When results (and/or result sets) are requested, the Statement is executed to produce the requested values. After the data is exhausted, the isLast( ) method returns true and the next( ) method returns false.

DBRowSet replaces the DBDataSet and DBStoredProcedure classes from NAB 3.0.

Package
com.netscape.server.servlet.extension

Constructors
Syntax 1
Use this syntax for the null constructor:

public DBRowSet() throws SQLException
Syntax 2
Use the following constructor to allocate a new DBRowSet with a given name and the name of the file from which queries will be loaded.

public DBRowSet(
	HttpServletRequest request,
	HttpServletResponse response,
	String name,
	String filename) throws SQLException
Syntax 3
Use the following constructor to allocate a new DBRowSet with a given name, the name of the file from which queries will be loaded later, and the name of the connection against which this query will be executed.

public DBRowSet(
	HttpServletRequest request,
	HttpServletResponse response,
	String name,
	String filename,
	String connectionName) throws SQLException
Syntax 4
Use this constructor like the previous one, but specify a query name as well.

public DBRowSet(
	HttpServletRequest request,
	HttpServletResponse response,
	String name,
	String filename,
	String connectionName,
	String queryName) throws SQLException

request. The request object.

response. The response object.

name. The name of the RowSet.

filename . The name of the query file from which the queries will be loaded.

connectionName. The default name of the connection to use.

queryName. The name of the query to load from the query file.

SQLException. This exception will be thrown by all constructors whenever the initMetaInfo( ) method throws SQLException.

Methods
This section is divided into four parts:

Methods That Auto-Execute

The following methods override the corresponding NASRowSet method and execute the RowSet if and only if the RowSet is not already executing. For more information, see either the Netscape-specific NASRowSet class or the javax.sql.RowSet interface. In particular, see the RowSet execute( ) method or the DBRowSet isExecuted( ) method.

absolute( )
getBytes( )
getShort( )
afterLast( )
getCharacterStream( )
getString( ) — see note below
beforeFirst( )
getClob( )
getTime( )
first( )
getDate( )
getTimeStamp( )
getArray( )
getDouble( )
isLast( )
getAsciiStream( )
getFloat( )
last( )
getBigDecimal( )
getInputFormat( )
moveToCurrentRow( )
getBinaryStream( )
getInt( )
moveToInsertRow( )
getBlob( )
getLong( )
next( )
getBoolean( )
getObject( )
previous( )
getByte( )
getRef( )
relative( )

Note:
The String-parameter version of getString( ) attempts to resolve references to method invocations as well as references to the database columns.

Methods That Auto-Initialize

The following methods override the corresponding NASRowSet method and initialize the RowSet if and only if the RowSet is not already initialized. For more information, see the Netscape-specific NASRowSet class or the standard RowSet interface. In addition, see the DBRowSet methods init( ) and isInitialized( ).

Methods That Take a Name Instead of an Index

Queries created with NAB identify their parameters by name. But JDBC uses query parameters that are identified by an index.

DBRowSet therefore provides a group of "set" methods that have counterparts in the RowSet interface. The only difference is that the DBRowSet method expects a String (for the parameter name), where the corresponding RowSet method expects an integer (for the parameter index). This group of "set" methods is listed below:

setArray( )
setByte( )
setDouble( )
setObject( )
setAsciiStream( )
setBytes( )
setFloat( )
setRef( )
setBigDecimal( )
setCharacterStream( )
setInt( )
setShort( )
setBinaryStream( )
setClob( )
setLong( )
setString( )
setBlob( )
setCommand( )
setName( )
setTime( )
setBoolean( )
setDate( )
setNull( )
setTimestamp( )

In order for your servlets to set parameters on the RowSets, you must translate parameter names to parameter indexes. There are two ways to do this:

For more information about the previous set methods, see the corresponding methods in the standard javax.sql.RowSet interface.

Other Methods

The remaining DBRowSet methods are described here, with the DBRowSet class. These methods are summarized in the following table:

Method
Description
bindLoadValue( )
Sets a parameter to a particular String value, prior to loading the query.
clearParameters( )
Clears the list of parameters.
getFetchSize( )
Retrieves the value required by the FetchSize hidden field for NAB's "VCR" support.
getLoadParameter( )
Gets the parameter index for a particular parameter in the query.
getName( )
Gets the name for the RowSet.
getNextRowNumber( )
Retrieves one record number beyond the last one that has been printed out.
getQueryFile( )
Gets the name of the file that was used (or will be used) to load queries.
getQueryName( )
Gets the name of the query to be loaded from the query file.
getRowNumber( )
Retrieves the last record number that has been displayed.
getStaticMethodCache( )
Retrieves the method cache for a particular class.
getString( )
Overloads the getString(String) method to use a NASString instead.
init( )
Loads the query.
initMetaInfo( )
Initializes the RowSet to match specific metadata.
isEqualToExpression( )
Evaluates a field specification in an HTML template.
isEqualToValue( )
Evaluates a field specification in an HTML template.
isExecuted( )
Determines whether the RowSet is being executed.
isInitialized( )
Determines whether the RowSet is initialized.
isLastFetchableRecord( )
Returns null if the current record is the last fetchable record; otherwise, it returns the null string.
setExecuted( )
Sets whether the RowSet is being executed.
setInitialized( )
Sets whether the RowSet is initialized.
setName( )
Sets the name for the RowSet.
setQueryFile( )
Sets the name of the file that was used or will be used to load queries.
setQueryName( )
Resets the DBRowSet to access only the given query.
setRequest( )
Sets the request object in which the RowSet will run.
setResponse( )
Sets the response object in which the RowSet will run.

bindLoadValue( )
Sets a parameter to a particular String value, prior to loading the query.

Syntax
public int bindLoadValue(
	String destVariable,
	String value)

destVariable. The name of the variable to set.

value. The value to set for the variable.

Usage
Use the bindLoadValue( ) method to set parameters when a query is loaded—before the query is executed. In other words, call bindLoadValue( ) before init( ) is called.

Sometimes, it is better to set a parameter at load time rather than at run time. In particular, sometimes you need to replace a parameter to make a SQL statement conform to standard SQL syntax. For example, the following SQL code is nonstandard:

select * from emp

where :whereClause
If you set the whereClause parameter at load time, this SQL will comply with standard syntax because the parameter is substituted before the command is set on the RowSet.

Return Value
GXE.SUCCESS if the method succeeds.

clearParameters( )
Clears the list of parameters.

Syntax
public void clearParameters() throws SQLException
Usage
Use clearParameters( ) to clear the list of parameters that were set by the developer.

In general, it is unnecessary to call clearParameters( ) because (typically) you don't re-execute your RowSet.

This method overrides the clearParameters( ) method on the NASRowSet. The NASRowSet, in turn, implements the clearParameters( ) method in javax.sql.RowSet.

Note that clearParameters( ) does not set the RowSet to be uninitialized. As a result, all information that maps parameter names to parameter indexes is lost. To preserve the parameter mapping information, first call the setInitialized( ) method to set the RowSet to be uninitialized. Then call init( ) again to reload the query (and thus the parameter information).

getFetchSize( )
Retrieves the value required by the FetchSize hidden field for NAB's "VCR" support.

Syntax
public String getFetchSize(
	NASString max)

max. The maximum number to retrieve for the next iteration.

Usage
The FetchSize hidden field supports a "VCR-like" display of records in a window. This type of display is useful when you want to get the next or previous set of records from a query that returns many pages worth of records. For example, the window might contain buttons for displaying the next, previous, first, or last page of data.

Example
The getFetchSize( ) method is invoked from the template engine using a gx-callback such as the following:

%gx type=cell id=RowSet.getFetchSize(#max)%%/gx%
Return Value
A String representing the value required by FetchSize.

Related Topics
NASString class

getLoadParameter( )
Gets the parameter index for a particular parameter in the query.

Syntax
public int getLoadParameter(
	String paramName)

paramName. The name of the parameter whose index is to be retrieved.

Usage
Use this method when setting parameters. In NAB, parameters are stored by name, but standard RowSets use parameter indexes. The DBRowSet class provides a group of "set" methods that automatically call getLoadParameter( ) to retrieve the index. For more information, see the section "Methods That Take a Name Instead of an Index."

After you load the query to define the name-index pairs, you can explicitly call getLoadParameter( ) to retrieve the indices.

If the query is not already loaded (in other words, if the RowSet is not already initialized), then getLoadParameter( ) initializes the RowSet.

Return Value
An integer index associated with a paramater name.

getName( )
Gets the name for the RowSet.

Syntax
public String getName()
Usage
Use this method to get the name for the RowSet. This is the name that is used to store the RowSet into the attribute list of the Request object.

Related Topics
setName( )

getNextRowNumber( )
Retrieves one record number beyond the last one that has been printed out.

Syntax
public String getNextRowNumber(
	NASString unused)

unused. Not used.

Usage
This method is useful for populating hidden values for supporting VCR-style display (for example, buttons that display next or previous values).

Example
The getNextRowNumber( ) method is invoked from the template engine, using a gx-callback such as this:

%gx type=cell id=RowSet.getNextRowNumber()%%/gx%
Return Value
A String.

Related Topics
getRowNumber( )

getQueryFile( )
Gets the name of the file that was used (or will be used) to load queries.

Syntax
public String getQueryFile()
Usage
Use this method to get the file name that was previously set using setQueryFile( ) or set in the constructor.

Return Value
A String.

Related Topics
setQueryFile( ), getQueryName( )

getQueryName( )
Gets the name of the query to be loaded from the query file.

Syntax
public String getQueryName()
Usage
Use this method to get the name of the query to be loaded from the query file.

Return Value
A String.

Related Topics
setQueryName( ), getQueryFile( )

getRowNumber( )
Retrieves the last record number that has been displayed.

Syntax
public String getRowNumber(
	NASString groupName)

groupName. Not used.

Usage
This method is useful for populating table outputs with a row number for each row.

Example
The getRowNumber( ) method is invoked from the template engine, using a gx-callback such as this:

%gx type=cell id=RowSet.getRowNumber()%%/gx%
Return Value
A String.

Related Topics
getNextRowNumber( )

getStaticMethodCache( )
Retrieves the method cache for a particular class.

Syntax
public MethodHash getStaticMethodCache()
Usage
In order for RowSet subclasses to be efficiently garbage-collected, each RowSet subclass must override this method to return a different MethodHash. In this way, each class caches only the methods defined in this class or its superclasses without dangling references to the methods of other classes.

Return Value
A MethodHash object.

Related Topics
createMethodCache( ) in the BaseUtils class

getString( )
Overloads the getString(String) method to use a NASString instead.

Syntax
public String getString(
	NASString colName) throws SQLException

colName. The name of the column, as a NASString.

The javax.sql.RowSet interface has a getString( ) method that takes a String parameter. The getString(NASString) version intercepts the getString(String) version, allowing you to specify a NASString instead.

A SQLException is thrown, as is done in the getString(String) form of the method.

Return Value
A String.

Related Topics
javax.sql.RowSet interface

init( )
Loads the query.

Syntax
public void init()
Usage
The init( ) method is called implicitly during the execute( ) call.

Related Topics
execute( ), initMetaInfo( )

initMetaInfo( )
Initializes the RowSet to match specific metadata.

Syntax
public boolean initMetaInfo(
	OrderedHash metaData) throws SQLException

metaData. An OrderedHash of properties. The RowSet will be initialized with these properties.

Usage
The initMetaInfo( ) is used to initialize a RowSet. This method is called by BaseUtils.initRowSets( ) when the RowSet is created.

The metaData parameter specifies the properties stored in a method in the NTV list. The properties specify the query file name, the query name, the connection name, and the input bindings for the query parameters. In this way, the RowSet is initialized so as to match the properties stored in the NTV-list method.

If any subclasses have cached metadata that differs from this RowSet's metadata, then the subclasses should override the method in the NTV list.

Return Value
Returns false if the initialization fails for some reason.

isEqualToExpression( )
Evaluates a field specification in an HTML template.

Syntax
public String isEqualToExpression(
	NASString expression)

expression. The expression to evaluate.

Usage
This method is similar to isEqualToValue( ). Both methods are intended to be called from the template engine, with the expression containing one equal sign (=) and the lefthand value being a full field specification. In isEqualToValue( ) the righthand value is a constant, whereas in isEqualToExpression( ), the righthand value is another field specification.

The isEqualtoValue( ) method lets you write more standard if statements in an HTML template. The isEqualToExpression( ) method is useful for filling a popup list.

Example
The following code fragment creates a data set as a list:

MemRowSet ds = new MemRowSet();

ds.setRequest(request);
ds.setResponse(response);
ds.setName("myList");

ds.addListItem("Star Trek", "1");
ds.addListItem("Babylon 5", "2");
ds.addListItem("Red Dwarf", "3");
ds.addListItem("Crusade", "4");
ds.setListSelection("2"); // Babylon 5 is the default selection
request.setAttribute(ds.getName(), ds);
To display this list on a web page, you might create an HTML template containing the following code:

<SELECT NAME="TVShow">

%gx type=tile id=myList%
<OPTION VALUE="%gx type=cell id=myList.value% %/gx%"
%gx
type=cell
id=myList.isEqualToExpression(
myList.value=myList.ListSelection)%SELECTED
%/gx%
>

%gx type=cell id=myList.label%%/gx%
%/gx%
</SELECT>
Return Value
Returns null if the expression is true, or "" if the expression is false.

Related Topics
isEqualToValue( ),
MemRowSet class

isEqualToValue( )
Evaluates a field specification in an HTML template.

Syntax
public String isEqualToExpression(
	NASString expression)

expression. The expression to evaluate.

Usage
This method is similar to isEqualToExpression( ). Both methods are intended to be called from the template engine, with the expression containing one equal sign (=) and the lefthand value being a full field specification. In isEqualToValue( ) the righthand value is a constant, whereas in isEqualToExpression( ), the righthand value is another field specification.

The isEqualtoValue( ) method lets you write more standard if statements in an HTML template. The isEqualToExpression( ) method is useful for filling a popup list.

For example, you can use isEqualToValue( ) to determine whether a checkbox should be "CHECKED" or not.

Example
<gx type=cell id=isEqualToValue(DataSet.field_name=ALLMINE)>

HTML specific to ALLMINE
</gx>
Return Value
Returns null if the expression is true, or "" if the expression is false.

Related Topics
isEqualToExpression( )

isExecuted( )
Determines whether the RowSet is being executed.

Syntax
public boolean isExecuted()
Usage
Use isExecuted( ) to determine whether the RowSet is being executed.

Return Value
Returns true if the RowSet is being executed; otherwise, returns false.

Related Topics
setExecuted( )

isInitialized( )
Determines whether the RowSet is initialized.

Syntax
public boolean isInitialized()
Usage
Use isInitialized( ) to determine whether the RowSet is initialized.

Return Value
Returns true if the RowSet is initialized; otherwise, returns false.

Related Topics
setInitialized( ), init( ), initMetaInfo( )

isLastFetchableRecord( )
Returns null if the current record is the last fetchable record; otherwise, it returns the null string.

Syntax
public String isLastFetchableRecord(
	NASString unused)

unused. Not used. The default query name is always used.

Usage
This method lets you write JavaScript code that, for example, changes the name of the Next button to be Refresh. In this way, users don't get a blank row when they press the ">" (Next) button at the end of a record set.

Return Value
Returns null if the current record is the last fetchable record; otherwise, it returns the null string.

Example
This method is invoked from the template engine using a gx-callback such as the following:

<%gx type=cell id=RowSet.isLastFetchableRecord()%>

<SCRIPT>
datasetFetchCommandNext.name = "datasetFetchCommandRefresh"
</SCRIPT>
<%/gx%>
setExecuted( )
Sets whether the RowSet is being executed.

Syntax
public void setExecuted(
	boolean executed)

executed. The state indicating whether the RowSet is executing or not.

Usage
Use setExecuted( ) to specify the state of RowSet execution. Specify true to indicate that the RowSet is being executed, and specify false otherwise. You can also use isExecuted( ) to determine whether the RowSet is being executed.

Related Topics
isExecuted( )

setInitialized( )
Sets whether the RowSet is initialized.

Syntax
public void setInitialized(
	boolean initialized)

initialized. The state indicating whether the RowSet is initialized.

Usage
Use setInitialized( ) to specify the initialization state. Specify true to indicate that the RowSet is initialized, which means that the init( ) method has been called. Otherwise, specify false . You can also use isInitialized( ) to determine whether the RowSet is initialized.

Related Topics
isInitialized( ), init( ), initMetaInfo( )

setName( )
Sets the name for the RowSet.

Syntax
public void setName(
	String name)
Usage
Use this method to set the name for the RowSet. You can also set the name using the constructor.

Note that this method also sets the query name—to the same name. If you don't want this to happen, then call setQueryName( ) to reset the query name.

setQueryFile( )
Sets the name of the file that was used or will be used to load queries.

Syntax
public int setQueryFile(
	String filename)

filename. The name of the file that contains the queries for this RowSet.

Usage
Use setQueryFile( ) to specify the file for loading queries. You can use getQueryFile( ) to retrieve the file name.

Rule
setQueryFile( ) must be called on an uninitialized RowSet.

Return Value
-1 if called on an initialized RowSet.

Related Topics
getQueryFile( ), setQueryName( )

setQueryName( )
Resets the DBRowSet to access only the given query.

Syntax
public int setQueryName(
	String query)

query. The name of the query that the DBRowSet should load.

Usage
Use setQueryName( ) to reset the DBRowSet to access the specified query. Call setQueryName( ) before executing the DBRowSet.

Return Value
-1 if called on an executed DBRowSet.

Related Topics
getQueryName( ), setQueryFile( )

setRequest( )
Sets the request object in which the RowSet will run.

Syntax
public void setRequest(
	HttpServletRequest request)

request. The HttpServletRequest object.

Usage
This method is called during construction. The HttpServletRequest is useful when implementing isEqualToExpression( ), where other RowSets may be required.

setResponse( )
Sets the response object in which the RowSet will run.

Syntax
public void setResponse(
	HttpServletResponse response)

response. The HttpServletResponse object.

Usage
Use setResponse( ) to set the response object in which the RowSet will run.

 

© Copyright 1999 Netscape Communications Corp.