org.hypergraphdb
Class HGIndexManager

java.lang.Object
  extended by org.hypergraphdb.HGIndexManager

public class HGIndexManager
extends java.lang.Object

The HGIndexManager allows you to create atom indices. Such indices allow quick lookup of atoms depending on their value and/or target sets.

Atom indexing in HyperGraph relies on the concept of a HGIndexer. Indexers are always bound to an atom type. They are mainly responsible for producing an index key given an atom instance. The index manager interacts with the HGStore to create and update indices at the storage level based on an implementation of the HGIndexer interface.

When an implementation of a HGIndexer does not produce keys of byte[] type, it is required to return a non-null ByteArrayConverter from its getConverter method. In addition, if a regular byte ordering is not appropriate for a given key type, the HGIndexer implementation must return a non-null Comparator from its getComparator method.

To create a new index for a given atom type, call the register(HGIndexer) method. To later remove it, call the unregister(HGIndexer) method. Registering an indexer will store the indexer as a HyperGraph atom and it will request a low-level storage index from the HGStore. All atom instance of the type for which a new indexer is being registered will be automatically indexed. Naturally, this may be a very long operation. Therefore it is recommended that indexer be registered at a time where there's no other activity on the HyperGraph database.

Author:
Borislav Iordanov

Constructor Summary
HGIndexManager(HyperGraph graph)
           
 
Method Summary
 void close()
           Cleanup reference to external resources for this indexer.
 void deleteIndex(HGIndexer indexer)
           
<KeyType,ValueType>
HGIndex<KeyType,ValueType>
getIndex(HGIndexer indexer)
           Retrieve the storage HGIndex associated to the passed-in HGIndexer.
 HGIndex<HGPersistentHandle,HGPersistentHandle> getIndexByType()
          Return the predefined index from types to atoms.
 HGIndex<HGPersistentHandle,HGPersistentHandle> getIndexByValue()
          Return the predefined index from values to atoms.
 java.util.List<HGIndexer> getIndexersForType(HGHandle type)
           Return all registered HGIndexers for a given HyperGraph type.
 boolean isRegistered(HGIndexer indexer)
          Return true if the given HGIndexer is registered with the index manager and false otherwise.
<KeyType,ValueType>
HGIndex<KeyType,ValueType>
register(HGIndexer indexer)
           Possibly create a new index based on the specified IndexDescriptor.
 boolean unregister(HGIndexer indexer)
           Remove an existing index.
 void unregisterAll(HGHandle typeHandle)
           Remove all indexers for the given type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HGIndexManager

public HGIndexManager(HyperGraph graph)
Method Detail

deleteIndex

public void deleteIndex(HGIndexer indexer)

close

public void close()

Cleanup reference to external resources for this indexer.


unregister

public boolean unregister(HGIndexer indexer)

Remove an existing index. If there's no index as specified by the indexer parameter, nothing is done.

Parameters:
indexer - The indexer to be removed.
Returns:
true if the indexer was removed and false if it didn't exist.

unregisterAll

public void unregisterAll(HGHandle typeHandle)

Remove all indexers for the given type. This is normally called only when the type is being from the HyperGraph instance.

Parameters:
typeHandle - The handle of the atom type whose indexers are to be deleted.

isRegistered

public boolean isRegistered(HGIndexer indexer)

Return true if the given HGIndexer is registered with the index manager and false otherwise.

Parameters:
indexer - The possibly registered HGIndexer.

register

public <KeyType,ValueType> HGIndex<KeyType,ValueType> register(HGIndexer indexer)

Possibly create a new index based on the specified IndexDescriptor. If an index corresponding to the descriptor already exists, the method does nothing and returns false. Otherwise it creates a new index, which triggers the automatic indexing of all atoms of the type specified in the descriptor and returns true at the end.

Parameters:
desc - The descriptor of the index to be created.
Returns:
true if a new index was created and false otherwise.

getIndex

public <KeyType,ValueType> HGIndex<KeyType,ValueType> getIndex(HGIndexer indexer)

Retrieve the storage HGIndex associated to the passed-in HGIndexer.

Parameters:
indexer - The HGIndexer whose associated HGIndex is desired.
Returns:
The method will return null if the passed in HGIndexer hasn't been registered with the index manager.

getIndexersForType

public java.util.List<HGIndexer> getIndexersForType(HGHandle type)

Return all registered HGIndexers for a given HyperGraph type.

Parameters:
type - The HGHandle of the HyperGraph type whose indexers are desired.
Returns:
The list of indexers. May be null if no indexer is currently registered for that type.

getIndexByType

public HGIndex<HGPersistentHandle,HGPersistentHandle> getIndexByType()

Return the predefined index from types to atoms. That is, each key in this index is a type handle and its values are all atoms with that type.


getIndexByValue

public HGIndex<HGPersistentHandle,HGPersistentHandle> getIndexByValue()

Return the predefined index from values to atoms. That is, each key in this index is a value handle and its index values are all atoms with that value handle.