org.apache.directory.server.xdbm.impl.avl
Class AvlIndex<K,O>

java.lang.Object
  extended by org.apache.directory.server.xdbm.AbstractIndex<K,O,Long>
      extended by org.apache.directory.server.xdbm.impl.avl.AvlIndex<K,O>
All Implemented Interfaces:
Index<K,O,Long>
Direct Known Subclasses:
AvlRdnIndex

public class AvlIndex<K,O>
extends AbstractIndex<K,O,Long>

An Index backed by an AVL Tree.

Author:
Apache Directory Project

Field Summary
protected  AvlTable<K,Long> forward
           
protected  org.apache.directory.shared.ldap.model.schema.Normalizer normalizer
           
protected  AvlTable<Long,K> reverse
           
 
Fields inherited from class org.apache.directory.server.xdbm.AbstractIndex
attributeId, attributeType, cacheSize, initialized
 
Fields inherited from interface org.apache.directory.server.xdbm.Index
DEFAULT_INDEX_CACHE_SIZE
 
Constructor Summary
AvlIndex()
           
AvlIndex(String attributeId)
           
 
Method Summary
 void add(K attrVal, Long id)
          Add an entry into the index, associated with the element ID.
 void close()
          
 int count()
          Gets the total scan count for this index.
 int count(K attrVal)
          Gets the scan count for the occurrence of a specific attribute value within the index.
 void drop(K attrVal, Long id)
          Remove the pair from the index for the given value and id.
 void drop(Long id)
          Remove all the reference to an entry from the index.
 boolean forward(K attrVal)
          
 boolean forward(K attrVal, Long id)
          
 IndexCursor<K,O,Long> forwardCursor()
          
 IndexCursor<K,O,Long> forwardCursor(K key)
          
 boolean forwardGreaterOrEq(K attrVal)
          
 boolean forwardGreaterOrEq(K attrVal, Long id)
          
 boolean forwardLessOrEq(K attrVal)
          
 boolean forwardLessOrEq(K attrVal, Long id)
          
 Long forwardLookup(K attrVal)
          
 org.apache.directory.shared.ldap.model.cursor.Cursor<Long> forwardValueCursor(K key)
          
 K getNormalized(K attrVal)
          Gets the normalized value for an attribute.
 URI getWkDirPath()
          this method always returns null for AvlIndex cause this is a in-memory index.
 int greaterThanCount(K attrVal)
          
 void init(org.apache.directory.shared.ldap.model.schema.SchemaManager schemaManager, org.apache.directory.shared.ldap.model.schema.AttributeType attributeType)
           
 boolean isDupsEnabled()
          tells whether the Index implementation supports storing duplicate keys
 int lessThanCount(K attrVal)
          
 boolean reverse(Long id)
          
 boolean reverse(Long id, K attrVal)
          
 IndexCursor<K,O,Long> reverseCursor()
          
 IndexCursor<K,O,Long> reverseCursor(Long id)
          
 boolean reverseGreaterOrEq(Long id)
          
 boolean reverseGreaterOrEq(Long id, K attrVal)
          
 boolean reverseLessOrEq(Long id)
          
 boolean reverseLessOrEq(Long id, K attrVal)
          
 K reverseLookup(Long id)
          
 org.apache.directory.shared.ldap.model.cursor.Cursor<K> reverseValueCursor(Long id)
          
 void setWkDirPath(URI wkDirPath)
          throws UnsupportedOperationException cause it is a in-memory index
 void sync()
          
 
Methods inherited from class org.apache.directory.server.xdbm.AbstractIndex
getAttribute, getAttributeId, getCacheSize, protect, setAttributeId, setCacheSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

normalizer

protected org.apache.directory.shared.ldap.model.schema.Normalizer normalizer

forward

protected AvlTable<K,Long> forward

reverse

protected AvlTable<Long,K> reverse
Constructor Detail

AvlIndex

public AvlIndex()

AvlIndex

public AvlIndex(String attributeId)
Method Detail

init

public void init(org.apache.directory.shared.ldap.model.schema.SchemaManager schemaManager,
                 org.apache.directory.shared.ldap.model.schema.AttributeType attributeType)
          throws Exception
Throws:
Exception

add

public void add(K attrVal,
                Long id)
         throws Exception
Description copied from interface: Index
Add an entry into the index, associated with the element ID. The added value is the key to retrieve the element having the given ID.

Parameters:
attrVal - The added value
id - The element ID pointed by the added value
Throws:
Exception - If the addition can't be done

close

public void close()
           throws Exception

Throws:
Exception

count

public int count()
          throws Exception
Gets the total scan count for this index.

Returns:
the number of key/value pairs in this index
Throws:
Exception - on failure to access index db files

count

public int count(K attrVal)
          throws Exception
Gets the scan count for the occurrence of a specific attribute value within the index.

