Search code examples
orientdb

how to check if two verticies are connected with an edge in orient DB using java


I am working with orientDB using Java and I need to check if two vertices are connected, I tried to do a workaround be checking out and in edges for vertices and see if the other vertex in there, the solution works fine so far, i have seen that there is a method called "getEdgesBetweenVertexes()" but seems this method not existing in v 2.2 anymore


Solution

  • You can use the method called getEdges()

    Example:

    OrientVertex v1=graph.getVertex("#21:0");
    OrientVertex v2=graph.getVertex("#26:1");
    
    if(v2!=null){
        Iterable<Edge> result=v1.getEdges(v2, Direction.BOTH, "E");
        boolean connected=false;
        for(Edge e:result){
            connected=true;
            break;
        }
        System.out.println(connected);
    }
    else{
        System.out.println(false);
    }
    

    Hope it helps.