ModSQL
Interface DatabaseTable

All Superinterfaces:
DatabaseTableBase
All Known Implementing Classes:
SelectTable, TableTemplate, Table, AsciiTable

public interface DatabaseTable
extends DatabaseTableBase

Interface to be implemented by classes representing database tables.

To create a new type of database, you need to implement DatabaseTable and DatabaseManager. DatabaseManager creates DatabaseTable objects.

Author:
chris.studholme@utoronto.ca
See Also:
DatabaseManager

Method Summary
 boolean absolute(Object rowid)
          Move to an absolute rowid in the table.
 void addColumn(String name, int type, int maxlen)
          Add a new column to the table.
 void addRow()
          Add a new row to the database.
 int findColumn(String columnName)
          Map a DatabaseTable column name to a DatabaseTable column index.
 int getColumnCount()
          What's the number of columns in the DatabaseTable?
 int getColumnDisplaySize(int column)
          What's the column's normal max width in chars? If the column type is not a string, or the maximum size is not known, this method may return -1.
 String getColumnLabel(int column)
          What's the suggested column title for use in printouts and displays? In many cases this method should return the same value as getColumnName() below.
 String getColumnName(int column)
          What's a column's name?
 int getColumnType(int column)
          What's a column's SQL type?
 String getTableName()
          What's the table's name?
 long getTableSignature()
          Calculates a unique signature for this table.
 long getTableSize()
          Returns the size of the table in bytes.
 boolean isIndexAvailable(int column)
          Determines if an index is available for the specified column.
 boolean isReadOnly()
          Is table read-only (ie.
 DatabaseIndex openIndex(int column)
          Returns an index on the specified column.
 
Methods inherited from interface ModSQL.DatabaseTableBase
afterLast, beforeFirst, close, commitUpdates, deleteRow, getObject, getRowCount, getRowId, isAfterLast, isBeforeFirst, next, updateObject
 

Method Detail

openIndex

public DatabaseIndex openIndex(int column)
                        throws DatabaseException
Returns an index on the specified column.
Parameters:
column - index of column to be indexed
Returns:
new DatabaseIndex to use, or null if no index exists
Throws:
DatabaseException - if a database-access error occurs

isIndexAvailable

public boolean isIndexAvailable(int column)
                         throws DatabaseException
Determines if an index is available for the specified column.
Parameters:
column - index of column to be indexed
Returns:
true if index is available, false otherwise
Throws:
DatabaseException - if a database-access error occurs

isReadOnly

public boolean isReadOnly()
                   throws DatabaseException
Is table read-only (ie. no update, insert or delete)?
Returns:
true if so
Throws:
DatabaseException - if a database-access error occurs

getTableName

public String getTableName()
                    throws DatabaseException
What's the table's name?
Returns:
table name or "" if not applicable
Throws:
DatabaseException - if a database-access error occurs

getColumnCount

public int getColumnCount()
                   throws DatabaseException
What's the number of columns in the DatabaseTable?
Returns:
the number
Throws:
DatabaseException - if a database-access error occurs

getTableSize

public long getTableSize()
                  throws DatabaseException
Returns the size of the table in bytes. This method may return an approximation, or -1 is the size is not known.
Returns:
table size in bytes
Throws:
DatabaseException - if a database-access error occurs

getTableSignature

public long getTableSignature()
                       throws DatabaseException

Calculates a unique signature for this table.

The signature should depend on values of:

Any change to the table that would invalidate an index should also change the signature. If this table will never be indexed, this method may return 0.

Returns:
unique signature for table
Throws:
DatabaseException - if a database-access error occurs

findColumn

public int findColumn(String columnName)
               throws DatabaseException
Map a DatabaseTable column name to a DatabaseTable column index. Columns should be sequentially numbered 1,2,3,etc.
Parameters:
columnName - the name of the column
Returns:
the column index
Throws:
DatabaseException - if a database-access error occurs

getColumnDisplaySize

public int getColumnDisplaySize(int column)
                         throws DatabaseException
What's the column's normal max width in chars? If the column type is not a string, or the maximum size is not known, this method may return -1.
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
max width
Throws:
DatabaseException - if a database-access error occurs

getColumnLabel

public String getColumnLabel(int column)
                      throws DatabaseException
What's the suggested column title for use in printouts and displays? In many cases this method should return the same value as getColumnName() below.
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
true if so
Throws:
DatabaseException - if a database-access error occurs

getColumnName

public String getColumnName(int column)
                     throws DatabaseException
What's a column's name?
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
column name
Throws:
DatabaseException - if a database-access error occurs

getColumnType

public int getColumnType(int column)
                  throws DatabaseException
What's a column's SQL type?
Parameters:
column - the first column is 1, the second is 2, ...
Returns:
SQL type
Throws:
DatabaseException - if a database-access error occurs
See Also:
Types

addColumn

public void addColumn(String name,
                      int type,
                      int maxlen)
               throws DatabaseException
Add a new column to the table.
Parameters:
name - column name
type - SQL type
maxlen - length of data (varying columns only)
Throws:
DatabaseException - if a database-access error occurs
See Also:
Types

addRow

public void addRow()
            throws DatabaseException
Add a new row to the database. This method creates a new row which must have columns set using updateObject().
Throws:
DatabaseException - if a database-access error occurs

absolute

public boolean absolute(Object rowid)
                 throws DatabaseException
Move to an absolute rowid in the table.
Parameters:
rowid - id of row to seek
Returns:
true if row was found, false otherwise
Throws:
DatabaseException - if a database-access error occurs