com.arsdigita.acs
Class Selection

java.lang.Object
  |
  +--com.arsdigita.acs.Selection
All Implemented Interfaces:
DataSource
Direct Known Subclasses:
ChatDataSource, GeneralCommentsDataSource, GroupDataSource, GroupField, GroupTypeDataSource, MemberField, MessagesDataSource, NewsDataSource, PortalsDataSource, SearchDataSource, SingleSelection, TopicsDataSource

public class Selection
extends Object
implements DataSource

Represents a generic multiple-row data source pulled in from the database. Provides a generic interface for getting properties and filling the datasource from either a ResultSet or a SqlStatement and a database handle.

Entity objects for doing logical operations on more specific database objects should extend Selection, adding additional accessors for derived properties as needed.


Field Summary
protected  int ctr
           
protected  Database db
           
protected  ResultSet rs
          The result set that we're managing
protected  ResultSetMetaData rsmd
           
 
Constructor Summary
Selection()
           
Selection(ResultSet rs)
          Creates a new Selection, initialized from a ResultSet.
Selection(SqlStatement sql, Database db)
          Utility constructor to initialize from a result set created from a SqlStatement and a database handle.
 
Method Summary
 boolean contains(String column)
          Returns true if this contains a column named column.
 void dumpBLOB(String key, OutputStream os)
          Dumps the contents of a BLOB column to an OutputStream.
protected  Hashtable freeze()
          Returns a mapping from column names to objects, to stash a current set of values for a row.
 String get(String key)
          Generic get-property accessor.
 byte[] getBLOB(String key)
          Returns the contents of a BLOB column in this Selection.
 String[] keys()
          Returns a list of available keys (column names) in the Selection.
 boolean next()
          Advances to the next row in the data source, if there is one.
 int rownum()
          Returns the current row number in the datasource.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rs

protected ResultSet rs
The result set that we're managing

rsmd

protected ResultSetMetaData rsmd

db

protected Database db

ctr

protected int ctr
Constructor Detail

Selection

public Selection()

Selection

public Selection(ResultSet rs)
          throws SQLException
Creates a new Selection, initialized from a ResultSet.

Selection

public Selection(SqlStatement sql,
                 Database db)
          throws SQLException
Utility constructor to initialize from a result set created from a SqlStatement and a database handle.
Method Detail

contains

public boolean contains(String column)
                 throws DataSourceException
Returns true if this contains a column named column.
Specified by:
contains in interface DataSource

freeze

protected Hashtable freeze()
                    throws SQLException,
                           IOException
Returns a mapping from column names to objects, to stash a current set of values for a row. Serves a similar purpose as set_variables_after_query.

get

public String get(String key)
           throws DataSourceException
Generic get-property accessor. Returns the value of the column named by key; if it's a CLOB column, still returns the text from the CLOB. If it's a DATE column, returns an ANSI date string (yyyy-mm-dd). Returns an empty string if the column is null (a perhaps unnecessary evil to prevent the string "null" from popping up in JSP pages--probably should get rid of this with more consistent use of ad:sub tag!).
Specified by:
get in interface DataSource
Throws:
InvalidKeyException - if key is not found.

next

public boolean next()
             throws DataSourceException
Advances to the next row in the data source, if there is one.
Specified by:
next in interface DataSource
Returns:
true; or false if there are no more elements.

keys

public String[] keys()
              throws DataSourceException
Returns a list of available keys (column names) in the Selection.
Specified by:
keys in interface DataSource

getBLOB

public byte[] getBLOB(String key)
               throws DataSourceException
Returns the contents of a BLOB column in this Selection. (note that, since CLOBs are handled transparently in get(), we don't need a getCLOB() method!)
Parameters:
key - The column name to retrieve
Returns:
A byte array with the BLOB contents.

dumpBLOB

public void dumpBLOB(String key,
                     OutputStream os)
              throws DataSourceException
Dumps the contents of a BLOB column to an OutputStream.
Parameters:
key - The column name
os - The output stream

rownum

public int rownum()
           throws DataSourceException
Returns the current row number in the datasource.
Specified by:
rownum in interface DataSource