org.apache.directory.server.core.partition.impl.btree.jdbm
Class JdbmTable<K,V>

java.lang.Object
  extended by org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmTable<K,V>
All Implemented Interfaces:
Table<K,V>
Direct Known Subclasses:
JdbmMasterTable

public class JdbmTable<K,V>
extends java.lang.Object
implements Table<K,V>

A jdbm Btree wrapper that enables duplicate sorted keys using collections.

Version:
$Rev: 689396 $
Author:
Apache Directory Project

Constructor Summary
JdbmTable(java.lang.String name, int numDupLimit, RecordManager manager, java.util.Comparator<K> keyComparator, java.util.Comparator<V> valueComparator, Serializer keySerializer, Serializer valueSerializer)
          Creates a Jdbm BTree based tuple Table abstraction that enables duplicates.
JdbmTable(java.lang.String name, RecordManager manager, SerializableComparator<K> keyComparator, Serializer keySerializer, Serializer valueSerializer)
          Creates a Jdbm BTree based tuple Table abstraction without duplicates enabled using a simple key comparator.
 
Method Summary
 void close()
          Closes the underlying Db of this Table.
 int count()
          Gets the count of the number of records in this Table.
 int count(K key)
          Gets the count of the number of records in this Table with a specific key: returns the number of duplicates for a key.
 Cursor<Tuple<K,V>> cursor()
          Creates a Cursor that traverses Tuples in a Table.
 Cursor<Tuple<K,V>> cursor(K key)
          Creates a Cursor that traverses Table Tuples for the same key.
 V get(K key)
          Gets the value of a record by key if the key exists.
 java.util.Comparator<K> getKeyComparator()
          Gets the key comparator used by this Table: may be null if this Table was not initialized with one.
 Serializer getKeySerializer()
           
 Marshaller<AvlTree<V>> getMarshaller()
           
 java.lang.String getName()
          Gets the name of this Table.
 java.util.Comparator<V> getValueComparator()
          Gets the value comparator used by this Table: may be null if this Table was not initialized with one.
 Serializer getValueSerializer()
           
 int greaterThanCount(K key)
          Gets the number of records greater than or equal to a key value.
 boolean has(K key)
          Checks to see if this table has one or more tuples with a specific key: this is exactly the same as a get call with a check to see if the returned value is null or not.
 boolean has(K key, V value)
          Checks to see if this table has a key with a specific value.
 boolean hasGreaterOrEqual(K key)
          Checks to see if this table has a record with a key greater than or equal to the key argument.
 boolean hasGreaterOrEqual(K key, V val)
          Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value greater than or equal to the value argument provided.
 boolean hasLessOrEqual(K key)
          Checks to see if this table has a record with a key less than or equal to the key argument.
 boolean hasLessOrEqual(K key, V val)
          Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value less than or equal to the value argument provided.
 boolean isCountExact()
          Checks whether or not calls to count the number of keys greater than or less than the key are exact.
 boolean isDupsEnabled()
          Checks to see if this Table has allows for duplicate keys (a.k.a.
 int lessThanCount(K key)
          Gets the number of records less than or equal to a key value.
 void put(K key, V value)
          Puts a record into this Table.
 void remove(K key)
          Removes all records with a specified key from this Table.
 void remove(K key, V value)
          Removes a single key value pair with a specified key and value from this Table.
 void sync()
          Synchronizes the buffers with disk.
 Cursor<V> valueCursor(K key)
          Creates a Cursor that traverses Table values for the same key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbmTable

public JdbmTable(java.lang.String name,
                 int numDupLimit,
                 RecordManager manager,
                 java.util.Comparator<K> keyComparator,
                 java.util.Comparator<V> valueComparator,
                 Serializer keySerializer,
                 Serializer valueSerializer)
          throws java.io.IOException
Creates a Jdbm BTree based tuple Table abstraction that enables duplicates.

Parameters:
name - the name of the table
numDupLimit - the size limit of duplicates before switching to BTrees for values instead of AvlTrees
manager - the record manager to be used for this table
keyComparator - a key comparator
valueComparator - a value comparator
keySerializer - a serializer to use for the keys instead of using default Java serialization which could be very expensive
valueSerializer - a serializer to use for the values instead of using default Java serialization which could be very expensive
Throws:
java.io.IOException - if the table's file cannot be created

JdbmTable

public JdbmTable(java.lang.String name,
                 RecordManager manager,
                 SerializableComparator<K> keyComparator,
                 Serializer keySerializer,
                 Serializer valueSerializer)
          throws java.io.IOException
Creates a Jdbm BTree based tuple Table abstraction without duplicates enabled using a simple key comparator.

Parameters:
name - the name of the table
manager - the record manager to be used for this table
keyComparator - a tuple comparator
keySerializer - a serializer to use for the keys instead of using default Java serialization which could be very expensive
valueSerializer - a serializer to use for the values instead of using default Java serialization which could be very expensive
Throws:
java.io.IOException - if the table's file cannot be created
Method Detail

getKeyComparator

public java.util.Comparator<K> getKeyComparator()
Description copied from interface: Table
Gets the key comparator used by this Table: may be null if this Table was not initialized with one.

Specified by:
getKeyComparator in interface Table<K,V>
Returns:
the key comparator or null if this Table was not created with one.
See Also:
Table.getKeyComparator()

getValueComparator

public java.util.Comparator<V> getValueComparator()
Description copied from interface: Table
Gets the value comparator used by this Table: may be null if this Table was not initialized with one.

Specified by:
getValueComparator in interface Table<K,V>
Returns:
the value comparator or null if this Table was not created with one.
See Also:
Table.getValueComparator()

getKeySerializer

public Serializer getKeySerializer()

getValueSerializer

public Serializer getValueSerializer()

isDupsEnabled

public boolean isDupsEnabled()
Description copied from interface: Table
Checks to see if this Table has allows for duplicate keys (a.k.a. multiple values for the same key).

Specified by:
isDupsEnabled in interface Table<K,V>
Returns:
true if duplicate keys are enabled, false otherwise
See Also:
Table.isDupsEnabled()

getName

public java.lang.String getName()
Description copied from interface: Table
Gets the name of this Table.

Specified by:
getName in interface Table<K,V>
Returns:
the name
See Also:
Table.getName()

isCountExact

public boolean isCountExact()
Description copied from interface: Table
Checks whether or not calls to count the number of keys greater than or less than the key are exact. Checking to see the number of values greater than or less than some key may be excessively costly. Since this is not a critical function but one that assists in optimizing searches some implementations can just return a worst case (maximum) guess.

Specified by:
isCountExact in interface Table<K,V>
Returns:
true if the count is an exact value or a worst case guess

greaterThanCount

public int greaterThanCount(K key)
                     throws java.io.IOException
Description copied from interface: Table
Gets the number of records greater than or equal to a key value. The specific key argument provided need not exist for this call to return a non-zero value.

Specified by:
greaterThanCount in interface Table<K,V>
Parameters:
key - the key to use in comparisons
Returns:
the number of keys greater than or equal to the key
Throws:
java.io.IOException
See Also:
Table.greaterThanCount(Object)

lessThanCount

public int lessThanCount(K key)
                  throws java.io.IOException
Description copied from interface: Table
Gets the number of records less than or equal to a key value. The specific key argument provided need not exist for this call to return a non-zero value.

Specified by:
lessThanCount in interface Table<K,V>
Parameters:
key - the key to use in comparisons
Returns:
the number of keys less than or equal to the key
Throws:
java.io.IOException
See Also:
Table.lessThanCount(Object)

count

public int count(K key)
          throws java.io.IOException
Description copied from interface: Table
Gets the count of the number of records in this Table with a specific key: returns the number of duplicates for a key.

Specified by:
count in interface Table<K,V>
Parameters:
key - the Object key to count.
Returns:
the number of duplicate records for a key.
Throws:
java.io.IOException
See Also:
Table.count(java.lang.Object)

count

public int count()
          throws java.io.IOException
Description copied from interface: Table
Gets the count of the number of records in this Table.

Specified by:
count in interface Table<K,V>
Returns:
the number of records
Throws:
java.io.IOException
See Also:
Table.count()

get

public V get(K key)
      throws java.lang.Exception
Description copied from interface: Table
Gets the value of a record by key if the key exists. If this Table allows duplicate keys then the first key will be returned. If this Table sorts keys then the key will be the smallest key in the Table as specificed by this Table's comparator or the default bytewise lexical comparator.

Specified by:
get in interface Table<K,V>
Parameters:
key - the key of the record
Returns:
the value of the record with the specified key if key exists or null if no such key exists.
Throws:
java.lang.Exception - if there is a failure to read the underlying Db

hasGreaterOrEqual

public boolean hasGreaterOrEqual(K key,
                                 V val)
                          throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value greater than or equal to the value argument provided. The key argument MUST exist for this call to return true and the underlying Db must allow for values of duplicate keys to be sorted. The entire basis to this method depends on the fact that tuples of the same key have values sorted according to a valid value comparator. If the table does not support duplicates then an UnsupportedOperationException is thrown.

Specified by:
hasGreaterOrEqual in interface Table<K,V>
Parameters:
key - the key
val - the value to compare values to
Returns:
true if a Tuple with a key equal to the key argument and a value greater than the value argument exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.hasGreaterOrEqual(Object,Object)

hasLessOrEqual

public boolean hasLessOrEqual(K key,
                              V val)
                       throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value less than or equal to the value argument provided. The key argument MUST exist for this call to return true and the underlying Db must allow for values of duplicate keys to be sorted. The entire basis to this method depends on the fact that tuples of the same key have values sorted according to a valid value comparator. If the table does not support duplicates then an UnsupportedOperationException is thrown.

Specified by:
hasLessOrEqual in interface Table<K,V>
Parameters:
key - the key
val - the value to compare values to
Returns:
true if a Tuple with a key equal to the key argument and a value less than the value argument exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.hasLessOrEqual(Object,Object)

hasGreaterOrEqual

public boolean hasGreaterOrEqual(K key)
                          throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has a record with a key greater than or equal to the key argument. The key argument need not exist for this call to return true. The underlying database must sort keys based on a key comparator because this method depends on key ordering.

Specified by:
hasGreaterOrEqual in interface Table<K,V>
Parameters:
key - the key to compare keys to
Returns:
true if a Tuple with a key greater than or equal to the key argument exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.hasGreaterOrEqual(Object)

hasLessOrEqual

public boolean hasLessOrEqual(K key)
                       throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has a record with a key less than or equal to the key argument. The key argument need not exist for this call to return true. The underlying database must sort keys based on a key comparator because this method depends on key ordering.

Specified by:
hasLessOrEqual in interface Table<K,V>
Parameters:
key - the key to compare keys to
Returns:
true if a Tuple with a key less than or equal to the key argument exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.hasLessOrEqual(Object)

has

public boolean has(K key,
                   V value)
            throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has a key with a specific value.

Specified by:
has in interface Table<K,V>
Parameters:
key - the key to check for
value - the value to check for
Returns:
true if a record with the key and value exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.has(java.lang.Object, java.lang.Object)

has

public boolean has(K key)
            throws java.io.IOException
Description copied from interface: Table
Checks to see if this table has one or more tuples with a specific key: this is exactly the same as a get call with a check to see if the returned value is null or not.

Specified by:
has in interface Table<K,V>
Parameters:
key - the Object of the key to check for
Returns:
true if the key exists, false otherwise
Throws:
java.io.IOException
See Also:
Table.has(java.lang.Object)

put

public void put(K key,
                V value)
         throws java.lang.Exception
Description copied from interface: Table
Puts a record into this Table. Null is not allowed for keys or values and should result in an IllegalArgumentException.

Specified by:
put in interface Table<K,V>
Parameters:
key - the key of the record
value - the value of the record.
Throws:
java.lang.Exception - if there is a failure to read or write to the underlying Db
java.lang.IllegalArgumentException - if a null key or value is used
See Also:
Table.put(java.lang.Object, java.lang.Object)

remove

public void remove(K key,
                   V value)
            throws java.io.IOException
Description copied from interface: Table
Removes a single key value pair with a specified key and value from this Table.

Specified by:
remove in interface Table<K,V>
Parameters:
key - the key of the record to remove
value - the value of the record to remove
Throws:
java.io.IOException
See Also:
Table.remove(java.lang.Object, java.lang.Object)

remove

public void remove(K key)
            throws java.io.IOException
Description copied from interface: Table
Removes all records with a specified key from this Table.

Specified by:
remove in interface Table<K,V>
Parameters:
key - the key of the records to remove
Throws:
java.io.IOException
See Also:
Table.remove(Object)

cursor

public Cursor<Tuple<K,V>> cursor()
                          throws java.lang.Exception
Description copied from interface: Table
Creates a Cursor that traverses Tuples in a Table.

Specified by:
cursor in interface Table<K,V>
Returns:
a Cursor over Tuples containing the key value pairs
Throws:
java.lang.Exception - if there are failures accessing underlying stores

cursor

public Cursor<Tuple<K,V>> cursor(K key)
                          throws java.lang.Exception
Description copied from interface: Table
Creates a Cursor that traverses Table Tuples for the same key. Only Tuples with the provided key will be returned if the key exists at all. If the key does not exist an empty Cursor is returned. The motivation behind this method is to minimize the need for callers to actively constrain Cursor operations based on the Tuples they return to a specific key. This Cursor is naturally limited to return only the tuples for the same key.

Specified by:
cursor in interface Table<K,V>
Parameters:
key - the duplicate key to return the Tuples of
Returns:
a Cursor over Tuples containing the same key
Throws:
java.lang.Exception - if there are failures accessing underlying stores

valueCursor

public Cursor<V> valueCursor(K key)
                      throws java.lang.Exception
Description copied from interface: Table
Creates a Cursor that traverses Table values for the same key. Only Tuples with the provided key will have their values returned if the key exists at all. If the key does not exist an empty Cursor is returned. The motivation behind this method is to minimize the need for callers to actively constrain Cursor operations to a specific key while removing overheads in creating new Tuples or population one that is reused to return key value pairs. This Cursor is naturally limited to return only the values for the same key.

Specified by:
valueCursor in interface Table<K,V>
Parameters:
key - the duplicate key to return the values of
Returns:
a Cursor over values of a key
Throws:
java.lang.Exception - if there are failures accessing underlying stores

close

public void close()
           throws java.io.IOException
Description copied from interface: Table
Closes the underlying Db of this Table.

Specified by:
close in interface Table<K,V>
Throws:
java.io.IOException
See Also:
Table.close()

sync

public void sync()
          throws java.io.IOException
Synchronizes the buffers with disk.

Throws:
java.io.IOException - if errors are encountered on the flush

getMarshaller

public Marshaller<AvlTree<V>> getMarshaller()


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.