cmu.survey.data
Interface TableFormat

All Known Subinterfaces:
TableFormat.TableFormatAndDoMore
All Known Implementing Classes:
DataBitStorageTable.AuxillaryOptionTableFormatClass, DataBitStorageTable.QuestionsTableFormatClass, DataBitStorageTable.RepeatedMeasureAnswerTableFormatClass, DataBitStorageTable.RepeatedMeasureTableFormatClass, DataBitStorageTable.SurveyPagesTableFormatClass, TableFormat.TableFormatStub, TableFormat.TableFormatStubAndDoMoreAddRow

public interface TableFormat

A table in the database that can be created upon demand, and can be upgraded on demand. Basically, it's a prototype of the format of a table in the database.

There may be differences between the TableFormat and the actual table -- this TableFormat only makes sure that the format matches what's required AS IT IS USED. So, for example, if you have a database table already created using a TableFormat, and then you add a new column to a TableFormat, the new column will not be created until it is used. Contrapositively, extra columns that are in the table but not in the TableFormat will not be deleted -- they will stay there. For example, in a survey's storage table, there is a TableFormat which has only the required columns -- all the extra columns for storing data that are variable are handled separately from the TableFormat.


Nested Class Summary
static interface TableFormat.ColumnFormat
           
static interface TableFormat.ColumnFormatKnowHowToCreate
          A column that is non-standard or expected to be needed in an upgrade, with special upgrade needs (more than just creating the column).
static class TableFormat.ColumnFormatRenamed
          This assumes that neither the old nor new columns are primary keys, and that the old and new columns are the same type.
static class TableFormat.ColumnFormatStub
           
static interface TableFormat.TableFormatAndDoMore
           
static class TableFormat.TableFormatStub
           
static class TableFormat.TableFormatStubAndDoMoreAddRow
          Adds a default row of data automatically when the table is created.
 
Method Summary
 TableFormat.ColumnFormat getColumn(java.lang.String name)
          Get a column by this name, if it exists.
 java.util.List<TableFormat.ColumnFormat> getColumns()
           
 java.util.List getDefaultData()
          The default data to initialize this table with, if it is initialized.
 java.lang.String getName()
           
 int getPrimaryKeyColumnIndex()
          The index of the column that is the primary key.
 int getVersion()
          The version of the table.
 

Method Detail

getColumns

java.util.List<TableFormat.ColumnFormat> getColumns()
Returns:
List of ColumnFormat

getColumn

TableFormat.ColumnFormat getColumn(java.lang.String name)
Get a column by this name, if it exists. If it doesn't exist, return null.

Parameters:
name -
Returns:

getName

java.lang.String getName()

getPrimaryKeyColumnIndex

int getPrimaryKeyColumnIndex()
The index of the column that is the primary key. This is optional, and it can be -1 if there's no primary key. However, in order to use the full functionality of TableFormat and of auto-updating columns, there must be a primary key. Basically, the primary key is needed after a new column is created or renamed, so that any queries on the database that are currently happening can be automatically re-done and reset to their previous location. Primary keys must be integers. When a new row is created, an unused integer will be set as the value of the primary key. (In MySQL, they are AUTO_INCREMENT columns).

Returns:
if no primary key returns -1, if there is a primary key it's the index in getColumns() of the column that's the primary key

getDefaultData

java.util.List getDefaultData()
The default data to initialize this table with, if it is initialized. If there is no default data for this table, return null.

Returns:

getVersion

int getVersion()
The version of the table. Increment this every time you make a new version of the table. This way, when an upgrade is needed, it will check to make sure that it's upgrading -- for example, if you upgrade, and then run an old version of the program, it might do reverse of the changes, or create an old column that shouldn't be there, etc., without realizing that it's not compatible with this version.

Returns: