Traverser and relationTypes

3 views
Skip to first unread message

Valère T

unread,
Jun 9, 2010, 9:38:38 AM6/9/10
to jo4neo
Hi there!

I've got a graph and I would like to retrieve a part of this graph
using a traverser.
I've got about 8 classes for the definition of the nodes; these
classes are located in a package Model.



package Model;
public class User extends SomeBaseClass {
transient Nodeid node;

@neo
public String lastname;
@neo
public String firstname;
@neo("INTEREST")
public Collection<Interest> interestArr;
}


In the graph, the ReferenceNode points to the class Nodes with a
relation named [Package].[Class] (eg: Model.User )

I don't know how to define those relations in my RelationTypes to be
used in the Traverser.

public enum RelationTypes implements RelationshipType {
INTEREST,
// MODEL.USER, // ????
THEMA,
}


Traverser traverser = refNode.traverse(
Traverser.Order.DEPTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL,
RelationTypes.MODEL.USER, // ????
RelationTypes.MODEL.ITEM, // ????
RelationTypes.MODEL.THEMA, // ????
Direction.OUTGOING );

The dot between the Package and the Class names is the problem...

Any trick to handle this case ?

Thank you.

Peter Neubauer

unread,
Jun 9, 2010, 10:04:45 AM6/9/10
to jo4...@googlegroups.com
Valere,
The relationship types are just Strings, so you could use something
like for your Enum (taking the Userrole example graph from
http://code.google.com/p/jo4neo/source/browse/#svn/trunk/patterns/userroles):

import org.neo4j.graphdb.RelationshipType;

public enum RelationTypes implements RelationshipType
{

EXAMPLE_ROLE ("example.Role"),
EXAMPLE_USER ("example.User");

String name = "dummy";
private RelationTypes(String name)
{
this.name = name;
}
public String getName() {
return name;
}
}

Then, in the traversal, you specify RelationshipType/Direction pairs
to be traversed, like this:

refNode.traverse(
Traverser.Order.DEPTH_FIRST,
StopEvaluator.END_OF_GRAPH,
ReturnableEvaluator.ALL,
RelationTypes.EXAMPLE_USER,
Direction.OUTGOING,
RelationTypes.EXAMPLE_ROLE,
Direction.OUTGOING );

That way, you will get the right Strings returned from the relationship types.

Does that work out better?

Cheers,

/peter neubauer

COO and Sales, Neo Technology

GTalk: neubauer.peter
Skype peter.neubauer
Phone +46 704 106975
LinkedIn http://www.linkedin.com/in/neubauer
Twitter http://twitter.com/peterneubauer

http://www.neo4j.org - Your high performance graph database.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.

Reply all
Reply to author
Forward
0 new messages