org.neo4j.api.core
Interface NeoService

All Known Implementing Classes:
EmbeddedNeo, EmbeddedReadOnlyNeo

public interface NeoService

The main access point to a running Neo4j instance. The most common implementation is the EmbeddedNeo class, which is used to embed Neo4j in an application. Typically, you would create an EmbeddedNeo instance as follows:

NeoService neo = new EmbeddedNeo( "var/neo" );
 // ... use neo
 neo.shutdown();
NeoService provides operations to enable the shell, create nodes, get nodes given an id, get the reference node and ultimately shutdown Neo4j.

Please note that all operations that read or write to the node space must be invoked in a transactional context. Failure to do so will result in a NotInTransactionException being thrown.


Method Summary
 Transaction beginTx()
          Starts a new transaction.
 Node createNode()
          Creates a new node.
 boolean enableRemoteShell()
          Enables remote shell access (with default configuration) to this Neo4j instance, if the Neo4j shell component is available on the classpath.
 boolean enableRemoteShell(Map<String,Serializable> initialProperties)
          Enables remote shell access to this Neo4j instance, if the Neo4j shell component is available on the classpath.
 Iterable<Node> getAllNodes()
          Returns all nodes in the node space.
 Node getNodeById(long id)
          Looks up a node by id.
 Node getReferenceNode()
          Returns the reference node, which is a "starting point" in the node space.
 Relationship getRelationshipById(long id)
          Looks up a relationship by id.
 Iterable<RelationshipType> getRelationshipTypes()
          Returns all relationship types currently in the underlying store.
 void shutdown()
          Shuts down Neo4j.
 

Method Detail

createNode

Node createNode()
Creates a new node.

Returns:
the created node.

getNodeById

Node getNodeById(long id)
Looks up a node by id.

Parameters:
id - the id of the node
Returns:
the node with id id if found
Throws:
NotFoundException - if not found

getRelationshipById

Relationship getRelationshipById(long id)
Looks up a relationship by id.

Parameters:
id - the id of the relationship
Returns:
the relationship with id id if found
Throws:
NotFoundException - if not found

getReferenceNode

Node getReferenceNode()
Returns the reference node, which is a "starting point" in the node space. Usually, a client attaches relationships to this node that leads into various parts of the node space. For more information about common node space organizational patterns, see the design guide at http://neo4j.org/doc.

Returns:
the reference node
Throws:
NotFoundException - if unable to get the reference node

getAllNodes

Iterable<Node> getAllNodes()
Returns all nodes in the node space.

Returns:
all nodes in the node space

getRelationshipTypes

Iterable<RelationshipType> getRelationshipTypes()
Returns all relationship types currently in the underlying store. Relationship types are added to the underlying store the first time they are used in a successfully commited 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).

Returns:
all relationship types in the underlying store

shutdown

void shutdown()
Shuts down Neo4j. After this method has been invoked, it's invalid to invoke any methods in the Neo4j API and all references to this instance of NeoService should be discarded.


enableRemoteShell

boolean enableRemoteShell()
Enables remote shell access (with default configuration) to this Neo4j instance, if the Neo4j shell component is available on the classpath. This method is identical to invoking enableRemoteShell( null ).

Returns:
true if the shell has been enabled, false otherwise (false usually indicates that the shell jar dependency is not on the classpath)

enableRemoteShell

boolean enableRemoteShell(Map<String,Serializable> initialProperties)
Enables remote shell access to this Neo4j instance, if the Neo4j shell component is available on the classpath. This will publish a shell access interface on an RMI registry on localhost (with configurable port and RMI binding name). It can be accessed by a client that implements org.neo4j.util.shell.ShellClient from the Neo4J shell project. Typically, the shell binary package is used (see neo4j.org/download).

The shell is parameterized by a map of properties passed in to this method. Currently, two properties are used:

Parameters:
initialProperties - a set of properties that will be used to configure the remote shell, or null if the default properties should be used
Returns:
true if the shell has been enabled, false otherwise (false usually indicates that the shell jar dependency is not on the classpath)
Throws:
ClassCastException - if the shell library is available, but one (or more) of the configuration properties have an unexpected type
IllegalStateException - if the shell library is available, but the remote shell can't be enabled anyway

beginTx

Transaction beginTx()
Starts a new transaction.

Returns:
a new transaction instance


Copyright © 2009 Neo4j. All Rights Reserved.