btree
Class BTreeFile

java.lang.Object
  extended bybtree.IndexFile
      extended bybtree.BTreeFile
All Implemented Interfaces:
GlobalConst

public class BTreeFile
extends IndexFile
implements GlobalConst

btfile.java This is the main definition of class BTreeFile, which derives from abstract base class IndexFile. It provides an insert/delete interface.


Field Summary
 
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
BTreeFile(java.lang.String filename)
          BTreeFile class an index file with given filename should already exist; this opens it.
BTreeFile(java.lang.String filename, int keytype, int keysize, int delete_fashion)
          if index file exists, open it; else create it.
 
Method Summary
 void close()
          Close the B+ tree file.
 boolean Delete(KeyClass key, RID rid)
          delete leaf entry given its pair.
 void destroyFile()
          Destroy entire B+ tree file.
static void destroyTrace()
          Stop tracing.
 btree.BTreeHeaderPage getHeaderPage()
          Access method to data member.
 void insert(KeyClass key, RID rid)
          insert record with the given key and rid
 BTFileScan new_scan(KeyClass lo_key, KeyClass hi_key)
          create a scan with given keys Cases: (1) lo_key = null, hi_key = null scan the whole index (2) lo_key = null, hi_key!= null range scan from min to the hi_key (3) lo_key!= null, hi_key = null range scan from the lo_key to max (4) lo_key!= null, hi_key!= null, lo_key = hi_key exact match ( might not unique) (5) lo_key!= null, hi_key!= null, lo_key < hi_key range scan from lo_key to hi_key
static void traceFilename(java.lang.String filename)
          It causes a structured trace to be written to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BTreeFile

public BTreeFile(java.lang.String filename)
          throws GetFileEntryException,
                 PinPageException,
                 ConstructPageException
BTreeFile class an index file with given filename should already exist; this opens it.

Parameters:
filename - the B+ tree file name. Input parameter.
Throws:
GetFileEntryException - can not ger the file from DB
PinPageException - failed when pin a page
ConstructPageException - BT page constructor failed

BTreeFile

public BTreeFile(java.lang.String filename,
                 int keytype,
                 int keysize,
                 int delete_fashion)
          throws GetFileEntryException,
                 ConstructPageException,
                 java.io.IOException,
                 AddFileEntryException
if index file exists, open it; else create it.

Parameters:
filename - file name. Input parameter.
keytype - the type of key. Input parameter.
keysize - the maximum size of a key. Input parameter.
delete_fashion - full delete or naive delete. Input parameter. It is either DeleteFashion.NAIVE_DELETE or DeleteFashion.FULL_DELETE.
Throws:
GetFileEntryException - can not get file
ConstructPageException - page constructor failed
java.io.IOException - error from lower layer
AddFileEntryException - can not add file into DB
Method Detail

traceFilename

public static void traceFilename(java.lang.String filename)
                          throws java.io.IOException
It causes a structured trace to be written to a file. This output is used to drive a visualization tool that shows the inner workings of the b-tree during its operations.

Parameters:
filename - input parameter. The trace file name
Throws:
java.io.IOException - error from the lower layer

destroyTrace

public static void destroyTrace()
                         throws java.io.IOException
Stop tracing. And close trace file.

Throws:
java.io.IOException - error from the lower layer

getHeaderPage

public btree.BTreeHeaderPage getHeaderPage()
Access method to data member.

Returns:
Return a BTreeHeaderPage object that is the header page of this btree file.

close

public void close()
           throws PageUnpinnedException,
                  InvalidFrameNumberException,
                  HashEntryNotFoundException,
                  ReplacerException
Close the B+ tree file. Unpin header page.

Throws:
PageUnpinnedException - error from the lower layer
InvalidFrameNumberException - error from the lower layer
HashEntryNotFoundException - error from the lower layer
ReplacerException - error from the lower layer

destroyFile

public void destroyFile()
                 throws java.io.IOException,
                        IteratorException,
                        UnpinPageException,
                        FreePageException,
                        DeleteFileEntryException,
                        ConstructPageException,
                        PinPageException
Destroy entire B+ tree file.

