cmu.survey.data.mysql
Class TableStorageMySQL

java.lang.Object
  extended by cmu.survey.data.TableStorageStub<DataTableModelMySQL>
      extended by cmu.survey.data.mysql.TableStorageMySQL
All Implemented Interfaces:
TableStorage

public class TableStorageMySQL
extends TableStorageStub<DataTableModelMySQL>


Nested Class Summary
 
Nested classes/interfaces inherited from interface cmu.survey.data.TableStorage
TableStorage.SearchingForConnectionListener, TableStorage.TableListListener
 
Field Summary
 
Fields inherited from class cmu.survey.data.TableStorageStub
lastErrorMessage, searchingForConnectionListeners, tableListListeners, tableVersionStorage
 
Constructor Summary
TableStorageMySQL(DatabaseConnection databaseConnection)
           
TableStorageMySQL(java.lang.String databaseConnectionString)
           
TableStorageMySQL(java.lang.String databaseConnectionString, TableStorage.SearchingForConnectionListener connectionListener)
           
 
Method Summary
 void cancelSearchingForConnection()
          Stop waiting for the TableStorage to be connected -- and start throwing exceptions.
 void close()
          Closes all the DataTableModels that have been opened.
 DatabaseConnection databaseConnectionFailedPleaseRefresh()
           
protected  boolean deleteTableProtected(java.lang.String tableName)
           
 void doneWithDatabaseQuery(DatabaseQuery query)
          Call this when you are done with a DatabaseQuery that you created with getNewDatabaseQuery().
 DatabaseConnection getDatabaseConnection()
           
 java.lang.Integer getLastInsertID(DatabaseQuery db)
           
 DatabaseQuery getNewDatabaseQuery()
          Get a database query.
protected  DataTableModelSingularInfo<DataTableModelMySQL> getSingularInfo(java.lang.String tableName)
           
protected  DataTableModelSingularInfo<DataTableModelMySQL> getSingularInfo(TableFormat tableFormat)
           
 java.util.Vector<java.lang.String> getTableNames()
           
protected  DataTableModelMySQL getTableProtected(DataTableModelSingularInfo singularInfo)
           
 boolean isOpen()
           
 boolean isTableNamesCaseSensitive()
          Returns whether table names are case sensitive.
 boolean isValidLabelString(java.lang.String labelString)
          Returns whether or not a string is a valid name for tables, columns, etc.
protected  DataTableModelMySQL 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<DataTableModelMySQL> tableInfo)
          Returns a new table, or null if it fails.
protected  boolean renameTableProtected(java.lang.String oldTableName, java.lang.String newTableName)
           
 boolean tableExists(java.lang.String tableName)
           
 
Methods inherited from class cmu.survey.data.TableStorageStub
addSearchingForConnectionListener, addTableListListener, deleteTable, finalize, fireTableListChanged, getLastErrorMessage, getTable, getTable, getTableVersionStorage, newTable, newTable, newTable, newTable, newTable, newTable, newTable, removeSearchingForConnectionListener, removeTableListListener, renameTable
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TableStorageMySQL

public TableStorageMySQL(java.lang.String databaseConnectionString)
                  throws java.lang.Throwable
Throws:
java.lang.Throwable

TableStorageMySQL

public TableStorageMySQL(DatabaseConnection databaseConnection)

TableStorageMySQL

public TableStorageMySQL(java.lang.String databaseConnectionString,
                         TableStorage.SearchingForConnectionListener connectionListener)
                  throws java.lang.Throwable
Throws:
java.lang.Throwable
Method Detail

tableExists

public boolean tableExists(java.lang.String tableName)

newTable

protected DataTableModelMySQL 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<DataTableModelMySQL> tableInfo)
Returns a new table, or null if it fails.

Specified by:
newTable in class TableStorageStub<DataTableModelMySQL>
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 TableDataModelSQL with the table.

getTableNames

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

isTableNamesCaseSensitive

public boolean isTableNamesCaseSensitive()
Returns whether table names are case sensitive. There's a horrible "feature" in MySQL that's really a bug -- at least, it's a bug unless you knew about it before they started doing it. Under Windows, by default, MySQL servers are case-insensitive, in versions ?4.0? and newer. However, in linux, it is and always has been case sensitive. This means that your code needs to handle it differently unless you want to start messing around with MySQL startup variables. What a mess for novices -- no way will they do that, and it doesn't look like it can be done automatically! So we put this in to work around the "feature".

Returns:

getSingularInfo

protected DataTableModelSingularInfo<DataTableModelMySQL> getSingularInfo(java.lang.String tableName)
Specified by:
getSingularInfo in class TableStorageStub<DataTableModelMySQL>

getSingularInfo

protected DataTableModelSingularInfo<DataTableModelMySQL> getSingularInfo(TableFormat tableFormat)
Specified by:
getSingularInfo in class TableStorageStub<DataTableModelMySQL>

getTableProtected

protected DataTableModelMySQL getTableProtected(DataTableModelSingularInfo singularInfo)
Specified by:
getTableProtected in class TableStorageStub<DataTableModelMySQL>

deleteTableProtected

protected boolean deleteTableProtected(java.lang.String tableName)
Specified by:
deleteTableProtected in class TableStorageStub<DataTableModelMySQL>

renameTableProtected

protected boolean renameTableProtected(java.lang.String oldTableName,
                                       java.lang.String newTableName)
Specified by:
renameTableProtected in class TableStorageStub<DataTableModelMySQL>

getNewDatabaseQuery

public DatabaseQuery getNewDatabaseQuery()
Get a database query. You should call doneWithDatabaseQuery(DatabaseQuery) with this object once you're done with it.

Returns:

doneWithDatabaseQuery

public void doneWithDatabaseQuery(DatabaseQuery query)
Call this when you are done with a DatabaseQuery that you created with getNewDatabaseQuery(). It will cache the query for later usage, or clear it from memory.

Parameters:
query -

isOpen

public boolean isOpen()

getDatabaseConnection

public DatabaseConnection getDatabaseConnection()

isValidLabelString

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

Returns:

cancelSearchingForConnection

public void cancelSearchingForConnection()
Description copied from interface: TableStorage
Stop waiting for the TableStorage to be connected -- and start throwing exceptions.


databaseConnectionFailedPleaseRefresh

public DatabaseConnection databaseConnectionFailedPleaseRefresh()

getLastInsertID

public java.lang.Integer getLastInsertID(DatabaseQuery db)

close

public void close()
Description copied from class: TableStorageStub
Closes all the DataTableModels that have been opened.

Specified by:
close in interface TableStorage
Overrides:
close in class TableStorageStub<DataTableModelMySQL>