cmu.survey.data.mysql
Class DataTableModelMySQL

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by cmu.survey.data.DataTableModel
          extended by cmu.survey.data.sql.DataTableModelSQL
              extended by cmu.survey.data.mysql.DataTableModelMySQL
All Implemented Interfaces:
FilterChangedListener, java.io.Serializable, javax.swing.table.TableModel

public class DataTableModelMySQL
extends DataTableModelSQL

See Also:
Serialized Form

Nested Class Summary
 class DataTableModelMySQL.ForwardOnlyDataSQL
           
 
Nested classes/interfaces inherited from class cmu.survey.data.DataTableModel
DataTableModel.DataTableModelGUIListener, DataTableModel.Results
 
Field Summary
protected static boolean debug
           
 
Fields inherited from class cmu.survey.data.sql.DataTableModelSQL
CheckWhetherColumnNamesAreValid, filters, orderBys, resultSet, sqlOrderBy, sqlWhere
 
Fields inherited from class cmu.survey.data.DataTableModel
COLUMN_TYPES, COLUMN_TYPES_READABLE, holdFiredTableChangeEvents, INTEGER_TYPE_READABLE, levelOfEventsHeld, thisDataTableModel
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
DataTableModelMySQL(TableStorageMySQL objectStorage, DataTableModelSingularInfo tableInfo)
           
 
Method Summary
protected  void cacheColumnNames(java.sql.ResultSet resultSet)
           
 boolean changeColumnClass(java.lang.String columnName, java.lang.Class newColumnClass, boolean allowsNull, java.lang.String defaultValue)
           
 void close()
           
protected  void deleteColumnNoRefresh(java.lang.String columnName)
           
 boolean deleteDataBits(java.lang.String uniqueIDColumnName, java.lang.Integer uniqueID)
           
protected  boolean deleteRowProtected(int row)
          Implement this to delete a row.
 boolean equals(java.lang.Object o)
           
protected  void filtersWereChanged()
          Called after the Filters are changed.
 java.lang.Class<?> getColumnClass(int c)
           
 int getColumnCount()
           
 java.lang.String[] getColumnNames()
           
static java.lang.String getColumnTypeAsSQLString(java.lang.Class columnType)
           
 java.lang.Integer getCount(java.lang.String columnName, java.lang.String filterEquals, java.lang.Object value)
           
protected  DatabaseQuery getDatabaseQuery()
          Gets the query, also refreshes it if needed.
 Filter<?> getFilterForColumn(java.lang.String columnName, java.lang.String filterEquals, java.lang.Object value)
           
protected  java.lang.String getFilterWhereAsSQLWhere()
           
 ForwardOnlyData getForwardOnlyData()
           
 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.
 java.lang.Object getMax(java.lang.String columnName)
          Get the maximum value of a column.
 java.lang.Integer getPrimaryKey()
           
 int getRowCount()
           
 TableStorage getTableStorage()
           
 java.lang.Object getValueAt(int row, int col)
           
 java.lang.Object getValueAtGetErrors(int row, int col)
           
 boolean isCellEditable(int row, int col)
           
 boolean isColumnNullable(int col)
           
 boolean isEditable()
           
 boolean isFilterValid()
           
 boolean isOrderByValid()
          Should be used when a query with an orderby fails, to check if the order by was okay and give a better error message.
 boolean isValidColumnName(java.lang.String columnName)
          Check whether a column name is allowed or not.
static void main(java.lang.String[] args)
           
 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 newRow()
           
 boolean newRow(java.util.List<? extends java.lang.Object> rowValues)
           
 boolean newRow(java.util.List<java.lang.String> columnNames, java.util.List<? extends java.lang.Object> rowValues)
           
 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.
 DataTableModel.Results newRows(java.util.List<java.lang.String> columnNames, java.util.List<? extends java.util.List<? extends java.lang.Object>> rowOfRows)
           
protected  void orderBysWereChanged()
          Does not check whether the order bys are valid.
 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.
