Database Reference
In-Depth Information
Figure 3.8. Simple social network graph with users connected as friends
Relationshipsaretheothermainentityofthegraphdatabase,besidesnodes.Everyrelation-
ship has a name, which represents the label or type of relationship. In the Neo4j Core Java
API, relationships are defined using the RelationshipType interface, which defines a
single method that returns the relationship name, as illustrated in the following snippet:
public interface RelationshipType{
public String name();
}
In the social network example, you're going to create friendship relationships between the
users. For that, you need to implement the RelationshipType interface:
The RelationshipType interface has one interesting side effect: the signature of the
only method it defines ( String name() ) looks exactly like the signature of the method
available on all Java enumerations (enums). That gives you an option to implement Neo4j
relationship types in a strongly typed, more expressive, and concise manner, using Java
enums. The following snippet illustrates the same IS_FRIEND_OF relationship type im-
plemented as a Java enum:
 
Search WWH ::




Custom Search