【问题标题】:How to run multiple gremlin commands as a single transaction?如何将多个 gremlin 命令作为单个事务运行?
【发布时间】:2019-07-04 08:46:55
【问题描述】:

在 Amazon Neptune 中,我想在 Java 中将多个 Gremlin 命令作为单个事务运行。该文档说不支持 tx.commit() 和 tx.rollback() 。它表明这一点 - 由分号 (;) 或换行符 (\n) 分隔的多个语句包含在单个事务中。

文档中的示例显示 Java 支持 Gremlin,但我不明白如何“用分号分隔多个语句”

GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster));

    // Add a vertex.
    // Note that a Gremlin terminal step, e.g. next(), is required to make a request to the remote server.
    // The full list of Gremlin terminal steps is at https://tinkerpop.apache.org/docs/current/reference/#terminal-steps
    g.addV("Person").property("Name", "Justin").next();

    // Add a vertex with a user-supplied ID.
    g.addV("Custom Label").property(T.id, "CustomId1").property("name", "Custom id vertex 1").next();
    g.addV("Custom Label").property(T.id, "CustomId2").property("name", "Custom id vertex 2").next();

    g.addE("Edge Label").from(g.V("CustomId1")).to(g.V("CustomId2")).next();

【问题讨论】:

    标签: amazon-neptune


    【解决方案1】:

    您所指的doc 是使用“字符串”模式进行查询提交。在您的方法中,您通过使用图形遍历源的远程实例(“g”对象)来使用“字节码”模式。相反,您应该通过客户端对象提交字符串脚本

    Client client = gremlinCluster.connect();
    client.submit("g.V()...iterate(); g.V()...iterate(); g.V()...");  
    

    【讨论】:

      【解决方案2】:

      Gremlin sessions

      Java Example

      得到集群对象后,

      String sessionId = UUID.randomUUID().toString();
      Client client = cluster.connect(sessionId);
      client.submit(query1);
      client.submit(query2);
      .
      .
      .
      client.submit(query3);
      client.close();
      

      当你运行 .close() 时,所有的突变都会被提交。

      您还可以捕获来自查询reference 的响应。

      List<Result> results = client.submit(query);
      results.stream()...
      

      【讨论】:

        【解决方案3】:

        您还可以使用 SessionedClient,它会在 close() 时在同一事务中运行所有查询。

        更多信息在这里:https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-sessions.html#access-graph-gremlin-sessions-glv

        【讨论】:

          猜你喜欢
          • 2012-11-18
          • 1970-01-01
          • 2019-12-03
          • 1970-01-01
          • 2015-03-06
          • 2021-08-29
          • 1970-01-01
          • 2017-09-06
          • 1970-01-01
          相关资源
          最近更新 更多