cmu.survey.data
Class TableStorageStub<DTM extends DataTableModel>

java.lang.Object
  extended by cmu.survey.data.TableStorageStub<DTM>
All Implemented Interfaces:
TableStorage
Direct Known Subclasses:
TableStorageMySQL

public abstract class TableStorageStub<DTM extends DataTableModel>
extends java.lang.Object
implements TableStorage


Nested Class Summary
 
Nested classes/interfaces inherited from interface cmu.survey.data.TableStorage
TableStorage.SearchingForConnectionListener, TableStorage.TableListListener
 
Field Summary
protected  java.lang.String lastErrorMessage
           
protected  java.util.Vector<TableStorage.SearchingForConnectionListener> searchingForConnectionListeners
           
protected  java.util.Vector<TableStorage.TableListListener> tableListListeners
           
protected  TableVersionStorage tableVersionStorage
           
 
Constructor Summary
TableStorageStub()
           
 
Method Summary
 void addSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
          Add a listener to find when TableStorage is unavailable (usually due to network issues).
 void addTableListListener(TableStorage.TableListListener listener)
           
 void close()
          Closes all the DataTableModels that have been opened.
 boolean deleteTable(java.lang.String tableName)
          For convenience, this returns the DataTableModel passed into it and checks for null.
protected abstract  boolean deleteTableProtected(java.lang.String tableName)
           
 void finalize()
           
protected  void fireTableListChanged()
           
 java.lang.String getLastErrorMessage()
          Returns an error message, if there was one, from the most recent error.
protected abstract  DataTableModelSingularInfo<DTM> getSingularInfo(java.lang.String tableName)
           
protected abstract  DataTableModelSingularInfo<DTM> getSingularInfo(TableFormat tableFormat)
           
 DataTableModel getTable(java.lang.String tableName)
          Get the table so named.
 DataTableModel getTable(TableFormat tableFormat)
          Gets the table with that format.
protected abstract  DTM getTableProtected(DataTableModelSingularInfo singularInfo)
           
 TableVersionStorage getTableVersionStorage()
           
protected  DTM newTable(DataTableModelSingularInfo<DTM> singularInfo)
           
 DataTableModel newTable(java.lang.String tableName, java.util.List<java.lang.String> columnNames, java.util.List<java.lang.Class> columnTypes)
           
 DataTableModel newTable(java.lang.String tableName, java.util.List<java.lang.String> columnNames, java.util.List<java.lang.Class> columnTypes, java.lang.Integer primaryKeyColumn)
          Returns a new table, or null if it fails.
 DataTableModel newTable(java.lang.String tableName, java.util.List<java.lang.String> columnNames, java.util.List<java.lang.Class> columnTypes, java.util.List<java.lang.Boolean> columnAllowsNull, java.util.List<java.lang.Object> columnDefaultValues, java.lang.Integer primaryKeyColumn)
          Creates a new table in the database, and returns it, or null if it fails.
protected abstract  DTM newTable(java.lang.String tableName, java.util.List<java.lang.String> columnNames, java.util.List<java.lang.Class> columnTypes, java.util.List<java.lang.Boolean> columnAllowsNull, java.util.List<java.lang.Object> columnDefaultValues, java.lang.Integer primaryKeyColumn, DataTableModelSingularInfo<DTM> tableInfo)
           
 DataTableModel newTable(java.lang.String tableName, java.lang.String[] columnNames, java.lang.Class[] columnTypes)
           
 DataTableModel newTable(java.lang.String tableName, java.lang.String[] columnNames, java.lang.Class[] columnTypes, java.lang.Integer primaryKeyColumn)
           
 DataTableModel newTable(TableFormat tableFormat)
           
 void removeSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
          Removes a listener to find when TableStorage is unavailable (usually due to network issues).
 void removeTableListListener(TableStorage.TableListListener listener)
           
 boolean renameTable(java.lang.String oldTableName, java.lang.String newTableName)
           
protected abstract  boolean renameTableProtected(java.lang.String oldTableName, java.lang.String newTableName)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cmu.survey.data.TableStorage
cancelSearchingForConnection, getTableNames, isOpen, isTableNamesCaseSensitive, isValidLabelString, tableExists
 

Field Detail

lastErrorMessage

protected java.lang.String lastErrorMessage

tableVersionStorage

protected TableVersionStorage tableVersionStorage

searchingForConnectionListeners

protected java.util.Vector<TableStorage.SearchingForConnectionListener> searchingForConnectionListeners

tableListListeners

protected java.util.Vector<TableStorage.TableListListener> tableListListeners
Constructor Detail

TableStorageStub

public TableStorageStub()
Method Detail

newTable

public DataTableModel newTable(TableFormat tableFormat)
Specified by:
newTable in interface TableStorage
See Also:
newTable(String, List, List, List, List, int);

newTable

protected DTM newTable(DataTableModelSingularInfo<DTM> singularInfo)

getTableVersionStorage

public TableVersionStorage getTableVersionStorage()

getLastErrorMessage

public java.lang.String getLastErrorMessage()
Description copied from interface: TableStorage
Returns an error message, if there was one, from the most recent error.

Specified by:
getLastErrorMessage in interface TableStorage
Returns:

newTable

public DataTableModel newTable(java.lang.String tableName,
                               java.util.List<java.lang.String> columnNames,
                               java.util.List<java.lang.Class> columnTypes)
Specified by:
newTable in interface TableStorage
See Also:
newTable(String, List, List, List, List, int);

newTable

public DataTableModel newTable(java.lang.String tableName,
                               java.lang.String[] columnNames,
                               java.lang.Class[] columnTypes)
