JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.sql
Class CachedResultSetTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by net.sf.japi.sql.CachedResultSetTableModel
All Implemented Interfaces:
Serializable, TableModel, ResultSetTableModel

public class CachedResultSetTableModel
extends AbstractTableModel
implements ResultSetTableModel

An implementation of javax.swing.TableModel for an SQL ResultSet. In contrast to @see ResultSetTableModel this implementation reads all data upon setting the ResultSet. The advantage is that reading the ResultSet does not require the database connection anymore. The disadvantage is that this class requires much memory on large results and may fail for OutOfMemory on huge results. This class is fully serializable, at least in the way Swing classes are at all serializable.

Serialized instances will also serialize the cached data. The data source information is not serialized.

Author:
Christian Hujer
See Also:
ResultSet, TableModel, Serialized Form
Todo:
maybe setResultSet should throw SQLException?

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
CachedResultSetTableModel()
          Create a CachedResultSetTableModel.
CachedResultSetTableModel(ResultSet rs)
          Create a CachedResultSetTableModel.
 
Method Summary
 void addThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
          Adds a ThrowableHandler to this model.
 Class<?> getColumnClass(int columnIndex)
          Returns Object.class regardless of columnIndex. Always returns String.class.
 int getColumnCount()
          Returns the number of columns in the model.
 String getColumnName(int column)
          Returns a default name for the column using spreadsheet conventions: A, B, C, ...
 ResultSet getResultSet()
          Get the ResultSet.
 int getRowCount()
          Returns the number of rows in the model.
 Object getValueAt(int rowIndex, int columnIndex)
          Returns the value for the cell at columnIndex and rowIndex.
 void removeThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
          Removes a ThrowableHandler from this model.
 void setResultSet(ResultSet resultSet)
          Set the ResultSet.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, 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 javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener, setValueAt
 

Constructor Detail

CachedResultSetTableModel

public CachedResultSetTableModel()
Create a CachedResultSetTableModel.


CachedResultSetTableModel

public CachedResultSetTableModel(ResultSet rs)
Create a CachedResultSetTableModel.

Parameters:
rs - Initial ResultSet
Method Detail

setResultSet

public void setResultSet(ResultSet resultSet)
Set the ResultSet.

Specified by:
setResultSet in interface ResultSetTableModel
Parameters:
resultSet - ResultSet, maybe null

getResultSet

public ResultSet getResultSet()
Get the ResultSet.

Specified by:
getResultSet in interface ResultSetTableModel
Returns:
ResultSet or null if there is no current result set

addThrowableHandler

public void addThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
Adds a ThrowableHandler to this model.

Specified by:
addThrowableHandler in interface ResultSetTableModel
Parameters:
throwableHandler - ThrowableHandler to add

removeThrowableHandler

public void removeThrowableHandler(ThrowableHandler<? super SQLException> throwableHandler)
Removes a ThrowableHandler from this model.

Specified by:
removeThrowableHandler in interface ResultSetTableModel
Parameters:
throwableHandler - ThrowableHandler to add

getColumnCount

public int getColumnCount()
Description copied from interface: javax.swing.table.TableModel
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Specified by:
getColumnCount in interface TableModel
Returns:
the number of columns in the model
See Also:
TableModel

getRowCount

public int getRowCount()
Description copied from interface: javax.swing.table.TableModel
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

getValueAt

@Nullable
public Object getValueAt(int rowIndex,
                                  int columnIndex)
Description copied from interface: javax.swing.table.TableModel
Returns the value for the cell at columnIndex and rowIndex.

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

getColumnClass

public Class<?> getColumnClass(int columnIndex)
Returns Object.class regardless of columnIndex. Always returns String.class.

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

getColumnName

public 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

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright