net.obsearch.storage.bdb
Class AbstractBDBOBStoreJe<T extends Tuple>

java.lang.Object
  extended by net.obsearch.storage.bdb.AbstractBDBOBStoreJe<T>
All Implemented Interfaces:
OBStore<T>
Direct Known Subclasses:
BDBOBStoreJeByte, BDBOBStoreJeByteArray, BDBOBStoreJeDouble, BDBOBStoreJeFloat, BDBOBStoreJeInt, BDBOBStoreJeLong, BDBOBStoreJeShort

public abstract class AbstractBDBOBStoreJe<T extends Tuple>
extends Object
implements OBStore<T>

BDBOBStore is a storage abstraction for Berkeley DB. It is designed to work on byte array keys storing byte array values.

Author:
Arnoldo Jose Muller Molina

Nested Class Summary
protected  class AbstractBDBOBStoreJe.ByteArrayIterator
          Iterator used to process range results.
protected  class AbstractBDBOBStoreJe.CursorIterator<T>
          Base class used to iterate over cursors.
 
Field Summary
protected  com.sleepycat.je.Sequence counter
          Sequence counter
protected  com.sleepycat.je.Database db
          Berkeley DB database.
protected  com.sleepycat.je.Database sequence
          Database for sequences.
protected  hep.aida.bin.StaticBin1D stats
           
 
Constructor Summary
AbstractBDBOBStoreJe(String name, com.sleepycat.je.Database db, com.sleepycat.je.Database sequences, OBStoreFactory fact, boolean duplicates)
          Builds a new Storage system by receiving a Berkeley DB database.
 
Method Summary
 boolean allowsDuplicatedData()
           
 void close()
          Closes the storage system.
 OperationStatus delete(byte[] key)
          Deletes the given key and its corresponding value from the database.
 void deleteAll()
          Deletes all the items in the storage system.
 OBStoreFactory getFactory()
          Return the factory associated to this storage device.
 String getName()
          Get the name of this storage system.
 hep.aida.bin.StaticBin1D getReadStats()
          Returns the read stats, it contains the avg # of bytes read the std deviation and also the number of reads.
 Object getStats()
          Return the stats of this object (to be printed for the user)
 byte[] getValue(byte[] key)
          Returns the associated value for the given key.
 long nextId()
          Returns the next id from the database (incrementing sequences).
 void optimize()
          Somehow optimizes the underlying storage representation.
 byte[] prepareBytes(byte[] in)
          Transform Bytes in a format that can be used by the underlying index.
 CloseIterator<byte[]> processAllKeys()
          Transform Bytes in a format that can be used by the underlying index.
 CloseIterator<TupleBytes> processRange(byte[] low, byte[] high)
          Process the given range of items (from low to high), including low and high.
 CloseIterator<TupleBytes> processRangeNoDup(byte[] low, byte[] high)
          Process the given range of items (from low to high), including low and high.
 CloseIterator<TupleBytes> processRangeReverse(byte[] low, byte[] high)
          Process the given range of items (from high to low), including low and high.
 CloseIterator<TupleBytes> processRangeReverseNoDup(byte[] low, byte[] high)
          Process the given range of items (from high to low), including low and high.
 OperationStatus put(byte[] key, byte[] value)
          Inserts the key value pair.
 OperationStatus putIfNew(byte[] key, byte[] value)
           
 void setReadStats(hep.aida.bin.StaticBin1D stats)
          Sets the stats object to the given stats.
 long size()
          Returns the number of elements in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.obsearch.storage.OBStore
processAll
 

Field Detail

stats

protected hep.aida.bin.StaticBin1D stats

db

protected com.sleepycat.je.Database db
Berkeley DB database.


sequence

protected com.sleepycat.je.Database sequence
Database for sequences.


counter

protected com.sleepycat.je.Sequence counter
Sequence counter

Constructor Detail

AbstractBDBOBStoreJe

public AbstractBDBOBStoreJe(String name,
                            com.sleepycat.je.Database db,
                            com.sleepycat.je.Database sequences,
                            OBStoreFactory fact,
                            boolean duplicates)
                     throws com.sleepycat.je.DatabaseException
Builds a new Storage system by receiving a Berkeley DB database.

Parameters:
db - The database to be stored.
name - Name of the database.
sequences - Database used to store sequences.
Throws:
com.sleepycat.je.DatabaseException - if something goes wrong with the database.
Method Detail

getFactory

public OBStoreFactory getFactory()
Description copied from interface: OBStore
Return the factory associated to this storage device.

Specified by:
getFactory in interface OBStore<T extends Tuple>

close

public void close()
           throws OBStorageException
Description copied from interface: OBStore
Closes the storage system.

Specified by:
close in interface OBStore<T extends Tuple>
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

delete

public OperationStatus delete(byte[] key)
                       throws OBStorageException
Description copied from interface: OBStore
Deletes the given key and its corresponding value from the database. If the storage contains duplicates, then all the elements related to the key are removed.

Specified by:
delete in interface OBStore<T extends Tuple>
Parameters:
key - The key that will be deleted.
Returns:
Status.OK if the key was found, otherwise, Status.NOT_EXISTS.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

deleteAll

public void deleteAll()
               throws OBStorageException
Description copied from interface: OBStore
Deletes all the items in the storage system. Use with care!

