ModSQL
Class MetaManager

java.lang.Object
  |
  +--ModSQL.MetaManager
All Implemented Interfaces:
DatabaseManager

public final class MetaManager
extends Object
implements DatabaseManager

DatabaseManager that can be used to combine multiple DatabaseManagers into one metadatabase.

This implementation of DatabaseManager allows other classes implementing DatabaseManager to register themselves. When this object is asked for a particular DatabaseTable, the MetaManager searches its list of DatabaseManager's for one that can provide the required table.

Author:
chris.studholme@utoronto.ca

Field Summary
private static Vector managers
          Array of database managers.
 
Constructor Summary
MetaManager()
          Constructor.
 
Method Summary
 boolean createIndex(String name, String column)
          Create an index of the specified column in the specified table (if capable).
 DatabaseTable createTable(String name, boolean temporary)
          Create a new table using the first manager that will host it.
 boolean dropIndex(String name, String column)
          Drop an index.
 void dropTable(String name)
          Drop a table.
 Function getFunction(String name)
          Get a database specific function for use in SQL.
 int getMajorVersion()
          Major version number.
static DatabaseManager[] getManagers()
          Get current list of database managers.
 int getMinorVersion()
          Minor version number.
 boolean hasTable(String name)
          Check all managers for the specified table.
 DatabaseTable openTable(String name)
          Open table (read-only) using the first manager that provides the table.
 DatabaseTable openTable(String name, boolean readonly)
          Open table using the first manager that provides the table.
static void registerManager(DatabaseManager manager)
          Register a database manager with the meta-manager.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

managers

private static Vector managers
Array of database managers.
Constructor Detail

MetaManager

public MetaManager()
Constructor.
Method Detail

registerManager

public static void registerManager(DatabaseManager manager)
Register a database manager with the meta-manager.
Parameters:
manager - DatabaseManager to register

getManagers

public static DatabaseManager[] getManagers()
Get current list of database managers.
Returns:
array of database managers

getMajorVersion

public int getMajorVersion()
Major version number.
Specified by:
getMajorVersion in interface DatabaseManager
Returns:
major version number

getMinorVersion

public int getMinorVersion()
Minor version number.
Specified by:
getMinorVersion in interface DatabaseManager
Returns:
minor version number

hasTable

public boolean hasTable(String name)
                 throws DatabaseException
Check all managers for the specified table.
Specified by:
hasTable in interface DatabaseManager
Parameters:
name - table to search for
Returns:
true if some manager has the table
Throws:
DatabaseException - if a database-access error occurs

openTable

public DatabaseTable openTable(String name)
                        throws DatabaseException
Open table (read-only) using the first manager that provides the table.
Specified by:
openTable in interface DatabaseManager
Parameters:
name - table to search for
Returns:
open table or null if not found
Throws:
DatabaseException - if a database-access error occurs

openTable

public DatabaseTable openTable(String name,
                               boolean readonly)
                        throws DatabaseException
Open table using the first manager that provides the table.
Specified by:
openTable in interface DatabaseManager
Parameters:
name - table to search for
readonly - true for read-only, false for read-write
Returns:
open table or null if not found
Throws:
DatabaseException - if a database-access error occurs

createTable

public DatabaseTable createTable(String name,
                                 boolean temporary)
                          throws DatabaseException
Create a new table using the first manager that will host it. If an existing table is found with the same name before a manager willing to host the new table is found, an exception is thrown.
Specified by:
createTable in interface DatabaseManager
Parameters:
name - table to create
temporary - true if the table is temporary
Returns:
open table or null if no manager will host it
Throws:
DatabaseException - if a database-access error occurs

createIndex

public boolean createIndex(String name,
                           String column)
                    throws DatabaseException
Create an index of the specified column in the specified table (if capable).
Specified by:
createIndex in interface DatabaseManager
Parameters:
tablename - name of the table to index
columnname - name of the column to index
Returns:
true if index was created, false if database is not capable of creating indicies
Throws:
DatabaseException - if a database-access error occurs

dropTable

public void dropTable(String name)
               throws DatabaseException
Drop a table.
Specified by:
dropTable in interface DatabaseManager
Parameters:
tablename - name of the table to drop
Throws:
DatabaseException - if a database-access error occurs

dropIndex

public boolean dropIndex(String name,
                         String column)
                  throws DatabaseException
Drop an index. This method should throw an exception if the table does not exist, but should return false if the column has not been indexed.
Specified by:
dropIndex in interface DatabaseManager
Parameters:
tablename - name of the table with index
columnname - name of the column with index
Returns:
true if the index existed and has been dropped, false if it didn't exist
Throws:
DatabaseException - if a database-access error occurs

getFunction

public Function getFunction(String name)
                     throws DatabaseException
Get a database specific function for use in SQL. This method returns null if a function by the specified name is not found.
Specified by:
getFunction in interface DatabaseManager
Parameters:
name - name of function to lookup (always lowercase)
Returns:
new function object (or null if function not found)
Throws:
DatabaseException - if a database-access error occurs