Search code examples
javaorientdb

How can I retrieve lightweight edges from OrientDB


I am creating a graph using OrientGraphNoTx in order to achieve massive insertion. After the creation I want to test if everything went well by counting the amount of nodes and edges created. As far as I know the countEdges() function don't work because the lightweight feature is enabled. So I am trying to count the edges with some custom code:

int count = 0;
for(Edge edge : orientGraph.getEdges()) {
    count++;
}

This doesn't work either. I assume that getEdges() function doesn't work either with lightweight edges. So how can I retrieve lightweight edges?


Solution

  • If you're really interested on browsing the edges you can disabling the lightweight edges at the cost to slow down everything. Or if it's just for test purpose you can do:

    Set<Object> edges = new HashSet();
    for(Vertex v : orientGraph.getVertices()) {
        for( Edge e : v.getEdges( Direction.BOTH ) )
          edges.add( e.getIdentity() );
    }
    return edges.size();
    

    In this way you collect all the ids of all the edges (removing duplicates), and then return the edge's collection size.