heap
Class HeapFile

java.lang.Object
  extended by heap.HeapFile
All Implemented Interfaces:
GlobalConst

public class HeapFile
extends java.lang.Object
implements GlobalConst

Minibase Heap Files

A heap file is an unordered set of records, stored on a set of pages. This class provides basic support for inserting, selecting, updating, and deleting records. Temporary heap files are used for external sorting and in other relational operators. A sequential scan of a heap file (via the Scan class) is the most basic access method.


Field Summary
 
Fields inherited from interface global.GlobalConst
EMPTY_SLOT, FIRST_PAGEID, INVALID_PAGEID, MAX_COLSIZE, MAX_TUPSIZE, NAME_MAXLEN, PAGE_SIZE, PIN_DISKIO, PIN_MEMCPY, UNPIN_CLEAN, UNPIN_DIRTY
 
Constructor Summary
HeapFile(java.lang.String name)
          If the given name already denotes a file, this opens it; otherwise, this creates a new empty file.
 
Method Summary
 void deleteFile()
          Deletes the heap file from the database, freeing all of its pages.
 void deleteRecord(RID rid)
          Deletes the specified record from the heap file.
protected  void finalize()
          Called by the garbage collector when there are no more references to the object; deletes the heap file if it's temporary.
 int getRecCnt()
          Gets the number of records in the file.
 RID insertRecord(byte[] record)
          Inserts a new record into the file and returns its RID.
 HeapScan openScan()
          Initiates a sequential scan of the heap file.
 byte[] selectRecord(RID rid)
          Reads a record from the file, given its id.
 java.lang.String toString()
          Returns the name of the heap file.
 void updateRecord(RID rid, byte[] newRecord)
          Updates the specified record in the heap file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HeapFile

public HeapFile(java.lang.String name)
If the given name already denotes a file, this opens it; otherwise, this creates a new empty file. A null name produces a temporary heap file which requires no DB entry.

Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Called by the garbage collector when there are no more references to the object; deletes the heap file if it's temporary.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

deleteFile

public void deleteFile()
Deletes the heap file from the database, freeing all of its pages.


insertRecord

public RID insertRecord(byte[] record)
Inserts a new record into the file and returns its RID.

Throws:
java.lang.IllegalArgumentException - if the record is too large

selectRecord

public byte[] selectRecord(RID rid)
Reads a record from the file, given its id.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

updateRecord

public void updateRecord(RID rid,
                         byte[] newRecord)
Updates the specified record in the heap file.

Throws:
java.lang.IllegalArgumentException - if the rid or new record is invalid

deleteRecord

public void deleteRecord(RID rid)
Deletes the specified record from the heap file.

Throws:
java.lang.IllegalArgumentException - if the rid is invalid

getRecCnt

public int getRecCnt()
Gets the number of records in the file.


openScan

public HeapScan openScan()
Initiates a sequential scan of the heap file.


toString

public java.lang.String toString()
Returns the name of the heap file.

Overrides:
toString in class java.lang.Object