使用Java的Datastax DSE 5.0图形中实际上不需要executeGraph()?

使用Java的Datastax DSE 5.0图形中实际上不需要executeGraph()?,java,datastax,gremlin,datastax-java-driver,datastax-enterprise-graph,Java,Datastax,Gremlin,Datastax Java Driver,Datastax Enterprise Graph,似乎在这两种方法中,顶点都是存储的,以后可以正确地检索 通用配置: DseCluster dseCluster = DseCluster.builder() .addContactPoint("192.168.1.43") .build(); DseSession dseSession = dseCluster.connect(); GraphTraversalSource g = DseGraph.traversal( dseSession, new G

似乎在这两种方法中,顶点都是存储的,以后可以正确地检索

通用配置:

DseCluster dseCluster = DseCluster.builder()
        .addContactPoint("192.168.1.43")
        .build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(
    dseSession, new GraphOptions().setGraphName("graph")
);
方法1:

Vertex v = g.addV("User").property("uuid","testuuid231").next();
方法2:

GraphStatement graphStatement =  DseGraph.statementFromTraversal(
    g.addV("User").property("uuid","testuuid231")
);
GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName("graph"));
Vertex v = grs.one().asVertex() // as(Vertex.class) is not allowed after 1.1

看起来你在用,对吗?这是一个相对较新的API,仍处于测试阶段,它允许您在幕后使用DataStax企业Java驱动程序进行Gremlin遍历和Apache Tinkerpop

方法1的好处是,您可以确保您正在为其中一个生成有效的遍历,尽管您也可以通过statementFromTraversal获得此结果,但您也可以将字符串或GraphStatement传递到executeGraph,此时您无法确定您正在执行有效的遍历。此外,由于您使用的是Tinkerpop API而不是datastax驱动程序,因此您可以编写与供应商无关的代码。好的,您仍然在使用它,但在从DseSession获得GraphTraversalSource之后就不会直接使用它了

方法2有一些在方法1中还没有的好处:

如果您熟悉datastax驱动程序,您可以使用许多熟悉ResultSet、Statement等的API。。 TinkerPop的异步API是最近添加的,我不确定它是否能与JavaDSE一起使用,但我还没有尝试过。使用statementFromTraversal,可以将生成的GraphStatement传递到DseSession.executeAsync以执行异步。 DSE图形有一个不属于Gremlin的模式API。因此,您不能单独使用TinkerPop进行模式更改。将介绍一个模式API,用于使用JavaDSE图形执行此操作。在此之前,您必须使用executeGraphString | GraphStatement。 您可以使用方法2执行完整的groovy/gremlin代码。这允许您在一个调用中执行事务管理和多个遍历,这是目前使用方法1无法做到的。
我预计JavaDSE图方法1将来将成为与dse图交互的更惯用的方式。statementFromTraversal提供了一种很好的方法,可以充分利用Apache TinkerPop+与DataStax java驱动程序的接口带来的好处。

感谢您的解释:。我想看看是什么导致事情发生。。这似乎是方法1.的下一步。。这会将GraphTraversal转换为顶点,并且已存储该顶点。。我试图将我的TitanDB代码迁移到DataStax,我在很多地方传递Vertex,现在需要在它们被executeGraph’dIs 3之前进行GraphTraversals,这与我的问题有关:最重要的是,这两个不同,因为带有executeGraph的一个返回DSE Vertex对象,而另一个返回Gremlin/Tinkerpop顶点对象这一遗漏让我想到-如果你不介意的话,请在你的答案中添加这一点,以确保完整性。谢谢:事务处理似乎也是隐式的,因此当前如果executeGraph不用于字符串gremlin查询,那么gremlin的fluent api遍历将变得非常困难(如果无法写入),因此它们都在单个事务中