AlexAnand
AlexAnand

Reputation: 169

how to use Tinkerpop blueprints API in arangodb to get all vertices and edges

I have created graph and add vertices and edges using Tinkerpop api by using below code

ArangoDBBatchGraph arang = new ArangoDBBatchGraph("localhost", 8529, "testgraph", "testcollection", "testedgecollection");
        Vertex user = null;
        Vertex preVertex = null;
        preVertex = arang.addVertex(0);
        preVertex.setProperty("name", "edgevertex");

        long startTime = System.currentTimeMillis();
        for(int rec = 1; rec<=10; rec++) {

            user = arang.addVertex(rec);
            user.setProperty("name", "user"+ rec);
            user.setProperty("userid", rec);
            user.setProperty("gender", "male");
            user.setProperty("firstname", "user");
            user.setProperty("lastname", rec);
            user.setProperty("employee number", "emp0"+ rec);

            arang.addEdge(rec, user, preVertex, "edge"+ rec);
            preVertex = user;
        }

        System.out.println("write Time consumed : "+ (System.currentTimeMillis() - startTime));

but i want to get all the edges and vertices in the graph I tried below code, its not working throwing exception Exception in thread "main" java.lang.UnsupportedOperationException at com.arangodb.blueprints.batch.ArangoDBBatchGraph.getVertices(ArangoDBBatchGraph.java:277) at mydb.ArangodbTest.TestConnection.main(TestConnection.java:54)

startTime = System.currentTimeMillis();
        Iterable<Vertex>  iter = arang.getVertices();
        List<Vertex> list = new ArrayList<Vertex>();
        if(iter != null) {
            for(final Vertex vert : iter) {
                list.add(vert);
            }
        }
        Iterable<Edge>  iterEdge = arang.getEdges();
        List<Edge> listEdge = new ArrayList<Edge>();
        if(iter != null) {
            for(Edge edge : iterEdge) {
                listEdge.add(edge);
            }
        }

        System.out.println("Read vertices list: "+ list.size() + ", Edges List: "+listEdge+ "; Time consumed : "+ (System.currentTimeMillis() - startTime));

Please help to get all edges and vertices using tinkerpop api from arangodb

Thanks in advance

Upvotes: 1

Views: 413

Answers (1)

mpv89
mpv89

Reputation: 1891

ArangoDBBatchGraph does not support the methods getVertices() and getEdges(). You have to use ArangoDBGraph instead of ArangoDBBatchGraph.

Apart from this your code should work.

Upvotes: 0

Related Questions