public class HGStore extends Object
An instance of HGStore
is associated with each HyperGraph
to manage to low-level interaction with the underlying database mechanism.
Normally, the HyperGraphDB store is not accessed directly by applications. However, HyperGraphDB
type implementors will rely on the HGStore
to manage the way raw data
is stored and indexed based on a particular type.
Note that a HGStore
does not maintain any data cache, nor does it interact
in any special way with the semantic layer of HyperGraphDB and the way data and types are
laid out in the store.
The HGStore
will use the HGStorageImplementation
provided by the
HGConfiguration
parameter to the constructor of this class. In fact, this class
is merely a wrapper to the underlying storage implementation.
Constructor and Description |
---|
HGStore(String database,
HGConfiguration config)
Construct a
HGStore bound to a specific database
location. |
Modifier and Type | Method and Description |
---|---|
void |
addIncidenceLink(HGPersistentHandle targetHandle,
HGPersistentHandle linkHandle)
Update the incidence set of an atom with a newly created link pointing to it.
|
void |
attachOverlayGraph(StorageGraph sgraph)
Reserved to internal use.
|
void |
close()
Mainly for internal use - invoked by the main
HyperGraph instance. |
boolean |
containsData(HGPersistentHandle handle)
Return
true if there is a data item bound to the passed in
handle parameter and false otherwise. |
boolean |
containsLink(HGPersistentHandle handle)
Return
true if there is a storage link bound to the passed in
handle parameter and false otherwise. |
void |
detachOverlayGraph()
Reserved to internal use.
|
<KeyType,ValueType> |
getBidirectionalIndex(String name,
ByteArrayConverter<KeyType> keyConverter,
ByteArrayConverter<ValueType> valueConverter,
Comparator<byte[]> comparator,
boolean allowCreate)
Retrieve an existing
HGBidirectionalIndex by its name. |
byte[] |
getData(HGPersistentHandle handle)
Retrieve the raw data buffer stored at
handle . |
String |
getDatabaseLocation()
Return the physical, file system location of the HyperGraph store.
|
HGRandomAccessResult<HGPersistentHandle> |
getIncidenceResultSet(HGPersistentHandle handle)
Return a
HGSearchResult of atom handles in a given atom's incidence
set. |
long |
getIncidenceSetCardinality(HGPersistentHandle handle)
Return the number of atoms in the incidence set of a given atom.
|
<KeyType,ValueType> |
getIndex(String name)
Get the HyperGraphDB index with the given name.
|
<KeyType,ValueType> |
getIndex(String name,
ByteArrayConverter<KeyType> keyConverter,
ByteArrayConverter<ValueType> valueConverter,
Comparator<byte[]> comparator,
boolean allowCreate)
Retrieve an
HGIndex by its name. |
HGPersistentHandle[] |
getLink(HGPersistentHandle handle)
Retrieve an existing link by its handle.
|
HGTransactionFactory |
getTransactionFactory()
Create and return a transaction factory for this
HGStore . |
HGTransactionManager |
getTransactionManager()
Return this store's
HGTransactionManager . |
boolean |
hasOverlayGraph()
Reserved to internal use.
|
void |
removeData(HGPersistentHandle handle)
Remove a raw data value associated with a
HGPersistentHandle key. |
void |
removeIncidenceLink(HGPersistentHandle handle,
HGPersistentHandle oldLink)
Update the incidence set of an atom by removing a link that no longer points
to it.
|
void |
removeIncidenceSet(HGPersistentHandle handle)
Remove the whole incidence set of a given handle.
|
void |
removeIndex(String name)
Remove an index from the database.
|
void |
removeLink(HGPersistentHandle handle)
Remove a link value associated with a
HGPersistentHandle key. |
HGPersistentHandle |
store(byte[] data)
Write raw binary data to the store.
|
HGPersistentHandle |
store(HGPersistentHandle[] link)
Create a new link in the HyperGraphDB store.
|
HGPersistentHandle |
store(HGPersistentHandle handle,
byte[] data)
Write raw binary data to the store using a pre-created, unique persistent handle.
|
HGPersistentHandle |
store(HGPersistentHandle handle,
HGPersistentHandle[] link)
Create a new link in the HyperGraphDB store with an existing handle.
|
public HGStore(String database, HGConfiguration config)
Construct a HGStore
bound to a specific database
location.
database
- public HGTransactionFactory getTransactionFactory()
Create and return a transaction factory for this HGStore
.
public HGTransactionManager getTransactionManager()
Return this store's HGTransactionManager
.
public String getDatabaseLocation()
Return the physical, file system location of the HyperGraph store.
public HGPersistentHandle store(HGPersistentHandle[] link)
Create a new link in the HyperGraphDB store. A new HGPersistentHandle
is created to refer to the link.
link
- A non-null, but possibly empty array of persistent atom handles that
constitute the link to be created.HGPersistentHandle
.public HGPersistentHandle store(HGPersistentHandle handle, HGPersistentHandle[] link)
Create a new link in the HyperGraphDB store with an existing handle. It is up to the caller of this method to ensure that the passed in handle is unique.
handle
- A unique HGPersistentHandle
that will refer to the link
within the HyperGraphDB store.link
- A non-null, but possibly empty array of persistent atom handles that
constitute the link to be created.The
- handle
parameter.public HGPersistentHandle store(byte[] data)
Write raw binary data to the store. A new persistent handle is created to refer to the data.
A
- non-null, but possibly empty byte[]
holding the data to write.HGPersistentHandle
that refers to the recorded
data.public HGPersistentHandle store(HGPersistentHandle handle, byte[] data)
Write raw binary data to the store using a pre-created, unique persistent handle.
handle
- A unique HGPersistentHandle
to be recorded as the data key.A
- non-null, but possibly empty byte[]
holding the data to write.handle
parameter.public void removeLink(HGPersistentHandle handle)
Remove a link value associated with a HGPersistentHandle
key.
public void removeData(HGPersistentHandle handle)
Remove a raw data value associated with a HGPersistentHandle
key.
public HGPersistentHandle[] getLink(HGPersistentHandle handle)
Retrieve an existing link by its handle.
handle
- The persistent handle of the link. A NullPointerException
is
thrown if this parameter is null
.null
if there is no
link with that HGPersistentHandle
in the database. Note that if the passed
in handle points, the behavior is undefined - the method might throw an exception or return
an array of invalid links.public boolean containsLink(HGPersistentHandle handle)
Return true
if there is a storage link bound to the passed in
handle parameter and false
otherwise.
public boolean containsData(HGPersistentHandle handle)
Return true
if there is a data item bound to the passed in
handle parameter and false
otherwise. This may or may not be
any faster then calling the getData
method and checking for null.
It depends no the implementation.
public byte[] getData(HGPersistentHandle handle)
Retrieve the raw data buffer stored at handle
.
handle
- The HGPersistentHandle
of the data. Cannot
be null
.handle
or null
if it could not be found.public HGRandomAccessResult<HGPersistentHandle> getIncidenceResultSet(HGPersistentHandle handle)
Return a HGSearchResult
of atom handles in a given atom's incidence
set.
handle
- The HGPersistentHandle
of the atom whose incidence set
is desired.HGSearchResult
iterating over the incidence set.public long getIncidenceSetCardinality(HGPersistentHandle handle)
Return the number of atoms in the incidence set of a given atom. That is, return the number of links pointing to the atom.
public void addIncidenceLink(HGPersistentHandle targetHandle, HGPersistentHandle linkHandle)
Update the incidence set of an atom with a newly created link pointing to it. This method is only to be used internally by hypergraph.
If the link is already part of the incidence set of this atom, it will not be added again.
targetHandle
- The HGPersistentHandle
of the atom whose incidence set
is to be updated.linkHandle
- The HGPersistentHandle
of the new link pointing to that
atom.public void removeIncidenceLink(HGPersistentHandle handle, HGPersistentHandle oldLink)
Update the incidence set of an atom by removing a link that no longer points to it. This method is only to be used internally by hypergraph.
If the link is not part of the incidence set of this atom, nothing will be done.
handle
- The HGPersistentHandle
of the atom whose incidence set
is to be updated.oldLink
- The HGPersistentHandle
of the old link that no longer
points to that atom.public void removeIncidenceSet(HGPersistentHandle handle)
Remove the whole incidence set of a given handle. This method is normally used only when an atom is being removed from the hypergraph DB.
handle
- The handle of the atom whose incidence set must be removed.public <KeyType,ValueType> HGIndex<KeyType,ValueType> getIndex(String name)
null
if no
index with that name exists.public <KeyType,ValueType> HGIndex<KeyType,ValueType> getIndex(String name, ByteArrayConverter<KeyType> keyConverter, ByteArrayConverter<ValueType> valueConverter, Comparator<byte[]> comparator, boolean allowCreate)
Retrieve an HGIndex
by its name. An index will not
be automatically created if it does not exists. To create an index,
use the createIndex
method.
name
- The name of the desired index.HGIndex
with the given name or null
if no such index exists.public <KeyType,ValueType> HGBidirectionalIndex<KeyType,ValueType> getBidirectionalIndex(String name, ByteArrayConverter<KeyType> keyConverter, ByteArrayConverter<ValueType> valueConverter, Comparator<byte[]> comparator, boolean allowCreate)
Retrieve an existing HGBidirectionalIndex
by its name.
ClassCastException
- is the index with the specified name is not
bidirectional.public void removeIndex(String name)
Remove an index from the database. Note that all entries in this index will be lost.
public void close()
Mainly for internal use - invoked by the main HyperGraph
instance.
public void attachOverlayGraph(StorageGraph sgraph)
Reserved to internal use.
public void detachOverlayGraph()
Reserved to internal use.
public boolean hasOverlayGraph()
Reserved to internal use.
Copyright © 2015. All rights reserved.