Class for creating, destroying, opening, and closing B+ tree index files. More...
#include <IndexManager.h>
Public Member Functions | |
ReturnCode | createIndex (const char *fileName, int attrNo, AttributeType attrType, int attrLength) |
Creates a new index on the specified record file. | |
ReturnCode | removeIndex (const char *fileName, int attrNo) |
Deletes an index for the specified record file. | |
ReturnCode | openIndex (const char *fileName, int attrNo, IndexHandle **indexHandle) |
Opens an index for the specified record file. | |
ReturnCode | closeIndex (IndexHandle *indexHandle) |
Closes an index for the specified record file. | |
Static Public Member Functions | |
static IndexManager * | getInstance () |
Gets the singleton IndexManager instance. | |
static bool | getIndexFileName (const char *fileName, int attrNo, char *indexFileName, uint length) |
Get the name to be used for the index file for the specified record file and attribute number. |
Class for creating, destroying, opening, and closing B+ tree index files.
Class for creating, destroying, opening, and closing B+ tree index files. This is a singleton class; a reference to the singleton is obtained by calling IndexManager::getInstance. Manipulation of the contents of index files is done via the IndexHandle class; while scans of the index are done via the IndexScan class.
ReturnCode IndexManager::closeIndex | ( | IndexHandle * | indexHandle | ) |
Closes an index for the specified record file.
indexHandle | The handle to the open index |
Closes an index for the specified record file, and frees the indexHandle object. This method should close the underlying page file for this index. Returns RC_OK on success, and appropriate RC error codes otherwise.
ReturnCode IndexManager::createIndex | ( | const char * | fileName, | |
int | attrNo, | |||
AttributeType | attrType, | |||
int | attrLength | |||
) |
Creates a new index on the specified record file.
fileName | The name of the record file being indexed. | |
attrNo | A number specifying which attribute is being indexed | |
attrType | The type of the record attribute begin indexed | |
attrLength | The length in bytes of the attribute being indexed |
Creates a new B+ tree index on the specified record file. The name of the underlying file used to store this index should be the one returned by method IndexManager::getIndexFileName. attrNo is the logical index of the attribute being indexed in the records, with the first attribute having attrNo 0. This method should establish an empty index by creating the underlying page file and initializing it appropriately. Returns RC_OK on success, RC_FILE_ALREADY_EXISTS if an index file for the specified fileName and attrNo already exists, or other non-zero RC error codes for any other error.
bool IndexManager::getIndexFileName | ( | const char * | fileName, | |
int | attrNo, | |||
char * | indexFileName, | |||
uint | length | |||
) | [static] |
Get the name to be used for the index file for the specified record file and attribute number.
fileName | The file name for the record file | |
attrNo | The logical index of the attribute in the record | |
indexFileName | Out parameter where the index file name will be written | |
length | The length in bytes of the indexFileName buffer |
Get the name to be used for the index file for the specified record file and attribute number. Returns false if indexFileName may not be large enough to hold the index file name. Returns true on success.
ReturnCode IndexManager::openIndex | ( | const char * | fileName, | |
int | attrNo, | |||
IndexHandle ** | indexHandle | |||
) |
Opens an index for the specified record file.
fileName | The name of the record file associated with this index | |
attrNo | A number specifying which attribute this index is on | |
indexHandle | Out parameter where the newly allocated IndexHandle is returned |
Opens an existing index for the specified record file and attribute. Returns RC_OK on success and returns a newly allocated IndexHandle object in the indexHandle out parameter. Returns RC_FILE_NOT_FOUND if the specified index file is not found, or other RC error codes in other cases.
The returned IndexHandle is used to insert and delete entries from the index, and it can be passed into an IndexScan object constructor for performing a scan using the index. As with the RecordManager components, clients should be able to open an index more than once for reading, using a different IndexHandle object each time. However, you may make the assumption that if a client is modifying an index, then no other clients are using an IndexHandle to read or modify that index. An opened index must eventually be closed using IndexManager::closeIndex.
ReturnCode IndexManager::removeIndex | ( | const char * | fileName, | |
int | attrNo | |||
) |
Deletes an index for the specified record file.
fileName | The name of the record file that was indexed | |
attrNo | A number specifying which attribute was indexed |
Deletes a B+ tree index on the specified record file. The name of the underlying file used to store this index should be the one returned by method IndexManager::getIndexFileName. This method should destroy the index for attrNo on the record file named fileName by destroying the page file used to store the index. Returns RC_OK on success, RC_FILE_NOT_FOUND if the index file does not exist, or error codes as specified in PageFileManager::removeFile for other errors.