如何在arangodb中使用Tinkerpop蓝图API来获取所有顶点和边缘

时间:2016-10-24 10:23:30

标签: java arangodb tinkerpop tinkerpop-blueprint

我使用下面的代码

创建了图形并使用Tinkerpop api添加顶点和边缘
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));

但我希望得到图中的所有边和顶点 我尝试了下面的代码,它没有工作抛出异常Exception in thread&#34; main&#34; java.lang.UnsupportedOperationException     在com.arangodb.blueprints.batch.ArangoDBBatchGraph.getVertices(ArangoDBBatchGraph.java:277)     在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));

请使用arangodb中的tinkerpop api帮助获取所有边和顶点

提前致谢

1 个答案:

答案 0 :(得分:0)

ArangoDBBatchGraph不支持getVertices()getEdges()方法。您必须使用ArangoDBGraph代替ArangoDBBatchGraph

除此之外,您的代码应该有效。