From 596b7ef299f586ce78598abed01b834706d6bf09 Mon Sep 17 00:00:00 2001 From: David Montag Date: Mon, 28 Mar 2011 16:42:59 -0700 Subject: [PATCH] Added note about Direction.BOTH for @RelatedTo. Fixed code indentation issues (tabs). --- .../programming-model/annotations.xml | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/docbkx/reference/programming-model/annotations.xml b/src/docbkx/reference/programming-model/annotations.xml index a4ee07134..8137d4410 100644 --- a/src/docbkx/reference/programming-model/annotations.xml +++ b/src/docbkx/reference/programming-model/annotations.xml @@ -26,7 +26,7 @@ // simplest example @NodeEntity public class Movie { - String title; + String title; } ]]> @@ -47,20 +47,26 @@ public class Movie { null. For multi-relationships the field provides a managed collection (Set) that handles addition and removal of node entities and reflects those in the graph relationships. + + By setting direction to BOTH, relationships are created in the outgoing direction, but when the 1:N field + is read, it will include relationships in both directions. + movies; + @RelatedTo(type = "ACTS_IN", elementClass = Movie.class) + private Set movies; } ]]> @@ -82,8 +88,8 @@ public class Actor { public class Role { String title; - @StartNode private Actor actor; - @EndNode private Movie movie; + @StartNode private Actor actor; + @EndNode private Movie movie; } ]]> @@ -100,13 +106,13 @@ public class Role { roles; + @RelatedToVia(type = "ACTS_IN", elementClass = Role.class) + private Iterable roles; - public Role playedIn(Movie movie, String title) { - Role role=relateTo(movie,Role.class,"ACTS_IN"); - role.setTitle(title); - return role; + public Role playedIn(Movie movie, String title) { + Role role=relateTo(movie,Role.class,"ACTS_IN"); + role.setTitle(title); + return role; } } ]]> @@ -153,21 +159,19 @@ public class Actor { people; + @GraphTraversal(traversalBuilder = PeopleTraversalBuilder.class, + elementClass = Person.class, params = "persons") + private Iterable people; - private static class PeopleTraversalBuilder implements FieldTraversalDescriptionBuilder { - @Override - public TraversalDescription build(NodeBacked start, Field field, String...params) { - return new TraversalDescriptionImpl() - .relationships(DynamicRelationshipType.withName(params[0])) - .filter(Traversal.returnAllButStartNode()); - - } - } + private static class PeopleTraversalBuilder implements FieldTraversalDescriptionBuilder { + @Override + public TraversalDescription build(NodeBacked start, Field field, String...params) { + return new TraversalDescriptionImpl() + .relationships(DynamicRelationshipType.withName(params[0])) + .filter(Traversal.returnAllButStartNode()); + } + } } - ]]>