protected  void refreshTableSQL()
           
 boolean renameColumn(java.lang.String oldColumnName, java.lang.String newColumnName)
           
 boolean reorderColumn(java.lang.String columnName, int newIndex)
           
 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.
 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.
 boolean saveDataBits(java.util.List<? extends DataBit> dataBits, java.lang.String uniqueIDColumnName, java.lang.String uniqueID, boolean isNew)
          Save
 java.lang.Object saveDataBitsPrivate(java.util.List<? extends DataBit<?>> dataBits, java.lang.String uniqueIDColumnName, java.lang.Object uniqueID, boolean isNew)
           
protected  boolean setValueAtProtected(java.lang.Object value, int row, int col)
          Implement this to set values.
protected  void setValueAtProtected(java.sql.ResultSet resultSet, int columnIndex, java.lang.Object value)
          prerequisites: resultSet should be on the right row.
protected  void sqlOrderByWasChanged()
           
protected  void sqlTableNameWasChanged()
          Called after the sql table name was changed.
protected  void sqlWhereWasChanged()
           
 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).
 java.lang.String toString()
           
 
Methods inherited from class cmu.survey.data.sql.DataTableModelSQL
addFilter, addOrderBy, deleteAllRows, deleteColumn, deleteColumns, filterChanged, getFilters, getOrderBys, getSQLOrderBy, getSQLWhere, removeAllFilters, removeAllOrderBys, removeColumnFromPlaces, removeFilter, removeOrderBy, setFilters, setSQLOrderBy, setSQLWhere
 
Methods inherited from class cmu.survey.data.DataTableModel
addGUIListener, addOneLock, addTableModelListener, addUndoableEditListener, changeColumnClass, deleteColumn, deleteRow, deleteRows, finalize, fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, fireUndoableEdit, getColumnClass, getColumnIndex, getColumnIndexes, getColumnName, getColumnTypeReadable, getCount, getSingularInfo, getTableFormat, getTableName, hasPrimaryKey, isLocked, isMakingUndoableEdits, newColumn, newColumn, newColumnAfter, newColumnAfter, newColumnAfter, newColumnBefore, newRow, removeGUIListener, removeOneLock, removeTableModelListener, removeUndoableEditListener, renameColumn, reorderColumn, setValueAt, setValueAtGetErrors, setValuesAt, setValuesAt
 
Methods inherited from class javax.swing.table.AbstractTableModel
findColumn, fireTableChanged, getListeners, getTableModelListeners
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

protected static final boolean debug
See Also:
Constant Field Values
Constructor Detail

DataTableModelMySQL

public DataTableModelMySQL(TableStorageMySQL objectStorage,
                           DataTableModelSingularInfo tableInfo)
Method Detail

refreshTableSQL

protected void refreshTableSQL()

filtersWereChanged

protected void filtersWereChanged()
Description copied from class: DataTableModelSQL
Called after the Filters are changed.

Specified by:
filtersWereChanged in class DataTableModelSQL

getFilterWhereAsSQLWhere

protected java.lang.String getFilterWhereAsSQLWhere()
Specified by:
getFilterWhereAsSQLWhere in class DataTableModelSQL

isFilterValid

public boolean isFilterValid()

orderBysWereChanged

protected void orderBysWereChanged()
Does not check whether the order bys are valid. Use isOrderByValid() to check for that.

Specified by:
orderBysWereChanged in class DataTableModelSQL

sqlTableNameWasChanged

protected void sqlTableNameWasChanged()
Description copied from class: DataTableModelSQL
Called after the sql table name was changed.

Specified by:
sqlTableNameWasChanged in class DataTableModelSQL

sqlWhereWasChanged

protected void sqlWhereWasChanged()
Specified by:
sqlWhereWasChanged in class DataTableModelSQL

sqlOrderByWasChanged

protected void sqlOrderByWasChanged()
Specified by:
sqlOrderByWasChanged in class DataTableModelSQL

isOrderByValid

public boolean isOrderByValid()
Should be used when a query with an orderby fails, to check if the order by was okay and give a better error message. Note that this is not a safe method yet -- it calls getColumnIndex() which will recursively call

Returns:

getColumnTypeAsSQLString

public static java.lang.String getColumnTypeAsSQLString(java.lang.Class columnType)

getDatabaseQuery

