| java.lang.Object dinamica.Recordset
Recordset | public class Recordset implements Serializable(Code) | | Core-level framework class: Recordset - General purpose, tabular data structure.
Represents a disconnected recordset, a kind of multi-purpose ResultSet
without connection to the database, much like
the famous ADO disconnected recordset from VB6,
can be created from a SQL query or manufactured
by code to represent any tabular data. It is a kind of
generic data container that may save a lot of work because
it can be used to represent several entities avoiding the need
to write custom classes to represent each specific entity.
It is serializable, so it can be safely used in HTTP Sessions, JNDI, etc.
This recordset mantains all data in memory and does not need
an open connection to the database, provides several constructors
to isolate the programmer from the task of programming with the
JDBC API, but also provides low level access if desired.
Each field in the recordset is mantained in its native data type
as represented by the JDBC driver, or a java null value.
Creation date: 10/09/2003
Last Update: 11/09/2003
(c) 2003 Martin Cordova
This code is released under the LGPL license
author: Martin Cordova (dinamica@martincordova.com) |
Recordset | public Recordset(ResultSet rs) throws Throwable(Code) | | Create a recordset given a resultset. It is the
responsability of the caller of this method to close the resultset
and other jdbc objects involved.
Parameters: rs - ResultSet positiones before the first record throws: Throwable - |
Recordset | public Recordset(Connection conn, String sql) throws Throwable(Code) | | Creates a recordset given a SQL query
Parameters: conn - Database Connection Parameters: sql - SQL Query that returns a Resultset throws: Throwable - |
Recordset | public Recordset(java.sql.Connection conn, String sql, int limit) throws Throwable(Code) | | Creates a recordset given a SQL query.
Parameters: conn - Database Connection Parameters: sql - SQL Query that returns a Resultset Parameters: limit - Maximum number of rows to read from the DataBase throws: Throwable - |
Recordset | public Recordset()(Code) | | Default constructor used when creating
the recordset from code (a "manufactured" recordset)
|
addNew | public void addNew()(Code) | | Add a record to the recordset and set record number position
to the new inserted record
|
append | public void append(String fieldName, int type) throws RecordsetException(Code) | | Append a field to the recordset structure.
It is used when manufacturing a Recordset from code
Parameters: fieldName - Field Name Parameters: nativeSqlType - SQL native data type name Parameters: type - JDBC data type (java.sql.Types) - only INTEGER, LONG, VARCHAR, DATE, TIMESTAMP or DOUBLE are supported |
clear | public void clear() throws Throwable(Code) | | Clear current record values, set every field's value to null
|
containsField | public boolean containsField(String name)(Code) | | Check if recordset contains field with a given name
Parameters: name - Name of the field to check its existence TRUE if field exists, FALSE if not |
copyStructure | public Recordset copyStructure() throws Throwable(Code) | | Duplicate the Recordset structure in a new Recordset without any data
Empty Recordset with the same structure throws: Throwable - |
copyValues | public void copyValues(Recordset rs) throws Throwable(Code) | | Copy record values from this recordset to
a destination recordset, using the current
record of both recordsets. Destination recordset
fields that match names with source recordset fields
must be of the same type too. It does not matter if some
fields from the source recordset are not defined in the destination
recordset. Only name-matching fields will be considered
for the operation.
Parameters: rs - Destination recordsets throws: Throwable - |
delete | public void delete(int recNum) throws Throwable(Code) | | Delete record (from memory)
Parameters: recNum - Record Number (0..N-1) |
findRecord | public int findRecord(String colName, int value) throws Throwable(Code) | | Find a record where a column's value matches a given value
Parameters: colName - Column to use for the search Parameters: value - Value to search for Record position (0...N-1) or -1 if not found throws: Throwable - |
findRecord | public int findRecord(String colName, String value) throws Throwable(Code) | | Find a record where a column's value matches a given value
Parameters: colName - Column to use for the search Parameters: value - Value to search for Record position (0...N-1) or -1 if not found throws: Throwable - |
findRecord | public int findRecord(String colName, java.util.Date value) throws Throwable(Code) | | Find a record where a column's value matches a given Date value
Parameters: colName - Column to use for the search Parameters: value - Date value to search for Record position (0...N-1) or -1 if not found throws: Throwable - |
getChildrenRecordset | public Recordset getChildrenRecordset() throws Throwable(Code) | | Retrieve current record's children recordset
A reference to the children recordset or null if no children recordset exists throws: Throwable - If the record position is not valid |
getData | public ArrayList<Record> getData()(Code) | | Returns ArrayList containing the recordset data (the records)
|
getDate | public java.util.Date getDate(String colName) throws Throwable(Code) | | Wrapper method for getValue() - avoids casting the data type
Parameters: colName - Column name to retrieve its value from the current record The column value in its native data type throws: Throwable - |
getDouble | public double getDouble(String colName) throws Throwable(Code) | | Wrapper method for getValue() - avoids casting the data type
Parameters: colName - Column name to retrieve its value from the current record The column value in its native data type throws: Throwable - |
getField | public RecordsetField getField(String fieldName) throws Throwable(Code) | | Return a Recordset field object describing its properties
Parameters: fieldName - Field name to locate the field object Reference to Recordset field throws: Throwable - if fieldName does not exist in Recordset metadata |
getFieldCount | public int getFieldCount()(Code) | | Returns number of fields in recordset
|
getInt | public int getInt(String colName) throws Throwable(Code) | | Wrapper method for getValue() - avoids casting the data type
Parameters: colName - Column name to retrieve its value from the current record The column value in its native data type throws: Throwable - |
getInteger | public Integer getInteger(String colName) throws Throwable(Code) | | Wrapper method for getValue() - avoids casting the data type
Parameters: colName - Column name to retrieve its value from the current record The column value in its native data type throws: Throwable - |
getMetaData | public Recordset getMetaData() throws Throwable(Code) | | Retrieve recordset metadata. This method returns
a Recordset containing the columns: name, typename, typeid.
"typeid" is the java.sql.Type value
There will be one record for each column.
Recordset throws: Throwable - |
getPage | public Recordset getPage(int p) throws Throwable(Code) | | Paging support.
Get Recordset representing the requeste page of records
|
getPageCount | public int getPageCount()(Code) | | Paging support.
Returns the number of record pages determined by setPageSize
|
getPageNumber | public int getPageNumber()(Code) | | Paging support.
Returns the current page number (1...N)
|
getPageSize | public int getPageSize()(Code) | | Return records per page (page size) for recordsets
used in paged views
|
getRecordCount | public int getRecordCount()(Code) | | Returns the number of records in recordset
|
getRecordNumber | public int getRecordNumber()(Code) | | Returns the current record position (0...N-1)
|
getRecordsetInfo | public Recordset getRecordsetInfo() throws Throwable(Code) | | Create a recordset with one record containing
general recordset parameters like: recordcount, pagecount, currentpage
Recordset Object throws: Throwable - |
getString | public String getString(String colName) throws Throwable(Code) | | Wrapper method for getValue() - avoids casting the data type
Parameters: colName - Column name to retrieve its value from the current record The column value in its native data type throws: Throwable - |
getValue | public Object getValue(String fieldName) throws Throwable(Code) | | Return field value given a field name
Parameters: fieldName - Field Name. May be reserved field names: _rowIndex (0...N-1) or _rowNumber (1...N) throws: Throwable - |
isNull | public boolean isNull(String colName) throws Throwable(Code) | | Tests if the give column value is null for the
current record
Parameters: colName - Column name TRUE if the value is null throws: Throwable - If record position is not valid or the column does not exist in the recordset |
next | public boolean next()(Code) | | Move pointer to next record. Returns true if not EOF
|
setChildrenRecordset | public void setChildrenRecordset(Recordset rs) throws Throwable(Code) | | Set the children recordset for the current record
Parameters: rs - Children recordset throws: Throwable - If the record position is not valid |
setData | protected void setData(ArrayList data)(Code) | | Feed the recordset data
Parameters: data - ArrayList containing record objects |
setFields | protected void setFields(HashMap fields)(Code) | | Feed the recordset metadata (column structure)
Parameters: fields - HashMap containing the recordset field objects |
setID | public void setID(String id)(Code) | | Set recordset ID (an arbitrary String)
Parameters: id - |
setPageSize | public void setPageSize(int p) throws Throwable(Code) | | Paging support.
Define page size (records per page)
|
setRecordNumber | public void setRecordNumber(int recNum) throws RecordsetException(Code) | | Set record position inside recordset
Parameters: recNum - Record Number (0...getRecordCount()-1) throws: Throwable - |
setValue | public void setValue(String fieldName, Object value) throws RecordsetException(Code) | | Set field value for current record (determined by getRecordNumber())
Parameters: fieldName - Field Name Parameters: value - Field Value (Date, String, int, double, null) throws: Throwable - |
sort | public void sort(String col) throws Throwable(Code) | | Sort Recordset data in ascending order by the given column
Parameters: col - Name of the column to be used for the sort throws: Throwable - |
toString | public String toString()(Code) | | Returns a text-formatted report with the
structure of the recordset, very usefull for
debugging purposes
|
top | public void top()(Code) | | Set cursor position before first record,
it is like a "rewind" command
|
|
|