Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.table.db
Class AbstractDatabaseTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.citra.table.db.AbstractDatabaseTableModel
All Implemented Interfaces:
CacheableTableModel, DatabaseTableModel, Serializable, TableModel
Direct Known Subclasses:
DefaultCrosstabTableModel, DefaultDatabaseTableModel, DistinctDatabaseTableModel

public abstract class AbstractDatabaseTableModel
extends AbstractTableModel
implements DatabaseTableModel, CacheableTableModel

AbstractDatabaseTableModel represents a sortable and filterable database model that is also cached. Sorting is provided via an internal SortTableModel instance, whereas filtering through an internal FilterTableModel instance. Finally, caching is handled by a TableCache object.

See Also:
Serialized Form

Field Summary
protected  TableCache cache
          the cache
protected  FilterTableModel dbFilter
          the internal filter tablemodel instance
protected  SortTableModel dbSorter
          the internal sort tablemodel instance
protected  boolean rangedModel
          true if the model is going to fetch data in ranges
protected  int rowCount
          an index holding the last row count
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
AbstractDatabaseTableModel(TableCache cache)
          Constructs an AbstractDatabaseTableModel.
 
Method Summary
 void fireTableChanged(TableModelEvent e)
          Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.
 TableCache getCache()
          Retrieves the cache.
abstract  Class getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex.
abstract  String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 FilterTableModel getFilterTableModel()
          Returns the internal filter tablemodel instance.
 int getRowCount()
          Returns the number of rows in the model.
 SortTableModel getSortTableModel()
          Returns the internal sort tablemodel instance.
 List getUncachedRows(int fromRow, int toRow)
          Retrieves the rows from the table model by specifying a row interval.
 Object getValueAt(int row, int column)
          Returns the value for the cell at columnIndex and rowIndex.
 boolean isCountCached()
          Determines whether the row count has been evaluated.
 boolean isRangedModel()
          Determines whether the cache model can fetch data in ranges.
 boolean isValueCached(int row, int column)
          Determines whether the value at the specified cell has been evaluated.
abstract  void orderByClause()
          This method is called whenever sorting is requested.
protected  Object retrieveFromDB(ResultSet rs, int column)
          Performs the binding from a database value to a java value using the supplied resultset and the column's index, and returns the result.
protected  Object retrieveFromDB(ResultSet rs, int column, Class c)
          Performs the binding from a database value to a java value using the supplied resultset and the column's class, and returns the result.
 void setCache(TableCache newCache)
          Assigns a new cache.
 void setRangedModel(boolean rangedModel)
          Tells the database model whether to use ranges when fetching data from the database.
abstract  void whereClause()
          This method is called whenever filtering is requested.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.citra.table.db.DatabaseTableModel
readRowCount, retrieveRows
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnCount, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getColumnCount, isCellEditable, removeTableModelListener, setValueAt
 

Field Detail

rowCount

protected int rowCount
an index holding the last row count


dbSorter

protected SortTableModel dbSorter
the internal sort tablemodel instance


dbFilter

protected FilterTableModel dbFilter
the internal filter tablemodel instance


cache

protected TableCache cache
the cache


rangedModel

protected boolean rangedModel
true if the model is going to fetch data in ranges

Constructor Detail

AbstractDatabaseTableModel

public AbstractDatabaseTableModel(TableCache cache)
Constructs an AbstractDatabaseTableModel.

Method Detail

fireTableChanged

public void fireTableChanged(TableModelEvent e)
Forwards the given notification event to all TableModelListeners that registered themselves as listeners for this table model.

Overrides:
fireTableChanged in class AbstractTableModel
Parameters:
e - the event to be forwarded
See Also:
AbstractTableModel.addTableModelListener(javax.swing.event.TableModelListener), TableModelEvent, EventListenerList

getCache

public TableCache getCache()
Retrieves the cache.

Returns:
the assigned cache

getColumnClass

public abstract Class getColumnClass(int columnIndex)
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
columnIndex - the column being queried
Returns:
the Object.class

getColumnName

public abstract String getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found, returns an empty string.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column being queried
Returns:
a string containing the default name of column

getFilterTableModel

public FilterTableModel getFilterTableModel()
Returns the internal filter tablemodel instance.

Returns:
the filter table model instance.

getRowCount

public int getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.

Specified by:
getRowCount in interface TableModel
Returns:
the number of rows in the model
See Also:
TableModel.getColumnCount()

getSortTableModel

public SortTableModel getSortTableModel()
Returns the internal sort tablemodel instance.

Returns:
the sort table model instance.

getUncachedRows

public List getUncachedRows(int fromRow,
                            int toRow)
Retrieves the rows from the table model by specifying a row interval. The following condition must be true: from >= to. The List returned must contain the row elements starting at from. However, the List may contain less elements than those specified in the range.

Specified by:
getUncachedRows in interface CacheableTableModel
Parameters:
fromRow - the starting row
toRow - the ending row
Returns:
a list of objects, each element of which contains a row from the table model

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the value for the cell at columnIndex and rowIndex.

Specified by:
getValueAt in interface TableModel
Parameters:
row - the row whose value is to be queried
column - the column whose value is to be queried
Returns:
the value Object at the specified cell

isCountCached

public boolean isCountCached()
Determines whether the row count has been evaluated.

Specified by:
isCountCached in interface CacheableTableModel
Returns:
true if the model's row count has already been evaluated.

isRangedModel

public boolean isRangedModel()
Determines whether the cache model can fetch data in ranges.

Specified by:
isRangedModel in interface CacheableTableModel
Returns:
true if the cache model can fetch ranged data.

isValueCached

public boolean isValueCached(int row,
                             int column)
Determines whether the value at the specified cell has been evaluated.

Specified by:
isValueCached in interface CacheableTableModel
Parameters:
row - the cell's row index
column - the cell's column index
Returns:
true if the cell value at (row, column) has already been evaluated.

orderByClause

public abstract void orderByClause()
This method is called whenever sorting is requested. Preferrably, this method should reconstruct the sql select query according to the sorting columns of the internal SortTableModel instance.


retrieveFromDB

protected Object retrieveFromDB(ResultSet rs,
                                int column)
                         throws SQLException
Performs the binding from a database value to a java value using the supplied resultset and the column's index, and returns the result. This method will retrieve the class of the column using getColumnClass(column).

Parameters:
rs - the current result set
column - the column being fetched
Returns:
the java object that corresponds to the database value at column
Throws:
SQLException

retrieveFromDB

protected Object retrieveFromDB(ResultSet rs,
                                int column,
                                Class c)
                         throws SQLException
Performs the binding from a database value to a java value using the supplied resultset and the column's class, and returns the result. e.g. for the String.class, the value rs.getString(column + 1) is returned.

Parameters:
rs - the current result set
column - the column being fetched
c - the column's class
Returns:
the java object that corresponds to the database value at column
Throws:
SQLException

setCache

public void setCache(TableCache newCache)
Assigns a new cache.

Parameters:
newCache - the new cache to assign.

setRangedModel

public void setRangedModel(boolean rangedModel)
Tells the database model whether to use ranges when fetching data from the database. If ranges are used, the cache settings are respected, otherwise the model will fetch all rows in one sql statement.

Parameters:
rangedModel - true if the database model is to return data in ranges, false otherwise.

whereClause

public abstract void whereClause()
This method is called whenever filtering is requested. Preferrably, this method should reconstruct the sql select query according to the table filter of the internal FilterTableModel instance.


Copyright © 2011 Citra Technologies. All Rights Reserved.