org.neo4j.api.core
Class EmbeddedNeo

java.lang.Object
  extended by org.neo4j.api.core.EmbeddedNeo
All Implemented Interfaces:
NeoService

public class EmbeddedNeo
extends java.lang.Object
implements NeoService

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:


 NeoService neo = new EmbeddedNeo( MyRelationshipTypes.class, "var/neo" );
 // ... 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(java.lang.Class<? extends RelationshipType> validRelationshipTypes, java.lang.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(java.lang.Class<? extends RelationshipType> validRelationshipTypes, java.lang.String storeDir, boolean create)
          Creates an embedded neo instance with a given set of relationship types and that reads data from a given store.
EmbeddedNeo(java.lang.String dir, java.lang.Iterable<RelationshipType> relationshipTypes)
           
EmbeddedNeo(java.lang.String dir, RelationshipType[] relationshipTypes)
           
EmbeddedNeo(java.lang.String dir, RelationshipType[] relationshipTypes, java.util.Map<java.lang.String,java.lang.String> params)
           
 
Method Summary
 RelationshipType createAndRegisterRelationshipType(java.lang.String name)
           
 Node createNode()
          Creates a Node.
 boolean enableRemoteShell()
          Enables remote shell access to this Neo instance, if the Neo4j shell project is available on the classpath.
 boolean enableRemoteShell(java.util.Map<java.lang.String,java.io.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.
 RelationshipType getRelationshipType(java.lang.String name)
           
 java.lang.Iterable<RelationshipType> getRelationshipTypes()
           
 boolean hasRelationshipType(java.lang.String name)
           
 void registerEnumRelationshipTypes(java.lang.Class<? extends RelationshipType> relationshipTypes)
           
 RelationshipType registerRelationshipType(java.lang.String name)
           
 void registerRelationshipTypes(java.lang.Iterable<RelationshipType> types)
           
 void registerRelationshipTypes(RelationshipType[] types)
           
 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(java.lang.Class<? extends RelationshipType> validRelationshipTypes,
                   java.lang.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:
java.lang.NullPointerException - if clazz is null
java.lang.IllegalArgumentException - if clazz is not an enum

EmbeddedNeo

public EmbeddedNeo(java.lang.Class<? extends RelationshipType> validRelationshipTypes,
                   java.lang.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:
java.lang.NullPointerException - if clazz is null
java.lang.IllegalArgumentException - if clazz not an enum

EmbeddedNeo

public EmbeddedNeo(java.lang.String dir,
                   RelationshipType[] relationshipTypes)

EmbeddedNeo

public EmbeddedNeo(java.lang.String dir,
                   RelationshipType[] relationshipTypes,
                   java.util.Map<java.lang.String,java.lang.String> params)

EmbeddedNeo

public EmbeddedNeo(java.lang.String dir,
                   java.lang.Iterable<RelationshipType> relationshipTypes)
Method Detail

createNode

public Node createNode()
Description copied from interface: NeoService
Creates a Node.

Specified by:
createNode in interface NeoService
Returns:
the created node.

getNodeById

public Node getNodeById(long id)
Description copied from interface: NeoService
Looks up a node by id.

Specified by:
getNodeById in interface NeoService
Parameters:
id - the id of the node
Returns:
the node with id id if found

getReferenceNode

public Node getReferenceNode()
Description copied from interface: NeoService
Returns the reference node.

Specified by:
getReferenceNode in interface NeoService
Returns:
the reference node

shutdown

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

Specified by:
shutdown in interface NeoService

enableRemoteShell

public boolean enableRemoteShell()
Description copied from interface: NeoService
Enables remote shell access to this Neo instance, if the Neo4j shell project is available on the classpath. This method passed no configuration parameters and is identical to invoking enableRemoteShell( null ).

Specified by:
enableRemoteShell in interface NeoService
Returns:
true if the shell has been enabled, false otherwise (false usually indicates that the shell jar dependency is not on the classpath)

enableRemoteShell

public boolean enableRemoteShell(java.util.Map<java.lang.String,java.io.Serializable> initialProperties)
Description copied from interface: NeoService
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:

Specified by:
enableRemoteShell in interface NeoService
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)

registerEnumRelationshipTypes

public void registerEnumRelationshipTypes(java.lang.Class<? extends RelationshipType> relationshipTypes)
Specified by:
registerEnumRelationshipTypes in interface NeoService

getRelationshipTypes

public java.lang.Iterable<RelationshipType> getRelationshipTypes()
Specified by:
getRelationshipTypes in interface NeoService

getRelationshipType

public RelationshipType getRelationshipType(java.lang.String name)
Specified by:
getRelationshipType in interface NeoService

hasRelationshipType

public boolean hasRelationshipType(java.lang.String name)
Specified by:
hasRelationshipType in interface NeoService

createAndRegisterRelationshipType

public RelationshipType createAndRegisterRelationshipType(java.lang.String name)
Specified by:
createAndRegisterRelationshipType in interface NeoService

registerRelationshipType

public RelationshipType registerRelationshipType(java.lang.String name)
Specified by:
registerRelationshipType in interface NeoService

registerRelationshipTypes

public void registerRelationshipTypes(java.lang.Iterable<RelationshipType> types)
Specified by:
registerRelationshipTypes in interface NeoService

registerRelationshipTypes

public void registerRelationshipTypes(RelationshipType[] types)
Specified by:
registerRelationshipTypes in interface NeoService