br.usp.ime.jbase
Class HFPage

java.lang.Object
  |
  +--br.usp.ime.jbase.HFPage

final class HFPage
extends java.lang.Object

Auxiliary class with static methods that deal with heap file pages. Cannot be instantiated.

HFPage lay-out:

                        +---------------------------------------------+
     start of page ---> | start of a record  \                        |
                        | ...                 |                       |
                        | start of a record   |                       |
                        | ...                 | (n records)           |
                        | ...                 |                       |
                        | start of a record   |                       |
                        | ...                /                        |
                        | start of free area                          |
                        | ...                                         |
                        | slot dir area: recPos n-1         [2 bytes] |
                        |                recLen n-1         [2 bytes] |
                        |                ...                          |
                        |                recPos 1           [2 bytes] |
                        |                recLen 1           [2 bytes] |
                        |                recPos 0           [2 bytes] |
                        |                recLen 0           [2 bytes] |
                        | page id of this page              [8 bytes] |
                        | page id of next page              [8 bytes] |
                        | page id of previous page          [8 bytes] |
                        | page type                         [2 bytes] |
                        | number of free bytes in this page [2 bytes] |
                        | pointer to start of free area     [2 bytes] |
                        | number of slots (n in this case)  [2 bytes] |
     end of page -----> +---------------------------------------------+
 


Field Summary
(package private) static long FAIL
           
 
Method Summary
(package private) static int availableSpace(br.usp.ime.jbase.Page page)
          Returns the available space (in bytes) on a page.
(package private) static void compactSlotDir(Buffer b)
          Compacts the slot directory, if possible.
(package private) static boolean deleteRecord(Buffer b, long recId)
          Deletes a record from a page.
(package private) static void dump(Buffer b)
          Debugging method that prints out the fields of a page.
(package private) static long firstRecord(Buffer b)
          Starts an iteration over the records of a page.
(package private) static long getNext(Buffer b)
          Returns the page id stored in the "next" field of a page.
(package private) static long getPrevious(Buffer b)
          Returns the page id stored in the "previous" field of a page.
(package private) static boolean getRecord(Buffer b, long recId, br.usp.ime.jbase.DBObject obj)
          Gets a record from a page.
(package private) static int getSlot(Buffer b, long recId)
          Gets the lenght and the position of a record within a page.
(package private) static void init(br.usp.ime.jbase.Page page)
          Initializes a database page as a heap file page.
(package private) static long insertRecord(Buffer b, br.usp.ime.jbase.DBObject obj)
          Inserts a new record on a page.
(package private) static boolean isEmpty(Buffer b)
          Checks is a page is empty.
(package private) static long nextRecord(Buffer b, long curRecId)
          Continues an iteration over the records of a page.
(package private) static void setNext(Buffer b, long aPageId)
          Sets the "next" field of a page.
(package private) static void setPrevious(Buffer b, long aPageId)
          Sets the "previous" field of a page.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FAIL

static final long FAIL
Method Detail

init

static void init(br.usp.ime.jbase.Page page)
Initializes a database page as a heap file page.
Parameters:
page - the database page to be initialized.

dump

static void dump(Buffer b)
Debugging method that prints out the fields of a page.
Parameters:
b - a Buffer with the page.

getPrevious

static long getPrevious(Buffer b)
Returns the page id stored in the "previous" field of a page.
Parameters:
b - a Buffer with the page
Returns:
the page id of the previous page.

setPrevious

static void setPrevious(Buffer b,
                        long aPageId)
Sets the "previous" field of a page.
Parameters:
b - a Buffer with the page
aPageId - the new value of the "previous" field.

getNext

static long getNext(Buffer b)
Returns the page id stored in the "next" field of a page.
Parameters:
b - a Buffer with the page
Returns:
the page id of the next page.

setNext

static void setNext(Buffer b,
                    long aPageId)
Sets the "next" field of a page.
Parameters:
b - a Buffer with the page
aPageId - the new value of the "next" field.

insertRecord

static long insertRecord(Buffer b,
                         br.usp.ime.jbase.DBObject obj)
                  throws java.io.UTFDataFormatException
Inserts a new record on a page.
Parameters:
b - a Buffer with the page
obj - the object to be stored on the new record
Returns:
the record id of the new record, or FAIL if there is not enough space for the new record on the page.

deleteRecord

static boolean deleteRecord(Buffer b,
                            long recId)
Deletes a record from a page. Compacts the remaining records into a contiguous area of the page, but does not compact the slot directory. To make sure that the record ids of the remaining records do not change, deleteRecord leaves a hole in the slot directory entry which pointed to the deleted record.
Parameters:
b - a Buffer with the page
recId - the record id of the record to be deleted
Returns:
true if the record was deleted, false if there was no record with the given recId on the page.

firstRecord

static long firstRecord(Buffer b)
Starts an iteration over the records of a page.
Parameters:
b - a Buffer with the page
Returns:
the record id of the "first" record on the page, or FAIL if there is no record in the page.

nextRecord

static long nextRecord(Buffer b,
                       long curRecId)
Continues an iteration over the records of a page.
Parameters:
b - a Buffer with the page
curRecId - the record id of the "current record"
Returns:
the record id of the "next" record on the page, or FAIL if there is no such record.

getRecord

static boolean getRecord(Buffer b,
                         long recId,
                         br.usp.ime.jbase.DBObject obj)
                  throws java.io.UTFDataFormatException
Gets a record from a page.
Parameters:
b - a Buffer with the page
recId - the record id of the record
obj - an object whose fields are to be read from the record
Returns:
true if sucess, false if there was no record with the given recId on the page.

getSlot

static int getSlot(Buffer b,
                   long recId)
Gets the lenght and the position of a record within a page.
Parameters:
b - a Buffer with the page
recId - the record id of the record
Returns:
FAIL if there is record with the given recId on the page, otherwise returns an int made up of two shorts joined together. The low order (least significant) short is the record position within the page, the high order (most significant) short is the record length.

availableSpace

static int availableSpace(br.usp.ime.jbase.Page page)
Returns the available space (in bytes) on a page.
Parameters:
b - a Buffer with the page
Returns:
the number of unused bytes in the page.

isEmpty

static boolean isEmpty(Buffer b)
Checks is a page is empty.
Parameters:
b - a Buffer with the page
Returns:
true if the page is empty, false otherwise.

compactSlotDir

static void compactSlotDir(Buffer b)
Compacts the slot directory, if possible. The slot directory can only be compacted by removing a sequence of consecutive empty entries that are at the very end of the directory (otherwise the record ids of the remaining records would be changed).
Parameters:
b - a Buffer with the page