diskmgr
Class DB

java.lang.Object
  extended bydiskmgr.DB
All Implemented Interfaces:
GlobalConst

public class DB
extends java.lang.Object
implements GlobalConst


Field Summary
 
Fields inherited from interface global.GlobalConst
INVALID_PAGE, MAX_NAME, MAXATTRNAME, MAXFILENAME, MAXINDEXNAME, MINIBASE_BUFFER_POOL_SIZE, MINIBASE_DB_SIZE, MINIBASE_DEFAULT_SHAREDMEM_SIZE, MINIBASE_MAX_TRANSACTIONS, MINIBASE_MAXARRSIZE, NUMBUF, PAGE_SIZE, PAGESIZE
 
Constructor Summary
DB()
          default constructor.
 
Method Summary
 void add_file_entry(java.lang.String fname, PageId start_page_num)
          Adds a file entry to the header page(s).
 void allocate_page(PageId start_page_num)
          Allocate a set of pages where the run size is taken to be 1 by default.
 void allocate_page(PageId start_page_num, int runsize)
          user specified run_size
 void closeDB()
          Close DB file.
 java.lang.String db_name()
          Functions to return some characteristics of the database.
 int db_num_pages()
           
 int db_page_size()
           
 void DBDestroy()
          Destroy the database, removing the file that stores it.
 void deallocate_page(PageId start_page_num)
          Deallocate a set of pages starting at the specified page number with run size = 1
 void deallocate_page(PageId start_page_num, int run_size)
          Deallocate a set of pages starting at the specified page number and a run size can be specified.
 void delete_file_entry(java.lang.String fname)
          Delete the entry corresponding to a file from the header page(s).
 void dump_space_map()
          Print out the space map of the database.
 PageId get_file_entry(java.lang.String name)
          Get the entry corresponding to the given file.
 void openDB(java.lang.String fname)
          Open the database with the given name.
 void openDB(java.lang.String fname, int num_pgs)
          DB Constructors.
 void read_page(PageId pageno, Page apage)
          Read the contents of the specified page into a Page object
 void write_page(PageId pageno, Page apage)
          Write the contents in a page object to the specified page.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DB

public DB()
default constructor.

Method Detail

openDB

public void openDB(java.lang.String fname)
            throws java.io.IOException,
                   InvalidPageNumberException,
                   FileIOException,
                   DiskMgrException
Open the database with the given name.

Throws:
java.io.IOException - I/O errors
FileIOException - file I/O error
InvalidPageNumberException - invalid page number
DiskMgrException - error caused by other layers

openDB

public void openDB(java.lang.String fname,
                   int num_pgs)
            throws java.io.IOException,
                   InvalidPageNumberException,
                   FileIOException,
                   DiskMgrException
DB Constructors. Create a database with the specified number of pages where the page size is the default page size.

Throws:
java.io.IOException - I/O errors
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
DiskMgrException - error caused by other layers

closeDB

public void closeDB()
             throws java.io.IOException
Close DB file.

Throws:
java.io.IOException - I/O errors.

DBDestroy

public void DBDestroy()
               throws java.io.IOException
Destroy the database, removing the file that stores it.

Throws:
java.io.IOException - I/O errors.

read_page

public void read_page(PageId pageno,
                      Page apage)
               throws InvalidPageNumberException,
                      FileIOException,
                      java.io.IOException
Read the contents of the specified page into a Page object

Parameters:
pageno - pageId which will be read
apage - page object which holds the contents of page
Throws:
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
java.io.IOException - I/O errors

write_page

public void write_page(PageId pageno,
                       Page apage)
                throws InvalidPageNumberException,
                       FileIOException,
                       java.io.IOException
Write the contents in a page object to the specified page.

Parameters:
pageno - pageId will be wrote to disk
apage - the page object will be wrote to disk
Throws:
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
java.io.IOException - I/O errors

allocate_page

public void allocate_page(PageId start_page_num)
                   throws OutOfSpaceException,
                          InvalidRunSizeException,
                          InvalidPageNumberException,
                          FileIOException,
                          DiskMgrException,
                          java.io.IOException
Allocate a set of pages where the run size is taken to be 1 by default. Gives back the page number of the first page of the allocated run. with default run_size =1

