问题
It seems that in both approaches the vertex is stored and can be retrieved properly later.
Common configuration:
DseCluster dseCluster = DseCluster.builder()
.addContactPoint("192.168.1.43")
.build();
DseSession dseSession = dseCluster.connect();
GraphTraversalSource g = DseGraph.traversal(
dseSession, new GraphOptions().setGraphName("graph")
);
Approach 1:
Vertex v = g.addV("User").property("uuid","testuuid231").next();
Approach 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
回答1:
It looks like you are using java-dse-graph, is that right? This is a relatively new API (still in beta) which allows you to make Gremlin Traversals w/ Apache Tinkerpop using the DataStax Enterprise Java driver under the covers.
The benefits of approach 1 is that you can be sure that you are forming valid traversals for one, although you also get this via statementFromTraversal
(you can also pass a String
or GraphStatement
into executeGraph
at which point you can't be sure you are executing a valid traversal). Additionally, you can write code that is more vendor agnostic, since you are using the Tinkerpop API and not the datastax driver. Well, you are still using it, but not directly once you've got a GraphTraversalSource
from a DseSession
.
Approach 2 has a few benefits that aren't available in approach 1 (yet):
- If you are familiar with the datastax driver, you can use a lot of the same APIs that you are comfortable with (
ResultSet
,Statement
, etc.). - The async API for TinkerPop (TINKERPOP-1490) was very recently added and I'm not sure it would work with
java-dse-graph
(haven't tried it yet). UsingstatementFromTraversal
, you can pass the generatedGraphStatement
intoDseSession.executeAsync
to do async. - DSE Graph has a schema API that is not part of Gremlin. Therefore, you can't make schema changes with TinkerPop alone. JAVA-1061 will introduce a schema API for doing this using
java-dse-graph
. Until then you would have to useexecuteGraph(String|GraphStatement)
. - You can execute full groovy/gremlin code with approach 2. This allows you to do things like transaction management and execute multiple traversals in one call, which you can't currently do with approach 1.
I expect that java-dse-graph
(approach 1) will become the more idiomatic way to interact with DSE Graph in the future. statementFromTraversal
offers a nice way to get the best of both worlds (the benefit of Apache TinkerPop + an interface to the DataStax java driver).
来源:https://stackoverflow.com/questions/41231912/executegraph-is-not-really-needed-in-datastax-dse-5-0-graph-with-java