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

java.lang.Object
  extended by org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.ResultSetTableModelFactory

public final class ResultSetTableModelFactory
extends Object

Creates a TableModel which is backed up by a ResultSet. If the ResultSet is scrollable, a ScrollableResultSetTableModel is created, otherwise all data is copied from the ResultSet into a DefaultTableModel.

The creation of a DefaultTableModel can be forced if the system property "org.pentaho.reporting.engine.classic.core.modules.misc.tablemodel.TableFactoryMode" is set to "simple".

Author:
Thomas Morgner

Field Summary
static String COLUMN_NAME_MAPPING_KEY
          The configuration key defining how to map column names to column indices.
static String RESULTSET_FACTORY_MODE
          The 'ResultSet factory mode'.
 
Method Summary
 CloseableTableModel createTableModel(ResultSet rs)
          Creates a table model by using the given ResultSet as the backend.
 CloseableTableModel createTableModel(ResultSet rs, boolean labelMapping)
          Creates a table model by using the given ResultSet as the backend.
 CloseableTableModel createTableModel(ResultSet rs, boolean labelMapping, boolean closeStatement)
          Creates a table model by using the given ResultSet as the backend.
 CloseableTableModel generateDefaultTableModel(ResultSet rs)
          Generates a TableModel that gets its contents filled from a ResultSet.
 CloseableTableModel generateDefaultTableModel(ResultSet rs, boolean labelMapping)
          Generates a TableModel that gets its contents filled from a ResultSet.
static ResultSetTableModelFactory getInstance()
          Returns the singleton instance of the factory.
static void updateMetaData(ResultSetMetaData rsmd, DefaultTableMetaData metaData, int column)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLUMN_NAME_MAPPING_KEY

public static final String COLUMN_NAME_MAPPING_KEY
The configuration key defining how to map column names to column indices.

See Also:
Constant Field Values

RESULTSET_FACTORY_MODE

public static final String RESULTSET_FACTORY_MODE
The 'ResultSet factory mode'.

See Also:
Constant Field Values
Method Detail

createTableModel

public CloseableTableModel createTableModel(ResultSet rs)
                                     throws SQLException
Creates a table model by using the given ResultSet as the backend. If the ResultSet is scrollable (the type is not TYPE_FORWARD_ONLY), an instance of ScrollableResultSetTableModel is returned. This model uses the extended capabilities of scrollable resultsets to directly read data from the database without caching or the need of copying the complete ResultSet into the programs memory.

If the ResultSet lacks the scollable features, the data will be copied into a DefaultTableModel and the ResultSet gets closed.

Parameters:
rs - the result set.
Returns:
a closeable table model.
Throws:
SQLException - if there is a problem with the result set.

createTableModel

public CloseableTableModel createTableModel(ResultSet rs,
                                            boolean labelMapping)
                                     throws SQLException
Creates a table model by using the given ResultSet as the backend. If the ResultSet is scrollable (the type is not TYPE_FORWARD_ONLY), an instance of ScrollableResultSetTableModel is returned. This model uses the extended capabilities of scrollable resultsets to directly read data from the database without caching or the need of copying the complete ResultSet into the programs memory.

If the ResultSet lacks the scollable features, the data will be copied into a DefaultTableModel and the ResultSet gets closed.

Parameters:
rs - the result set.
labelMapping - defines, whether to use column names or column labels to compute the column index.
Returns:
a closeable table model.
Throws:
SQLException - if there is a problem with the result set.

createTableModel

public CloseableTableModel createTableModel(ResultSet rs,
                                            boolean labelMapping,
                                            boolean closeStatement)
                                     throws SQLException
Creates a table model by using the given ResultSet as the backend. If the ResultSet is scrollable (the type is not TYPE_FORWARD_ONLY), an instance of ScrollableResultSetTableModel is returned. This model uses the extended capabilities of scrollable resultsets to directly read data from the database without caching or the need of copying the complete ResultSet into the programs memory.

If the ResultSet lacks the scollable features, the data will be copied into a DefaultTableModel and the ResultSet gets closed.

Parameters:
rs - the result set.
labelMapping - defines, whether to use column names or column labels to compute the column index.
closeStatement - a flag indicating whether closing the resultset should also close the statement.
Returns:
a closeable table model.
Throws:
SQLException - if there is a problem with the result set.

generateDefaultTableModel

public CloseableTableModel generateDefaultTableModel(ResultSet rs)
                                              throws SQLException
Generates a TableModel that gets its contents filled from a ResultSet. The column names of the ResultSet will form the column names of the table model.

Hint: To customize the names of the columns, use the SQL column aliasing (done with SELECT nativecolumnname AS "JavaColumnName" FROM ....

Parameters:
rs - the result set.
Returns:
a closeable table model.
Throws:
SQLException - if there is a problem with the result set.

generateDefaultTableModel

public CloseableTableModel generateDefaultTableModel(ResultSet rs,
                                                     boolean labelMapping)
                                              throws SQLException
Generates a TableModel that gets its contents filled from a ResultSet. The column names of the ResultSet will form the column names of the table model.

Hint: To customize the names of the columns, use the SQL column aliasing (done with SELECT nativecolumnname AS "JavaColumnName" FROM ....

Parameters:
rs - the result set.
labelMapping - defines, whether to use column names or column labels to compute the column index.
Returns:
a closeable table model.
Throws:
SQLException - if there is a problem with the result set.

updateMetaData

public static void updateMetaData(ResultSetMetaData rsmd,
                                  DefaultTableMetaData metaData,
                                  int column)

getInstance

public static ResultSetTableModelFactory getInstance()
Returns the singleton instance of the factory.

Returns:
an instance of this factory.