Specified by:
newTable in interface TableStorage
See Also:
newTable(String, List, List, List, List, int);

newTable

public DataTableModel newTable(java.lang.String tableName,
                               java.lang.String[] columnNames,
                               java.lang.Class[] columnTypes,
                               java.lang.Integer primaryKeyColumn)
Specified by:
newTable in interface TableStorage
See Also:
newTable(String, List, List, List, List, int);

newTable

public DataTableModel newTable(java.lang.String tableName,
                               java.util.List<java.lang.String> columnNames,
                               java.util.List<java.lang.Class> columnTypes,
                               java.lang.Integer primaryKeyColumn)
Returns a new table, or null if it fails.

Specified by:
newTable in interface TableStorage
Parameters:
tableName -
columnNames - A Vector of String of the names of each column
columnTypes - A Vector of Class with the types of each column -- must be the same size() as columnNames.
primaryKeyColumn - An index into columnNames with the primary key column. If there is no primary key, it should be -1. If the primary key column is an Integer, it will also be made as an auto_increment column.
Returns:
if the old table already exists this returns null. If the create fails, this returns null. If it succeeds, it returs a DataTableModel with the table.
See Also:
newTable(String, List, List, List, List, int);

newTable

public DataTableModel newTable(java.lang.String tableName,
                               java.util.List<java.lang.String> columnNames,
                               java.util.List<java.lang.Class> columnTypes,
                               java.util.List<java.lang.Boolean> columnAllowsNull,
                               java.util.List<java.lang.Object> columnDefaultValues,
                               java.lang.Integer primaryKeyColumn)
Description copied from interface: TableStorage
Creates a new table in the database, and returns it, or null if it fails. Assumes you have already checked that this table name does not exist.

Specified by:
newTable in interface TableStorage
columnNames - A Vector of String of the names of each column
columnTypes - A Vector of Class with the types of each column -- must be the same size() as columnNames.
columnAllowsNull - (optional) A Vector of Boolean as to whether or not the column allows null as a value.
columnDefaultValues - (optional) A Vector of Object, for the default value in each column when it's there.
primaryKeyColumn - (optional, -1 if none) An index into columnNames with the primary key column. If there is no primary key, it should be -1. If the primary key column is an Integer, it will also be made as an auto-incrementing column.
Returns:
if the old table already exists this returns null. If the create fails, this returns null. If it succeeds, it returs a DataTableModel with the table.

newTable

protected abstract DTM newTable(java.lang.String tableName,
                                java.util.List<java.lang.String> columnNames,
                                java.util.List<java.lang.Class> columnTypes,
                                java.util.List<java.lang.Boolean> columnAllowsNull,
                                java.util.List<java.lang.Object> columnDefaultValues,
                                java.lang.Integer primaryKeyColumn,
                                DataTableModelSingularInfo<DTM> tableInfo)

getTable

public DataTableModel getTable(java.lang.String tableName)
Description copied from interface: TableStorage
Get the table so named. This assumes that you have picked a valid table name and/or that in a GUI where there is any user input that you have validated their input or made sure that the table name is in getTableNames().

Specified by:
getTable in interface TableStorage
Returns:

getTable

public DataTableModel getTable(TableFormat tableFormat)
Description copied from interface: TableStorage
Gets the table with that format. If the table does not exist, it will create it with the requested TableFormat.

Specified by:
getTable in interface TableStorage
Parameters:
tableFormat - format the table should be in
Returns:

getSingularInfo

protected abstract DataTableModelSingularInfo<DTM> getSingularInfo(java.lang.String tableName)

getSingularInfo

protected abstract DataTableModelSingularInfo<DTM> getSingularInfo(TableFormat tableFormat)

getTableProtected

protected abstract DTM getTableProtected(DataTableModelSingularInfo singularInfo)

deleteTable

public boolean deleteTable(java.lang.String tableName)
For convenience, this returns the DataTableModel passed into it and checks for null. This means we can simply wrap this around your calls, before a return, etc. It's already been added to all the newTable and getTable methods (above)

Specified by:
deleteTable in interface TableStorage
Parameters:
tableName -
dataTableModel -
Returns:

deleteTableProtected

protected abstract boolean deleteTableProtected(java.lang.String tableName)

renameTable

public boolean renameTable(java.lang.String oldTableName,
                           java.lang.String newTableName)
Specified by:
renameTable in interface TableStorage

renameTableProtected

protected abstract boolean renameTableProtected(java.lang.String oldTableName,
                                                java.lang.String newTableName)

addSearchingForConnectionListener

public void addSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
Description copied from interface: TableStorage
Add a listener to find when TableStorage is unavailable (usually due to network issues). The TableStorage will only wait for the network to become re-available if there's at least one of these. If none of these have been added, any commands that come in will just fail when the connection fails.

Specified by:
addSearchingForConnectionListener in interface TableStorage

removeSearchingForConnectionListener

public void removeSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
Description copied from interface: TableStorage
Removes a listener to find when TableStorage is unavailable (usually due to network issues).

Specified by:
removeSearchingForConnectionListener in interface TableStorage

addTableListListener

public void addTableListListener(TableStorage.TableListListener listener)
Specified by:
addTableListListener in interface TableStorage

removeTableListListener

public void removeTableListListener(TableStorage.TableListListener listener)
Specified by:
removeTableListListener in interface TableStorage

fireTableListChanged

protected void fireTableListChanged()

close

public void close()
Closes all the DataTableModels that have been opened.

Specified by:
close in interface TableStorage

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object