com.sun.jsfcl.data
Class DataCache

java.lang.Object
  extended bycom.sun.jsfcl.data.DataCache
All Implemented Interfaces:
java.io.Serializable

public class DataCache
extends java.lang.Object
implements java.io.Serializable

Cache for row and column values that supports persisting the data behind a UIData component across HTTP requests, without requiring that the underlying JDBC connection remain open. It also includes mechanisms to detect which row and column values have been updated, in order to support minimal database activity when synchronizing these changes to the underlying database.

DataCache declares itself to be Serializable to conform to the J2EE platform requirement that session scope attributes should be serializable on a distributable container. However, this will only succeed if the actual cached column values are themselves Serializable as well.

Author:
craigmcc
See Also:
Serialized Form

Nested Class Summary
 class DataCache.Column
          Column encapsulates the stored information about a single "column" of data, typically corresponding to a column from an individual row in an underlying relational database.
 class DataCache.Row
          Row encapsulates the stored information about a single "row" of data, typically corresponding to a row in an underlying relational database.
 
Constructor Summary
DataCache()
           
 
Method Summary
 void add(int rowIndex, DataCache.Row row)
          Add a new row entry to the cache, replacing any existing cache entry for the same rowIndex value.
 void clear()
          Clear any cached row and column data.
 void commit()
          Commit the updated state of all cached rows.
 DataCache.Column createColumn(java.lang.String schemaName, java.lang.String tableName, java.lang.String columnName, int sqlType, java.lang.Class javaType, java.lang.Object original)
          Create and return a Column instance configured with the specified parameters.
 DataCache.Column createColumn(java.lang.String schemaName, java.lang.String tableName, java.lang.String columnName, int sqlType, java.lang.Object original)
          Create and return a Column instance configured with the specified parameters.
 DataCache.Row createRow(DataCache.Column[] columns)
          Create and return a Row instance configured with the specified parameters.
 DataCache.Row get(int rowIndex)
          Return the cached row associated with the specified row index, if any; otherwise, return null.
 java.util.Iterator iterator()
          Return an Iterator over the row index values (of type java.lang.Integer) for which cached data is present.
 void remove(int rowIndex)
          Remove any row entry corresponding to the specified rowIndex.
 void reset()
          Reset the updated state of all rows and columns in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataCache

public DataCache()
Method Detail

add

public void add(int rowIndex,
                DataCache.Row row)

Add a new row entry to the cache, replacing any existing cache entry for the same rowIndex value.

Parameters:
rowIndex - Row index this row corresponds to
row - DataCache.Row to be added

clear

public void clear()

Clear any cached row and column data.


commit

public void commit()

Commit the updated state of all cached rows. After this method completes, the current values for all columns will appear to be original, any rows marked deleted will be removed, and no row will be considered updated.


createColumn

public DataCache.Column createColumn(java.lang.String schemaName,
                                     java.lang.String tableName,
                                     java.lang.String columnName,
                                     int sqlType,
                                     java.lang.Object original)

Create and return a Column instance configured with the specified parameters.

Parameters:
schemaName - Schema name of the table containing this column (if any)
tableName - Table name containing this column (if any)
columnName - Column name of this column
sqlType - SQL type (from java.sql.Types)
original - Original value for this column

createColumn

public DataCache.Column createColumn(java.lang.String schemaName,
                                     java.lang.String tableName,
                                     java.lang.String columnName,
                                     int sqlType,
                                     java.lang.Class javaType,
                                     java.lang.Object original)

Create and return a Column instance configured with the specified parameters.

Parameters:
schemaName - Schema name of the table containing this column (if any)
tableName - Table name containing this column (if any)
columnName - Column name of this column
sqlType - SQL type (from java.sql.Types)
javaType - Java type as would be returned by Class.forName(ResultSetMetaData.getColumnClassName)
original - Original value for this column

createRow

public DataCache.Row createRow(DataCache.Column[] columns)

Create and return a Row instance configured with the specified parameters.

Parameters:
columns - Column instances for this row

get

public DataCache.Row get(int rowIndex)

Return the cached row associated with the specified row index, if any; otherwise, return null.

Parameters:
rowIndex - Row index for which to retrieve a row

iterator

public java.util.Iterator iterator()

Return an Iterator over the row index values (of type java.lang.Integer) for which cached data is present.

S


remove

public void remove(int rowIndex)

Remove any row entry corresponding to the specified rowIndex.

Parameters:
rowIndex - Row index for which to remove any cached data

reset

public void reset()

Reset the updated state of all rows and columns in the cache.