How to limit parsing depth using Tinkerpop Frames

141 views Asked by At

Hi I have an interface and a corresponding implementation class like:

public interface IActor extends VertexFrame {

    @Property(ActorProps.nodeClass)
    public String getNodeClass();

    @Property(ActorProps.nodeClass)
    public void setNodeClass(String str);

    @Property(ActorProps.id)
    public String getId();

    @Property(ActorProps.id)
    public void setId(String id);

    @Property(ActorProps.name)
    public String getName();

    @Property(ActorProps.name)
    public void setText(String text);

    @Property(ActorProps.uuid)
    public String getUuid();

    @Property(ActorProps.uuid)
    public void setUuid(String uuid);

    @Adjacency(label = RelClasses.CoActors, direction = Direction.OUT)
    public Iterable<IActor> getCoactors();
}

And I use OrientDB with it that looks something like that. I had similar implementation with Neo4j as well:

Graph graph = new OrientGraph("remote:localhost/actordb");
FramedGraph<Graph> manager = new FramedGraphFactory().create(graph);
IActor actor = manager.frame(((OrientGraph)graph).getVertexByKey("Actor.uuid",uuid), IActor.class);

Above works but the problem is that in this case or similar, because there is a relationship between two vertices of class Actor, there could be potentially a graph loop. Is there a way to define either by Annotation or some other way (e.g through Manager) to stop after x steps for a specific @Adjacency so this won't go forever? If @GremlinGroovy (https://github.com/tinkerpop/frames/wiki/Gremlin-Groovy) annotation is the answer could you please give an example ?

1

There are 1 answers

1
Nick Grealy On

I'm not sure I understand the question/problem. (You say "potentially", but haven't actually proven that there's a problem!)

  • Is the problem that there is a loop in the Vertex/Frames, and (you think) loading the object will result in an infinite loop?
  • Have you been able to prove that there is a problem loading a Vertex/Frame with a loop? (show me the code/problem)

As I understand it, the Pipelines will lazy-load objects (only load then when required). The frames (I imagine) only load adjacent frames when requested. Basically, as far as I can tell, theres no problem.

Example (Groovy)

// create some framed vertices
Person nick = createPerson(name: 'Nick')
Person michail = createPerson(name: 'Michail')

// create a recursive loop
nick.addKnows(michail)
michail.addKnows(nick)

// handles recursion = true!
Person nick2 = framedGraph.getVertex(nick.asVertex().id, Person)
assert nick2.knows.knows.knows.knows.knows.name == 'Michail'