DBFile Class Reference

#include <DBFile.h>

List of all members.


Detailed Description

Low level database file.

This abstraction allows the user to treat a database as a collection of pages.

Author:
Dave Musicant, with considerable material reused from the UW-Madison Minibase project


Public Member Functions

 DBFile (string name, int numPages)
 Creates a database with the specified number of pages.
 DBFile (string name)
 Opens the database with the given name.
int allocatePages (int runSize)
 Allocates a set of pages.
void deallocatePages (int startPageNum, int runSize)
 Deallocates a set of pages.
void readPage (int pageNum, Page *page)
 Reads the contents of the specified page from disk into the page object provided.
void writePage (int pageNum, const Page *page)
 Writes the contents of the specified page to disk.

Static Public Member Functions

static bool erase (string name)
 Erases the database entirely from the filesystem.


Constructor & Destructor Documentation

DBFile::DBFile ( string  name,
int  numPages 
)

Creates a database with the specified number of pages.

The number of pages in the database can never be increased.

Parameters:
name name to be given to database.
numPages maximum number of pages in database.
Exceptions:
IOException if problem with file system.

DBFile::DBFile ( string  name  ) 

Opens the database with the given name.

Parameters:
name name of the database.
Exceptions:
IOException if problem with file system.


Member Function Documentation

int DBFile::allocatePages ( int  runSize  ) 

Allocates a set of pages.

Parameters:
runSize number of pages to be allocated in the run.
Returns:
page number of the first page of the allocated run.
Exceptions:
NonPositiveRunSizeException if the run size is less than or equal to zero.
FileFullException if there are not enough free pages.

void DBFile::deallocatePages ( int  startPageNum,
int  runSize 
)

Deallocates a set of pages.

Does not ensure that the pages being deallocated are in fact allocated to begin with. If the pages were already deallocated, they remain so.

Parameters:
startPageNum page number at the beginning of the run to be deallocated.
runSize number of pages to deallocate.
Exceptions:
NonPositiveRunSizeException if the run size is less than or equal to zero.
BadPageNumberException if startPageNum is illegal.

static bool DBFile::erase ( string  name  )  [static]

Erases the database entirely from the filesystem.

Dangerous to do if still have a DBFile object that refers to this file.

Parameters:
name name of the database.
Returns:
true if operation succeeded.

void DBFile::readPage ( int  pageNum,
Page *  page 
)

Reads the contents of the specified page from disk into the page object provided.

Parameters:
pageNum the page number to be read.
page a pointer to an already allocated Page object.
Exceptions:
BadPageNumberException if pageNum is not in the file.

void DBFile::writePage ( int  pageNum,
const Page *  page 
)

Writes the contents of the specified page to disk.

Parameters:
pageNum the page number to be written.
page a pointer to a Page object with data to be written.
Exceptions:
EmptyFileException() if the file has no pages within it.
BadPageNumberException if pageNum is not in the file.


Generated on Wed Aug 29 07:32:08 2007 for Minibase by  doxygen 1.4.7