SystemManager Class Reference

Class for executing commands issued via the DavisDB shell. More...

#include <SystemManager.h>

List of all members.

Public Member Functions

ReturnCode createDb (const char *dbName)
 Creates a new database.
ReturnCode dropDb (const char *dbName)
 Drops an existing database.
ReturnCode openDb (const char *dbName)
 Opens a database.
ReturnCode closeDb ()
 Closes the open database.
ReturnCode createTable (const char *relName, int attrCount, AttributeInfo *attributes)
 Creates a new table.
ReturnCode dropTable (const char *relName)
 Drops an existing table.
ReturnCode createIndex (const char *relName, const char *attrName)
 Creates an index on a table.
ReturnCode dropIndex (const char *relName, const char *attrName)
 Drops an index on a table.
ReturnCode load (const char *relName, const char *fileName)
 Bulk loads the contents of a file into a table.
ReturnCode info ()
 Displays metadata about the database.
ReturnCode info (const char *relName)
 Display metadata about a table.
ReturnCode print (const char *relName)
 Print the contents of a table.
bool isOpen ()
 Returns true iff a database is currently open.

Static Public Member Functions

static SystemManagergetInstance ()
 Gets the singleton instance.


Detailed Description

Class for executing commands issued via the DavisDB shell.

Member Function Documentation

ReturnCode SystemManager::createDb ( const char *  dbName  ) 

Creates a new database.

Parameters:
dbName The name of the database to be created
Creates a new database. The method should create a subdirectory dbName for the new database, and create and initialize the system catalogs inside that subdirectory. Returns RC_OK on success, fails with RC_FILE_EXISTS if the subdirectory already exists, and other RC error codes otherwise.

ReturnCode SystemManager::dropDb ( const char *  dbName  ) 

Drops an existing database.

Parameters:
dbName The name of the database to be deleted
Deletes an existing database by removing the subdirectory dbName and all its contents (by using, e.g., a call to system("rm -rf <dbName>")). Returns RC_OK on success, RC_FILE_NOT_FOUND if no such subdirectory exists, RC_FILE_OPEN if a database is currently open, and other RC error codes otherwise.

ReturnCode SystemManager::openDb ( const char *  dbName  ) 

Opens a database.

Parameters:
dbName The name of the database to be opened
Opens a database by changing into the directory dbName and performing any appropriate initialization, such as opening the system catalogs. Returns RC_OK on success, RC_FILE_NOT_FOUND if subdirectory dbName does not exist, and other RC error codes otherwise.

ReturnCode SystemManager::closeDb (  ) 

Closes the open database.

Closes the database currently open by closing any open files and changing out of the database subdirectory. Returns RC_OK on success, and other RC error codes otherwise.

ReturnCode SystemManager::createTable ( const char *  relName,
int  attrCount,
AttributeInfo attributes 
)

Creates a new table.

Parameters:
relName The name of the table to be created
attrCount The number of attributes for the table
attributes An array of AttributeInfo pointers describing the attributes.
Creates a new table in the current database, updating the system catalogs appropriately. Returns RC_OK on success, RC_FILE_EXISTS if a table by that name already exists, and other RC error codes otherwise.

ReturnCode SystemManager::dropTable ( const char *  relName  ) 

Drops an existing table.

Parameters:
relName The name of the table to be deleted
Deletes a table from the current database, along with any indices on the table, and updates the system catalogs appropriately. Returns RC_OK on success, RC_FILE_NOT_FOUND if no such table exists, and other RC error codes otherwise.

ReturnCode SystemManager::createIndex ( const char *  relName,
const char *  attrName 
)

Creates an index on a table.

Parameters:
relName The name of the table to be indexed
attrName The name of the attribute to be indexed
Creates a B+ tree index on the specified table and attribute, updating the system catalogs appropriately. Returns RC_OK on success, RC_FILE_NOT_FOUND if no such table exists, RC_FILE_EXISTS if the specified index already exists, and other RC error codes otherwise.

ReturnCode SystemManager::dropIndex ( const char *  relName,
const char *  attrName 
)

Drops an index on a table.

Parameters:
relName The name of the table for the index
attrName The name of the attribute for the index
Deletes the B+ tree index on the specified table and attribute, updating the system catalogs appropriately. Returns RC_OK on success, RC_FILE_NOT_FOUND if no such table or index exists, and other RC error codes otherwise.

ReturnCode SystemManager::load ( const char *  relName,
const char *  fileName 
)

Bulk loads the contents of a file into a table.

Parameters:
relName The name of the target table
fileName The name of the source file
Bulk loads the contents of the specified text file into the specified table, while updating any indices on the attributes of the table. The file should contain data in comma-separated format, with one line per tuple. Integers and floats in the file may be assumed to use the standard C library string encodings of those data types, hence can be parsed using strtol and strtof, respectively. (See the man pages for those functions for a description of the formats.) Strings in the file may be assumed to not contain any commas.

A typical implementation of SystemManager::load will first open the file (using fopen or ifstream::open), then read the contents of the file one line at a time, breaking each line into a comma-delimited attribute values using, e.g., strtok, parsing the attribute values according to their types, serializing the sequence of parsed attribute values into a record, then inserting the record into the target table (and the relevant keys into any indices on that table).

Character strings in the text file can be of any length up to the length specified for the corresponding attribute, including zero length (no characters for that field in the text file). If a character string is too long, you may silently truncate it, or you may generate a nonzero return code and stop loading, whichever behavior you prefer.

ReturnCode SystemManager::info (  ) 

Displays metadata about the database.

Displays (i.e., outputs to stdout) metadata about the database. This information should include the names of all relations in the database, as well as any other information you would like to include. Returns RC_OK on success and other RC error codes on failure.

ReturnCode SystemManager::info ( const char *  relName  ) 

Display metadata about a table.

Parameters:
relName The name of the table
Displays (i.e., outputs to stdout) metadata about a table in the database. This information should include the name, type, length, and offset of each attribute in the specified relation, together with any other information you feel may be useful. Returns RC_OK on success, RC_FILE_NOT_FOUND if the specified table does not exist, and other RC error codes otherwise.

ReturnCode SystemManager::print ( const char *  relName  ) 

Print the contents of a table.

Parameters:
relName The name of the table
Prints the contents of a table to stdout. For uniformity, this must be done using the provided SystemPrinter class, using a call to SystemPrinter::printHeader (to print header information such as the name of each attribute), then a call to SystemPrinter::printRecord for each row in the table, and finally a call to SystemPrinter::printFooter (to output footer information including the total number of rows in the table). Returns RC_OK on success, RC_FILE_NOT_FOUND if the specified table does not exist, and other RC error codes otherwise.

bool SystemManager::isOpen (  ) 

Returns true iff a database is currently open.

Returns true iff a database is currently open. SystemManager should support multiple databases, but only one is allowed to be open at any given time. SystemParser uses this method to determine whether a given command may be issued (e.g., it will only call SystemManager::closeDatabase if the database is currently open).


The documentation for this class was generated from the following files:

Generated on Mon May 16 17:05:06 2011 by  doxygen 1.5.6