0

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

Michail Michailidis
  • 11,792
  • 6
  • 63
  • 106

1 Answers1

1

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)

IVert

@JavaHandlerClass(Vert.class)
public interface IVert extends VertexFrame {

    @JavaHandler
    public void setTestVar(IVert vert);

}

Vert

abstract class Vert implements JavaHandlerContext<Vertex>, IVert {

    public void setTestVar(IVert testVar){
        Edge edge = asVertex().addEdge('foobar', testVar.asVertex())
        edge.setProperty('alias', 'chickens')
    }

}

Main method (Groovy)

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'
Community
  • 1
  • 1
Nick Grealy
  • 24,216
  • 9
  • 104
  • 119
  • Nice! Could you please also add a getter for that edge property for completion of this question – Michail Michailidis Apr 15 '15 at 19:51
  • @MichailMichailidis, StackOverflow isn't about writing code for other people, and getting an `Edge` property is not pivotal/required for this problem/solution. I'd prefer if you have a go at doing it yourself first, then if you have further problems, I'll try to help you. To write a getter for the edge property is simple, and I've provided everything you require to do this yourself. If you look at the last two lines of the "Main method", you'll see I've already provided the code to the get Edge property! Now just wrap this in a getter method. – Nick Grealy Apr 15 '15 at 23:23