Previous Next Contents Index


MemRowSet class

MemRowSet is a subclass of DBRowSet that implements the IListRowSet interface. MemRowSet provides hooks to the in-memory TemplateDataBasic class of NAS. Specifically, MemRowSet wraps the TemplateDataBasic class, adding support for callback methods. For example, a tag such as the following:

<gx type=cell id=Jack.callMe(Boisenberry)>
would call the method callMe( ) on the rowset named Jack.

Although anyone developing a NAS application can use MemRowSet, this class is typically used in components generated by Netscape Application Builder.

MemRowSet replaces the DataSet class from NAB 3.0.

Package
com.netscape.server.servlet.extension

Constructor
The MemRowSet class has two constructors. The first one, the null constructor, is required:

public MemRowSet() throws SQLException
The second one is a convenience constructor:

public MemRowSet(
	HttpServletRequest request,
	HttpServletResponse response,
	String name,
	ITemplateData dataSource) throws SQLException
In addition to the request and response objects, the dataSource parameter is the ITemplateData object to use to store data. The name parameter is the MemRowSet name and must correspond with the dataSource's groupName.

Both constructors throw SQLException if it occurs.

Methods
MemRowSet has dozens of methods. Most of them override a corresponding method from one of the following sources:

The MemRowSet methods are overridden to prevent undesirable behavior. In most cases, a developer should not call the overridden methods, because calling them has no meaning. You might unintentionally call one of these methods on a RowSet object if the RowSet is implemented by MemRowSet, which does not represent a query.

The methods of MemRowSet are listed in the following table. For methods that override a correspondingly named method, only a summary is provided. For new methods of MemRowSet, additional description is also provided after the table. New methods are marked in boldface type.

Method
New Behavior of Overridden Method
absolute( )
See separate description below table.
addListItem( )
New method. Adds a new item into a MemRowSet that is being used as an IListRowSet. See separate description below table.
addRow( )
New method. Adds data as a separate row into the data source. See separate description below table.
addValue( )
New method. Queues a value for later addition into the data source. See separate description below table.
afterLast( )
Can never be called. Always throws SQLException.
beforeFirst( )
Can never be called. Always throws SQLException.
cancelRowUpdates( )
Does nothing.
clearWarnings( )
Does nothing.
close( )
Removes the reference to the ITemplateData object.
deleteRow( )
Can never be called. Always throws SQLException.
execute( )
Sets MemRowSet to the "executing" status.
findColumn( )
Returns -1. Columns are not indexed for MemRowSets.
first( )
Can never be called. Always throws SQLException.
getArray( )
Returns null.
getAsciiStream( )
Returns null.
getBigDecimal( )
Returns null.
getBinaryStream( )
Returns null.
getBlob( )
Returns null.
getBoolean( )
Returns false.
getByte( )
Returns -1.
getBytes( )
Returns null.
getCharacterStream( )
Returns null.
getClob( )
Returns null.
getCommand( )
Returns null.
getConcurrency( )
Returns -1.
getCursorName( )
Returns null.
getDate( )
Returns null.
getDouble( )
Returns -1.
getFetchDirection( )
Returns -1.
getFetchSize( )
Rreturns -1.
getFloat( )
Returns -1.
getInt( )
Returns -1.
getListSelection( )
New method. Gets the list selection of the MemRowSet that is being used as an IListRowSet. See separate description below table.
getLoadParameter( )
Returns 0.
getLong( )
Returns -1.
getMetaData( )
Returns a class that can use ITemplateData objects.
getObject( )
With a String parameter, returns the value returned by getString( ); with an int parameter, returns null.
getQueryName( )
Returns null.
getRef( )
Returns null.
getRow( )
Returns the row number whose contents can currently be examined.
getShort( )
Returns -1.
getStatement( )
Returns null.
getStaticMethodCache( )
Retrieves the method cache for a particular class.
getString( )
With a String parameter, returns the value returned by its superclass; this form is not overridden. With an int parameter, returns null.
getString( )
With a NASString parameter, either returns the list selection or redirects to the underlying ITemplateData data source.
getTemplateData( )
New method. Gets the data source of the RowSet. See separate description below table.
getTime( )
Returns null.
getTimeStamp( )
Returns null.
getType( )
Returns -1.
getUnicodeStream( )
Returns null.
insertRow( )
Can never be called. Always throws SQLException.
isAfterLast( )
Delegates to the ITemplateData data source. If the RowSet hasn't been accessed, this method returns the value of isEmpty( ) on the ITemplateData. Otherwise, this method returns false.
isBeforeFirst( )
Returns the value of the ITemplateData's isEmpty( ).
isFirst( )
Returns true.
isLast( )
Returns false.
last( )
Must never be called. Always throws SQLException.
moveToCurrentRow( )
Does nothing.
moveToInsertRow( )
Does nothing.
next( )
Called by the template engine to return the next row.
previous( )
Can never be called. Always throws SQLException.
refreshRow( )
Does nothing.
relative( )
Does nothing.
rowDeleted( )
Returns false.
rowInserted( )
Returns false.
rowUpdated( )
Returns false.
setCommand( )
Stubs out uninteresting DBRowSet functionality.
setFetchDirection( )
Does nothing.
setFetchSize( )
Does nothing.
setListSelection( )
New method. Sets the list selection on the MemRowSet that is being used as an IListRowSet. See separate description below table.
setName( )
Does nothing.
setQueryName( )
Stubs out uninteresting DBRowSet functionality.
setTemplateData( )
New method. Sets the data source to the provided TemplateDataBasic. See separate description below table.
setupQuery( )
Stubs out uninteresting DBRowSet functionality.
updateAsciiStream( )
Does nothing.
updateBigDecimal( )
Does nothing.
updateBinaryStream( )
Does nothing.
updateBoolean( )
Does nothing.
updateByte( )
Does nothing.
updateBytes( )
Does nothing.
updateCharacterStream( )
Does nothing.
updateDate( )
Does nothing.
updateDouble( )
Does nothing.
updateFloat( )
Does nothing.
updateInt( )
Does nothing.
updateLong( )
Does nothing.
updateNull( )
Does nothing.
updateObject( )
Does nothing.
updateShort( )
Does nothing.
updateString( )
Does nothing.
updateTime( )
Does nothing.
updateTimestamp( )
Does nothing.
wasNull( )
Returns false.