Specified by:
deleteAll in interface OBStore<T extends Tuple>
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

getName

public String getName()
Description copied from interface: OBStore
Get the name of this storage system.

Specified by:
getName in interface OBStore<T extends Tuple>
Returns:
the name of this storage system.

getValue

public byte[] getValue(byte[] key)
                throws IllegalArgumentException,
                       OBStorageException
Description copied from interface: OBStore
Returns the associated value for the given key. If the underlying storage system can hold multiple keys, then an IllegalArgumentException is thrown.

Specified by:
getValue in interface OBStore<T extends Tuple>
Parameters:
key - The key that will be searched.
Returns:
the associated value for the given key or null if the key could not be found.
Throws:
IllegalArgumentException - If the underlying storage system can hold multiple keys ( #allowsDuplicatedData() == true).
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

put

public OperationStatus put(byte[] key,
                           byte[] value)
                    throws OBStorageException
Description copied from interface: OBStore
Inserts the key value pair. If the key existed, it will be overwritten.

Specified by:
put in interface OBStore<T extends Tuple>
Parameters:
key - Key to insert
value - The value that the key will hold after this operation completes.
Returns:
Status.OK the record was inserted/updated successfully. Status.ERROR if the record could not be updated.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

putIfNew

public OperationStatus putIfNew(byte[] key,
                                byte[] value)
                         throws OBStorageException
Throws:
OBStorageException

allowsDuplicatedData

public boolean allowsDuplicatedData()

processAllKeys

public CloseIterator<byte[]> processAllKeys()
                                     throws OBStorageException
Transform Bytes in a format that can be used by the underlying index.

Parameters:
in - Input byte array
Returns:
transformed bytes ready to be sorted.`
Throws:
OBStorageException

prepareBytes

public byte[] prepareBytes(byte[] in)
Description copied from interface: OBStore
Transform Bytes in a format that can be used by the underlying index.

Specified by:
prepareBytes in interface OBStore<T extends Tuple>
Parameters:
in - Input byte array
Returns:
transformed bytes ready to be sorted.`

processRange

public CloseIterator<TupleBytes> processRange(byte[] low,
                                              byte[] high)
                                       throws OBStorageException
Description copied from interface: OBStore
Process the given range of items (from low to high), including low and high. The TupleProcessor's process method will be called for each value found within the range.

Specified by:
processRange in interface OBStore<T extends Tuple>
Parameters:
low - lowest key value to return.
high - highest key value to return.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

processRangeNoDup

public CloseIterator<TupleBytes> processRangeNoDup(byte[] low,
                                                   byte[] high)
                                            throws OBStorageException
Description copied from interface: OBStore
Process the given range of items (from low to high), including low and high. The TupleProcessor's process method will be called for each value found within the range. No duplicate values will be returned.

Specified by:
processRangeNoDup in interface OBStore<T extends Tuple>
Parameters:
low - lowest key value to return.
high - highest key value to return.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

processRangeReverse

public CloseIterator<TupleBytes> processRangeReverse(byte[] low,
                                                     byte[] high)
                                              throws OBStorageException
Description copied from interface: OBStore
Process the given range of items (from high to low), including low and high. The TupleProcessor's process method will be called for each value found within the range.

Specified by:
processRangeReverse in interface OBStore<T extends Tuple>
Parameters:
low - lowest key value to return.
high - highest key value to return.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

processRangeReverseNoDup

public CloseIterator<TupleBytes> processRangeReverseNoDup(byte[] low,
                                                          byte[] high)
                                                   throws OBStorageException
Description copied from interface: OBStore
Process the given range of items (from high to low), including low and high. The TupleProcessor's process method will be called for each value found within the range. No duplicate values will be returned.

Specified by:
processRangeReverseNoDup in interface OBStore<T extends Tuple>
Parameters:
low - lowest key value to return.
high - highest key value to return.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

size

public long size()
          throws OBStorageException
Description copied from interface: OBStore
Returns the number of elements in the database.

Specified by:
size in interface OBStore<T extends Tuple>
Returns:
The number of elements in the database.
Throws:
OBStorageException - If an exception occurs at the underlying storage system. You can query the exception to see more details regarding the nature of the error.

optimize

public void optimize()
Description copied from interface: OBStore
Somehow optimizes the underlying storage representation.

Specified by:
optimize in interface OBStore<T extends Tuple>

nextId

public long nextId()
            throws OBStorageException
Returns the next id from the database (incrementing sequences).

Specified by:
nextId in interface OBStore<T extends Tuple>
Returns:
The next id that can be inserted.
Throws:
OBStorageException

getReadStats

public hep.aida.bin.StaticBin1D getReadStats()
Description copied from interface: OBStore
Returns the read stats, it contains the avg # of bytes read the std deviation and also the number of reads.

Specified by:
getReadStats in interface OBStore<T extends Tuple>
Returns:

setReadStats

public void setReadStats(hep.aida.bin.StaticBin1D stats)
Description copied from interface: OBStore
Sets the stats object to the given stats. If null, then we stop storing the stats info.

Specified by:
setReadStats in interface OBStore<T extends Tuple>

getStats

public Object getStats()
Description copied from interface: OBStore
Return the stats of this object (to be printed for the user)

Specified by:
getStats in interface OBStore<T extends Tuple>
Returns:


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.