displayRelationship(r05);
/* Perform selections on the graph database */
System.out.println("\n*** MEMBERS RELATIONSHIPS SELECTION ***");
// Use a transaction for selections because it's required by Neo4J...
Transaction transaction = graphDatabase.beginTx();
// Find a node according to a property value (search for Tony member)
System.out.println("** Find a node according to a property value (search for Tony member)");
Iterable<Node> members = graphDatabase.getAllNodes();
long tonyId = -1;
for (Node member : members) {
if (member.hasProperty("MemberName") && "Tony".equals(member.getProperty("MemberName"))) {
System.out.printf("Tony found, is node ID is %s\n", member.getId());
tonyId = member.getId();
}
}
// Get all relationships of a specific node (of Tony member in this
// case)
System.out.println("** Get all relationships of a specific node (of Tony member in this case)");
// --Get directory access to the node using is unique ID
Node tonyNode = graphDatabase.getNodeById(tonyId);
// --Get is relationships in both directions (from this node to another
// node (OUTGOING direction name) and another node to this node
// (INCOMING direction name))
Iterator<Relationship> relationships = tonyNode.getRelationships(Direction.BOTH).iterator();
while (relationships.hasNext()) {
displayRelationship(relationships.next());
}
// Use a traverser to traverse all specific relationships that ending to
// a specific node (our goal here is to find all teamate member of
// Guillaume)
System.out.println("** Use a traverser to traverse all specific relationships that ending to a specific node (our goal here is to find all teamate member of Guillaume)");
Node guillaumeNode = graphDatabase.getNodeById(3);
Traverser teammates = guillaumeNode.traverse(Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, SocialNetworkRelationship.TEAMMATE, Direction.INCOMING);
for (Node teammateMember : teammates) {
System.out.printf("%s (NodeID=%s)\n", teammateMember.getProperty("MemberName"), teammateMember.getId());
}
// Finalize transaction
// If success() method isn't call (it's our case because we only
// perforrm read operations) the transaction is rolledback on finish()
// method invocation...
transaction.finish();
}