Parameters:
attrVal - the value of the attribute to get a scan count for
Returns:
the number of key/value pairs in this index with the value value
Throws:
Exception - on failure to access index db files

drop

public void drop(Long id)
          throws Exception
Remove all the reference to an entry from the index.
As an entry might be referenced more than once in the forward index, depending on which index we are dealing with, we need to iterate over all the values contained into the reverse index for this entryId.
For instance, considering the ObjectClass index for an entry having three ObjectClasses (top, person, inetOrgPerson), then the reverse index will contain :
 [entryId, [top, person, inetOrgPerson]]
 
and the forward index will contain many entries like :
 [top, [..., entryId, ...]]
 [person,  [..., entryId, ...]]
 [inetOrgPerson,  [..., entryId, ...]]
 
So dropping the entryId means that we must first get all the values from the reverse index (and we will get [top, person, inetOrgPerson]) then to iterate through all those values to remove entryId from the associated list of entryIds.

Parameters:
id - The master table entry ID to remove
Throws:
Exception

drop

public void drop(K attrVal,
                 Long id)
          throws Exception
Remove the pair from the index for the given value and id.

Parameters:
attrVal - The value we want to remove from the index
id - The associated ID
Throws:
Exception - If the removal can't be done

forward

public boolean forward(K attrVal)
                throws Exception

Throws:
Exception

forward

public boolean forward(K attrVal,
                       Long id)
                throws Exception

Throws:
Exception

forwardCursor

public IndexCursor<K,O,Long> forwardCursor()
                                    throws Exception

Throws:
Exception

forwardCursor

public IndexCursor<K,O,Long> forwardCursor(K key)
                                    throws Exception

Throws:
Exception

forwardGreaterOrEq

public boolean forwardGreaterOrEq(K attrVal)
                           throws Exception

Throws:
Exception

forwardGreaterOrEq

public boolean forwardGreaterOrEq(K attrVal,
                                  Long id)
                           throws Exception

Throws:
Exception

forwardLessOrEq

public boolean forwardLessOrEq(K attrVal)
                        throws Exception

Throws:
Exception

forwardLessOrEq

public boolean forwardLessOrEq(K attrVal,
                               Long id)
                        throws Exception

Throws:
Exception

forwardLookup

public Long forwardLookup(K attrVal)
                   throws Exception

Throws:
Exception

forwardValueCursor

public org.apache.directory.shared.ldap.model.cursor.Cursor<Long> forwardValueCursor(K key)
                                                                              throws Exception

Throws:
Exception

getNormalized

public K getNormalized(K attrVal)
                throws Exception
Gets the normalized value for an attribute.

Parameters:
attrVal - the user provided value to normalize
Returns:
the normalized value.
Throws:
Exception - if something goes wrong.

greaterThanCount

public int greaterThanCount(K attrVal)
                     throws Exception

Throws:
Exception

lessThanCount

public int lessThanCount(K attrVal)
                  throws Exception

Throws:
Exception

reverse

public boolean reverse(Long id)
                throws Exception

Throws:
Exception

reverse

public boolean reverse(Long id,
                       K attrVal)
                throws Exception

Throws:
Exception

reverseCursor

public IndexCursor<K,O,Long> reverseCursor()
                                    throws Exception

Throws:
Exception

reverseCursor

public IndexCursor<K,O,Long> reverseCursor(Long id)
                                    throws Exception

Throws:
Exception

reverseGreaterOrEq

public boolean reverseGreaterOrEq(Long id)
                           throws Exception

Throws:
Exception

reverseGreaterOrEq

public boolean reverseGreaterOrEq(Long id,
                                  K attrVal)
                           throws Exception

Throws:
Exception

reverseLessOrEq

public boolean reverseLessOrEq(Long id)
                        throws Exception

Throws:
Exception

reverseLessOrEq

public boolean reverseLessOrEq(Long id,
                               K attrVal)
                        throws Exception

Throws:
Exception

reverseLookup

public K reverseLookup(Long id)
                throws Exception

Throws:
Exception

reverseValueCursor

public org.apache.directory.shared.ldap.model.cursor.Cursor<K> reverseValueCursor(Long id)
                                                                           throws Exception

Throws:
Exception

setWkDirPath

public void setWkDirPath(URI wkDirPath)
throws UnsupportedOperationException cause it is a in-memory index

Parameters:
wkDirPath - optional working directory path

getWkDirPath

public URI getWkDirPath()
this method always returns null for AvlIndex cause this is a in-memory index.

Returns:
optional working directory path

isDupsEnabled

public boolean isDupsEnabled()
tells whether the Index implementation supports storing duplicate keys

Specified by:
isDupsEnabled in interface Index<K,O,Long>
Overrides:
isDupsEnabled in class AbstractIndex<K,O,Long>
Returns:
true if duplicate keys are allowed false otherwise

sync

public void sync()
          throws Exception

Throws:
Exception


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.