|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.table.AbstractTableModel cmu.survey.data.DataTableModel
public abstract class DataTableModel
Accesses database data in a generic fashion. Can be used for a GUI (JTable, e.g. TablePanel
), or for simply accessing the database from code.
You can access any generic database table and do most operations without writing any SQL, thus keeping your implementation non-specific to any particular SQL language or database.
The extra layer adds some functionality, and makes databases more swappable if you need to.
Many methods are implemented here and have abstract "___Protected" methods, in order to support different features.
TableStorage
,
Serialized FormNested Class Summary | |
---|---|
static interface |
DataTableModel.DataTableModelGUIListener
|
class |
DataTableModel.Results
|
Field Summary | |
---|---|
static java.lang.Class[] |
COLUMN_TYPES
These are the types of columns that are supported in Java types. |
static java.lang.String[] |
COLUMN_TYPES_READABLE
|
protected int |
holdFiredTableChangeEvents
|
static java.lang.String |
INTEGER_TYPE_READABLE
|
protected int |
levelOfEventsHeld
|
protected DataTableModel |
thisDataTableModel
|
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
DataTableModel(DataTableModelSingularInfo tableInfo)
|
Method Summary | |
---|---|
abstract boolean |
addFilter(Filter<?> filter)
|
void |
addGUIListener(DataTableModel.DataTableModelGUIListener listener)
|
void |
addOneLock(java.lang.String description)
Start holding the firing of events -- add one more thing that's holding this. |
abstract boolean |
addOrderBy(OrderBy orderBy)
Adds OrderBy to the list at the highest-priority slot (0 in the Vector returned by getOrderBys()). |
void |
addTableModelListener(javax.swing.event.TableModelListener l)
|
void |
addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Registers the given observer to begin receiving notifications when undoable edits are made to the document. |
abstract boolean |
changeColumnClass(java.lang.String columnName,
java.lang.Class newColumnClass,
boolean allowsNull,
java.lang.String defaultValue)
|
boolean |
changeColumnClass(java.lang.String columnName,
java.lang.Class newColumnClass,
java.lang.String defaultValue)
|
abstract void |
close()
|
boolean |
deleteAllRows()
Deletes all current rows (considering the Filter list!). |
void |
deleteColumn(int columnIndex)
|
abstract void |
deleteColumn(java.lang.String columnName)
|
abstract void |
deleteColumns(int[] columnIndexes)
|
abstract boolean |
deleteDataBits(java.lang.String uniqueIDColumnName,
java.lang.Integer uniqueID)
|
boolean |
deleteRow(int row)
|
protected abstract boolean |
deleteRowProtected(int row)
Implement this to delete a row. |
boolean |
deleteRows(int[] rows)
|
void |
finalize()
|
void |
fireTableCellUpdated(int r,
int r2)
|
void |
fireTableDataChanged()
|
void |
fireTableRowsDeleted(int r,
int r2)
|
void |
fireTableRowsInserted(int r,
int r2)
|
void |
fireTableRowsUpdated(int r,
int r2)
|
void |
fireTableStructureChanged()
|
protected void |
fireUndoableEdit(javax.swing.undo.UndoableEdit edit)
|
java.lang.Class<?> |
getColumnClass(java.lang.String columnName)
|
java.lang.Integer |
getColumnIndex(java.lang.String columnName)
TODO refactor to make this throw FailedRequest.BadColumnNameException and make everything handle it. |
java.lang.Integer[] |
getColumnIndexes(java.lang.String[] columnNames)
|
java.lang.String |
getColumnName(int col)
|
abstract java.lang.String[] |
getColumnNames()
|
static java.lang.String |
getColumnTypeReadable(java.lang.Class columnType)
|
java.lang.Integer |
getCount(java.lang.String columnName,
java.lang.Object value)
Get the number of times a specific value shows up in a column. |
abstract java.lang.Integer |
getCount(java.lang.String columnName,
java.lang.String filterEquals,
java.lang.Object value)
|
abstract VectorDataSet<Filter<?>> |
getFilters()
|
abstract ForwardOnlyData |
getForwardOnlyData()
|
abstract java.lang.String |
getInvalidColumnNameMessage(java.lang.String columnName)
If this column name is not allowed, returns a brief message saying what's invalid about the name. |
abstract java.lang.Object |
getMax(java.lang.String columnName)
Get the maximum value of a column. |
abstract java.util.List<OrderBy> |
getOrderBys()
|
abstract java.lang.Integer |
getPrimaryKey()
|
DataTableModelSingularInfo |
getSingularInfo()
|
protected TableFormat |
getTableFormat()
|
java.lang.String |
getTableName()
|
abstract TableStorage |
getTableStorage()
|
boolean |
hasPrimaryKey()
|
abstract boolean |
isColumnNullable(int col)
|
abstract boolean |
isEditable()
|
boolean |
isLocked()
Whether there is currently a lock on this table -- i.e. |
protected boolean |
isMakingUndoableEdits()
|
abstract boolean |
isValidColumnName(java.lang.String columnName)
Check whether a column name is allowed or not. |
boolean |
newColumn(java.lang.String columnName,
java.lang.Class type)
Creates a new column at the end of the table |
boolean |
newColumn(java.lang.String columnName,
java.lang.Class type,
java.lang.String afterColumnName,
boolean createAsFirstColumn,
boolean isPrimaryKey)
|
abstract boolean |
newColumn(java.lang.String columnName,
java.lang.Class type,
java.lang.String afterColumnName,
boolean createAsFirstColumn,
boolean isPrimaryKey,
boolean allowsNull,
java.lang.Object defaultValue)
|
boolean |
newColumnAfter(java.lang.String columnName,
java.lang.Class type,
int columnIDtoPutThisAfter)
|
boolean |
newColumnAfter(java.lang.String columnName,
java.lang.Class type,
java.lang.String afterColumnName)
|
boolean |
newColumnAfter(java.lang.String columnName,
java.lang.Class type,
java.lang.String afterColumnName,
boolean isPrimaryKey)
|
boolean |
newColumnBefore(java.lang.String columnName,
java.lang.Class type,
int columnIDtoPutThisBefore)
|
abstract boolean |
newRow()
|
abstract boolean |
newRow(java.util.List<? extends java.lang.Object> rowValues)
|
abstract boolean |
newRow(java.util.List<java.lang.String> columnNames,
java.util.List<? extends java.lang.Object> rowValues)
|
boolean |
newRow(java.lang.String[] columnNames,
java.lang.Object[] values)
|
abstract DataTableModel.Results |
newRows(java.util.List<? extends java.util.List<? extends java.lang.Object>> rowOfRows)
See Results class for description of what the boolean's mean. |
abstract void |
refresh()
Refreshes its data -- reloads any data from any info from the database that it can reload, and should call fireTableStructureChanged() or another appropriate fire to update GUIs. |
abstract void |
removeAllFilters()
|
abstract void |
removeAllOrderBys()
|
abstract boolean |
removeFilter(Filter<?> filter)
|
boolean |
removeGUIListener(DataTableModel.DataTableModelGUIListener listener)
|
void |
removeOneLock()
Remove one hold from firing events. |
abstract boolean |
removeOrderBy(OrderBy orderBy)
|
void |
removeTableModelListener(javax.swing.event.TableModelListener l)
|
void |
removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
Unregisters the given observer from the notification list so it will no longer receive updates. |
boolean |
renameColumn(int oldColumn,
java.lang.String newColumnName)
|
abstract boolean |
renameColumn(java.lang.String oldColumnName,
java.lang.String newColumnName)
|
boolean |
reorderColumn(int oldColumnIndex,
int newIndex)
|
abstract boolean |
reorderColumn(java.lang.String columnName,
int newIndex)
|
abstract void |
resetPrimaryKeyColumnIndex()
If the primary key is an integer column, and an auto-incrementing column, it resets the column's next new integer to the lowest possible (if the table is empty, starts at 1) -- if it is not an integer and not an auto-incrementing column, it will NOT reset the column's index. |
abstract java.lang.Integer |
saveDataBits(java.util.List<? extends DataBit> dataBits,
java.lang.String uniqueIDColumnName,
java.lang.Integer uniqueID,
boolean isNew)
Takes a set of data bits. |
abstract boolean |
saveDataBits(java.util.List<? extends DataBit> dataBits,
java.lang.String uniqueIDColumnName,
java.lang.String uniqueID,
boolean isNew)
Save |
abstract void |
setFilters(VectorDataSet<Filter<?>> filters)
|
void |
setValueAt(java.lang.Object newValue,
int row,
int column)
Set the value at a cell. |
void |
setValueAtGetErrors(java.lang.Object newValue,
int row,
int column)
|
protected abstract boolean |
setValueAtProtected(java.lang.Object value,
int row,
int column)
Implement this to set values. |
void |
setValuesAt(java.util.List<? extends java.lang.Object> values,
java.util.List<java.awt.Point> points)
|
void |
setValuesAt(java.lang.Object[] values,
java.awt.Point[] points)
Set many cells to different values at once. |
abstract void |
tableWasRenamedTo(java.lang.String oldTableName,
java.lang.String newTableName)
Notification that a used table name was renamed (and that you should refresh queries, names, etc). |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
findColumn, fireTableChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.swing.table.TableModel |
---|
getColumnCount, getRowCount, getValueAt |
Field Detail |
---|
public static final java.lang.Class[] COLUMN_TYPES
for the user-readable formatting.
public static final java.lang.String INTEGER_TYPE_READABLE
public static final java.lang.String[] COLUMN_TYPES_READABLE
protected DataTableModel thisDataTableModel
protected int holdFiredTableChangeEvents
protected int levelOfEventsHeld
Constructor Detail |
---|
public DataTableModel(DataTableModelSingularInfo tableInfo)
Method Detail |
---|
public abstract boolean isEditable()
public abstract java.lang.Integer getPrimaryKey()
public boolean hasPrimaryKey()
public java.lang.Integer getColumnIndex(java.lang.String columnName)
columnName
-
public java.lang.Integer[] getColumnIndexes(java.lang.String[] columnNames)
public abstract java.lang.String[] getColumnNames()
public java.lang.String getColumnName(int col)
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.AbstractTableModel
public abstract boolean isColumnNullable(int col)
public static final java.lang.String getColumnTypeReadable(java.lang.Class columnType)
public java.lang.Class<?> getColumnClass(java.lang.String columnName) throws FailedRequest
FailedRequest
public java.lang.String getTableName()
protected TableFormat getTableFormat()
public DataTableModelSingularInfo getSingularInfo()
public abstract TableStorage getTableStorage()
public abstract void refresh()
public abstract boolean addFilter(Filter<?> filter)
filter
-
public abstract void removeAllFilters()
public abstract boolean removeFilter(Filter<?> filter)
public abstract VectorDataSet<Filter<?>> getFilters()
public abstract void setFilters(VectorDataSet<Filter<?>> filters)
public abstract boolean addOrderBy(OrderBy orderBy)
orderBy
- a direction to order the columns
public abstract boolean removeOrderBy(OrderBy orderBy)
public abstract void removeAllOrderBys()
public abstract java.util.List<OrderBy> getOrderBys()
public boolean renameColumn(int oldColumn, java.lang.String newColumnName)
public boolean changeColumnClass(java.lang.String columnName, java.lang.Class newColumnClass, java.lang.String defaultValue)
public abstract boolean changeColumnClass(java.lang.String columnName, java.lang.Class newColumnClass, boolean allowsNull, java.lang.String defaultValue)
public abstract boolean renameColumn(java.lang.String oldColumnName, java.lang.String newColumnName)
public abstract boolean isValidColumnName(java.lang.String columnName)
columnName
-
public abstract java.lang.String getInvalidColumnNameMessage(java.lang.String columnName)
columnName
-
public boolean newColumn(java.lang.String columnName, java.lang.Class type)
public boolean newColumnBefore(java.lang.String columnName, java.lang.Class type, int columnIDtoPutThisBefore)
public boolean newColumnAfter(java.lang.String columnName, java.lang.Class type, int columnIDtoPutThisAfter)
public boolean newColumnAfter(java.lang.String columnName, java.lang.Class type, java.lang.String afterColumnName)
public boolean newColumnAfter(java.lang.String columnName, java.lang.Class type, java.lang.String afterColumnName, boolean isPrimaryKey)
public boolean newColumn(java.lang.String columnName, java.lang.Class type, java.lang.String afterColumnName, boolean createAsFirstColumn, boolean isPrimaryKey)
public abstract boolean newColumn(java.lang.String columnName, java.lang.Class type, java.lang.String afterColumnName, boolean createAsFirstColumn, boolean isPrimaryKey, boolean allowsNull, java.lang.Object defaultValue)
public boolean reorderColumn(int oldColumnIndex, int newIndex)
public abstract boolean reorderColumn(java.lang.String columnName, int newIndex)
public abstract void deleteColumn(java.lang.String columnName) throws FailedRequest
FailedRequest
public void deleteColumn(int columnIndex) throws FailedRequest
FailedRequest
public abstract void deleteColumns(int[] columnIndexes) throws FailedRequest
FailedRequest
public abstract boolean newRow()
public boolean newRow(java.lang.String[] columnNames, java.lang.Object[] values)
public abstract boolean newRow(java.util.List<? extends java.lang.Object> rowValues)
rowValues
- The values, in order by the column order. Each value must be of the correct class for the type of the column (i.e. An int must be class Integer).public abstract DataTableModel.Results newRows(java.util.List<? extends java.util.List<? extends java.lang.Object>> rowOfRows)
rowOfRows
-
public abstract boolean newRow(java.util.List<java.lang.String> columnNames, java.util.List<? extends java.lang.Object> rowValues)
columnNames
- The names of the columns that values should be inserted into.rowValues
- The values for this row for each column. Each value must be of the correct class for the type of the column (i.e. An int must be class Integer).
public boolean deleteRows(int[] rows)
rows
- -- MUST be in order from lowest rowID to highest rowID, but does not need to be consecutive. Order from lowest to highest is required because as you delete each row, the rowIDs of any higher rows change. (The method then deletes the rows in reverse order, from highest row to lowest row).
public boolean deleteRow(int row)
public boolean deleteAllRows()
protected abstract boolean deleteRowProtected(int row)
row
-
public void setValuesAt(java.lang.Object[] values, java.awt.Point[] points) throws FailedRequest
values
- points
-
FailedRequest
public void setValuesAt(java.util.List<? extends java.lang.Object> values, java.util.List<java.awt.Point> points) throws FailedRequest
FailedRequest
public void setValueAt(java.lang.Object newValue, int row, int column)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
public void setValueAtGetErrors(java.lang.Object newValue, int row, int column) throws FailedRequest
FailedRequest
protected abstract boolean setValueAtProtected(java.lang.Object value, int row, int column) throws FailedRequest
FailedRequest
public void addUndoableEditListener(javax.swing.event.UndoableEditListener listener)
listener
- the observer to registerUndoableEditEvent
public void removeUndoableEditListener(javax.swing.event.UndoableEditListener listener)
listener
- the observer to registerUndoableEditEvent
protected boolean isMakingUndoableEdits()
protected void fireUndoableEdit(javax.swing.undo.UndoableEdit edit)
public abstract void tableWasRenamedTo(java.lang.String oldTableName, java.lang.String newTableName)
public abstract java.lang.Integer saveDataBits(java.util.List<? extends DataBit> dataBits, java.lang.String uniqueIDColumnName, java.lang.Integer uniqueID, boolean isNew)
dataBits
- uniqueIDColumnName
- uniqueID
- isNew
- whether or not this is a new record that has not been previously saved -- whether or not the row exists already.
public abstract boolean saveDataBits(java.util.List<? extends DataBit> dataBits, java.lang.String uniqueIDColumnName, java.lang.String uniqueID, boolean isNew)
dataBits
- uniqueIDColumnName
- uniqueID
- The unique ID to save as -- cannot be null, since it can't be automatically assigned.isNew
-
public abstract boolean deleteDataBits(java.lang.String uniqueIDColumnName, java.lang.Integer uniqueID)
public abstract ForwardOnlyData getForwardOnlyData()
public abstract java.lang.Object getMax(java.lang.String columnName) throws FailedRequest
columnName
-
FailedRequest
public java.lang.Integer getCount(java.lang.String columnName, java.lang.Object value) throws FailedRequest
columnName
- value
-
FailedRequest
public abstract java.lang.Integer getCount(java.lang.String columnName, java.lang.String filterEquals, java.lang.Object value) throws FailedRequest
FailedRequest
public abstract void resetPrimaryKeyColumnIndex() throws FailedRequest
FailedRequest
public void addGUIListener(DataTableModel.DataTableModelGUIListener listener)
public boolean removeGUIListener(DataTableModel.DataTableModelGUIListener listener)
public boolean isLocked()
public void removeOneLock()
public void addOneLock(java.lang.String description)
holdFiredTableChangeEvents
- public void addTableModelListener(javax.swing.event.TableModelListener l)
addTableModelListener
in interface javax.swing.table.TableModel
addTableModelListener
in class javax.swing.table.AbstractTableModel
public void removeTableModelListener(javax.swing.event.TableModelListener l)
removeTableModelListener
in interface javax.swing.table.TableModel
removeTableModelListener
in class javax.swing.table.AbstractTableModel
public void fireTableDataChanged()
fireTableDataChanged
in class javax.swing.table.AbstractTableModel
public void fireTableStructureChanged()
fireTableStructureChanged
in class javax.swing.table.AbstractTableModel
public void fireTableRowsInserted(int r, int r2)
fireTableRowsInserted
in class javax.swing.table.AbstractTableModel
public void fireTableRowsUpdated(int r, int r2)
fireTableRowsUpdated
in class javax.swing.table.AbstractTableModel
public void fireTableRowsDeleted(int r, int r2)
fireTableRowsDeleted
in class javax.swing.table.AbstractTableModel
public void fireTableCellUpdated(int r, int r2)
fireTableCellUpdated
in class javax.swing.table.AbstractTableModel
public abstract void close()
public void finalize()
finalize
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |