使用批处理模式在ArangoDB中创建顶点

时间:2016-02-15 18:06:10

标签: arangodb

尝试使用ArangoDB Java API创建顶点和边缘而不激活批处理模式,一切正常。但是,启用批处理模式时,它会在创建顶点时抛出未知错误。下面是Java代码和异常详细信息。 知道为什么会这样吗? 提前谢谢!

代码

public static void main(String[] args) throws ArangoException {

    createNodesInBatch();

}
static public void createNodesInBatch() throws ArangoException {
    ArangoConfigure configure = new ArangoConfigure();
    configure.init();
    ArangoDriver arangoDriver = new ArangoDriver(configure);            

    arangoDriver.createDatabase("small_db"); 
    System.out.println("Database created.");
    arangoDriver.setDefaultDatabase("small_db"); 

    arangoDriver.createCollection("testEdgeCollection",
    new CollectionOptions().setType(CollectionType.EDGE));

    arangoDriver.createCollection("testVertexCollection",
        new CollectionOptions().setType(CollectionType.DOCUMENT));

    EdgeDefinitionEntity ed = new EdgeDefinitionEntity();
    // add edge collection name
    ed.setCollection("testEdgeCollection");

    // add vertex collection names
    ed.getFrom().add("testVertexCollection");

    // add vertex collection names
    ed.getTo().add("testVertexCollection");

    List<EdgeDefinitionEntity> edgeDefinitions = new ArrayList<EdgeDefinitionEntity>();
    edgeDefinitions.add(ed);


    arangoDriver.createGraph("testGraph", edgeDefinitions, null, false);
    System.out.println("Graph created.");

    arangoDriver.startBatchMode();;
    System.out.println("Batch mode started.");

    for (int nodeIdx = 0; nodeIdx < 10; nodeIdx++)
    {
        String nodeName = "node_" + nodeIdx;
        SimpleNode node = new SimpleNode(nodeName);
        VertexEntity<SimpleNode> vertex = arangoDriver.graphCreateVertex("testGraph", "vertextCollection", node, false);            
    }

    System.out.println("Batch execution started to create nodes");
    arangoDriver.executeBatch();

}

异常消息

创建数据库。

创建图表。

批处理模式已开始。

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
    at com.sun.proxy.$Proxy14.createVertex(Unknown Source)
    at com.arangodb.ArangoDriver.graphCreateVertex(ArangoDriver.java:4570)
    at WhichDB.ArangoDBTest.App.createNodesInBatch(App.java:311)
    at WhichDB.ArangoDBTest.App.main(App.java:327)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.arangodb.http.InvocationHandlerImpl.invoke(InvocationHandlerImpl.java:38)
    ... 4 more
Caused by: com.arangodb.ArangoException: unknown error
    at com.arangodb.impl.InternalGraphDriverImpl.createVertex(InternalGraphDriverImpl.java:329)
    at com.arangodb.impl.InternalGraphDriverImpl.createVertex(InternalGraphDriverImpl.java:294)
    ... 9 more

1 个答案:

答案 0 :(得分:7)

ArangoDB Java驱动程序出错。版本2.7.3修复了驱动程序中的问题。

我将您的示例代码添加到my tests并使用ArangoDB 2.8.6对其进行了测试。

github下载ArangoDB java驱动程序,并使用maven编译:

mvn clean install -DskipTests=true -Dgpg.skip=true -Dmaven.javadoc.skip=true -B

Maven创建包含目标目录中所有依赖项的独立驱动程序JAR文件(arangodb-java-driver-X.X.X-SNAPSHOT-standalone.jar)。

获取示例代码:

wget https://gist.githubusercontent.com/anonymous/a430ba1129ccfb0dc1ac31af4dd02d98/raw/8db1033cacd9656f92b8c5b34f5fb1431df8730c/NodesInBatchExample.java

编译示例代码:

javac -classpath arangodb-java-driver-X.X.X-SNAPSHOT-standalone.jar NodesInBatchExample.java

在默认端口上启动ArangoDB而不进行身份验证,然后运行示例代码:

java -classpath arangodb-java-driver-X.X.X-SNAPSHOT-standalone.jar:. NodesInBatchExample