net.xoetrope.optional.data.sql
Class CachedDatabaseTable

java.lang.Object
  extended by net.xoetrope.optional.data.sql.DatabaseTable
      extended by net.xoetrope.optional.data.sql.CachedDatabaseTable

public class CachedDatabaseTable
extends DatabaseTable

A class that extends the DatabaseTable class by caching the data from the query result set. This class maintains a copy of the database tables's data and has limited updated capabilities. The class is designed for use as a disconnected rowset. At some stage we may replace its implementation with the JDBC CachedRowSet

Copyright (c) Xoetrope Ltd. 2001-2005

$Revision: 2.8 $ License: see license.txt


Field Summary
protected  java.lang.String origSQL
           
protected  java.lang.Object[] rowData
           
 
Fields inherited from class net.xoetrope.optional.data.sql.DatabaseTable
caseSensitive, connection, connName, currentProject, currentRow, defaultWhereClause, dirty, distinct, fieldNames, fieldTypes, NORMAL_UPDATE, numFields, numRows, OPTIMISTIC_UPDATE, orderField, params, PARANOID_UPDATE, queryFields, queryTable, RS, sqlStatement, writable
 
Constructor Summary
CachedDatabaseTable(XProject project, java.lang.String sqlStr, java.lang.String connName, boolean writable)
          Setup a table with the full sql statement
CachedDatabaseTable(XProject project, java.lang.String tableName, java.lang.String fields, java.lang.String where, java.lang.String connName, boolean writable)
          Create a new database table wrapper
 
Method Summary
protected  void cacheData()
          Internally store the latest result set data and then close the dataset
 java.lang.String getOriginalSql()
           
 java.lang.String getValue(int fieldIdx)
          Get a field value from the current row
 java.lang.String getValue(int rowIdx, int fieldIdx)
          Get a field value
 void setValue(int rowIdx, int fieldIdx, java.lang.String value)
          Set the cache value for a field.
 void setValue(int fieldIdx, java.lang.String value)
          Set the cache value for a field.
 
Methods inherited from class net.xoetrope.optional.data.sql.DatabaseTable
commit, executeUpdate, finalize, first, getConnName, getCurrentRow, getDoesEscapeProcessing, getFieldIndex, getFieldName, getFields, getNextPseudoId, getNumFields, getNumRows, getPreparedStatement, getPreparedStatement, getSQL, getTableName, getTableName, getWhereClause, hasMoreRows, isDistinct, last, next, previous, releasePreparedStatement, retrieve, retrieve, retrieve, setAutoCommit, setCaseSensitive, setCurrentRow, setDistinct, setDoesEscapeProcessing, setOrderField, setParams, setSql
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowData

protected java.lang.Object[] rowData

origSQL

protected java.lang.String origSQL
Constructor Detail

CachedDatabaseTable

public CachedDatabaseTable(XProject project,
                           java.lang.String sqlStr,
                           java.lang.String connName,
                           boolean writable)
Setup a table with the full sql statement

Parameters:
project - the owner project
sqlStr - the full SQL statement
connName - the connection name
writable - true if the table is writeable/updatable

CachedDatabaseTable

public CachedDatabaseTable(XProject project,
                           java.lang.String tableName,
                           java.lang.String fields,
                           java.lang.String where,
                           java.lang.String connName,
                           boolean writable)
Create a new database table wrapper

Parameters:
project - the owner project
tableName - the table name
fields - the fields to retrieve
where - the where clause to use in the query
connName - the connection name
writable - true if the result set is to be updatable
Method Detail

getOriginalSql

public java.lang.String getOriginalSql()

cacheData

protected void cacheData()
                  throws java.sql.SQLException
Internally store the latest result set data and then close the dataset

Overrides:
cacheData in class DatabaseTable
Throws:
java.sql.SQLException

getValue

public java.lang.String getValue(int fieldIdx)
Get a field value from the current row

Overrides:
getValue in class DatabaseTable
Parameters:
fieldIdx - the field (zero based) to retrieve
Returns:
the model node at the specified index (the DatabaseRowModel child node)

getValue

public java.lang.String getValue(int rowIdx,
                                 int fieldIdx)
Get a field value

Overrides:
getValue in class DatabaseTable
Parameters:
rowIdx - the row (zero based) to retrieve
fieldIdx - the field (zero based) to retrieve
Returns:
the field value

setValue

public void setValue(int fieldIdx,
                     java.lang.String value)
Set the cache value for a field. This method does not write the data back to the database.

Parameters:
value - the new field value
fieldIdx - the field (zero based) to retrieve

setValue

public void setValue(int rowIdx,
                     int fieldIdx,
                     java.lang.String value)
Set the cache value for a field. This method does not write the data back to the database. Does not update the current row.

Overrides:
setValue in class DatabaseTable
Parameters:
value - the new field value
rowIdx - the row (zero based) to retrieve
fieldIdx - the field (zero based) to retrieve