Thursday 28 January 2016

How to get edge between to vertex in orientdb

There are 2 ways to get Edge between the edges.

OrientVertex v1
OrientVertex v2
Iterable<Edge> edges = v1.getEdges( v2, Direction.BOTH, "Friends" );
edges.iterator().hasNext();

But it some times return false even if edges exists between v1 and v2.

Instead Use below code to get Edges.

String query="select from (traverse V.out, E.in from "+node1.getIdentity()+" while $depth <=1) "+
                      "where @class='Friends' and in=?";
            OSQLSynchQuery<ODocument> query1 = new OSQLSynchQuery<ODocument>(query);
            Iterable<ODocument> result = graph.command(query1).execute(node2.getIdentity());
            if (null != result && result.iterator().hasNext()) {
                connAdded = true;
            }

No comments:

Post a Comment