Database Reference
In-Depth Information
public enum MyRelationshipTypes implements RelationshipType{
IS_FRIEND_OF;
}
The name of the enum represents the relationship name, as per the standard enum contract.
The DynamicRelationshipType class
If you know what relationship types are required at compile time, defining an actual
class or (preferably) using the enum idiom to represent relationships is the recommended
way to go. There may, however, be cases where you can only detect the relationship
type at runtime and you still need a way to represent it. For these scenarios, the
org.neo4j.graphdb.DynamicRelationshipType class can come in very
handy.
The following snippet shows how the IS_FRIEND_OF relationship could be created with
a DynamicRelationshipType class:
String runtimeVal = "IS_FRIEND_OF";
RelationshipType rel = DynamicRelationshipType.withName(runtimeVal);
Now that you've defined the relationship type you're going to use, you can create relation-
ships between user nodes. To create relationships between two nodes, you need only call
the Node.createRelationshipTo(...) method on one of the nodes, and pass in
the target node and the relationship type.
Note
As we mentioned earlier, Neo4j's graphs are directed, with relationships having defined
start and end nodes. When calling the createRelationshipTo method, the node on
which the method is called will become the start node, and the node passed as an argu-
ment will become the end node. This will not affect the query flexibility or performance,
as you'll see in the next chapters.
Search WWH ::




Custom Search