protected DatabaseQuery getDatabaseQuery()
Gets the query, also refreshes it if needed.

Specified by:
getDatabaseQuery in class DataTableModelSQL
Returns:

refresh

public void refresh()
Description copied from class: DataTableModel
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.

Specified by:
refresh in class DataTableModel

getColumnCount

public int getColumnCount()

getRowCount

public int getRowCount()

getValueAtGetErrors

public java.lang.Object getValueAtGetErrors(int row,
                                            int col)
                                     throws FailedRequest
Throws:
FailedRequest

getValueAt

public java.lang.Object getValueAt(int row,
                                   int col)

setValueAtProtected

protected void setValueAtProtected(java.sql.ResultSet resultSet,
                                   int columnIndex,
                                   java.lang.Object value)
                            throws FailedRequest
prerequisites: resultSet should be on the right row. value is the right type of object

Parameters:
resultSet - -- is assumed to already be on the right row.
columnName - this OR columnName is required
columnIndex - this OR columnName is required
value -
Throws:
FailedRequest

setValueAtProtected

protected boolean setValueAtProtected(java.lang.Object value,
                                      int row,
                                      int col)
Description copied from class: DataTableModel
Implement this to set values. You should not generate undoable events, and you should not fire the row changed events -- this will be done for you automatically.

Specified by:
setValueAtProtected in class DataTableModel
Returns:
whether or not it worked successfully (return false if there were errors, which it assumes were reported to the user in the form of bugs)

getColumnNames

public java.lang.String[] getColumnNames()
Specified by:
getColumnNames in class DataTableModel

cacheColumnNames

protected void cacheColumnNames(java.sql.ResultSet resultSet)

getColumnClass

public java.lang.Class<?> getColumnClass(int c)
Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel

getPrimaryKey

public java.lang.Integer getPrimaryKey()
Specified by:
getPrimaryKey in class DataTableModel

isEditable

public boolean isEditable()
Specified by:
isEditable in class DataTableModel

isCellEditable

public boolean isCellEditable(int row,
                              int col)
Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel

isColumnNullable

public boolean isColumnNullable(int col)
Specified by:
isColumnNullable in class DataTableModel

deleteRowProtected

protected boolean deleteRowProtected(int row)
Description copied from class: DataTableModel
Implement this to delete a row. You should not generate undoable events, and you should not fire the row changed events -- this will be done for you automatically.

Specified by:
deleteRowProtected in class DataTableModel
Parameters:
rows - -- MUST be in order from lowest rowID to highest rowID, but does not need to be consecutive.
Returns:
whether it succeeded

newRow

public boolean newRow()
Specified by:
newRow in class DataTableModel

newRow

public boolean newRow(java.util.List<? extends java.lang.Object> rowValues)
Specified by:
newRow in class DataTableModel
Parameters:
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).

newRows

public DataTableModel.Results newRows(java.util.List<? extends java.util.List<? extends java.lang.Object>> rowOfRows)
Description copied from class: DataTableModel
See Results class for description of what the boolean's mean.

Specified by:
newRows in class DataTableModel
Returns:

newRows

public DataTableModel.Results newRows(java.util.List<java.lang.String> columnNames,
                                      java.util.List<? extends java.util.List<? extends java.lang.Object>> rowOfRows)

newRow

public boolean newRow(java.util.List<java.lang.String> columnNames,
                      java.util.List<? extends java.lang.Object> rowValues)
Specified by:
newRow in class DataTableModel
Parameters:
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).
Returns:

getTableStorage

public TableStorage getTableStorage()
Specified by:
getTableStorage in class DataTableModel

changeColumnClass

public boolean changeColumnClass(java.lang.String columnName,
                                 java.lang.Class newColumnClass,
                                 boolean allowsNull,
                                 java.lang.String defaultValue)
Specified by:
changeColumnClass in class DataTableModel

isValidColumnName

public boolean isValidColumnName(java.lang.String columnName)
Description copied from class: DataTableModel
Check whether a column name is allowed or not.

Specified by:
isValidColumnName in class DataTableModel
Returns:

getInvalidColumnNameMessage

