com.jrefinery.report.tablemodel
Class ScrollableResultSetTableModel

java.lang.Object
  extended byjavax.swing.table.AbstractTableModel
      extended bycom.jrefinery.report.tablemodel.ScrollableResultSetTableModel
All Implemented Interfaces:
CloseableTableModel, java.io.Serializable, javax.swing.table.TableModel

public class ScrollableResultSetTableModel
extends javax.swing.table.AbstractTableModel
implements CloseableTableModel

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

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
protected ScrollableResultSetTableModel()
          Default constructor.
  ScrollableResultSetTableModel(java.sql.ResultSet resultset)
          Constructs the model.
 
Method Summary
 void close()
          Clears the model of the current result set.
 java.lang.Class getColumnClass(int column)
          Returns the class of the resultset column.
 java.lang.String getColumnClassName(int column)
          Returns the classname of the resultset column.
 int getColumnCount()
          Returns the number of columns in the ResultSet.
 java.lang.String getColumnName(int column)
          Returns the columnLabel for the given column.
 int getRowCount()
          Get a rowCount.
 java.lang.Object getValueAt(int row, int column)
          Returns the value of the specified row and the specified column from within the resultset.
 void updateResultSet(java.sql.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
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

ScrollableResultSetTableModel

public ScrollableResultSetTableModel(java.sql.ResultSet resultset)
                              throws java.sql.SQLException
Constructs the model.

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

ScrollableResultSetTableModel

protected ScrollableResultSetTableModel()
Default constructor.

Method Detail

updateResultSet

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

Parameters:
resultset - the new result set.
Throws:
java.sql.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 javax.swing.table.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 javax.swing.table.TableModel
Returns:
the column count.
See Also:
ResultSetMetaData.getColumnCount()

getColumnName

public java.lang.String getColumnName(int column)
Returns the columnLabel for the given column.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Parameters:
column - the column index.
Returns:
the column name.
See Also:
ResultSetMetaData.getColumnLabel(int)

getValueAt

public java.lang.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 javax.swing.table.TableModel
Parameters:
row - the row index.
column - the column index.
Returns:
the value.

getColumnClass

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

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Parameters:
column - the column index.
Returns:
the column class.

getColumnClassName

public java.lang.String getColumnClassName(int column)
Returns the classname of the resultset column. Returns Object.class if an error occurred.

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