public interface GraphDatabaseService
GraphDatabaseService
is as follows:
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( new File("var/graphDb") );
// ... use Neo4j
graphDb.shutdown()
;
GraphDatabaseService provides operations to create
nodes
, get nodes given an id
and ultimately shutdown Neo4j
.
Please note that all operations on the graph must be invoked in a
transactional context
. Failure to do so will result in a
NotInTransactionException
being thrown.
Modifier and Type | Method and Description |
---|---|
Transaction |
beginTx()
Starts a new
transaction and associates it with the current thread. |
Transaction |
beginTx(long timeout,
TimeUnit unit)
Starts a new
transaction with custom timeout and associates it with the current thread. |
BidirectionalTraversalDescription |
bidirectionalTraversalDescription()
Factory method for bidirectional traversal descriptions.
|
Node |
createNode()
Creates a new node.
|
Node |
createNode(Label... labels)
Creates a new node and adds the provided labels to it.
|
Long |
createNodeId()
Deprecated.
This method will be removed in a future major release.
|
Result |
execute(String query)
Executes a query and returns an iterable that contains the result set.
|
Result |
execute(String query,
long timeout,
TimeUnit unit)
Executes a query and returns an iterable that contains the result set.
|
Result |
execute(String query,
Map<String,Object> parameters)
Executes a query and returns an iterable that contains the result set.
|
Result |
execute(String query,
Map<String,Object> parameters,
long timeout,
TimeUnit unit)
Executes a query and returns an iterable that contains the result set.
|
Node |
findNode(Label label,
String key,
Object value)
Equivalent to
findNodes(Label, String, Object) , however it must find no more than one
node or it will throw an exception. |
ResourceIterator<Node> |
findNodes(Label label)
|
default ResourceIterator<Node> |
findNodes(Label label,
Map<String,Object> propertyValues)
Returns all nodes having the label, and the wanted property values.
|
ResourceIterator<Node> |
findNodes(Label label,
String key,
Object value)
Returns all nodes having the label, and the wanted property value.
|
default ResourceIterator<Node> |
findNodes(Label label,
String key1,
Object value1,
String key2,
Object value2)
Returns all nodes having the label, and the wanted property values.
|
default ResourceIterator<Node> |
findNodes(Label label,
String key1,
Object value1,
String key2,
Object value2,
String key3,
Object value3)
Returns all nodes having the label, and the wanted property values.
|
default ResourceIterator<Node> |
findNodes(Label label,
String key,
String template,
StringSearchMode searchMode)
Returns all nodes having a given label, and a property value of type String or Character matching the
given value template and search mode.
|
ResourceIterable<Label> |
getAllLabels()
Returns all labels currently in the underlying store.
|
ResourceIterable<Label> |
getAllLabelsInUse()
Returns all labels currently in the underlying store.
|
ResourceIterable<Node> |
getAllNodes()
Returns all nodes in the graph.
|
ResourceIterable<String> |
getAllPropertyKeys()
Returns all property keys currently in the underlying store.
|
ResourceIterable<Relationship> |
getAllRelationships()
Returns all relationships in the graph.
|
ResourceIterable<RelationshipType> |
getAllRelationshipTypes()
Returns all relationship types currently in the underlying store.
|
ResourceIterable<RelationshipType> |
getAllRelationshipTypesInUse()
Returns all relationship types currently in the underlying store.
|
Node |
getNodeById(long id)
Looks up a node by id.
|
Relationship |
getRelationshipById(long id)
Looks up a relationship by id.
|
IndexManager |
index()
Deprecated.
The
IndexManager based indexes will be removed in the next major release. Please consider using schema indexes instead. |
boolean |
isAvailable(long timeout)
Use this method to check if the database is currently in a usable state.
|
KernelEventHandler |
registerKernelEventHandler(KernelEventHandler handler)
Registers
handler as a handler for kernel events which
are generated from different places in the lifecycle of the kernel. |
<T> TransactionEventHandler<T> |
registerTransactionEventHandler(TransactionEventHandler<T> handler)
Registers
handler as a handler for transaction events which
are generated from different places in the lifecycle of each
transaction. |
Schema |
schema()
Returns the
schema manager where all things related to schema,
for example constraints and indexing on labels . |
void |
shutdown()
Shuts down Neo4j.
|
TraversalDescription |
traversalDescription()
Factory method for unidirectional traversal descriptions.
|
KernelEventHandler |
unregisterKernelEventHandler(KernelEventHandler handler)
Unregisters
handler from the list of kernel event handlers. |
<T> TransactionEventHandler<T> |
unregisterTransactionEventHandler(TransactionEventHandler<T> handler)
Unregisters
handler from the list of transaction event handlers. |
Node createNode()
@Deprecated Long createNodeId()
Node createNode(Label... labels)
labels
- labels
to add to the created node.Node getNodeById(long id)
id
- the id of the nodeid
if foundNotFoundException
- if not foundRelationship getRelationshipById(long id)
id
- the id of the relationshipid
if foundNotFoundException
- if not foundResourceIterable<Node> getAllNodes()
ResourceIterable<Relationship> getAllRelationships()
ResourceIterator<Node> findNodes(Label label, String key, Object value)
If no indexes exist for the label/property combination, the database will scan all labeled nodes looking for the property value.
Note that equality for values do not follow the rules of Java. This means that the number 42 is equals to all other 42 numbers, regardless of whether they are encoded as Integer, Long, Float, Short, Byte or Double.
Same rules follow Character and String - the Character 'A' is equal to the String 'A'.
Finally - arrays also follow these rules. An int[] {1,2,3} is equal to a double[] {1.0, 2.0, 3.0}
Please ensure that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
label
- consider nodes with this labelkey
- required property keyvalue
- required property valueResourceIterator
for responsibilities.default ResourceIterator<Node> findNodes(Label label, String key1, Object value1, String key2, Object value2)
If no indexes exist for the label with all provided properties, the database will scan all labeled nodes looking for matching nodes.
Note that equality for values do not follow the rules of Java. This means that the number 42 is equals to all other 42 numbers, regardless of whether they are encoded as Integer, Long, Float, Short, Byte or Double.
Same rules follow Character and String - the Character 'A' is equal to the String 'A'.
Finally - arrays also follow these rules. An int[] {1,2,3} is equal to a double[] {1.0, 2.0, 3.0}
Please ensure that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
label
- consider nodes with this labelkey1
- required property key1value1
- required property value of key1key2
- required property key2value2
- required property value of key2ResourceIterator
for responsibilities.default ResourceIterator<Node> findNodes(Label label, String key1, Object value1, String key2, Object value2, String key3, Object value3)
If no indexes exist for the label with all provided properties, the database will scan all labeled nodes looking for matching nodes.
Note that equality for values do not follow the rules of Java. This means that the number 42 is equals to all other 42 numbers, regardless of whether they are encoded as Integer, Long, Float, Short, Byte or Double.
Same rules follow Character and String - the Character 'A' is equal to the String 'A'.
Finally - arrays also follow these rules. An int[] {1,2,3} is equal to a double[] {1.0, 2.0, 3.0}
Please ensure that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
label
- consider nodes with this labelkey1
- required property key1value1
- required property value of key1key2
- required property key2value2
- required property value of key2key3
- required property key3value3
- required property value of key3ResourceIterator
for responsibilities.default ResourceIterator<Node> findNodes(Label label, Map<String,Object> propertyValues)
If no indexes exist for the label with all provided properties, the database will scan all labeled nodes looking for matching nodes.
Note that equality for values do not follow the rules of Java. This means that the number 42 is equals to all other 42 numbers, regardless of whether they are encoded as Integer, Long, Float, Short, Byte or Double.
Same rules follow Character and String - the Character 'A' is equal to the String 'A'.
Finally - arrays also follow these rules. An int[] {1,2,3} is equal to a double[] {1.0, 2.0, 3.0}
Please ensure that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
label
- consider nodes with this labelpropertyValues
- required property key-value combinationsResourceIterator
for responsibilities.default ResourceIterator<Node> findNodes(Label label, String key, String template, StringSearchMode searchMode)
If an online index is found, it will be used to look up the requested nodes. If no indexes exist for the label/property combination, the database will scan all labeled nodes looking for matching property values.
The search mode and value template are used to select nodes of interest. The search mode can be one of
findNode(Label, String, Object)
.
Please ensure that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
label
- consider nodes with this labelkey
- required property keytemplate
- required property value templatesearchMode
- required property value templateResourceIterator
for responsibilities.Node findNode(Label label, String key, Object value)
findNodes(Label, String, Object)
, however it must find no more than one
node
or it will throw an exception.label
- consider nodes with this labelkey
- required property keyvalue
- required property valuenull
if none could be foundMultipleFoundException
- if more than one matching node
is foundResourceIterator<Node> findNodes(Label label)
nodes
with a specific label
.
Please take care that the returned ResourceIterator
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.label
- the Label
to return nodes for.ResourceIterator
for responsibilities.ResourceIterable<Label> getAllLabelsInUse()
ResourceIterable
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.ResourceIterable<RelationshipType> getAllRelationshipTypesInUse()
node.createRelationshipTo(...)
. This method guarantees that it will
return all relationship types currently in use.ResourceIterable<Label> getAllLabels()
ResourceIterable
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.ResourceIterable<RelationshipType> getAllRelationshipTypes()
node.createRelationshipTo(...)
. Note that this method is guaranteed to
return all known relationship types, but it does not guarantee that it
won't return more than that (e.g. it can return "historic"
relationship types that no longer have any relationships in the node
space).ResourceIterable<String> getAllPropertyKeys()
ResourceIterable
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.boolean isAvailable(long timeout)
timeout
- timeout (in milliseconds) to wait for the database to become available.
If the database has been shut down false
is returned immediately.true
if it is available, otherwise false
void shutdown()
Transaction beginTx()
transaction
and associates it with the current thread.
All database operations must be wrapped in a transaction.
If you attempt to access the graph outside of a transaction, those operations will throw
NotInTransactionException
.
Please ensure that any returned ResourceIterable
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
Transaction beginTx(long timeout, TimeUnit unit)
transaction
with custom timeout and associates it with the current thread.
Timeout will be taken into account only when execution guard is enabled.
All database operations must be wrapped in a transaction.
If you attempt to access the graph outside of a transaction, those operations will throw
NotInTransactionException
.
Please ensure that any returned ResourceIterable
is closed correctly and as soon as possible
inside your transaction to avoid potential blocking of write operations.
timeout
- transaction timeoutunit
- time unit of timeout argumentResult execute(String query) throws QueryExecutionException
execute(String, java.util.Map)
with an empty parameters-map.query
- The query to executeResult
that contains the result set.QueryExecutionException
- If the Query contains errorsResult execute(String query, long timeout, TimeUnit unit) throws QueryExecutionException
execute(String, java.util.Map)
with an empty parameters-map.query
- The query to executetimeout
- The maximum time interval within which query should be completed.unit
- time unit of timeout argumentResult
that contains the result set.QueryExecutionException
- If the Query contains errorsResult execute(String query, Map<String,Object> parameters) throws QueryExecutionException
query
- The query to executeparameters
- Parameters for the queryResult
that contains the result setQueryExecutionException
- If the Query contains errorsResult execute(String query, Map<String,Object> parameters, long timeout, TimeUnit unit) throws QueryExecutionException
query
- The query to executeparameters
- Parameters for the querytimeout
- The maximum time interval within which query should be completed.unit
- time unit of timeout argumentResult
that contains the result setQueryExecutionException
- If the Query contains errors<T> TransactionEventHandler<T> registerTransactionEventHandler(TransactionEventHandler<T> handler)
handler
as a handler for transaction events which
are generated from different places in the lifecycle of each
transaction. To guarantee that the handler gets all events properly
it shouldn't be registered when the application is running (i.e. in the
middle of one or more transactions). If the specified handler instance
has already been registered this method will do nothing.T
- the type of state object used in the handler, see more
documentation about it at TransactionEventHandler
.handler
- the handler to receive events about different states
in transaction lifecycles.<T> TransactionEventHandler<T> unregisterTransactionEventHandler(TransactionEventHandler<T> handler)
handler
from the list of transaction event handlers.
If handler
hasn't been registered with
registerTransactionEventHandler(TransactionEventHandler)
prior
to calling this method an IllegalStateException
will be thrown.
After a successful call to this method the handler
will no
longer receive any transaction events.T
- the type of state object used in the handler, see more
documentation about it at TransactionEventHandler
.handler
- the handler to receive events about different states
in transaction lifecycles.IllegalStateException
- if handler
wasn't registered prior
to calling this method.KernelEventHandler registerKernelEventHandler(KernelEventHandler handler)
handler
as a handler for kernel events which
are generated from different places in the lifecycle of the kernel.
To guarantee proper behavior the handler should be registered right
after the graph database has been started. If the specified handler
instance has already been registered this method will do nothing.handler
- the handler to receive events about different states
in the kernel lifecycle.KernelEventHandler unregisterKernelEventHandler(KernelEventHandler handler)
handler
from the list of kernel event handlers.
If handler
hasn't been registered with
registerKernelEventHandler(KernelEventHandler)
prior to calling
this method an IllegalStateException
will be thrown.
After a successful call to this method the handler
will no
longer receive any kernel events.handler
- the handler to receive events about different states
in the kernel lifecycle.IllegalStateException
- if handler
wasn't registered prior
to calling this method.Schema schema()
schema manager
where all things related to schema,
for example constraints and indexing on labels
.schema manager
for this database.@Deprecated IndexManager index()
IndexManager
based indexes will be removed in the next major release. Please consider using schema indexes instead.IndexManager
paired with this graph database service
and is the entry point for managing indexes coupled with this database.IndexManager
for this database.TraversalDescription traversalDescription()
TraversalDescription
BidirectionalTraversalDescription bidirectionalTraversalDescription()
BidirectionalTraversalDescription
Copyright © 2023. All rights reserved.