addListItem( )
Adds a new item into a MemRowSet that is being used as an IListRowSet.

Syntax
public void addListItem(
	String label,
	String value)

label. The name of the item as it appears in the list.

value. The value assigned to the label.

Usage
When working with an IListRowSet, use addListItem( ) with setListSelection( ) to create a selection list or a group of radio buttons.

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

MemRowSet ds = new MemRowSet();

ds.setRequest(req);
ds.setResponse(res);
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
req.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>
Related Topics
setListSelection( )

addRow( )
Adds data as a separate row into the data source.

Syntax
public int addRow()
Usage
Use addRow( ) to add a new row to a data set. The values of the row must have been previously added using addValue( ); otherwise, no row is added.

Example
MemRowSet ds = new MemRowSet();

ds.setRequest(req);
ds.setResponse(res);
ds.setName("tryMe");
ds.addValue("col1", "Hello");
ds.addValue("col2", "World");
ds.addRow();
ds.addValue("col1", "GoodBye");
ds.addValue("col2", "World");
ds.addRow();
req.setAttribute(ds.getName(),ds);
The previous code, along with an HTML template containing the following:

<gx type=tile id=tryMe>

<gx type=cell id=tryMe.col1></gx> <gx type=cell id=tryMe.col2><%gx>
<BR>
</gx>
would produce:

Hello World

Goodbye World
Return Value
Unused. Always 0.

Related Topics
addValue( ), addListItem( )

addValue( )
Queues a value for later addition into the data source.

Syntax
public int addValue(
	String name,
	String value)

name. The column name of the value.

value. The value to add to the data source.

Usage
In-memory data sources start out without any data. Use a series of addValue( ) and addRow( ) calls to populate a data source with values.

Note that data is not actually added to the data source until addRow() is called.

Example
See addRow( ) for an example.

Return Value
Unused. Always 0.

Related Topics
addRow( )

getListSelection( )
Gets the list selection of the MemRowSet that is being used as an IListRowSet.

Syntax
public String getListSelection(
	String value)

value. The value to add to the data source.

Usage
Use getListSelection( ) to obtain the list selection previously set by a call to setListSelection( ).

Return Value
A String representing the list selection.

Related Topics
setListSelection( )

getTemplateData( )
Gets the data source of the RowSet.

Syntax
public ITemplateData getTemplateData()
Usage
Use getTemplateData( ) to obtain the ITemplateData that serves as the data source of the RowSet. This ITemplateData object was created in either of two ways:

Return Value
An ITemplateData representing the data source.

Related Topics
setTemplateData( )

setListSelection( )
Sets the list selection on the MemRowSet that is being used as an IListRowSet.

Syntax
public void setListSelection(
	String value)

value. The value to be set for the list selection.

Usage
When working with an IListRowSet, use addListItem( ) with setListSelection( ) to create a selection list or a group of radio buttons. Use getListSelection( ) to obtain the list selection previously set by a call to setListSelection( ).

Example
See addListItem( ) for an example.

Related Topics
addListItem( ), getListSelection( )

setTemplateData( )
Sets the data source to the provided TemplateDataBasic.

Creates an ITemplateData object on a data set.

Syntax
public void setTemplateData(
	ITemplateData td)

td. The name of the ITemplateData object to create.

Usage
After you call setTemplateData( ) with a specified ITemplateData object, data requests such as calls to getString( ) and next( ) will be routed through the passed-in ITemplateData. Therefore, if you already have an ITemplateData (for example, from an extension), you can wrap a data set around it by creating a MemRowSet and calling setTemplateData( ) on the MemRowSet to pass in the ITemplateData.

Furthermore, if the ITemplateData is also a TemplateDataBasic, then calls to addRow( ) and setHint( ) will succeed. However, if the ITemplateData is not a TemplateDataBasic, calls to add a row or set the hint will fail, returning a value of -1.

Related Topics
getTemplateData( )

 

© Copyright 1999 Netscape Communications Corp.