public class HGIndexManager extends 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 and they are 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. Atom instances of the type for which a new indexer
is being registered will be automatically indexed henceforth. If there are already atoms of that
type in the database, they be indexed the next time the database is opened. You can force this
indexing of existing data to happen right away by calling the runMaintenance of
the HyperGraph instance.
NOTE: this class is not thread safe and its methods do not participate in database transactions. Modification of the database indexing schema are meant to be used during initialization or other times when there's no other database activity.
| Constructor and Description |
|---|
HGIndexManager(HyperGraph graph) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Cleanup reference to external resources for this indexer.
|
<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.
|
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. |
void |
maybeIndex(HGPersistentHandle typeHandle,
HGAtomType type,
HGPersistentHandle atomHandle,
Object atom)
Called when an atom is being added to hypergraph to check and possibly
add index entries for the indexed dimensions of the atom's type.
|
void |
maybeUnindex(HGPersistentHandle typeHandle,
HGAtomType type,
HGPersistentHandle atomHandle,
Object atom)
Called when an atom is being added to hypergraph to check and possibly
add index entries for the indexed dimensions of the atom's type.
|
<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.
|
public HGIndexManager(HyperGraph graph)
public void close()
Cleanup reference to external resources for this indexer.
public boolean unregister(HGIndexer indexer)
Remove an existing index. If there's no index as specified by
the indexer parameter, nothing is done.
indexer - The indexer to be removed.true if the indexer was removed and
false if it didn't exist.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.
typeHandle - The handle of the atom type whose indexers are to be
deleted.public boolean isRegistered(HGIndexer<?,?> indexer)
Return true if the given HGIndexer is registered
with the index manager and false otherwise.
indexer - The possibly registered HGIndexer.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
will become active right away if there's no data with the specified HGIndexer's
type. If there is already some data with the type (or sub-types) being indexed, the index
will become active the next time the database is opened when a potentially long indexing
operation will be triggered. If you want to do the indexing right after creating an index
on existing data, call the HyperGraph.runMaintenance method.
desc - The descriptor of the index to be created.true if a new index was created and false
otherwise.public <KeyType,ValueType> HGIndex<KeyType,ValueType> getIndex(HGIndexer<?,?> indexer)
Retrieve the storage HGIndex associated to the passed-in
HGIndexer.
indexer - The HGIndexer whose associated HGIndex
is desired.null if the passed in HGIndexer
hasn't been registered with the index manager.public List<HGIndexer<?,?>> getIndexersForType(HGHandle type)
Return all registered HGIndexers for a given HyperGraph type.
type - The HGHandle of the HyperGraph type whose indexers
are desired.null if no indexer is
currently registered for that type.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.
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.
public void maybeIndex(HGPersistentHandle typeHandle, HGAtomType type, HGPersistentHandle atomHandle, Object atom)
Called when an atom is being added to hypergraph to check and possibly add index entries for the indexed dimensions of the atom's type.
typeHandle - type - atomHandle - atom - public void maybeUnindex(HGPersistentHandle typeHandle, HGAtomType type, HGPersistentHandle atomHandle, Object atom)
Called when an atom is being added to hypergraph to check and possibly add index entries for the indexed dimensions of the atom's type.
typeHandle - type - atom - atomHandle - Copyright © 2015. All rights reserved.