|
Copyright © 2005 Scientific Applications. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
com.sciapp.table.db.AbstractDatabaseTableModel
com.sciapp.table.db.DefaultDatabaseTableModel
public class DefaultDatabaseTableModel
DefaultDatabaseTableModel uses a Connection
to connect to a database.
The column names and their java types can be specified via a String and a class array
respectively. Alternatively, this information can also be provided by a TableModel
or a DatabaseTableDefinition
.
DefaultDatabaseTableModel uses simple sql select statements to retrieve the database data. A "select count(*) from table" is used to get the row count, while a "limit" keyword is used to retrieve a given row or rows.
The "where" clause is constructed from the FilterTableModel instance, with the help
of a SQLFilterConverter
, while the "order by" clause from the SortTableModel instance.
DefaultDatabaseTableModel was extensively tested under MYSQL v4.0, 4.1 and 5.0, with complete success. It should work with other databases as well, at least those that support the 'limit' keyword. For databases that do not, you can try turning on cursors, by calling setCursors(true).
Field Summary | |
---|---|
protected Connection |
c
The current connection to the database |
protected SQLFilterConverter |
converter
utility class that converts a TableFilter to an sql 'where' clause. |
protected boolean |
cursors
boolean indicating if a cursor will be used to fetch data from the database. |
protected DatabaseTableDefinition |
definition
the database definition. |
protected String |
joinStatement
a string representing the table or tables and the criteria (if any) that will be used to fetch the database data. |
protected String |
orderSQL
a string which is used to hold the order byclause of the sql statement |
protected String |
whereSQL
a string which is used to hold the where clause of the sql statement |
Fields inherited from class com.sciapp.table.db.AbstractDatabaseTableModel |
---|
cache, dbFilter, dbSorter, rangedModel, rowCount |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
DefaultDatabaseTableModel(Connection c,
String joinStatement,
DatabaseTableDefinition def)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTableModel(Connection c,
String table,
String[] columns)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTableModel(Connection c,
String table,
String[] columns,
Class[] classes)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTableModel(Connection c,
String table,
TableModel model)
Constructs a DefaultDatabaseTableModel. |
Method Summary | |
---|---|
Class |
getColumnClass(int column)
Returns Object.class regardless of columnIndex . |
int |
getColumnCount()
Returns the number of columns in the model. |
String |
getColumnName(int column)
Returns a default name for the column using spreadsheet conventions: A, B, C, ... Z, AA, AB, etc. If column cannot be found,
returns an empty string. |
SQLFilterConverter |
getSQLFilterConverter()
Returns the object that will be used to convert a TableFilter to an sql 'where' clause. |
void |
orderByClause()
This method is called whenever sorting is requested. |
int |
readRowCount()
Reads and returns the row count from the underlying data source. |
protected String |
readRowCountStatement()
Retrieves the sql statement for the readRowCount method. |
List |
retrieveRows(int from,
int to)
Fetches multiple rows from the underlying data source. |
protected String |
retrieveRowsStatement(int from,
int to)
Retrieves the sql statement for the retrieveRows method. |
void |
setCursors(boolean useCursors)
Tells DefaultDatabaseTreeTableModel to use cursors when fetching a range of rows from the database. |
void |
setSQLFilterConverter(SQLFilterConverter converter)
Assigns the object that will be used to convert a TableFilter to an sql 'where' clause. |
void |
whereClause()
This method is called whenever filtering is requested. |
Methods inherited from class com.sciapp.table.db.AbstractDatabaseTableModel |
---|
fireTableChanged, getCache, getFilterTableModel, getRowCount, getSortTableModel, getUncachedRows, getValueAt, isCountCached, isRangedModel, isValueCached, retrieveFromDB, retrieveFromDB, setCache, setRangedModel |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, 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 |
Methods inherited from interface javax.swing.table.TableModel |
---|
addTableModelListener, isCellEditable, removeTableModelListener, setValueAt |
Field Detail |
---|
protected String joinStatement
protected transient SQLFilterConverter converter
TableFilter
to an sql 'where' clause.
protected DatabaseTableDefinition definition
protected boolean cursors
protected transient Connection c
protected String whereSQL
protected String orderSQL
Constructor Detail |
---|
public DefaultDatabaseTableModel(Connection c, String table, String[] columns)
public DefaultDatabaseTableModel(Connection c, String table, String[] columns, Class[] classes)
public DefaultDatabaseTableModel(Connection c, String joinStatement, DatabaseTableDefinition def)
c
- the database connectionjoinStatement
- a string epresenting the table or tables and the criteria (if any) that will be used to fetch the database data.def
- the column defintionpublic DefaultDatabaseTableModel(Connection c, String table, TableModel model)
Method Detail |
---|
public Class getColumnClass(int column)
Object.class
regardless of columnIndex
.
getColumnClass
in interface TableModel
getColumnClass
in class AbstractDatabaseTableModel
column
- the column being queried
public int getColumnCount()
JTable
uses this method to determine how many columns it
should create and display by default.
TableModel.getRowCount()
public String getColumnName(int column)
column
cannot be found,
returns an empty string.
getColumnName
in interface TableModel
getColumnName
in class AbstractDatabaseTableModel
column
- the column being queried
column
public SQLFilterConverter getSQLFilterConverter()
public void orderByClause()
orderByClause
in class AbstractDatabaseTableModel
public int readRowCount()
protected String readRowCountStatement()
readRowCount
method.
public List retrieveRows(int from, int to)
from
- the starting rowto
- the ending row
protected String retrieveRowsStatement(int from, int to)
retrieveRows
method.
from
- the starting rowto
- the ending row
public void setCursors(boolean useCursors)
useCursors
- true if cursors are to be used.public void setSQLFilterConverter(SQLFilterConverter converter)
converter
- the sql filter converter to assign.public void whereClause()
whereClause
in class AbstractDatabaseTableModel
|
Copyright © 2005 Scientific Applications. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |