Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.table.db
Class DistinctDatabaseTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by com.citra.table.db.AbstractDatabaseTableModel
          extended by com.citra.table.db.DistinctDatabaseTableModel
All Implemented Interfaces:
CacheableTableModel, DatabaseTableModel, Serializable, TableModel

public class DistinctDatabaseTableModel
extends AbstractDatabaseTableModel

DistinctDatabaseTableModel behaves just like DefaultDatabaseTableModel, with the difference that it queries a database for unique rows, using the 'distinct' keyword.

See Also:
Serialized Form

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  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.citra.table.db.AbstractDatabaseTableModel
cache, dbFilter, dbSorter, rangedModel, rowCount
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DistinctDatabaseTableModel(Connection c, String joinStatement, DatabaseTableDefinition def)
          Constructs a DistinctDatabaseTableModel.
DistinctDatabaseTableModel(Connection c, String table, String[] columns)
          Constructs a DistinctDatabaseTableModel.
DistinctDatabaseTableModel(Connection c, String table, String[] columns, Class[] classes)
          Constructs a DistinctDatabaseTableModel.
DistinctDatabaseTableModel(Connection c, String table, TableModel model)
          Constructs a DistinctDatabaseTableModel.
 
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.
 boolean isRangedModel()
          Determines whether the cache model can fetch data in ranges.
 void orderByClause()
          This method is called whenever sorting is requested.
 int readRowCount()
          Reads and returns the row count from the underlying data source.
 int readRowCount(int column)
          Reads and returns the row count from the underlying data source for the distinct column supplied.
protected  String readRowCountStatement(int column)
          Retrieves the sql statement for the readRowCount method.
 List retrieveRows(int column)
          Fetches distinct rows from the underlying data source for the supplied column argument.
 List retrieveRows(int from, int to)
          Fetches multiple rows from the underlying data source.
protected  String retrieveRowsStatement(int column)
          Retrieves the sql statement for the retrieveRows method.
 void setRangedModel(boolean rangedModel)
          Tells the database model whether to use ranges when fetching data 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.citra.table.db.AbstractDatabaseTableModel
fireTableChanged, getCache, getFilterTableModel, getRowCount, getSortTableModel, getUncachedRows, getValueAt, isCountCached, isValueCached, retrieveFromDB, retrieveFromDB, setCache
 
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

joinStatement

protected String joinStatement
a string representing the table or tables and the criteria (if any) that will be used to fetch the database data.


converter

protected transient SQLFilterConverter converter
utility class that converts a TableFilter to an sql 'where' clause.


definition

protected DatabaseTableDefinition definition
the database definition.


c

protected transient Connection c
The current connection to the database


whereSQL

protected String whereSQL
a string which is used to hold the where clause of the sql statement


orderSQL

protected String orderSQL
a string which is used to hold the order byclause of the sql statement

Constructor Detail

DistinctDatabaseTableModel

public DistinctDatabaseTableModel(Connection c,
                                  String table,
                                  String[] columns)
Constructs a DistinctDatabaseTableModel.


DistinctDatabaseTableModel

public DistinctDatabaseTableModel(Connection c,
                                  String table,
                                  String[] columns,
                                  Class[] classes)
Constructs a DistinctDatabaseTableModel.


DistinctDatabaseTableModel

public DistinctDatabaseTableModel(Connection c,
                                  String joinStatement,
                                  DatabaseTableDefinition def)
Constructs a DistinctDatabaseTableModel.

Parameters:
c - the database connection
joinStatement - a string epresenting the table or tables and the criteria (if any) that will be used to fetch the database data.
def - the column defintion

DistinctDatabaseTableModel

public DistinctDatabaseTableModel(Connection c,
                                  String table,
                                  TableModel model)
Constructs a DistinctDatabaseTableModel.

Method Detail

getColumnClass

public Class getColumnClass(int column)
Returns Object.class regardless of columnIndex.

Specified by:
getColumnClass in interface TableModel
Specified by:
getColumnClass in class AbstractDatabaseTableModel
Parameters:
column - the column being queried
Returns:
the Object.class

getColumnCount

public int getColumnCount()
Returns the number of columns in the model. A JTable uses this method to determine how many columns it should create and display by default.

Returns:
the number of columns in the model
See Also:
TableModel.getRowCount()

getColumnName

public 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.

Specified by:
getColumnName in interface TableModel
Specified by:
getColumnName in class AbstractDatabaseTableModel
Parameters:
column - the column being queried
Returns:
a string containing the default name of column

getSQLFilterConverter

public SQLFilterConverter getSQLFilterConverter()
Returns the object that will be used to convert a TableFilter to an sql 'where' clause.

Returns:
the assigned sql filter converter.

isRangedModel

public boolean isRangedModel()
Determines whether the cache model can fetch data in ranges.

Specified by:
isRangedModel in interface CacheableTableModel
Overrides:
isRangedModel in class AbstractDatabaseTableModel
Returns:
true if the cache model can fetch ranged data.

orderByClause

public void orderByClause()
This method is called whenever sorting is requested. Preferrably, this method should reconstruct the sql select query according to the sorting columns of the internal SortTableModel instance.

Specified by:
orderByClause in class AbstractDatabaseTableModel

readRowCount

public int readRowCount()
Reads and returns the row count from the underlying data source.

Returns:
the row count

readRowCount

public int readRowCount(int column)
Reads and returns the row count from the underlying data source for the distinct column supplied.

Parameters:
column - the database column for which the distinct count is read
Returns:
the row count for the column

readRowCountStatement

protected String readRowCountStatement(int column)
Retrieves the sql statement for the readRowCount method.

Parameters:
column - the database column for which the distinct count is read
Returns:
the sql statement as a string

retrieveRows

public List retrieveRows(int column)
Fetches distinct rows from the underlying data source for the supplied column argument.

Parameters:
column - the database column for which distinct rows are read
Returns:
the retrieved rows

retrieveRows

public List retrieveRows(int from,
                         int to)
Fetches multiple rows from the underlying data source. 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.

Parameters:
from - the starting row
to - the ending row
Returns:
the retrieved rows

retrieveRowsStatement

protected String retrieveRowsStatement(int column)
Retrieves the sql statement for the retrieveRows method.

Parameters:
column - the database column for which distinct rows are read
Returns:
the sql statement as a string

setRangedModel

public void setRangedModel(boolean rangedModel)
Tells the database model whether to use ranges when fetching data from the database. If ranges are used, the cache settings are respected, otherwise the model will fetch all rows in one sql statement.

Overrides:
setRangedModel in class AbstractDatabaseTableModel
Parameters:
rangedModel - true if the database model is to return data in ranges, false otherwise.

setSQLFilterConverter

public void setSQLFilterConverter(SQLFilterConverter converter)
Assigns the object that will be used to convert a TableFilter to an sql 'where' clause.

Parameters:
converter - the sql filter converter to assign.

whereClause

public void whereClause()
This method is called whenever filtering is requested. Preferrably, this method should reconstruct the sql select query according to the table filter of the internal FilterTableModel instance.

Specified by:
whereClause in class AbstractDatabaseTableModel

Copyright © 2011 Citra Technologies. All Rights Reserved.