Database Reference
In-Depth Information
Asyoucan see in figure 3.10 , both user and movie nodesare represented asboxes.This
isaveryimportantpointaboutNeo4jgraphdatabases:thereisnodifferencebetween user
nodes and movie nodes from the Neo4j perspective. In Neo4j, by default, nodes are not
typed, and determining the strategy for how each node is represented in the domain model
is the responsibility of the developer.
In Neo4j 1.9 and below, the simplest strategy you can use is to add a type property to
each node, with the value of the property determining the node type. This is a well-known
strategy used in other NoSQL technologies (such as document databases) because it's easy
to implement and understand. From Neo4j 2.0 onward, the recommended strategy is to
make use of a new feature called “labels,” which we'll cover in section 3.3 . For now, we'll
start with the Neo4j 1.9-compatible non-label strategies.
Using the type property strategy involves adding a type property to each node in the
same way you previously added the name property to all nodes:
Listing 3.8. Adding a type property to determine node types
Asinallpreviousexamples,allgraphdatabaseoperationsmustbewrappedwithinthe try
transaction-handling block of code.
With the addition of node types, you can now determine the node type by simply checking
the property value:
if("Movie".equals(node.getProperty("type"))){
//this is a movie
}
if("User".equals(node.getProperty("type"))){
Search WWH ::




Custom Search