org.neo4j.api.core
Class EmbeddedNeo

java.lang.Object
  extended by org.neo4j.api.core.EmbeddedNeo

public class EmbeddedNeo
extends Object

The main Neo factory, with functionality to start and shutdown Neo, create and get nodes and define valid relationship types. This class is typically used in the outer loop in a Neo-enabled application, for example as follows:


 EmbeddedNeo neo = new EmbeddedNeo( MyRelationshipTypes.class, "var/neo", true );
 // ... use neo
 neo.shutdown();
 
Neo is started when this class is instantiated. It provides operations to create notes, get nodes given an id, get the reference node and ultimately shutdown Neo. Typically, once instantiated the reference to EmbeddedNeo is stored away in a service registry or in a singleton instance.

Please note that after startup (i.e. constructor invocation), all operations that read or write to the node space must be invoked in a transactional context.


Constructor Summary
EmbeddedNeo(Class<? extends RelationshipType> validRelationshipTypes, String storeDir)
          Creates an embedded neo instance with a given set of relationship types, that reads data from a given store which will be created if it doesn't already exist.
EmbeddedNeo(Class<? extends RelationshipType> validRelationshipTypes, String storeDir, boolean create)
          Creates an embedded neo instance with a given set of relationship types and that reads data from a given store.
 
Method Summary
 Node createNode()
          Creates a Node.
 boolean enableRemoteShell(Map<String,Serializable> initialProperties)
          Enables remote shell access to this Neo instance, if the Neo4j shell project is available on the classpath.
 Node getNodeById(long id)
          Looks up a node by id.
 Node getReferenceNode()
          Returns the reference node.
 Class<? extends RelationshipType> getRelationshipTypes()
          Returns the valid relationship types for this Neo instance invocation.
 void shutdown()
          Shuts down Neo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmbeddedNeo

public EmbeddedNeo(Class<? extends RelationshipType> validRelationshipTypes,
                   String storeDir,
                   boolean create)
Creates an embedded neo instance with a given set of relationship types and that reads data from a given store.

Parameters:
validRelationshipTypes - an enum class containing your relationship types
storeDir - the store directory for the neo db files
create - whether a new store directory will be created if it doesn't already exist
Throws:
NullPointerException - if clazz is null
IllegalArgumentException - if clazz is not an enum

EmbeddedNeo

public EmbeddedNeo(Class<? extends RelationshipType> validRelationshipTypes,
                   String storeDir)
Creates an embedded neo instance with a given set of relationship types, that reads data from a given store which will be created if it doesn't already exist. Invoking this constructor is equivalent to invoke new EmbeddedNeo( clazz, storeDir, true ).

Parameters:
validRelationshipTypes - an enum class containing your relationship types
storeDir - the store directory for the neo db files
Throws:
NullPointerException - if clazz is null
IllegalArgumentException - if clazz not an enum
Method Detail

createNode

public Node createNode()
Creates a Node.

Returns:
the created node.

getNodeById

public 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:
RuntimeException - if not found

getReferenceNode

public Node getReferenceNode()
Returns the reference node.

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

shutdown

public void shutdown()
Shuts down Neo. After this method has been invoked, it's invalid to invoke any methods in the Neo API.


getRelationshipTypes

public Class<? extends RelationshipType> getRelationshipTypes()
Returns the valid relationship types for this Neo instance invocation. This is the exact same class instance that was passed to the constructor of this EmbeddedNeo.

Returns:
the valid relationship types for this Neo instance invocation

enableRemoteShell

public boolean enableRemoteShell(Map<String,Serializable> initialProperties)
Enables remote shell access to this Neo instance, if the Neo4j shell project 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 neoshell 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
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


Copyright © 2007 Neo4j. All Rights Reserved.