heap
Class Heapfile

java.lang.Object
  extended byheap.Heapfile
All Implemented Interfaces:
heap.Filetype, GlobalConst

public class Heapfile
extends java.lang.Object
implements heap.Filetype, GlobalConst


Field Summary
static int ORDINARY
           
static int TEMP
           
 
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
Heapfile(java.lang.String name)
          Initialize.
 
Method Summary
 void deleteFile()
          Delete the file from the database.
 boolean deleteRecord(RID rid)
          Delete record from file with given rid.
 int getRecCnt()
          Return number of records in file.
 Tuple getRecord(RID rid)
          Read record from file, returning pointer and length.
 RID insertRecord(byte[] recPtr)
          Insert record into file, return its Rid.
 Scan openScan()
          Initiate a sequential scan.
 boolean updateRecord(RID rid, Tuple newtuple)
          Updates the specified record in the heapfile.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP

public static final int TEMP
See Also:
Constant Field Values

ORDINARY

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

Heapfile

public Heapfile(java.lang.String name)
         throws HFException,
                HFBufMgrException,
                HFDiskMgrException,
                java.io.IOException
Initialize. A null name produces a temporary heapfile which will be deleted by the destructor. If the name already denotes a file, the file is opened; otherwise, a new empty file is created.

Throws:
HFException - heapfile exception
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.io.IOException - I/O errors
Method Detail

getRecCnt

public int getRecCnt()
              throws InvalidSlotNumberException,
                     InvalidTupleSizeException,
                     HFDiskMgrException,
                     HFBufMgrException,
                     java.io.IOException
Return number of records in file.

Throws:
InvalidSlotNumberException - invalid slot number
InvalidTupleSizeException - invalid tuple size
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.io.IOException - I/O errors

insertRecord

public RID insertRecord(byte[] recPtr)
                 throws InvalidSlotNumberException,
                        InvalidTupleSizeException,
                        SpaceNotAvailableException,
                        HFException,
                        HFBufMgrException,
                        HFDiskMgrException,
                        java.io.IOException
Insert record into file, return its Rid.

Parameters:
recPtr - pointer of the record
Returns:
the rid of the record
Throws:
InvalidSlotNumberException - invalid slot number
InvalidTupleSizeException - invalid tuple size
SpaceNotAvailableException - no space left
HFException - heapfile exception
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.io.IOException - I/O errors

deleteRecord

public boolean deleteRecord(RID rid)
                     throws InvalidSlotNumberException,
                            InvalidTupleSizeException,
                            HFException,
                            HFBufMgrException,
                            HFDiskMgrException,
                            java.lang.Exception
Delete record from file with given rid.

Returns:
true record deleted false:record not found
Throws:
InvalidSlotNumberException - invalid slot number
InvalidTupleSizeException - invalid tuple size
HFException - heapfile exception
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.lang.Exception - other exception

updateRecord

public boolean updateRecord(RID rid,
                            Tuple newtuple)
                     throws InvalidSlotNumberException,
                            InvalidUpdateException,
                            InvalidTupleSizeException,
                            HFException,
                            HFDiskMgrException,
                            HFBufMgrException,
                            java.lang.Exception
Updates the specified record in the heapfile.

Returns:
ture:update success false: can't find the record
Throws:
InvalidSlotNumberException - invalid slot number
InvalidUpdateException - invalid update on record
InvalidTupleSizeException - invalid tuple size
HFException - heapfile exception
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.lang.Exception - other exception

getRecord

public Tuple getRecord(RID rid)
                throws InvalidSlotNumberException,
                       InvalidTupleSizeException,
                       HFException,
                       HFDiskMgrException,
                       HFBufMgrException,
                       java.lang.Exception
Read record from file, returning pointer and length.

Parameters:
rid - Record ID
Returns:
a Tuple. if Tuple==null, no more tuple
Throws:
InvalidSlotNumberException - invalid slot number
InvalidTupleSizeException - invalid tuple size
SpaceNotAvailableException - no space left
HFException - heapfile exception
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.lang.Exception - other exception

openScan

public Scan openScan()
              throws InvalidTupleSizeException,
                     java.io.IOException
Initiate a sequential scan.

Throws:
InvalidTupleSizeException - Invalid tuple size
java.io.IOException - I/O errors

deleteFile

public void deleteFile()
                throws InvalidSlotNumberException,
                       FileAlreadyDeletedException,
                       InvalidTupleSizeException,
                       HFBufMgrException,
                       HFDiskMgrException,
                       java.io.IOException
Delete the file from the database.

Throws:
InvalidSlotNumberException - invalid slot number
InvalidTupleSizeException - invalid tuple size
FileAlreadyDeletedException - file is deleted already
HFBufMgrException - exception thrown from bufmgr layer
HFDiskMgrException - exception thrown from diskmgr layer
java.io.IOException - I/O errors