heap
Class HFPage

java.lang.Object
  extended bydiskmgr.Page
      extended byheap.HFPage
All Implemented Interfaces:
heap.ConstSlot, GlobalConst
Direct Known Subclasses:
BTSortedPage

public class HFPage
extends Page
implements heap.ConstSlot, GlobalConst

Class heap file page. The design assumes that records are kept compacted when deletions are performed.


Field Summary
static int CUR_PAGE
           
static int DPFIXED
           
static int EMPTY_SLOT
           
static int FREE_SPACE
           
static int INVALID_SLOT
           
static int NEXT_PAGE
           
static int PREV_PAGE
           
static int SIZE_OF_SLOT
           
static int SLOT_CNT
           
static int TYPE
           
static int USED_PTR
           
 
Fields inherited from interface global.GlobalConst
INVALID_PAGE, MAX_NAME, MAX_SPACE, MAXATTRNAME, MAXFILENAME, MAXINDEXNAME, MINIBASE_BUFFER_POOL_SIZE, MINIBASE_DB_SIZE, MINIBASE_DEFAULT_SHAREDMEM_SIZE, MINIBASE_MAX_TRANSACTIONS, MINIBASE_MAXARRSIZE, MINIBASE_PAGESIZE, NUMBUF
 
Constructor Summary
HFPage()
          Default constructor
HFPage(Page page)
          Constructor of class HFPage open a HFPage and make this HFpage piont to the given page
 
Method Summary
 int available_space()
          returns the amount of available space on the page.
 void deleteRecord(RID rid)
          delete the record with the specified rid
 void dumpPage()
          Dump contents of a page
 boolean empty()
          Determining if the page is empty
 RID firstRecord()
           
 PageId getCurPage()
           
 byte[] getHFpageArray()
           
 PageId getNextPage()
           
 PageId getPrevPage()
           
 Tuple getRecord(RID rid)
          copies out record with RID rid into record pointer.
 short getSlotCnt()
           
 short getSlotLength(int slotno)
           
 short getSlotOffset(int slotno)
           
 short getType()
           
 void init(PageId pageNo, Page apage)
          Constructor of class HFPage initialize a new page
 RID insertRecord(byte[] record)
          inserts a new record onto the page, returns RID of this record
 RID nextRecord(RID curRid)
           
 void openHFpage(Page apage)
          Constructor of class HFPage open a existed hfpage
 Tuple returnRecord(RID rid)
          returns a tuple in a byte array[pageSize] with given RID rid.
 void setCurPage(PageId pageNo)
          sets value of curPage to pageNo
 void setNextPage(PageId pageNo)
          sets value of nextPage to pageNo
 void setPrevPage(PageId pageNo)
          sets value of prevPage to pageNo
 void setSlot(int slotno, int length, int offset)
          sets slot contents
 void setType(short valtype)
          sets value of type
 
Methods inherited from class diskmgr.Page
getpage, setpage
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_OF_SLOT

public static final int SIZE_OF_SLOT
See Also:
Constant Field Values

DPFIXED

public static final int DPFIXED
See Also:
Constant Field Values

SLOT_CNT

public static final int SLOT_CNT
See Also:
Constant Field Values

USED_PTR

public static final int USED_PTR
See Also:
Constant Field Values

FREE_SPACE

public static final int FREE_SPACE
See Also:
Constant Field Values

TYPE

public static final int TYPE
See Also:
Constant Field Values

PREV_PAGE

public static final int PREV_PAGE
See Also:
Constant Field Values

NEXT_PAGE

public static final int NEXT_PAGE
See Also:
Constant Field Values

CUR_PAGE

public static final int CUR_PAGE
See Also:
Constant Field Values

INVALID_SLOT

public static final int INVALID_SLOT
See Also:
Constant Field Values

EMPTY_SLOT

public static final int EMPTY_SLOT
See Also:
Constant Field Values
Constructor Detail

HFPage

public HFPage()
Default constructor


HFPage

public HFPage(Page page)
Constructor of class HFPage open a HFPage and make this HFpage piont to the given page

Parameters:
page - the given page in Page type
Method Detail

openHFpage

public void openHFpage(Page apage)
Constructor of class HFPage open a existed hfpage

Parameters:
apage - a page in buffer pool

init

public void init(PageId pageNo,
                 Page apage)
          throws java.io.IOException
Constructor of class HFPage initialize a new page

Parameters:
pageNo - the page number of a new page to be initialized
apage - the Page to be initialized
Throws:
java.io.IOException - I/O errors
See Also:
Page

getHFpageArray

public byte[] getHFpageArray()
Returns:
byte array

dumpPage

public void dumpPage()
              throws java.io.IOException
Dump contents of a page

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

