简体   繁体   English

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

[英]Creating vertex in ArangoDB with batch mode

Tried creating vertexes and edges with ArangoDB Java API without activating batch mode, all works well. 尝试使用ArangoDB Java API创建顶点和边缘而不激活批处理模式,一切正常。 However, when batch mode is enabled, it throws an unknown error when creating vertex. 但是,启用批处理模式时,它会在创建顶点时抛出未知错误。 Below is the Java code, and the exception details. 下面是Java代码和异常详细信息。 Any idea why this is happening? 知道为什么会这样吗? Thanks in advance! 提前致谢!

Code

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 Message 异常消息

Database created. 数据库创建。

Graph created. 图表已创建。

Batch mode started. 批量模式已开始。

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

There was an error in the ArangoDB Java driver. ArangoDB Java驱动程序出错。 The problem in the driver was fixed in version 2.7.3. 版本2.7.3中修复了驱动程序中的问题。

I added your nice example code to my tests and tested it with ArangoDB 2.8.6. 我将您的好示例代码添加到我的测试中并使用ArangoDB 2.8.6进行测试。

Download the ArangoDB java driver on github and compile it with maven: github上下载ArangoDB java驱动程序并使用maven编译它:

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

Maven creates the standalone driver JAR file (arangodb-java-driver-XXX-SNAPSHOT-standalone.jar) containing all dependencies in the target directory. Maven创建包含目标目录中所有依赖项的独立驱动程序JAR文件(arangodb-java-driver-XXX-SNAPSHOT-standalone.jar)。

Fetch the example code: 获取示例代码:

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

Compile the example code: 编译示例代码:

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

Start the ArangoDB without authentication on the default port and run the example code: 在默认端口上启动ArangoDB而不进行身份验证并运行示例代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM