Holger's Java API

## com.antelmann.sql
Class ResultSetTableModel

    java.lang.Object
      javax.swing.table.AbstractTableModel
          com.antelmann.sql.ResultSetTableModel

All Implemented Interfaces:
  Refreshable, ObjectTableModel<RowItem>, Wrapped<ResultSet>, Serializable, TableModel

    public class ResultSetTableModel

extends AbstractTableModel
implements ObjectTableModel<RowItem>, Wrapped<ResultSet>

ResultSetTableModel provides a convenient way to display (or otherwise use) a query result in table format. SQLExceptions that might occur are wrapped into RuntimeExceptions.

Since:
  10/24/2002
Author:
  Holger Antelmann
See Also:
  `JTable`, `JDBCTableModel`, Serialized Form

Field Summary

Fields inherited from class javax.swing.table.AbstractTableModel
`listenerList`

Constructor Summary
`ResultSetTableModel(ResultSet rs)` the result set must NOT be of type ResultSet.TYPE_FORWARD_ONLY
`ResultSetTableModel(ResultSet rs, String idField)`

Method Summary
`Class<?>` `getColumnClass(int column)`
`int` `getColumnCount()`
`String` `getColumnName(int column)`
`String` `getIdField()`
`ResultSet` `getResultSet()`
`RowItem` `getRow(int row)` this only works if the idField has been set correctly
`int` `getRowCount()`
`int` `getRowFor(RowItem entry)` only works if the idField is set
`RowItem` `getRowValue(int row)` retrieves the value that is represented by the given row in this model.
`Object` `getValueAt(int row, int column)`
`boolean` `isCellEditable(int row, int column)`
`boolean` `isEditable()` determines whether the embedded ResultSet allows updates
`boolean` `isInsertMode()`
`ResultSet` `refresh(ResultSet rs, String idField)` returns the previous ResultSet so that it can be closed according to the application needs
`void` `refreshContent()` refreshes the embedded content
`void` `setIdField(String idField)`
`void` `setInsertMode(boolean flag)`
`void` `setRowValues(Iterable<? extends RowItem> updatedList)` allows to change the underlying table data based on the given collection.
`void` `setValueAt(Object value, int row, int column)` the display after update doesn't work well for e.g.
`ResultSet` `unwrap()` returns the embedded instance that this wrapper encloses

Methods inherited from class javax.swing.table.AbstractTableModel
`addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener`

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, removeTableModelListener`

Constructor Detail

### ResultSetTableModel

    public ResultSetTableModel(ResultSet rs)
                        throws SQLException

  the result set must NOT be of type ResultSet.TYPE_FORWARD_ONLY

  Throws:
    `SQLException`

### ResultSetTableModel

    public ResultSetTableModel(ResultSet rs,
                               String idField)
                        throws SQLException

Throws:
  `SQLException`

Method Detail

### unwrap

    public ResultSet unwrap()

  Description copied from interface: `Wrapped`
  returns the embedded instance that this wrapper encloses

  Specified by:
    `unwrap` in interface `Wrapped<ResultSet>`

### refreshContent

    public void refreshContent()
                        throws IOException

  Description copied from interface: `Refreshable`
  refreshes the embedded content

  Specified by:
    `refreshContent` in interface `Refreshable`
  Throws:
    `IOException` - if the refresh failed

### refresh

    public ResultSet refresh(ResultSet rs,
                             String idField)
                      throws SQLException

  returns the previous ResultSet so that it can be closed according to the application needs

  Throws:
    `SQLException`

### getIdField

    public String getIdField()

### setIdField

    public void setIdField(String idField)

### getRow

    public RowItem getRow(int row)
                   throws SQLException

  this only works if the idField has been set correctly

  Throws:
    `SQLException`

### getResultSet

    public ResultSet getResultSet()

### isEditable

    public boolean isEditable()
                       throws RuntimeException

  determines whether the embedded ResultSet allows updates

  Throws:
    `RuntimeException`

### isInsertMode

    public boolean isInsertMode()

### setInsertMode

    public void setInsertMode(boolean flag)

### getRowCount

    public int getRowCount()

  Specified by:
    `getRowCount` in interface `TableModel`

### getColumnCount

    public int getColumnCount()
                       throws RuntimeException

  Specified by:
    `getColumnCount` in interface `TableModel`
  Throws:
    `RuntimeException`

### getValueAt

    public Object getValueAt(int row,
                             int column)
                      throws RuntimeException

  Specified by:
    `getValueAt` in interface `TableModel`
  Throws:
    `RuntimeException`

### getColumnName

    public String getColumnName(int column)

  Specified by:
    `getColumnName` in interface `TableModel`
  Overrides:
    `getColumnName` in class `AbstractTableModel`

### getColumnClass

    public Class<?> getColumnClass(int column)

  Specified by:
    `getColumnClass` in interface `TableModel`
  Overrides:
    `getColumnClass` in class `AbstractTableModel`

### isCellEditable

    public boolean isCellEditable(int row,
                                  int column)

  Specified by:
    `isCellEditable` in interface `TableModel`
  Overrides:
    `isCellEditable` in class `AbstractTableModel`

### setValueAt

    public void setValueAt(Object value,
                           int row,
                           int column)
                    throws RuntimeException

  the display after update doesn't work well for e.g. String and Boolean, I'm afraid

  Specified by:
    `setValueAt` in interface `TableModel`
  Overrides:
    `setValueAt` in class `AbstractTableModel`
  Throws:
    `RuntimeException`

### getRowValue

    public RowItem getRowValue(int row)

  Description copied from interface: `ObjectTableModel`
  retrieves the value that is represented by the given row in this model. If the given row does not exist in the model, various RuntimeExceptions may occur.

  Specified by:
    `getRowValue` in interface `ObjectTableModel<RowItem>`
  Returns:
    the Object value representing the given row

### getRowFor

    public int getRowFor(RowItem entry)

  only works if the idField is set

  Specified by:
    `getRowFor` in interface `ObjectTableModel<RowItem>`
  Returns:
    the row where the entry is found in the model or -1 if the entry doesn't exist in this model

### setRowValues

    public void setRowValues(Iterable<? extends RowItem> updatedList)
                      throws UnsupportedOperationException

  Description copied from interface: `ObjectTableModel`
  allows to change the underlying table data based on the given collection. Unless specified otherwise, the given collection remains untouched and the elements are copied into the internal data structure of the model.

  Specified by:
    `setRowValues` in interface `ObjectTableModel<RowItem>`
  Throws:
    `UnsupportedOperationException` - if this model doesn't allow such changes

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads