org.netbeans.mdr.persistence.btreeimpl.btreeindex
Class Btree

java.lang.Object
  extended by org.netbeans.mdr.persistence.btreeimpl.btreeindex.Btree
All Implemented Interfaces:
Index, StorageClient, Streamable
Direct Known Subclasses:
MultivaluedBtree, SinglevaluedBtree

public abstract class Btree
extends java.lang.Object
implements Index, Streamable, StorageClient

Btree index implementation. This is the top of the Btree hierarchy which implements the org.netbeans.mdr.persistence.Index interface hierarchy. This abstract class and its subclasses contain the persistent state of a Btree and the public interface methods for accessing it. The main logic for searching and updating a Btree is contained in the BtreePage class.

The btreeindex package is as much as possible independent of the btreestorage implementation. However, there are a few dependencies which would need to be addressed if this code was to be used with some other storage mechanism. The main one is the need, when instantiating a that was retrieved from the repository via Btree.read(), to instantiate the specific BtreePageSource implementation that this btree will use. The MOFID class also comes from the btreestorage package, and the Converter routines from that package are used to convert integers to byte arrays and back.

Version:
1.0
Author:
Dana Bergen

Field Summary
protected  EntryTypeInfo dataInfo
           
protected  int dataLength
           
protected  Storage.EntryType dataType
           
protected  boolean hasBigKeys
           
protected  EntryTypeInfo keyInfo
           
protected  Storage.EntryType keyType
           
protected  java.lang.String name
           
protected  int pageIdLength
           
protected  int pageSize
           
protected  BtreePageSource pageSource
           
protected  byte[] rootPageId
           
protected  BtreeStorage storage
           
protected  boolean uniqueKeys
           
protected  boolean uniqueValues
           
 
Constructor Summary
Btree()
           
Btree(java.lang.String name, Storage.EntryType keyType, Storage.EntryType dataType, BtreePageSource pageSource)
           
 
Method Summary
 void add(java.lang.Object key, java.lang.Object data)
          Add a new entry to the index.
protected  void beginRead()
           
protected  void beginWrite()
           
protected  void btreePut(java.lang.Object key, java.lang.Object data, byte operation, int index)
           
 int consistencyCheck(java.io.PrintWriter out)
          Check the btree for consistency, for testing and debugging.
 void dumpTree(java.io.PrintWriter out)
          Print the contents of the btree for debugging purposes.
protected  void endRead()
           
protected  void endWrite()
           
 Storage.EntryType getKeyType()
          Returns the type of keys in index.
 java.lang.String getName()
          Returns the unique name of the index in the Storage.
 Storage.EntryType getValueType()
          Returns the type of values indexed by this index.
protected  void init()
           
 java.util.Set keySet()
          Returns a set view of the keys contained in this index.
 BtreePage pageFactory()
          Returns the right kind of BtreePage for this btree.
 void read(java.io.InputStream inputStream)
          Populate this Btree from the InputStream.
 boolean remove(java.lang.Object key)
          Remove all entries associated with the specified key.
 void setStorage(Storage storage)
          Pass the object the Storage implementation.
 void write(java.io.OutputStream outputStream)
          Write the state of this Btree to the OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageSource

protected BtreePageSource pageSource

storage

protected BtreeStorage storage

keyType

protected Storage.EntryType keyType

dataType

protected Storage.EntryType dataType

name

protected java.lang.String name

keyInfo

protected EntryTypeInfo keyInfo

dataInfo

protected EntryTypeInfo dataInfo

dataLength

protected int dataLength

pageIdLength

protected int pageIdLength

pageSize

protected int pageSize

rootPageId

protected byte[] rootPageId

uniqueKeys

protected boolean uniqueKeys

uniqueValues

protected boolean uniqueValues

hasBigKeys

protected boolean hasBigKeys
Constructor Detail

Btree

public Btree(java.lang.String name,
             Storage.EntryType keyType,
             Storage.EntryType dataType,
             BtreePageSource pageSource)
      throws StorageException
Throws:
StorageException

Btree

public Btree()
Method Detail

init

protected void init()
             throws StorageException
Throws:
StorageException

write

public void write(java.io.OutputStream outputStream)
           throws StorageException
Write the state of this Btree to the OutputStream.

Specified by:
write in interface Streamable
Parameters:
outputStream - OutputStream
Throws:
StorageException

read

public void read(java.io.InputStream inputStream)
          throws StorageException
Populate this Btree from the InputStream. The Storage reference will have already been set up in setStorage.

Specified by:
read in interface Streamable
Parameters:
inputStream - InputStream
Throws:
StorageException

setStorage

public void setStorage(Storage storage)
Description copied from interface: StorageClient
Pass the object the Storage implementation. The object can use this to fetch other objects from the MDR.

Specified by:
setStorage in interface StorageClient
Parameters:
storage - the Stroage implementation which instantiated the object

getKeyType

public Storage.EntryType getKeyType()
Returns the type of keys in index.

Specified by:
getKeyType in interface Index
Returns:
Throws:
StorageException

getValueType

public Storage.EntryType getValueType()
Returns the type of values indexed by this index.

Specified by:
getValueType in interface Index
Returns:
Throws:
StorageException

getName

public java.lang.String getName()
Returns the unique name of the index in the Storage.

Specified by:
getName in interface Index
Returns:
Throws:
StorageException

keySet

public java.util.Set keySet()
                     throws StorageException
Returns a set view of the keys contained in this index. Returned set is read only and may not be modified.

Specified by:
keySet in interface Index
Returns:
keys contained in this index
Throws:
StorageException

add

public void add(java.lang.Object key,
                java.lang.Object data)
         throws StorageException
Add a new entry to the index.

Specified by:
add in interface Index
Parameters:
key - key to insert
data - data associated with key
Throws:
StorageBadRequestException - If key or data are incorrect type, or if the insert would violate the constraints of this index
StorageException - If a problem was encountered accessing storage

remove

public boolean remove(java.lang.Object key)
               throws StorageException
Remove all entries associated with the specified key.

Specified by:
remove in interface Index
Parameters:
key - key for entry to be removed
Returns:
true if a matching entry was found
Throws:
StorageException - If there was a problem reading or writing pages

pageFactory

public BtreePage pageFactory()
Returns the right kind of BtreePage for this btree.


btreePut

protected void btreePut(java.lang.Object key,
                        java.lang.Object data,
                        byte operation,
                        int index)
                 throws StorageException
Throws:
StorageException

beginRead

protected void beginRead()

endRead

protected void endRead()

beginWrite

protected void beginWrite()

endWrite

protected void endWrite()

dumpTree

public void dumpTree(java.io.PrintWriter out)
              throws StorageException
Print the contents of the btree for debugging purposes.

Parameters:
out - PrintWriter to print btree to
Throws:
StorageException

consistencyCheck

public int consistencyCheck(java.io.PrintWriter out)
                     throws StorageException
Check the btree for consistency, for testing and debugging.

Parameters:
out - PrintWriter to print results to
Returns:
number of errors encountered
Throws:
StorageException


Copyright © 2005-2012 Apache Software Foundation. All Rights Reserved.