|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnextapp.echo2.app.table.AbstractTableModel
com.sptci.echo2.table.AbstractTableModel<RowSet>
com.sptci.echo2.table.RowSetTableModel
com.sptci.echo2.table.DatabaseTableModel
public class DatabaseTableModel
A custom TableModel used to represent
data contained in in a database table.
Note: This class requires quite a lot of configuration prior
to initialisation. Hence no convenient constructor's are provided. You
must configure the model as appropriate and invoke the init()
method. The following shows sample code for initialising this model:
import com.sptci.echo2.table.DatabaseTableModel;
import com.sptci.echo2.table.RowSetTable;
import com.sptci.echo2.table.TableNavigation;
...
List columns = new ArrayList();
columns.add( "col1" );
columns.add( "col2" );
List order = new ArrayList();
order.add( "col2 desc" );
DatabaseTableModel model = new DatabaseTableModel();
model.setDisplayColumns( columns );
model.setSchema( null );
model.setTable( "table1" );
model.setDataSourceName( "java:/comp/env/jdbc/db" );
model.setPrefix( "table1.headings" );
model.setPageSize( 10 );
model.setOrderBy( order );
try
{
model.init();
}
catch ( Throwable t )
{
// Handle exception
}
© Copyright 2007 Sans Pareil Technologies, Inc.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.sptci.echo2.table.SortableTableModel |
|---|
SortableTableModel.Direction |
| Field Summary | |
|---|---|
protected DataSource |
dataSource
The DataSource to use to fetch data. |
protected String |
dataSourceName
The JNDI name of the DataSource to use to fetch data. |
protected List<String> |
displayColumns
The list of columns that are to be displayed in the model. |
protected boolean |
initialised
A flag used to indicate whether the model has been initialised. |
protected List<String> |
orderBy
The list of columns to order the table data by. |
protected int |
page
The current page being displayed in the table. |
protected int |
pageSize
The number of rows to display on one page. |
protected List<String> |
primaryKeys
The list of primary key columns for the table. |
protected String |
schema
The name of database schema in which the table exists. |
protected String |
table
The name of the database table to represent in the model. |
protected int |
totalRows
The total number of records available in the database. |
| Fields inherited from class com.sptci.echo2.table.RowSetTableModel |
|---|
columns, prefix, rowCount, rowSet |
| Fields inherited from class com.sptci.echo2.table.AbstractTableModel |
|---|
sortDirection, sortIndex |
| Constructor Summary | |
|---|---|
DatabaseTableModel()
Default constructor. |
|
| Method Summary | |
|---|---|
protected void |
fetchData()
Fetch the data from table. |
String |
getDataSourceName()
Returns dataSourceName. |
List<String> |
getDisplayColumns()
Returns displayColumns. |
List<String> |
getOrderBy()
Returns orderBy. |
int |
getPage()
Returns page. |
int |
getPageSize()
Returns pageSize. |
List<String> |
getPrimaryKeys()
Returns primaryKeys list of primary key column names. |
String |
getSchema()
Returns schema. |
String |
getTable()
Returns table. |
int |
getTotalPages()
Return the total number of pages that may be displayed by fetching records from table. |
void |
init()
Intialise this table model with data from the table. |
protected void |
introspect()
Introspect the table and determine its primary key columns. |
protected void |
processColumns()
Process the RowSetMetaData associated with
RowSetTableModel.rowSet and populate RowSetTableModel.columns. |
void |
setDataSourceName(String dataSourceName)
Sets dataSourceName. |
void |
setDisplayColumns(List<String> columns)
Sets displayColumns. |
void |
setOrderBy(List<String> order)
Sets orderBy. |
void |
setPage(int page)
Sets the value of page. |
void |
setPageSize(int pageSize)
Sets the value of pageSize. |
void |
setSchema(String schema)
Sets the schema in which the table represented by
this model exists. |
void |
setTable(String table)
Sets the name of the table to represent in this model. |
void |
sort(int column)
Sort the data displayed in the table by the specified column. |
void |
sort(int column,
SortableTableModel.Direction direction)
Sort the data displayed in the table by the specified column. |
| Methods inherited from class com.sptci.echo2.table.RowSetTableModel |
|---|
addRow, deleteRow, dispose, getColumnClass, getColumnCount, getColumnName, getObjectAt, getPrefix, getRowCount, getValueAt, setColumn, setPrefix, setRowCount, setRowCount, updateRow |
| Methods inherited from class com.sptci.echo2.table.AbstractTableModel |
|---|
getSortDirection |
| Methods inherited from class nextapp.echo2.app.table.AbstractTableModel |
|---|
addTableModelListener, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getEventListenerList, removeTableModelListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.sptci.echo2.table.SortableTableModel |
|---|
getSortDirection |
| Field Detail |
|---|
protected String schema
table exists.
protected String table
protected String dataSourceName
DataSource to use to fetch data.
protected DataSource dataSource
DataSource to use to fetch data.
protected int totalRows
protected final List<String> displayColumns
protected final List<String> primaryKeys
table.
protected final List<String> orderBy
protected int page
protected int pageSize
TableNavigation.MINIMUM_PAGE_SIZE
protected boolean initialised
| Constructor Detail |
|---|
public DatabaseTableModel()
init() method.
| Method Detail |
|---|
public void init()
throws RuntimeException
table.
init in class RowSetTableModelRuntimeException - If a NamingException or
SQLException are encountered while initialising
dataSource or RowSetTableModel.rowSet.introspect(),
fetchData(),
processColumns(),
RowSetTableModel.setRowCount()
protected void introspect()
throws SQLException
table and determine its primary key columns.
SQLException - If errors are encountered while introspecting the
table.DatabaseHelper.getPrimaryKeys(javax.sql.DataSource, java.lang.String, java.lang.String)
protected void fetchData()
throws SQLException
table. If RowSetTableModel.columns have been
specified, only data from those columns will be retrieved. All
columns in primaryKeys will be retrieved regardless of whether
they are specified in RowSetTableModel.columns or not.
SQLException - If errors are encountered while fetching data from
the table.RowSetTableModel.setRowCount(),
DatabaseHelper.getData(java.lang.String, javax.sql.DataSource, java.lang.String, java.util.List, int, int) ,
AbstractTableModel.fireTableDataChanged()
protected void processColumns()
throws SQLException
RowSetMetaData associated with
RowSetTableModel.rowSet and populate RowSetTableModel.columns. Over-ridden to process
only columns specified in displayColumns if specified.
processColumns in class RowSetTableModelSQLException - If errors are encountered while introspecting the
meta data.
public void sort(int column)
throws RuntimeException
table ordered by the specified
column.
sort in interface SortableTableModelcolumn - The index of the column in RowSetTableModel.columns by which
to order the results.
RuntimeException - If errors are encountered while fetching
the data.SortableTableModel.sort( int ),
AbstractTableModel.getSortDirection(int),
SortableTableModel.sort( int, Direction )
public void sort(int column,
SortableTableModel.Direction direction)
throws RuntimeException
table ordered by the specified
column. The page is set to point to the first page of
data since the re-sorted data will usually have no reference to the
original data.
sort in interface SortableTableModelcolumn - The index of the column in RowSetTableModel.columns by which
to order the results.direction - The direction in which to sort the data.
RuntimeException - If errors are encountered while fetching
the data.SortableTableModel.sort( int, Direction ),
fetchData()public int getPage()
page.
getPage in interface PageableTableModelPageableTableModel.getPage()public void setPage(int page)
page.
setPage in interface PageableTableModelpage - The current page of data to load in the model.
RuntimeException - If SQLException is raised
by fetchData().PageableTableModel.setPage(int),
fetchData()public int getPageSize()
pageSize.
getPageSize in interface PageableTableModelPageableTableModel.getPageSize()public void setPageSize(int pageSize)
pageSize.
setPageSize in interface PageableTableModelpageSize - The number of rows to display in the model.
RuntimeException - If SQLException is raised
by fetchData().PageableTableModel.setPageSize(int),
fetchData()public int getTotalPages()
table.
getTotalPages in interface PageableTableModelpublic List<String> getDisplayColumns()
displayColumns.
public void setDisplayColumns(List<String> columns)
displayColumns. Note that this cannot be set after the
model is initialised through init().
columns - The list of columns to display.public List<String> getPrimaryKeys()
primaryKeys list of primary key column names.
public String getDataSourceName()
dataSourceName.
public void setDataSourceName(String dataSourceName)
dataSourceName.
dataSourceName - The JNDI resource name.public String getSchema()
schema.
public void setSchema(String schema)
schema in which the table represented by
this model exists.
schema - The name of the schema.public String getTable()
table.
public void setTable(String table)
table to represent in this model.
table - The name of the table.public List<String> getOrderBy()
orderBy.
public void setOrderBy(List<String> order)
throws SQLException
orderBy. This method may be invoked after initialising
the model to resort the results.
order - The list of order by clauses.
SQLException - If errors are encountered while refetching the
data from the table.
|
SPT Core API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||