|
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.DefaultPivotTableModel
public class DefaultPivotTableModel
DefaultPivotTableModel is the default PivotTableModel implementation to use for cross tab queries.
You need to supply DefaultPivotTableModel with two database table definitions in its sole constructor.
The first (nonPivotDefinition) defines the non-pivot column(s) to display. These are placed to the left
of the model.
The second (functionDefinition) defines the sql group function to evaluate. In this definition,
the getColumnName method refers to the name of the column as it is shown on the table, while its
getDatabaseColumn method should contain the sql group function that will contain the database column
in parentheses.
Example:
Suppose we have the database table with columns (id, company, city, sales, tax, orderDate).
DefaultDatabaseTableDefinition nonPivot;
nonPivot = new DefaultDatabaseTableDefinition(new String[]{"Company Name", "City"}, null, new String[] {"company", "city"});
DefaultDatabaseTableDefinition functions;
functions = new DefaultDatabaseTableDefinition(new String[]{"Yearly sales", "Yearly tax"}, new Class[]{Integer.class, Integer.class}, new String[] { "sum(sales)", "sum(tax)" });
Supposing table is the database table and c the database connection:
DefaultPivotTableModel ptm = new DefaultPivotTableModel(c, nonPivot, functions, "year(orderDate)", table);
If you have more than one function in your function definition, you can also use a GroupTableHeader:
//table is an AdvancedJTable
GroupTableHeader groupHeader = (GroupTableHeader) table.getTableHeader();
ptm.prepareGroupTableHeader(groupHeader);
| Nested Class Summary | |
|---|---|
class |
DefaultPivotTableModel.SQLFilterPivotConverter
SQLFilterConverter should take care of pivot columns. |
| Field Summary | |
|---|---|
protected DatabaseTableDefinition |
aggregateDefinition
the database definition for all the columns. |
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 MeasureDefinition |
functionDefinition
the database definition for the function columns. |
protected String |
havingSQL
a string which is used to hold the havingclause of the sql statement |
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 DatabaseTableDefinition |
nonPivotDefinition
the database definition for the columns that are not pivoted. |
protected String |
orderSQL
a string which is used to hold the order byclause of the sql statement |
protected String[] |
pivotColumns
the pivot columns. |
protected PivotDefinition |
pivotDefinition
the pivot definition |
protected String |
pivotStatement
a string representing the table or tables and the criteria (if any) that will be used to fetch the pivot values. |
protected Object[] |
pivotValues
the pivot values. |
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 | |
|---|---|
DefaultPivotTableModel(Connection c,
DatabaseTableDefinition nonPivotDefinition,
DatabaseTableDefinition functionDefinition,
String pivotColumn,
String table)
Constructs a DefaultPivotTableModel. |
|
DefaultPivotTableModel(Connection c,
DatabaseTableDefinition nonPivotDefinition,
MeasureDefinition functionDefinition,
PivotDefinition pivotDefinition,
String joinStatement,
String pivotStatement)
Constructs a DefaultPivotTableModel. |
|
| Method Summary | |
|---|---|
void |
fireTableChanged(TableModelEvent e)
Forwards the given notification event to all TableModelListeners that registered
themselves as listeners for this table model. |
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. |
String[] |
getPivotColumns()
Returns the pivot columns. |
int |
getRowCount()
Returns the number of rows in the model. A JTable uses this method to determine how many rows it
should display. This method should be quick, as it
is called frequently during rendering. |
Object |
getValueAt(int row,
int column)
Returns the value for the cell at columnIndex and
rowIndex. |
protected void |
initColumns()
Initializes the DefaultPivotTableModel. |
boolean |
isValueCached(int row,
int column)
Determines whether the value at the specified cell has been evaluated. |
void |
orderByClause()
This method is called whenever sorting is requested. |
void |
prepareGroupTableHeader(GroupTableHeader groupableHeader)
Utility method that creates the necessary group table headers according to the definition of this pivot table model. |
int |
readRowCount()
Reads and returns the row count from the underlying data source. |
protected String |
readRowCountStatement()
Retrieves the sql statement for the readRowCount method. |
String[] |
retrievePivotColumns(String pivotColumn)
Retrieves the pivot columns from the underlying data source. |
protected String |
retrievePivotColumnsStatement(String pivotColumn)
Retrieves the sql statement for the retrievePivotColumns 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 DefaultPivotTableModel to use cursors when fetching a range of rows from the database. |
void |
whereClause()
This method is called whenever filtering is requested. |
| Methods inherited from class com.sciapp.table.db.AbstractDatabaseTableModel |
|---|
getCache, getFilterTableModel, getSortTableModel, getUncachedRows, isCountCached, isRangedModel, 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 |
| Field Detail |
|---|
protected String pivotStatement
protected PivotDefinition pivotDefinition
protected String[] pivotColumns
protected Object[] pivotValues
protected SQLFilterConverter converter
protected DatabaseTableDefinition nonPivotDefinition
protected MeasureDefinition functionDefinition
protected DatabaseTableDefinition aggregateDefinition
protected boolean cursors
protected transient Connection c
protected String joinStatement
protected String whereSQL
protected String orderSQL
protected String havingSQL
| Constructor Detail |
|---|
public DefaultPivotTableModel(Connection c,
DatabaseTableDefinition nonPivotDefinition,
DatabaseTableDefinition functionDefinition,
String pivotColumn,
String table)
c - the database connection.nonPivotDefinition - these columns will appear on the left side of the table.functionDefinition - these columns will appear next.pivotColumn - the pivot columntable - the table of the crosstab query
public DefaultPivotTableModel(Connection c,
DatabaseTableDefinition nonPivotDefinition,
MeasureDefinition functionDefinition,
PivotDefinition pivotDefinition,
String joinStatement,
String pivotStatement)
c - the database connection.nonPivotDefinition - these columns will appear on the left side of the table.functionDefinition - these columns will appear next.pivotDefinition - the pivot definition.joinStatement - a string epresenting the table or tables and the criteria (if any) that will be used to fetch the database data.pivotStatement - a string epresenting the table or tables and the criteria (if any) that will be used to fetch the pivot columns.| Method Detail |
|---|
public void fireTableChanged(TableModelEvent e)
TableModelListeners that registered
themselves as listeners for this table model.
fireTableChanged in class AbstractDatabaseTableModele - the event to be forwardedAbstractTableModel.addTableModelListener(javax.swing.event.TableModelListener),
TableModelEvent,
EventListenerListpublic Class getColumnClass(int column)
Object.class regardless of columnIndex.
getColumnClass in interface TableModelgetColumnClass in class AbstractDatabaseTableModelcolumn - the column being queried
public int getColumnCount()
JTable uses this method to determine how many columns it
should create and display by default.
getColumnCount in interface TableModelTableModel.getRowCount()public String getColumnName(int column)
column cannot be found,
returns an empty string.
getColumnName in interface TableModelgetColumnName in class AbstractDatabaseTableModelcolumn - the column being queried
columnpublic String[] getPivotColumns()
public int getRowCount()
JTable uses this method to determine how many rows it
should display. This method should be quick, as it
is called frequently during rendering.
getRowCount in interface TableModelgetRowCount in class AbstractDatabaseTableModelTableModel.getColumnCount()
public Object getValueAt(int row,
int column)
columnIndex and
rowIndex.
getValueAt in interface TableModelgetValueAt in class AbstractDatabaseTableModelrow - the row whose value is to be queriedcolumn - the column whose value is to be queried
protected void initColumns()
aggregateDefinition is created by iterating through
the nonPivotDefinition, functionDefinition and pivot columns.
public boolean isValueCached(int row,
int column)
isValueCached in interface CacheableTableModelisValueCached in class AbstractDatabaseTableModelrow - the cell's row indexcolumn - the cell's column index
public void orderByClause()
orderByClause in class AbstractDatabaseTableModelpublic void prepareGroupTableHeader(GroupTableHeader groupableHeader)
groupableHeader - the group tableheader to configure appropriately.public int readRowCount()
readRowCount in interface DatabaseTableModelprotected String readRowCountStatement()
readRowCount method.
public String[] retrievePivotColumns(String pivotColumn)
retrievePivotColumns in interface PivotTableModelpivotColumn - a column or a column function used as the pivot.
protected String retrievePivotColumnsStatement(String pivotColumn)
retrievePivotColumns method.
pivotColumn - the pivot column
public List retrieveRows(int from,
int to)
retrieveRows in interface DatabaseTableModelfrom - 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 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 | ||||||||