cmu.survey.data
Interface TableStorage

All Known Implementing Classes:
TableStorageMySQL, TableStorageStub

public interface TableStorage

Load tables from a database through this generic interface. You can use tables loaded through here for a GUI (JTable, e.g. TablePanel), or for simply accessing the database from code. Between this generic interface and DataTableModel, you can access any generic database 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. By using TableFormat to load a table, you can have the table automatically created if needed, and upgraded if you make a newer version of it. Also, for a bit of help, see TableStorageStub. For anyone trying to implement this class: Unmentioned it this interface is that you're required to use TableVersionStorage when creating a new table and upgrading an old table.

See Also:
DataTableModel

Nested Class Summary
static interface TableStorage.SearchingForConnectionListener
          Recieves notifications of whether the TableStorage is currently unavailable and waiting for a new connection.
static interface TableStorage.TableListListener
          Recieves notifications whenever the list of tables changes -- i.e. on any of these events:
- a table is created
- a table is deleted
- a table is renamed
 
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 cancelSearchingForConnection()
          Stop waiting for the TableStorage to be connected -- and start throwing exceptions.
 void close()
          Call this when you're done with this class and will not use it again.
 boolean deleteTable(java.lang.String tableName)
           
 java.lang.String getLastErrorMessage()
          Returns an error message, if there was one, from the most recent error.
 DataTableModel getTable(java.lang.String tableName)
          Get the table so named.
 DataTableModel getTable(TableFormat tableFormat)
          Gets the table with that format.
 java.util.Vector<java.lang.String> getTableNames()
           
 boolean isOpen()
           
 boolean isTableNamesCaseSensitive()
          True if table names are case sensitive, false if table names are not case sensitive.
 boolean isValidLabelString(java.lang.String labelString)
          Returns whether or not a string is a valid name for tables, columns, etc.
 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)
           
 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.
 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)
           
 boolean tableExists(java.lang.String tableName)
           
 

Method Detail

tableExists

boolean tableExists(java.lang.String tableName)

newTable

DataTableModel newTable(TableFormat tableFormat)
See Also:
newTable(String, List, List, List, List, int);

newTable

DataTableModel newTable(java.lang.String tableName,
                        java.util.List<java.lang.String> columnNames,
                        java.util.List<java.lang.Class> columnTypes)
See Also:
newTable(String, List, List, List, List, int);

newTable

DataTableModel newTable(java.lang.String tableName,
                        java.lang.String[] columnNames,
                        java.lang.Class[] columnTypes)
See Also:
newTable(String, List, List, List, List, int);

newTable

DataTableModel newTable(java.lang.String tableName,
                        java.lang.String[] columnNames,
                        java.lang.Class[] columnTypes,
                        java.lang.Integer primaryKeyColumn)
See Also:
newTable(String, List, List, List, List, int);

newTable

DataTableModel newTable(java.lang.String tableName,
                        java.util.List<java.lang.String> columnNames,
                        java.util.List<java.lang.Class> columnTypes,
                        java.lang.Integer primaryKeyColumn)
See Also:
newTable(String, List, List, List, List, int);

newTable

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. Assumes you have already checked that this table name does not exist.

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

getTableNames

java.util.Vector<java.lang.String> getTableNames()

isTableNamesCaseSensitive

boolean isTableNamesCaseSensitive()
True if table names are case sensitive, false if table names are not case sensitive.

Returns:

getTable

DataTableModel getTable(java.lang.String tableName)
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().

Parameters:
tableName -
Returns:

getTable

DataTableModel getTable(TableFormat tableFormat)
Gets the table with that format. If the table does not exist, it will create it with the requested TableFormat.

Parameters:
tableFormat - format the table should be in
Returns:

deleteTable

boolean deleteTable(java.lang.String tableName)

renameTable

boolean renameTable(java.lang.String oldTableName,
                    java.lang.String newTableName)

isValidLabelString

boolean isValidLabelString(java.lang.String labelString)
Returns whether or not a string is a valid name for tables, columns, etc. If not, getLastErrorMessage() will be the error.

Parameters:
labelString -
Returns:

cancelSearchingForConnection

void cancelSearchingForConnection()
Stop waiting for the TableStorage to be connected -- and start throwing exceptions.


addSearchingForConnectionListener

void addSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
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.


removeSearchingForConnectionListener

void removeSearchingForConnectionListener(TableStorage.SearchingForConnectionListener listener)
Removes a listener to find when TableStorage is unavailable (usually due to network issues).

Parameters:
listener -

addTableListListener

void addTableListListener(TableStorage.TableListListener listener)

removeTableListListener

void removeTableListListener(TableStorage.TableListListener listener)

getLastErrorMessage

java.lang.String getLastErrorMessage()
Returns an error message, if there was one, from the most recent error.

Returns:

isOpen

boolean isOpen()

close

void close()
Call this when you're done with this class and will not use it again.