public interface GraphDatabaseService
EmbeddedGraphDatabase class, which is used to
embed Neo4j in an application. Typically, you would create an
EmbeddedGraphDatabase instance as follows:
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase( "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. |
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.
|
ResourceIterable<Node> |
findNodesByLabelAndProperty(Label label,
String key,
Object value)
Returns all nodes having the label, and the wanted property value.
|
Iterable<Node> |
getAllNodes()
Deprecated.
this operation can be found in
GlobalGraphOperations instead. |
Node |
getNodeById(long id)
Looks up a node by id.
|
Relationship |
getRelationshipById(long id)
Looks up a relationship by id.
|
Iterable<RelationshipType> |
getRelationshipTypes()
Deprecated.
this operation can be found in
GlobalGraphOperations instead. |
IndexManager |
index()
Returns the
IndexManager paired with this graph database service
and is the entry point for managing indexes coupled with this database. |
boolean |
isAvailable(long timeout)
Use this method to check if the database is 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()
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 found@Deprecated Iterable<Node> getAllNodes()
GlobalGraphOperations instead.ResourceIterable<Node> findNodesByLabelAndProperty(Label label, String key, Object value)
ResourceIterable 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 value@Deprecated Iterable<RelationshipType> getRelationshipTypes()
GlobalGraphOperations instead.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).boolean isAvailable(long timeout)
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.<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.IndexManager index()
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()
BidirectionalTraversalDescription bidirectionalTraversalDescription()
Copyright © 2002–2015 The Neo4j Graph Database Project. All rights reserved.