首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在单个事务中运行多个gremlin命令?

如何在单个事务中运行多个gremlin命令?
EN

Stack Overflow用户
提问于 2019-07-04 16:46:56
回答 3查看 1.6K关注 0票数 3

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

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

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

代码语言:javascript
复制
    // 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();
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-07-05 12:54:44

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

代码语言:javascript
复制
Client client = gremlinCluster.connect();
client.submit("g.V()...iterate(); g.V()...iterate(); g.V()...");  
票数 3
EN

Stack Overflow用户

发布于 2020-11-10 08:57:53

Gremlin sessions

Java Example

在获得集群对象之后,

代码语言:javascript
复制
String sessionId = UUID.randomUUID().toString();
Client client = cluster.connect(sessionId);
client.submit(query1);
client.submit(query2);
.
.
.
client.submit(query3);
client.close();

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

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

代码语言:javascript
复制
List<Result> results = client.submit(query);
results.stream()...
票数 3
EN

Stack Overflow用户

发布于 2020-02-15 02:38:29

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

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56883983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档