getPrevPage

public PageId getPrevPage()
                   throws java.io.IOException
Returns:
PageId of previous page
Throws:
java.io.IOException - I/O errors

setPrevPage

public void setPrevPage(PageId pageNo)
                 throws java.io.IOException
sets value of prevPage to pageNo

Parameters:
pageNo - page number for previous page
Throws:
java.io.IOException - I/O errors

getNextPage

public PageId getNextPage()
                   throws java.io.IOException
Returns:
page number of next page
Throws:
java.io.IOException - I/O errors

setNextPage

public void setNextPage(PageId pageNo)
                 throws java.io.IOException
sets value of nextPage to pageNo

Parameters:
pageNo - page number for next page
Throws:
java.io.IOException - I/O errors

getCurPage

public PageId getCurPage()
                  throws java.io.IOException
Returns:
page number of current page
Throws:
java.io.IOException - I/O errors

setCurPage

public void setCurPage(PageId pageNo)
                throws java.io.IOException
sets value of curPage to pageNo

Parameters:
pageNo - page number for current page
Throws:
java.io.IOException - I/O errors

getType

public short getType()
              throws java.io.IOException
Returns:
the ype
Throws:
java.io.IOException - I/O errors

setType

public void setType(short valtype)
             throws java.io.IOException
sets value of type

Parameters:
valtype - an arbitrary value
Throws:
java.io.IOException - I/O errors

getSlotCnt

public short getSlotCnt()
                 throws java.io.IOException
Returns:
slotCnt used in this page
Throws:
java.io.IOException - I/O errors

setSlot

public void setSlot(int slotno,
                    int length,
                    int offset)
             throws java.io.IOException
sets slot contents

Parameters:
slotno - the slot number
length - length of record the slot contains
offset - offset of record
Throws:
java.io.IOException - I/O errors

getSlotLength

public short getSlotLength(int slotno)
                    throws java.io.IOException
Parameters:
slotno - slot number
Returns:
the length of record the given slot contains
Throws:
java.io.IOException - I/O errors

getSlotOffset

public short getSlotOffset(int slotno)
                    throws java.io.IOException
Parameters:
slotno - slot number
Returns:
the offset of record the given slot contains
Throws:
java.io.IOException - I/O errors

insertRecord

public RID insertRecord(byte[] record)
                 throws java.io.IOException
inserts a new record onto the page, returns RID of this record

Parameters:
record - a record to be inserted
Returns:
RID of record, null if sufficient space does not exist
Throws:
java.io.IOException - I/O errors in C++ Status insertRecord(char *recPtr, int recLen, RID& rid)

deleteRecord

public void deleteRecord(RID rid)
                  throws java.io.IOException,
                         InvalidSlotNumberException
delete the record with the specified rid

Parameters:
rid - the record ID
Throws:
InvalidSlotNumberException - Invalid slot number
java.io.IOException - I/O errors in C++ Status deleteRecord(const RID& rid)

firstRecord

public RID firstRecord()
                throws java.io.IOException
Returns:
RID of first record on page, null if page contains no records.
Throws:
java.io.IOException - I/O errors in C++ Status firstRecord(RID& firstRid)

nextRecord

public RID nextRecord(RID curRid)
               throws java.io.IOException
Parameters:
curRid - current record ID
Returns:
RID of next record on the page, null if no more records exist on the page
Throws:
java.io.IOException - I/O errors in C++ Status nextRecord (RID curRid, RID& nextRid)

getRecord

public Tuple getRecord(RID rid)
                throws java.io.IOException,
                       InvalidSlotNumberException
copies out record with RID rid into record pointer.
Status getRecord(RID rid, char *recPtr, int& recLen)

Parameters:
rid - the record ID
Returns:
a tuple contains the record
Throws:
InvalidSlotNumberException - Invalid slot number
java.io.IOException - I/O errors
See Also:
Tuple

returnRecord

public Tuple returnRecord(RID rid)
                   throws java.io.IOException,
                          InvalidSlotNumberException
returns a tuple in a byte array[pageSize] with given RID rid.
in C++ Status returnRecord(RID rid, char*& recPtr, int& recLen)

Parameters:
rid - the record ID
Returns:
a tuple with its length and offset in the byte array
Throws:
InvalidSlotNumberException - Invalid slot number
java.io.IOException - I/O errors
See Also:
Tuple

available_space

public int available_space()
                    throws java.io.IOException
returns the amount of available space on the page.

Returns:
the amount of available space on the page
Throws:
java.io.IOException - I/O errors

empty

public boolean empty()
              throws java.io.IOException
Determining if the page is empty

Returns:
true if the HFPage is has no records in it, false otherwise
Throws:
java.io.IOException - I/O errors