Parameters:
start_page_num - page number to start with
Throws:
OutOfSpaceException - database is full
InvalidRunSizeException - invalid run size
InvalidPageNumberException - invalid page number
FileIOException - DB file I/O errors
java.io.IOException - I/O errors
DiskMgrException - error caused by other layers

allocate_page

public void allocate_page(PageId start_page_num,
                          int runsize)
                   throws OutOfSpaceException,
                          InvalidRunSizeException,
                          InvalidPageNumberException,
                          FileIOException,
                          DiskMgrException,
                          java.io.IOException
user specified run_size

Parameters:
start_page_num - the starting page id of the run of pages
Throws:
OutOfSpaceException - No space left
InvalidRunSizeException - invalid run size
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
java.io.IOException - I/O errors
DiskMgrException - error caused by other layers

deallocate_page

public void deallocate_page(PageId start_page_num,
                            int run_size)
                     throws InvalidRunSizeException,
                            InvalidPageNumberException,
                            java.io.IOException,
                            FileIOException,
                            DiskMgrException
Deallocate a set of pages starting at the specified page number and a run size can be specified.

Parameters:
start_page_num - the start pageId to be deallocate
run_size - the number of pages to be deallocated
Throws:
InvalidRunSizeException - invalid run size
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
java.io.IOException - I/O errors
DiskMgrException - error caused by other layers

deallocate_page

public void deallocate_page(PageId start_page_num)
                     throws InvalidRunSizeException,
                            InvalidPageNumberException,
                            java.io.IOException,
                            FileIOException,
                            DiskMgrException
Deallocate a set of pages starting at the specified page number with run size = 1

Parameters:
start_page_num - the start pageId to be deallocate
Throws:
InvalidRunSizeException - invalid run size
InvalidPageNumberException - invalid page number
FileIOException - file I/O error
java.io.IOException - I/O errors
DiskMgrException - error caused by other layers

add_file_entry

public void add_file_entry(java.lang.String fname,
                           PageId start_page_num)
                    throws FileNameTooLongException,
                           InvalidPageNumberException,
                           InvalidRunSizeException,
                           DuplicateEntryException,
                           OutOfSpaceException,
                           FileIOException,
                           java.io.IOException,
                           DiskMgrException
Adds a file entry to the header page(s).

Parameters:
fname - file entry name
start_page_num - the start page number of the file entry
Throws:
FileNameTooLongException - invalid file name (too long)
InvalidPageNumberException - invalid page number
InvalidRunSizeException - invalid DB run size
DuplicateEntryException - entry for DB is not unique
OutOfSpaceException - database is full
FileIOException - file I/O error
java.io.IOException - I/O errors
DiskMgrException - error caused by other layers

delete_file_entry

public void delete_file_entry(java.lang.String fname)
                       throws FileEntryNotFoundException,
                              java.io.IOException,
                              FileIOException,
                              InvalidPageNumberException,
                              DiskMgrException
Delete the entry corresponding to a file from the header page(s).

Parameters:
fname - file entry name
Throws:
FileEntryNotFoundException - file does not exist
FileIOException - file I/O error
java.io.IOException - I/O errors
InvalidPageNumberException - invalid page number
DiskMgrException - error caused by other layers

get_file_entry

public PageId get_file_entry(java.lang.String name)
                      throws java.io.IOException,
                             FileIOException,
                             InvalidPageNumberException,
                             DiskMgrException
Get the entry corresponding to the given file.

Parameters:
name - file entry name
Throws:
java.io.IOException - I/O errors
FileIOException - file I/O error
InvalidPageNumberException - invalid page number
DiskMgrException - error caused by other layers

db_name

public java.lang.String db_name()
Functions to return some characteristics of the database.


db_num_pages

public int db_num_pages()

db_page_size

public int db_page_size()

dump_space_map

public void dump_space_map()
                    throws DiskMgrException,
                           java.io.IOException,
                           FileIOException,
                           InvalidPageNumberException
Print out the space map of the database. The space map is a bitmap showing which pages of the db are currently allocated.

Throws:
FileIOException - file I/O error
java.io.IOException - I/O errors
InvalidPageNumberException - invalid page number
DiskMgrException - error caused by other layers