Throws:
java.io.IOException - error from the lower layer
IteratorException - iterator error
UnpinPageException - error when unpin a page
FreePageException - error when free a page
DeleteFileEntryException - failed when delete a file from DM
ConstructPageException - error in BT page constructor
PinPageException - failed when pin a page

insert

public void insert(KeyClass key,
                   RID rid)
            throws KeyTooLongException,
                   KeyNotMatchException,
                   LeafInsertRecException,
                   IndexInsertRecException,
                   ConstructPageException,
                   UnpinPageException,
                   PinPageException,
                   NodeNotMatchException,
                   ConvertException,
                   DeleteRecException,
                   IndexSearchException,
                   IteratorException,
                   LeafDeleteException,
                   InsertException,
                   java.io.IOException
insert record with the given key and rid

Specified by:
insert in class IndexFile
Parameters:
key - the key of the record. Input parameter.
rid - the rid of the record. Input parameter.
Throws:
KeyTooLongException - key size exceeds the max keysize.
KeyNotMatchException - key is not integer key nor string key
java.io.IOException - error from the lower layer
LeafInsertRecException - insert error in leaf page
IndexInsertRecException - insert error in index page
ConstructPageException - error in BT page constructor
UnpinPageException - error when unpin a page
PinPageException - error when pin a page
NodeNotMatchException - node not match index page nor leaf page
ConvertException - error when convert between revord and byte array
DeleteRecException - error when delete in index page
IndexSearchException - error when search
IteratorException - iterator error
LeafDeleteException - error when delete in leaf page
InsertException - error when insert in index page

Delete

public boolean Delete(KeyClass key,
                      RID rid)
               throws DeleteFashionException,
                      LeafRedistributeException,
                      RedistributeException,
                      InsertRecException,
                      KeyNotMatchException,
                      UnpinPageException,
                      IndexInsertRecException,
                      FreePageException,
                      RecordNotFoundException,
                      PinPageException,
                      IndexFullDeleteException,
                      LeafDeleteException,
                      IteratorException,
                      ConstructPageException,
                      DeleteRecException,
                      IndexSearchException,
                      java.io.IOException
delete leaf entry given its pair. `rid' is IN the data entry; it is not the id of the data entry)

Specified by:
Delete in class IndexFile
Parameters:
key - the key in pair . Input Parameter.
rid - the rid in pair . Input Parameter.
Returns:
true if deleted. false if no such record.
Throws:
DeleteFashionException - neither full delete nor naive delete
LeafRedistributeException - redistribution error in leaf pages
RedistributeException - redistribution error in index pages
InsertRecException - error when insert in index page
KeyNotMatchException - key is neither integer key nor string key
UnpinPageException - error when unpin a page
IndexInsertRecException - error when insert in index page
FreePageException - error in BT page constructor
RecordNotFoundException - error delete a record in a BT page
PinPageException - error when pin a page
IndexFullDeleteException - fill delete error
LeafDeleteException - delete error in leaf page
IteratorException - iterator error
ConstructPageException - error in BT page constructor
DeleteRecException - error when delete in index page
IndexSearchException - error in search in index pages
java.io.IOException - error from the lower layer

new_scan

public BTFileScan new_scan(KeyClass lo_key,
                           KeyClass hi_key)
                    throws java.io.IOException,
                           KeyNotMatchException,
                           IteratorException,
                           ConstructPageException,
                           PinPageException,
                           UnpinPageException
create a scan with given keys Cases: (1) lo_key = null, hi_key = null scan the whole index (2) lo_key = null, hi_key!= null range scan from min to the hi_key (3) lo_key!= null, hi_key = null range scan from the lo_key to max (4) lo_key!= null, hi_key!= null, lo_key = hi_key exact match ( might not unique) (5) lo_key!= null, hi_key!= null, lo_key < hi_key range scan from lo_key to hi_key

Parameters:
lo_key - the key where we begin scanning. Input parameter.
hi_key - the key where we stop scanning. Input parameter.
Throws:
java.io.IOException - error from the lower layer
KeyNotMatchException - key is not integer key nor string key
IteratorException - iterator error
ConstructPageException - error in BT page constructor
PinPageException - error when pin a page
UnpinPageException - error when unpin a page