user3508123
user3508123

Reputation: 1

Tinkerpop Frames: Get Edge when adding a vertex

i followed the example on https://github.com/tinkerpop/frames/wiki/Getting-Started and wanted to do the following: When adding a new Project, for example

marko.addCreatedProject(pr);

i also want to get the edge between marko and pr to set the weight, for example. One way to do this is to get all outgoing vertices of marko and find pr in the list of vertices. Is there a better way to do this? Is it possible to return the edge, when i call addCreatedProject, to do the following:

CreatededInfo cr = marko.addCreatedProject(pr);
cr.setWeight(3);

Upvotes: 0

Views: 145

Answers (1)

waltron
waltron

Reputation: 151

You could try using the addEdge method on FramedGraph which returns the Edge when you supply two vertices to relate. So a little more fine grained.

E.g.

com.tinkerpop.frames.FramedGraphFactory.FramedTransactionalGraph graph = ...
Vertex user1 = graph.addVertex(null);
Vertex project1 = graph.addVertex(null);
Edge newEdge = graph.addEdge(null, user1, project1, "CREATED");
// ... do something with newEdge

The tinkerpop FramedGraph interface also has overloaded methods for addVertex and addEdge, so that you can supply your framed Class type, to have a Framed vertex or edge returned which can be convenient.

E.g.

Vertex user1 = graph.addVertex(null, Person.class);
Vertex project1 = graph.addVertex(null, Project.class);
Edge newEdge = graph.addEdge(null, user1, project1, "CREATED",Direction.OUT, MyEdge.class);

And of course you can graph.frame(newEdge, MyEdge.class) after the fact too, if you only have a com.tinkerpop.blueprints.Edge.

Here is the Javadoc for FramedGraph

Upvotes: 1

Related Questions