AsciiDatabase
Class Manager

java.lang.Object
  |
  +--AsciiDatabase.Manager
All Implemented Interfaces:
DatabaseManager

public class Manager
extends Object
implements DatabaseManager

A flexable method of turning flat ascii files into databases. The config file hard coded here contains pointers to table configuration files and data files. The table configuration file describes the format of the data in the data file.

At the moment, this code also handles the choice of file names for indexes of tables. This needs to be rethought as ModSQL should handle indices it creates all by itself.

Author:
chris.studholme@utoronto.ca

Field Summary
static String defasciiconf
          Default config file location for AsciiDatabase
private static int majorVersion
           
private static int minorVersion
           
private  RCFile rcfile
           
 
Constructor Summary
Manager()
          Create new Manager.
Manager(String rcfilename)
          Create new Manager with specifed configuration file.
 
Method Summary
 boolean createIndex(String name, String column)
          Create an index of the specifed column in the specified table.
 DatabaseTable createTable(String tablename, boolean temporary)
          Create the named table.
 boolean dropIndex(String name, String column)
          Delete the specified index.
 void dropTable(String name)
          Delete the specified table.
protected  void finalize()
          Closes the configuration file to free up a file descriptor.
 Function getFunction(String function_name)
          Get a database specific function for use in SQL.
 int getMajorVersion()
          Returns the major version number of this database.
 int getMinorVersion()
          Returns the minor version number of this database.
 boolean hasTable(String name)
          Checks if this database contains the named table.
 DatabaseTable openTable(String name)
          Opens the named table for read only access.
 DatabaseTable openTable(String name, boolean readonly)
          Opens the named table.
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

defasciiconf

public static final String defasciiconf
Default config file location for AsciiDatabase

majorVersion

private static final int majorVersion

minorVersion

private static final int minorVersion

rcfile

private RCFile rcfile
Constructor Detail

Manager

public Manager()
        throws IOException
Create new Manager. Config file location is read from ModSQL.DriverConfig, or default is used.
Parameters:
rcfilename - name of configuration file
Throws:
IOException - if an error occurs reading the configuration file

Manager

public Manager(String rcfilename)
        throws IOException
Create new Manager with specifed configuration file.
Parameters:
rcfilename - name of configuration file
Throws:
IOException - if an error occurs reading the configuration file
Method Detail

finalize

protected void finalize()
Closes the configuration file to free up a file descriptor.
Overrides:
finalize in class Object

getMajorVersion

public int getMajorVersion()
Returns the major version number of this database.
Specified by:
getMajorVersion in interface DatabaseManager
Returns:
major version number

getMinorVersion

public int getMinorVersion()
Returns the minor version number of this database.
Specified by:
getMinorVersion in interface DatabaseManager
Returns:
minor version number

hasTable

public boolean hasTable(String name)
Checks if this database contains the named table.
Specified by:
hasTable in interface DatabaseManager
Parameters:
name - table desired
Returns:
true if this database has the desired table, false otherwise

openTable

public DatabaseTable openTable(String name)
                        throws DatabaseException
Opens the named table for read only access.
Specified by:
openTable in interface DatabaseManager
Parameters:
name - desired table
Returns:
DatabaseTable requested, or null if the table was not found

openTable

public DatabaseTable openTable(String name,
                               boolean readonly)
                        throws DatabaseException
Opens the named table. Read/write access is not currently supported.
Specified by:
openTable in interface DatabaseManager
Parameters:
name - desired table
readonly - flag indicating that the table be opened readonly
Returns:
DatabaseTable requested, or null if the table was not found
Throws:
DatabaseException - if read/write access was requested

createTable

public DatabaseTable createTable(String tablename,
                                 boolean temporary)
                          throws DatabaseException
Create the named table.
Specified by:
createTable in interface DatabaseManager
Parameters:
tablename - name of new table
Returns:
DatabaseTable object representing the new table

createIndex

public boolean createIndex(String name,
                           String column)
Create an index of the specifed column in the specified table.
Specified by:
createIndex in interface DatabaseManager
Parameters:
name - name of table to index
column - name of column to index
Returns:
true if the index was successfully created, false otherwise

dropTable

public void dropTable(String name)
               throws DatabaseException
Delete the specified table.
Specified by:
dropTable in interface DatabaseManager
Parameters:
tablename - name of table to drop
Throws:
DatabaseException - if the operation failed

dropIndex

public boolean dropIndex(String name,
                         String column)
                  throws DatabaseException
Delete the specified index.
Specified by:
dropIndex in interface DatabaseManager
Parameters:
tablename - name of indexed table
columnname - name of indexed column

getFunction

public Function getFunction(String function_name)
Description copied from interface: DatabaseManager

Get a database specific function for use in SQL. This function may be used in any SQL query (not just queries involving this database's tables). Note that when looking up function names, ModSQL will always check for database specific functions before using built-in functions, so this method may be used to override the built-in SQL functions.

This method should return null if a function by the specified name is not found.

Specified by:
getFunction in interface DatabaseManager
Following copied from interface: ModSQL.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