SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
File Class Referenceabstract

#include <file.h>

Inheritance diagram for File:
Inheritance graph
[legend]
Collaboration diagram for File:
Collaboration graph
[legend]

Public Member Functions

 File (Catalog *catalog, BufferManager *buf_mgr)
 Constructor. Initializes common state associated with every file, including catalog, buf_mgr, and schema.
 
virtual ~File ()
 Destructor. Data members are cleaned up, but none of the dynamically allocated data members are deleted. The underlying Unix file is not deleted.
 
virtual void createHeader ()=0
 Allocates and initializes the header. Is a virtual method to be overridden at each derived class.
 
virtual void flushHeader ()=0
 Flushes Header Page to disk. Is a virtual method to be overridden at each derived class.
 
FileId getFileId ()
 Returns the FileId of the File.
 
virtual void printFile ()
 Prints out information and/or the contents of the file. Can be overwritten in derived classes. Useful for debugging and testing purposes.
 
PageId getHeaderId ()
 Returns Header PageId.
 

Protected Member Functions

void _setFileId (FileId file_id)
 Sets the file_id and the schema fields of this File.
 

Protected Attributes

FileId file_id
 
Catalogcatalog
 
BufferManagerbuf_mgr
 
PageId header_id
 

Friends

class Catalog
 
class FileManager
 

Detailed Description

SwatDB File Class. The base class for all file-type objects in the system. A File is used to represent a relation or index in the system. This base class inludes state and methods that are common to every type of file in the system.

Constructor & Destructor Documentation

◆ File()

File::File ( Catalog catalog,
BufferManager buf_mgr 
)

Constructor. Initializes common state associated with every file, including catalog, buf_mgr, and schema.

Parameters
catalogPointer to the SwatDB Catalog. Needed for getting file and idex relation files and schema.
buf_mgrPointer to the SwatDB Buffer Manager. Needed for de/allocating Pages, for getting and flushing Pages.
Precondition
Input paramaters (pointers) are all valid.
Postcondition
The data members of File are initialized. file_id and header_id, however, are not set.

Member Function Documentation

◆ _setFileId()

void File::_setFileId ( FileId  file_id)
protected

Sets the file_id and the schema fields of this File.

NOTE: this is called by

  1. Catalog.createFile so that a File object can be added to the Catalog as part of an entry before the Catalog has determined its fileId (our solution to a chicken and egg problem).
  2. FileManager._loadFile via its constructor when initializing SwatDB from saved db state, we add entries to the Catalog without Files, and the File manager creates File * for them and updates each file's fid field after creation (could just have another constructor to handle this case)
Precondition
The given FileId is valid.
Postcondition
file_id is set to the given value.
Parameters
file_idThe File's FileId.

◆ createHeader()

virtual void File::createHeader ( )
pure virtual

Allocates and initializes the header. Is a virtual method to be overridden at each derived class.

Implemented in HashIndexFile, and HeapFile.

◆ flushHeader()

virtual void File::flushHeader ( )
pure virtual

Flushes Header Page to disk. Is a virtual method to be overridden at each derived class.

Implemented in HashIndexFile, and HeapFile.

◆ getFileId()

FileId File::getFileId ( )

Returns the FileId of the File.

Returns
The FileId of the File.

◆ getHeaderId()

PageId File::getHeaderId ( )

Returns Header PageId.

Precondition
None.
Postcondition
Header PageId of the File is returned.
Returns
The Header PageId.

Member Data Documentation

◆ buf_mgr

BufferManager* File::buf_mgr
protected

Pointer to the SwatDB BufferManager

◆ catalog

Catalog* File::catalog
protected

Pointer to the SwatDB Catalog

◆ file_id

FileId File::file_id
protected

The File's FileId.

◆ header_id

PageId File::header_id
protected

PageId for the header Page of the File.


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