public class IlvRowSetTableModel extends AbstractTableModel implements IlvTableModel
IlvRowSetTableModel
is an implementation of the Swing
TableModel
that connects to a RowSet
. A
RowSet
usually corresponds to results of a database query which
means this class allows the model to be connected to a database. This
implementation allows both read and write operations on the
TableModel
if the underlying RowSet
is not
readonly. For that purpose IlvRowSetTableModel
also implements
IlvTableModel
and fires events provided by
IlvTableModelEvent
to correctly warn listeners a
modification is going to happen. If caching is needed one can use an
implementation of CachedRowSet
instead of a regular
RowSet
as data provider.listenerList
Constructor and Description |
---|
IlvRowSetTableModel()
Builds an
IlvRowSetTableModel instance to be initialized later
on with a call to setRowSet(RowSet) . |
IlvRowSetTableModel(boolean autocommit)
Builds a
IlvRowSetTableModel instance to be initialized later on
with a call to setRowSet(RowSet) . |
IlvRowSetTableModel(RowSet rowSet)
Builds and initializes a
IlvRowSetTableModel instance. |
IlvRowSetTableModel(RowSet rowSet,
boolean autocommit)
Builds and initializes a
IlvRowSetTableModel instance. |
Modifier and Type | Method and Description |
---|---|
void |
addRow(Object[] rowData)
Adds a row.
|
void |
commit()
Tries to commit the rows content modifications that occur since last commit
to the back end.
|
static RowSet |
createRowSet(Connection connection,
String command,
boolean readonly,
int pageSize)
Creates a
RowSet instance with the given parameters that can be
used by a IlvRowSetTableModel . |
static RowSet |
createRowSet(Connection connection,
String command,
Object[] parameters,
boolean readonly,
int pageSize)
Creates a
RowSet instance with the given parameters that can be
used by a IlvRowSetTableModel . |
static RowSet |
createRowSet(ResultSet resultSet,
int pageSize)
Creates a
RowSet instance with the given parameters that can be
used by a IlvRowSetTableModel . |
static RowSet |
createRowSet(String url,
String username,
String password,
String command,
boolean readonly,
int pageSize)
Creates a
RowSet instance with the given parameters that can be
used by a IlvRowSetTableModel . |
static RowSet |
createRowSet(String url,
String username,
String password,
String command,
Object[] parameters,
boolean readonly,
int pageSize)
Creates a
RowSet instance with the given parameters that can be
used by a IlvRowSetTableModel . |
Class<?> |
getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.
|
int |
getColumnCount()
Returns the number of columns in this table model.
|
String |
getColumnName(int columnIndex)
Returns the name of the column at index
columnIndex . |
int |
getRowCount()
Returns the number of row in this table model.
|
RowSet |
getRowSet()
Returns the
RowSet that is connected to this
IlvRowSetTableModel . |
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value at the specified indexes.
|
void |
insertRow(int rowIndex,
Object[] rowData)
Deprecated.
use
addRow(Object[]) instead. |
boolean |
isAutoCommit()
Returns whether or not the
RowSet will use auto commit. |
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns whether or not the given cell is editable.
|
void |
refreshRows()
Tries to refresh the rows content from the back end.
|
void |
removeRow(int rowIndex)
Removes the row at
row from the model. |
void |
rollback()
Tries to rollback the rows to the content they have last time a commit
occurred.
|
void |
setAutoCommit(boolean value)
Tries to override whether or not the
RowSet will use auto
commit. |
void |
setRowSet(RowSet rowSet)
Initializes the
IlvRowSetTableModel instance with the given
RowSet . |
void |
setValueAt(Object value,
int rowIndex,
int columnIndex)
Sets the value at the specified indexes.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addTableModelListener, removeTableModelListener
public IlvRowSetTableModel()
IlvRowSetTableModel
instance to be initialized later
on with a call to setRowSet(RowSet)
.public IlvRowSetTableModel(RowSet rowSet) throws SQLException
IlvRowSetTableModel
instance. No
autocommit will be performed so commit()
must be called when needed.
Once the RowSet
has been passed to the
IlvRowSetTable
, user must not interact with it anymore. If
caching is needed one can use an implementation of CachedRowSet
instead of a regular RowSet
.rowSet
- the RowSet
used to populate the
TableModel
SQLException
- if a problem occurs with the RowSet
setRowSet(RowSet)
public IlvRowSetTableModel(boolean autocommit)
IlvRowSetTableModel
instance to be initialized later on
with a call to setRowSet(RowSet)
.autocommit
- whether or not the IlvRowSetTableModel
will be in
auto commit mode.public IlvRowSetTableModel(RowSet rowSet, boolean autocommit) throws SQLException
IlvRowSetTableModel
instance. Once the
RowSet
has been passed to the IlvRowSetTable
, user
must not interact with it anymore. If caching is needed one can use an
implementation of CachedRowSet
instead of a regular
RowSet
.rowSet
- the RowSet
used to populate the
TableModel
autocommit
- whether or not the IlvRowSetTableModel
will be in
auto commit mode.SQLException
- if a problem occurs with the RowSet
setRowSet(RowSet)
,
setAutoCommit(boolean)
public final void setRowSet(RowSet rowSet) throws SQLException
IlvRowSetTableModel
instance with the given
RowSet
. Once the RowSet
has been passed to this
method, user must not interact with it anymore. If caching is needed one can
use an implementation of CachedRowSet
instead of a regular
RowSet
. To fully benefit from disconnected caching the
CachedRowSet
must not be populated using
CachedRowSet.populate()
method but by correctly setting
connection and query parameters on the CachedRowSet
or by
calling createRowSet(String, String, String, String, boolean, int)
or
createRowSet(String, String, String, String, Object[], boolean, int)
. The RowSet
is never closed by IlvRowSetTableModel
and must thus be closed by the user when not needed anymore.rowSet
- the RowSet
used to populate the
TableModel
SQLException
- if a problem occurs with the RowSet
createRowSet(String, String, String, String, boolean, int)
,
createRowSet(String, String, String, String, Object[], boolean, int)
public final RowSet getRowSet()
RowSet
that is connected to this
IlvRowSetTableModel
. User must not interact with that
RowSet
.RowSet
public void setAutoCommit(boolean value) throws SQLException
RowSet
will use auto
commit. This works only with RowSet
that supports this features
(i.e. JdbcRowSet
or CachedRowSet
). In auto commit
mode IlvRowSetTableModel
will automatically commit
modifications. Otherwise it will wait for a call to
commit()
. Be careful if you are sharing a
Connection
among different JdbcRowSet
this call may
affect several of them and thus it is not recommended to change it.value
- whether or not the RowSet
use auto commit.SQLException
isAutoCommit()
public boolean isAutoCommit()
RowSet
will use auto commit. In auto
commit mode IlvRowSetTableModel
will automatically commit
modifications. Otherwise it will wait for a call to
commit()
. The default values is
false
.setAutoCommit(boolean)
public void refreshRows() throws SQLException
RowSet
has not been fully configured with the
connection and query parameters. For example RowSet
created from
createRowSet(ResultSet, int)
cannot be refreshed while the ones
created from
createRowSet(String, String, String, String, boolean, int)
or
createRowSet(String, String, String, String, Object[], boolean, int)
can.SQLException
- if the refresh operation is not possiblepublic void commit() throws SQLException
RowSet
doesn't support commit.SQLException
- if commit is not possibleSyncProviderException
- if conflicts occurisAutoCommit()
public void rollback() throws SQLException
RowSet
doesn't support rollback. When the
RowSet
is a CachedRowSet
in page mode (i.e.
CachedRowSet.getPageSize()
returns a value different from
0
), this method throws an exception as rollback is not possible.
When the RowSet
has not been fully configured with the
connection and query parameters, for example when the RowSet
is
created from createRowSet(ResultSet, int)
, this method throws an
exception as rollback is not possible.SQLException
- if rollback is not possiblecommit()
,
isAutoCommit()
public int getRowCount()
getRowCount
in interface TableModel
public int getColumnCount()
getColumnCount
in interface TableModel
public String getColumnName(int columnIndex)
columnIndex
.getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
public Class<?> getColumnClass(int columnIndex)
JTable
to set up a default renderer and
editor for the column.getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
columnIndex
- the index of the columnpublic Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface TableModel
public boolean isCellEditable(int rowIndex, int columnIndex)
RowSet
is read-only this will always return false
.isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
public void setValueAt(Object value, int rowIndex, int columnIndex)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
public void addRow(Object[] rowData)
null
values unless
rowData
is specified. Notification of the row being added will
be generated.addRow
in interface IlvTableModel
rowData
- optional data of the row being added@Deprecated public void insertRow(int rowIndex, Object[] rowData)
addRow(Object[])
instead.null
values
unless rowData
is specified. Notification of the row being added
will be generated. In IlvRowSetTableModel
implementation this
method just calls addRow(Object[])
.insertRow
in interface IlvTableModel
rowIndex
- the row index of the row to be inserted, because of a limitation
of most RowSet
implementations that row index will be
ignored and the insertion my occur any place. In most
RowSet
implementations, insertion occurs at the end
of the model.rowData
- optional data of the row being addedArrayIndexOutOfBoundsException
- if the row was invalidpublic void removeRow(int rowIndex)
row
from the model. Notification of the row
being removed will be sent to all the listeners.removeRow
in interface IlvTableModel
rowIndex
- the row index of the row to be removedArrayIndexOutOfBoundsException
- if the row was invalidpublic static RowSet createRowSet(String url, String username, String password, String command, boolean readonly, int pageSize) throws SQLException
RowSet
instance with the given parameters that can be
used by a IlvRowSetTableModel
. Auto commit mode can be set later
on using setAutoCommit(boolean)
. url
- the database url to which the RowSet
must connect to.username
- the username for the database connection.password
- the password for the database connection.command
- the SQL command that will be executed to retrieve the rows.readonly
- whether or not the RowSet
and thus the
IlvRowSetTableModel
will accept modifications.pageSize
- one of the following values:
0
if no caching of the data must be performed
Integer.MAX_VALUE
if full caching of the data
must be performedRowSet
SQLException
public static RowSet createRowSet(String url, String username, String password, String command, Object[] parameters, boolean readonly, int pageSize) throws SQLException
RowSet
instance with the given parameters that can be
used by a IlvRowSetTableModel
. Auto commit mode can be set later
on using setAutoCommit(boolean)
. url
- the database url to which the RowSet
must connect to.username
- the username for the database connection.password
- the password for the database connection.command
- the SQL command that will be executed to retrieve the rows.parameters
- parameters for the SQL command, or null
for none.readonly
- whether or not the RowSet
and thus the
IlvRowSetTableModel
will accept modifications.pageSize
- one of the following values:
0
if no caching of the data must be performed
Integer.MAX_VALUE
if full caching of the data
must be performedRowSet
SQLException
public static RowSet createRowSet(Connection connection, String command, boolean readonly, int pageSize) throws SQLException
RowSet
instance with the given parameters that can be
used by a IlvRowSetTableModel
. Auto commit mode can be set later
on using setAutoCommit(boolean)
.connection
- the connection to the database.command
- the SQL command that will be executed to retrieve the rows.readonly
- whether or not the RowSet
and thus the
IlvRowSetTableModel
will accept modifications.pageSize
- one of the following values:
0
if no caching of the data must be performed
Integer.MAX_VALUE
if full caching of the data
must be performedRowSet
SQLException
public static RowSet createRowSet(Connection connection, String command, Object[] parameters, boolean readonly, int pageSize) throws SQLException
RowSet
instance with the given parameters that can be
used by a IlvRowSetTableModel
. Auto commit mode can be set later
on using setAutoCommit(boolean)
.connection
- the connection to the database.command
- the SQL command that will be executed to retrieve the rows.parameters
- parameters for the SQL command, or null
for none.readonly
- whether or not the RowSet
and thus the
IlvRowSetTableModel
will accept modifications.pageSize
- one of the following values:
0
if no caching of the data must be performed
Integer.MAX_VALUE
if full caching of the data
must be performedRowSet
SQLException
public static RowSet createRowSet(ResultSet resultSet, int pageSize) throws SQLException
RowSet
instance with the given parameters that can be
used by a IlvRowSetTableModel
. Auto commit mode can be set later
on using setAutoCommit(boolean)
.
refreshRows()
and
rollback()
don't work with RowSet
created that way. If caching is not used the read-only status will depend on
whether or not the ResultSet
is updateable. If caching is used
such a RowSet
can only be read-only.resultSet
- the ResultSet
that contains the data. This
ResultSet
must not be of type
ResultSet.TYPE_FORWARD_ONLY
.pageSize
- one of the following values:
0
if no caching of the data must be performed
Integer.MAX_VALUE
if full caching of the data
must be performedRowSet
SQLException
- if it is impossible to create the RowSet
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.