public java.lang.String getInvalidColumnNameMessage(java.lang.String columnName)
Description copied from class: DataTableModel
If this column name is not allowed, returns a brief message saying what's invalid about the name. If this column name is allowed, returns null.

Specified by:
getInvalidColumnNameMessage in class DataTableModel
Returns:

renameColumn

public boolean renameColumn(java.lang.String oldColumnName,
                            java.lang.String newColumnName)
Specified by:
renameColumn in class DataTableModel

reorderColumn

public boolean reorderColumn(java.lang.String columnName,
                             int newIndex)
Specified by:
reorderColumn in class DataTableModel

newColumn

public boolean newColumn(java.lang.String columnName,
                         java.lang.Class type,
                         java.lang.String afterColumnName,
                         boolean createAsFirstColumn,
                         boolean isPrimaryKey,
                         boolean allowsNull,
                         java.lang.Object defaultValue)
Specified by:
newColumn in class DataTableModel

deleteColumnNoRefresh

protected void deleteColumnNoRefresh(java.lang.String columnName)
                              throws FailedRequest
Specified by:
deleteColumnNoRefresh in class DataTableModelSQL
Throws:
FailedRequest

tableWasRenamedTo

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

Specified by:
tableWasRenamedTo in class DataTableModel

saveDataBits

public java.lang.Integer saveDataBits(java.util.List<? extends DataBit> dataBits,
                                      java.lang.String uniqueIDColumnName,
                                      java.lang.Integer uniqueID,
                                      boolean isNew)
Description copied from class: DataTableModel
Takes a set of data bits. If uniqueID!=null, creates the row with uniqueIDColumnName=uniqueID -- if uniqueID is null, it auto-increments that column, creates a new uniqueID, and returns it.

Specified by:
saveDataBits in class DataTableModel
isNew - whether or not this is a new record that has not been previously saved -- whether or not the row exists already.
Returns:
null if it failed, the new uniqueID if it succeeds.

saveDataBits

public boolean saveDataBits(java.util.List<? extends DataBit> dataBits,
                            java.lang.String uniqueIDColumnName,
                            java.lang.String uniqueID,
                            boolean isNew)
Description copied from class: DataTableModel
Save

Specified by:
saveDataBits in class DataTableModel
uniqueID - The unique ID to save as -- cannot be null, since it can't be automatically assigned.
Returns:

saveDataBitsPrivate

public java.lang.Object saveDataBitsPrivate(java.util.List<? extends DataBit<?>> dataBits,
                                            java.lang.String uniqueIDColumnName,
                                            java.lang.Object uniqueID,
                                            boolean isNew)

deleteDataBits

public boolean deleteDataBits(java.lang.String uniqueIDColumnName,
                              java.lang.Integer uniqueID)
Specified by:
deleteDataBits in class DataTableModel

getForwardOnlyData

public ForwardOnlyData getForwardOnlyData()
Specified by:
getForwardOnlyData in class DataTableModel

getFilterForColumn

public Filter<?> getFilterForColumn(java.lang.String columnName,
                                    java.lang.String filterEquals,
                                    java.lang.Object value)
                             throws FailedRequest
Throws:
FailedRequest

getMax

public java.lang.Object getMax(java.lang.String columnName)
                        throws FailedRequest
Description copied from class: DataTableModel
Get the maximum value of a column.

Specified by:
getMax in class DataTableModel
Returns:
Throws:
FailedRequest

getCount

public java.lang.Integer getCount(java.lang.String columnName,
                                  java.lang.String filterEquals,
                                  java.lang.Object value)
                           throws FailedRequest
Specified by:
getCount in class DataTableModel
Throws:
FailedRequest

resetPrimaryKeyColumnIndex

public void resetPrimaryKeyColumnIndex()
                                throws FailedRequest
Description copied from class: DataTableModel
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. This is good for resetting the index after clearing out all of your data, for example.

Specified by:
resetPrimaryKeyColumnIndex in class DataTableModel
Throws:
FailedRequest

close

public void close()
Specified by:
close in class DataTableModel

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

main

public static final void main(java.lang.String[] args)
                       throws java.lang.Throwable
Throws:
java.lang.Throwable