FileHandle Class Reference

Page file handle class. More...

#include <FileHandle.h>

List of all members.

Public Member Functions

ReturnCode initialize (PageFileManager *mgr, const char *fileName, FILE *file)
 Initializes the file handle.
ReturnCode getFirstPage (PageHandle *pageHandle)
 Gets the first page in the file.
ReturnCode getLastPage (PageHandle *pageHandle)
 Gets the last page in the file.
ReturnCode getNextPage (int pageNo, PageHandle *pageHandle)
 Get the next page in the file following the one specified.
ReturnCode getPrevPage (int pageNo, PageHandle *pageHandle)
 Gets the page in the file previous to the one specified.
ReturnCode getThisPage (int pageNo, PageHandle *pageHandle)
 Gets the specified page in the file.
ReturnCode allocatePage (PageHandle *pageHandle)
 Allocates a fresh page in the page file.
ReturnCode disposePage (int pageNo)
 Frees a page in the page file.
ReturnCode markDirty (int pageNo)
 Marks a page in the file as dirty.
ReturnCode unpinPage (int pageNo)
 Unpins the specified page.
ReturnCode forcePage (int pageNo)
 Writes a dirty page to disk.
ReturnCode forceAllPages ()
 Writes all dirty pages to disk.
const char * getFileName ()
 Gets the name of the underlying file.
FILE * getFile ()
 Gets the pointer to the underlying file stream.
int countPages ()
 Returns a count of allocated pages.
PageFileManagergetPageFileManager ()

Static Public Member Functions

static ReturnCode onCreate (PageFileManager *mgr, const char *fileName, FILE *file)

Detailed Description

Page file handle class.


Member Function Documentation

ReturnCode FileHandle::allocatePage ( PageHandle pageHandle  ) 

Allocates a fresh page in the page file.

Parameters:
pageHandle Out pointer to page handle structures.

Allocates a new page in the page file, storing the page number and the contents of the page block in the supplied PageHandle structure, and pinning the page block in the buffer pool. The block must eventually be unpinned by a call to FileHandle::unpinPage. Returns RC_OK on success, RC_FILE_TOO_BIG if no more pages can be allocated in the file, or RC_OUT_OF_BUFFER if there are no free blocks in the buffer pool.

ReturnCode FileHandle::disposePage ( int  pageNo  ) 

Frees a page in the page file.

Parameters:
pageNo The number of the page to free.

Frees the specified page in the page file for subsequent re-allocation. Returns RC_OK on success, RC_PAGE_PINNED if the page block is pinned in the buffer pool and therefore cannot be disposed, or RC_PAGE_NOT_FOUND if the page number does not correspond to an allocated page.

ReturnCode FileHandle::forceAllPages (  ) 

Writes all dirty pages to disk.

Writes all dirty pages to disk, clearing their dirty bits. Returns RC_OK on success, and RC_UNIX if there is a file system error during the write.

ReturnCode FileHandle::forcePage ( int  pageNo  ) 

Writes a dirty page to disk.

Parameters:
pageNo The number of the page to write to disk.

Writes a dirty page to disk, and clears the page's dirty bit. Returns RC_OK on success, RC_PAGE_NOT_FOUND if the page number is invalid or if the page is not currently in the buffer pool, RC_PAGE_NOT_DIRTY if the page is not dirty (in which case nothing is written to disk), or RC_UNIX if there is a file system error during the write.

FILE * FileHandle::getFile (  ) 

Gets the pointer to the underlying file stream.

Gets the pointer to the underlying file stream. This method is intended to be used only by PageFileManager, who owns the file stream.

ReturnCode FileHandle::getFirstPage ( PageHandle pageHandle  ) 

Gets the first page in the file.

Parameters:
pageHandle Out pointer to page handle structure.

Gets the first allocated page in the file, storing the page number and the contents of the page block in the supplied PageHandle structure, and pinning the page block in the buffer pool. The block must eventually be unpinned by a call to FileHandle::unpinPage. Returns RC_OK on success, RC_EOF if there are no allocated pages in the file, or RC_OUT_OF_BUFFER if there are no free blocks in the buffer pool.

ReturnCode FileHandle::getLastPage ( PageHandle pageHandle  ) 

Gets the last page in the file.

Parameters:
pageHandle Out pointer to page handle structure.

Gets the last allocated page in the file, similarly to FileHandle::getFirstPage.

ReturnCode FileHandle::getNextPage ( int  pageNo,
PageHandle pageHandle 
)

Get the next page in the file following the one specified.

Parameters:
pageNo The number of the current page.
pageHandle Out pointer to page handle structure.

Gets the first allocated page in the file following the specified page, storing the page number and the contents of the page block in the supplied PageHandle structure, and pinning the page block in the buffer pool. The block must eventually be unpinned by a call to FileHandle::unpinPage. Returns RC_OK on success, RC_EOF if there are no more pages in the file, or RC_OUT_OF_BUFFER if there are no free blocks in the buffer pool.

ReturnCode FileHandle::getPrevPage ( int  pageNo,
PageHandle pageHandle 
)

Gets the page in the file previous to the one specified.

Parameters:
pageNo The number of the current page.
pageHanlde Out pointer to page handle structure.

Gets the first allocated page in the file preceding the specified page, similarly to FileHandle::getNextPage.

ReturnCode FileHandle::getThisPage ( int  pageNo,
PageHandle pageHandle 
)

Gets the specified page in the file.

Parameters:
pageNo The number of the page to be retrieved.
pageHandle Out pointer to page handle structure.

Retrieves the specified page from the file, storing the page number and the contents of the page block in the supplied PageHandle structure, and pinning the page block in the buffer pool. The block must eventually be unpinned by a call to FileHandle::unpinPage. Returns RC_OK on success, RC_PAGE_NOT_FOUND if the page number does not correspond to an allocated page, or RC_OUT_OF_BUFFER if there are no free blocks in the buffer pool.

ReturnCode FileHandle::initialize ( PageFileManager mgr,
const char *  fileName,
FILE *  file 
)

Initializes the file handle.

Parameters:
mgr Back-pointer to the page file manager that created this handle.
fileName The name of the file on disk.
file The open file stream.

Initializes the file handle. Returns RC_OK on success, RC_CORRUPT_FILE if the file appears corrupt, as detected when the header page is read, or RC_UNIX, if there is any other error reading the file stream. This method is only called by the PageFileManager.

ReturnCode FileHandle::markDirty ( int  pageNo  ) 

Marks a page in the file as dirty.

Parameters:
pageNo The number of the page to mark.

Marks the specified page as dirty, indicating that it needs to be written back to disk. Returns RC_PAGE_NOT_FOUND if the specified page does not correspond to an allocated page or is not currently in the buffer pool, and RC_OK on success.

ReturnCode FileHandle::unpinPage ( int  pageNo  ) 

Unpins the specified page.

Parameters:
pageNo The number of the page to unpin.

Unpins the specified page, i.e., decrements the page's pin count in the buffer pool. Returns RC_OK on success, RC_PAGE_NOT_FOUND if the specified page number does not correspond to an allocated page or is not currently in the buffer pool, and RC_PAGE_UNPINNED if the page's pin count was already zero.


The documentation for this class was generated from the following files:
Generated on Sun May 16 23:18:41 2010 for DavisDB by  doxygen 1.6.3