在亚马逊海王星,我想在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();发布于 2019-07-05 12:54:44
您引用的doc是用于使用"string“模式提交查询的。在您的方法中,您通过使用图遍历源的远程实例( "g“对象)来使用"bytecode”模式。相反,您应该通过客户端对象提交字符串脚本
Client client = gremlinCluster.connect();
client.submit("g.V()...iterate(); g.V()...iterate(); g.V()..."); 发布于 2020-11-10 08:57:53
在获得集群对象之后,
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()...发布于 2020-02-15 02:38:29
您还可以使用SessionedClient,它将在close()时运行同一事务中的所有查询。
https://stackoverflow.com/questions/56883983
复制相似问题