org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel
Class ScrollableResultSetTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.ScrollableResultSetTableModel
All Implemented Interfaces:
Serializable, TableModel, MetaTableModel, CloseableTableModel

public class ScrollableResultSetTableModel
extends AbstractTableModel
implements CloseableTableModel, MetaTableModel

A tableModel which is backed up by a java.sql.ResultSet. Use this to directly feed your database data into JFreeReport. If you have trouble using this TableModel and you have either enough memory or your query result is not huge, you may want to use ResultSetTableModelFactory.generateDefaultTableModel (ResultSet rs). That implementation will read all data from the given ResultSet and keep that data in memory.

Use the close() function to close the ResultSet contained in this model.

Author:
Thomas Morgner
See Also:
Serialized Form

Constructor Summary
ScrollableResultSetTableModel(ResultSet resultset, boolean labelMapMode)
          Deprecated.  
ScrollableResultSetTableModel(ResultSet resultset, boolean labelMapMode, boolean closeStatement)
          Constructs the model.
 
Method Summary
 void close()
          Clears the model of the current result set.
 DataAttributes getCellDataAttributes(int row, int column)
          Returns the meta-attribute as Java-Object.
 DataAttributes getColumnAttributes(int column)
          Returns the column-level attributes for the given column.
 Class getColumnClass(int column)
          Returns the class of the resultset column.
 String getColumnClassName(int column)
          Deprecated.  
 int getColumnCount()
          Returns the number of columns in the ResultSet.
 String getColumnName(int column)
          Returns the columnLabel or column name for the given column.
 int getRowCount()
          Get a rowCount.
 DataAttributes getTableAttributes()
          Returns table-wide attributes.
 Object getValueAt(int row, int column)
          Returns the value of the specified row and the specified column from within the resultset.
 boolean isCellDataAttributesSupported()
          Checks, whether cell-data attributes are supported by this tablemodel implementation.
 boolean isLabelMapMode()
          Returns the column name mode used to map column names into column indices.
 void updateResultSet(ResultSet resultset)
          Updates the result set in this model with the given ResultSet object.
 
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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, isCellEditable, removeTableModelListener, setValueAt
 

Constructor Detail

ScrollableResultSetTableModel

public ScrollableResultSetTableModel(ResultSet resultset,
                                     boolean labelMapMode)
                              throws SQLException
Deprecated. 

Constructs the model.

Parameters:
resultset - the result set.
labelMapMode - defines, whether to use column names or column labels to compute the column index.
Throws:
SQLException - if there is a problem with the result set.

ScrollableResultSetTableModel

public ScrollableResultSetTableModel(ResultSet resultset,
                                     boolean labelMapMode,
                                     boolean closeStatement)
                              throws SQLException
Constructs the model.

Parameters:
resultset - the result set.
labelMapMode - defines, whether to use column names or column labels to compute the column index.
closeStatement - a flag indicating whether the statement, that created the resultset should be closed when the resultset gets closed.
Throws:
SQLException - if there is a problem with the result set.
Method Detail

isLabelMapMode

public boolean isLabelMapMode()
Returns the column name mode used to map column names into column indices. If true, then the Label is used, else the Name is used.

Returns:
true, if the column label is used for the mapping, false otherwise.
See Also:
ResultSetMetaData.getColumnLabel(int), ResultSetMetaData.getColumnName(int)

updateResultSet

public void updateResultSet(ResultSet resultset)
                     throws SQLException
Updates the result set in this model with the given ResultSet object.

Parameters:
resultset - the new result set.
Throws:
SQLException - if there is a problem with the result set.

close

public void close()
Clears the model of the current result set. The resultset is closed.

Specified by:
close in interface CloseableTableModel

getRowCount

public int getRowCount()
Get a rowCount. This can be a very expensive operation on large datasets. Returns -1 if the total amount of rows is not known to the result set.

Specified by:
getRowCount in interface TableModel
Returns:
the row count.

getColumnCount

public int getColumnCount()
Returns the number of columns in the ResultSet. Returns 0 if no result set is set or the column count could not be retrieved.

Specified by:
getColumnCount in interface TableModel
Returns:
the column count.
See Also:
ResultSetMetaData.getColumnCount()

getColumnName

public String getColumnName(int column)
Returns the columnLabel or column name for the given column. Whether the label or the name is returned depends on the label map mode.

Specified by:
getColumnName in interface TableModel
Overrides:
getColumnName in class AbstractTableModel
Parameters:
column - the column index.
Returns:
the column name.
See Also:
ResultSetMetaData.getColumnLabel(int)

getValueAt

public Object getValueAt(int row,
                         int column)
Returns the value of the specified row and the specified column from within the resultset.

Specified by:
getValueAt in interface TableModel
Parameters:
row - the row index.
column - the column index.
Returns:
the value.

getColumnClass

public Class getColumnClass(int column)
Returns the class of the resultset column. Returns Object.class if an error occurred.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class AbstractTableModel
Parameters:
column - the column index.
Returns:
the column class.

getColumnClassName

public String getColumnClassName(int column)
Deprecated. 

Returns the classname of the resultset column. Returns Object.class if an error occurred.

Parameters:
column - the column index.
Returns:
the column class name.

getCellDataAttributes

public DataAttributes getCellDataAttributes(int row,
                                            int column)
Returns the meta-attribute as Java-Object. The object type that is expected by the report engine is defined in the TableMetaData property set. It is the responsibility of the implementor to map the native meta-data model into a model suitable for reporting.

Meta-data models that only describe meta-data for columns can ignore the row-parameter.

Specified by:
getCellDataAttributes in interface MetaTableModel
Parameters:
row - the row of the cell for which the meta-data is queried.
column - the index of the column for which the meta-data is queried.
Returns:
the meta-data object.

isCellDataAttributesSupported

public boolean isCellDataAttributesSupported()
Description copied from interface: MetaTableModel
Checks, whether cell-data attributes are supported by this tablemodel implementation.

Specified by:
isCellDataAttributesSupported in interface MetaTableModel
Returns:
true, if the model supports cell-level attributes, false otherwise.

getColumnAttributes

public DataAttributes getColumnAttributes(int column)
Description copied from interface: MetaTableModel
Returns the column-level attributes for the given column.

Specified by:
getColumnAttributes in interface MetaTableModel
Parameters:
column - the column.
Returns:
data-attributes, never null.

getTableAttributes

public DataAttributes getTableAttributes()
Returns table-wide attributes. This usually contain hints about the data-source used to query the data as well as hints on the sort-order of the data.

Specified by:
getTableAttributes in interface MetaTableModel
Returns: