|
Copyright © 2011 Citra Technologies. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.citra.treetable.AbstractTreeTableModel
com.citra.treetable.db.AbstractDatabaseTreeTableModel
com.citra.treetable.db.DefaultDatabaseTreeTableModel
public class DefaultDatabaseTreeTableModel
DefaultDatabaseTreeTableModel provides grouping for a DatabaseTreeTableModel with the help of a set of column indexes. These indexes refer to the database columns as they are defined in the model.
This class uses a Connection
object to connect to the 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.
DefaultDatabaseTreeTableModel 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).
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.citra.treetable.db.AbstractDatabaseTreeTableModel |
---|
AbstractDatabaseTreeTableModel.DefaultTreeTableAggregateRowCache |
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 TreeTableCache |
groupCache
the object that is used to cache the GROUP values of the tree's nodes. |
protected String |
orderSQL
a string which is used to hold the order byclause of the sql statement |
protected String |
table
string that holds the name of the table to query |
protected String |
whereSQL
a string which is used to hold the where clause of the sql statement |
Fields inherited from class com.citra.treetable.db.AbstractDatabaseTreeTableModel |
---|
aggregateRowCache, aggregator, cache, dbFilter, dbSorter |
Fields inherited from class com.citra.treetable.AbstractTreeTableModel |
---|
listenerList, root |
Fields inherited from interface com.citra.treetable.TreeTableModel |
---|
CHANGE_COLUMN_SOURCE |
Fields inherited from interface com.citra.treetable.TreeTableModel |
---|
CHANGE_COLUMN_SOURCE |
Constructor Summary | |
---|---|
DefaultDatabaseTreeTableModel(Connection c,
String table,
DatabaseTableDefinition def)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTreeTableModel(Connection c,
String table,
DatabaseTableDefinition def,
TreeTableCache groupCache)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTreeTableModel(Connection c,
String table,
String[] columns)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTreeTableModel(Connection c,
String table,
String[] columns,
Class[] classes)
Constructs a DefaultDatabaseTableModel. |
|
DefaultDatabaseTreeTableModel(Connection c,
String table,
TableModel model)
Constructs a DefaultDatabaseTableModel. |
Method Summary | |
---|---|
protected DatabaseAggregator |
createDefaultAggregator()
Creates and returns the default aggregator. |
protected TreeTableRow |
createTableRow(TreeTableRow ttr,
int index)
Creates and returns a TreeTableRow for the node parent at its
child index identified by index . |
List |
fetchChildren(Object parentNode,
int from,
int to)
This method retrieves the data from the database for the children of parent
in the range from - to . |
protected String |
fetchChildrenStatement(Object parentNode,
int from,
int to)
Retrieves the sql statement for the fetchChildren method. |
int |
fetchGroupCount(Object n)
This method retrieves the aggregate values for the children of parent
in the range from - to , and assigns them on the treeModel. |
protected String |
fetchGroupCountStatement(Object node)
Retrieves the sql statement for the fetchGroupCount method. |
List |
fetchGroups(Object parentNode,
int from,
int to)
This method retrieves the group values from the database for the children of parent
in the range from - to . |
List |
fetchGroups(Object parentNode,
int from,
int to,
String[] selectExpr)
A utility method to fetch group values from the database. |
protected String |
fetchGroupsStatement(Object parentNode,
int from,
int to,
String[] selectExpr)
Retrieves the sql statement for the fetchGroups method. |
Class |
getColumnClass(int column)
Returns the class of all the cells in the column. |
int |
getColumnCount()
Returns the number of columns. |
String |
getColumnName(int column)
Returns the name of the column at columnIndex as it will be displayed by the table |
DatabaseTableDefinition |
getDatabaseDefinition()
|
String |
getGroupColumns(int level)
Returns the column or columns that this level is grouped by. |
String |
getGroupCriteria(TreeTableRow node)
Returns a clause that identifies the criteria for the supplied node. |
int[] |
getGroupingColumns()
Returns the group columns as a list array. |
SQLFilterConverter |
getSQLFilterConverter()
Returns the object that will be used to convert a TableFilter to an sql 'where' clause. |
int |
getTotalGroupCount()
Returns the total number of groups defined. |
boolean |
isGroupedBy(TreeTableRow node,
int columnIndex)
Determines whether or not columnIndex at node
was used to group the model. |
void |
orderByClause()
This method is called whenever sorting is requested. |
void |
setCursors(boolean useCursors)
Tells DefaultDatabaseTreeTableModel to use cursors when fetching a range of rows from the database. |
void |
setGroupCache(TreeTableCache newGroupCache)
Assigns a new cache for the the group values of aggregate rows. |
void |
setGroupingColumns(int[] columns)
Assigns a new set of grouping columns. |
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.citra.treetable.db.AbstractDatabaseTreeTableModel |
---|
getAggregator, getChild, getChildCount, getFilterTableModel, getIndexOfChild, getPathToRoot, getPathToRoot, getSortTableModel, getUncachedChildren, getUncachedGroupCount, getUncachedGroups, getValueAt, isCellEditable, isCountCached, isLeaf, isRangedModel, isValueCached, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, retrieveFromDB, retrieveFromDB, setAggregator, setCache, setValueAt, valueForPathChanged |
Methods inherited from class com.citra.treetable.AbstractTreeTableModel |
---|
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeTableStructureChanged, fireTreeTableStructureChanged, getRoot, isAggregate, isFooter, isHeader, removeTreeModelListener, setRoot |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.citra.treetable.TreeTableModel |
---|
isAggregate, isFooter, isHeader |
Methods inherited from interface javax.swing.tree.TreeModel |
---|
addTreeModelListener, getRoot, removeTreeModelListener |
Methods inherited from interface com.citra.treetable.TreeTableModel |
---|
isAggregate, isFooter, isHeader |
Methods inherited from interface javax.swing.tree.TreeModel |
---|
addTreeModelListener, getRoot, removeTreeModelListener |
Field Detail |
---|
protected TreeTableCache groupCache
protected SQLFilterConverter converter
protected DatabaseTableDefinition definition
protected boolean cursors
protected Connection c
protected String table
protected String whereSQL
protected String orderSQL
Constructor Detail |
---|
public DefaultDatabaseTreeTableModel(Connection c, String table, String[] columns)
public DefaultDatabaseTreeTableModel(Connection c, String table, String[] columns, Class[] classes)
public DefaultDatabaseTreeTableModel(Connection c, String table, DatabaseTableDefinition def)
public DefaultDatabaseTreeTableModel(Connection c, String table, DatabaseTableDefinition def, TreeTableCache groupCache)
public DefaultDatabaseTreeTableModel(Connection c, String table, TableModel model)
Method Detail |
---|
protected DatabaseAggregator createDefaultAggregator()
createDefaultAggregator
in class AbstractDatabaseTreeTableModel
protected TreeTableRow createTableRow(TreeTableRow ttr, int index)
parent
at its
child index identified by index
.
createTableRow
in class AbstractDatabaseTreeTableModel
ttr
- the parent nodeindex
- the child index of parent
that we want returned
parent
at index
public List fetchChildren(Object parentNode, int from, int to)
parent
in the range from - to
. The following condition must be true:
from >= to. The List returned must contain the row elements starting at from
.
However, the List may contain less elements than those specified in the range.
parentNode
- the parent nodefrom
- the index of the first childto
- the index of the last child
protected String fetchChildrenStatement(Object parentNode, int from, int to)
fetchChildren
method.
parentNode
- the parent nodefrom
- the index of the first childto
- the index of the last child
public int fetchGroupCount(Object n)
parent
in the range from - to
, and assigns them on the treeModel.
n
- the node to consider
node
protected String fetchGroupCountStatement(Object node)
fetchGroupCount
method.
node
- the node to consider
public List fetchGroups(Object parentNode, int from, int to)
parent
in the range from - to
. The following condition must be true:
from >= to. The List returned must contain the row elements starting at from
.
However, the List may contain less elements than those specified in the range.
parentNode
- the parent nodefrom
- the index of the first childto
- the index of the last child
parent
as a List.public List fetchGroups(Object parentNode, int from, int to, String[] selectExpr)
parentNode
- the parent nodefrom
- the index of the first childto
- the index of the last childselectExpr
- the columns (or functions of columns) to select.
parent
as a List.protected String fetchGroupsStatement(Object parentNode, int from, int to, String[] selectExpr)
fetchGroups
method.
parentNode
- the parent nodefrom
- the index of the first childto
- the index of the last childselectExpr
- the columns (or functions of columns) to select.
public Class getColumnClass(int column)
column
- the index of the column
public int getColumnCount()
public String getColumnName(int column)
column
- the index of the column
public DatabaseTableDefinition getDatabaseDefinition()
public String getGroupColumns(int level)
level
- the current level in the tree
public String getGroupCriteria(TreeTableRow node)
node
- the node to consider
node
public int[] getGroupingColumns()
public SQLFilterConverter getSQLFilterConverter()
public int getTotalGroupCount()
public boolean isGroupedBy(TreeTableRow node, int columnIndex)
columnIndex
at node
was used to group the model.
node
- the node to considercolumnIndex
- the column that was used in grouping
columnIndex
was used in grouping, false otherwisepublic void orderByClause()
orderByClause
in class AbstractDatabaseTreeTableModel
public void setCursors(boolean useCursors)
useCursors
- true if cursors are to be used.public void setGroupCache(TreeTableCache newGroupCache)
newGroupCache
- the new cache to assign.public void setGroupingColumns(int[] columns)
columns
- the new column indexes to group bypublic void setSQLFilterConverter(SQLFilterConverter converter)
converter
- the sql filter converter to assign.public void whereClause()
whereClause
in class AbstractDatabaseTreeTableModel
|
Copyright © 2011 Citra Technologies. All Rights Reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |