#include <SystemManager.h>
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 SystemManager * | getInstance () |
Gets the singleton instance. |
ReturnCode SystemManager::createDb | ( | const char * | dbName | ) |
Creates a new database.
dbName | The name of the database to be created |
ReturnCode SystemManager::dropDb | ( | const char * | dbName | ) |
Drops an existing database.
dbName | The name of the database to be deleted |
ReturnCode SystemManager::openDb | ( | const char * | dbName | ) |
Opens a database.
dbName | The name of the database to be opened |
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.
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. |
ReturnCode SystemManager::dropTable | ( | const char * | relName | ) |
Drops an existing table.
relName | The name of the table to be deleted |
ReturnCode SystemManager::createIndex | ( | const char * | relName, | |
const char * | attrName | |||
) |
Creates an index on a table.
relName | The name of the table to be indexed | |
attrName | The name of the attribute to be indexed |
ReturnCode SystemManager::dropIndex | ( | const char * | relName, | |
const char * | attrName | |||
) |
Drops an index on a table.
relName | The name of the table for the index | |
attrName | The name of the attribute for the index |
ReturnCode SystemManager::load | ( | const char * | relName, | |
const char * | fileName | |||
) |
Bulk loads the contents of a file into a table.
relName | The name of the target table | |
fileName | The name of the source file |
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.
relName | The name of the table |
ReturnCode SystemManager::print | ( | const char * | relName | ) |
Print the contents of a table.
relName | The name of the table |
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).