Reputation: 12201
I want to have a Java class to bind to this relationship:
Vertex - Relationship - Vertex (a:Clause)-[r:HasClause]-(b:Clause)
The problem is that the edge of class "HasClause" should have a property called "alias" on the same class - I don't know how I should annotate the class to do that automatically:
@JsonDeserialize(as = Clause.class)
public interface IClause extends VertexFrame {
@Property("nodeClass")
public String getNodeClass();
@Property("nodeClass")
public void setNodeClass(String str);
/* that would be a property on the Vertex not on the Edge
@Property("alias")
public void setAlias(String id);
@Property("alias")
public String getAlias();
*/
@Adjacency(label = "HasClause", direction = Direction.OUT)
public Iterable<IClause> getClauses();
@Adjacency(label = "HasClause", direction = Direction.OUT)
public void setClauses(Iterable<IClause> clauses);
}
Thanks
Upvotes: 0
Views: 52
Reputation: 25942
I don't know if there's a way you can do this using the @Adjacency
annotation (I can't see any way).
One way you could do this, is by using a @JavaHandlerClass
. This basically allows you to customise the implementation of your Frame's methods. In the following example, we'll join two Vertex
's, and add a custom property 'alias' to the Edge
.
Just to make things easier, I'll use the same classes from your other question - Why simple set and then get on Dynamic Proxy does not persist? (using TinkerPop Frames JavaHandler)
@JavaHandlerClass(Vert.class)
public interface IVert extends VertexFrame {
@JavaHandler
public void setTestVar(IVert vert);
}
abstract class Vert implements JavaHandlerContext<Vertex>, IVert {
public void setTestVar(IVert testVar){
Edge edge = asVertex().addEdge('foobar', testVar.asVertex())
edge.setProperty('alias', 'chickens')
}
}
IVert vert = framedGraph.addVertex('myuniqueid', IVert)
IVert vert2 = framedGraph.addVertex('myuniqueid2', IVert)
vert.setTestVar(vert2)
Edge e = g.getVertex('myuniqueid').getEdges(Direction.BOTH, 'foobar').iterator().next()
assert e.getProperty('alias') == 'chickens'
Upvotes: 1