Remotely connected traversal source

The DSE Java driver also provides full compatibility with Apache TinkerPop‘s query execution model and result types.

It is fully compatible with Tinkerpop’s concept of remote traversal sources, and may be used as an alternative to building queries with the Fluent API however, it may offer fewer features than the Fluent API queries would be able to offer in the future.

The module with the classes necessary to be able to use remote connected traversal sources with DSE Graph can be found on Maven:

<dependency>
    <groupId>com.datastax.dse</groupId>
    <artifactId>dse-java-driver-graph</artifactId>
    <version>1.8.2</version>
</dependency>

The following is an example of how to get a Apache TinkerPop GraphTraversalSource that is remotely connected to a DseGraph server, and which communicates to DseGraph via the DSE Java driver under the covers:

DseCluster dseCluster = DseCluster.builder()
    .addContactPoint("1.2.3.4")
    .withGraphOptions(new GraphOptions()
                        .setGraphName("mygraph"))
    .build();
DseSession dseSession = dseCluster.connect();

GraphTraversalSource g = DseGraph.traversal(dseSession);

// Now you can use the Traversal source and use it **as if** it was working against a local graph, and with the usual TinkerPop API. All the communication with the DSE Graph server is done transparently.
List<Vertex> vertices = g.V().hasLabel("person").toList();

Traversal sources with different configurations can easily be created. By default the options specific to DseGraph are taken from the DseCluster configuration, however the API exposes a way to override each individual setting, per traversal source:

GraphTraversalSource gOLTP = DseGraph.traversal(dseSession, new GraphOptions().setGraphName("mygraph"));
GraphTraversalSource gOLAP = DseGraph.traversal(dseSession, new GraphOptions().setGraphName("myothergraph").setGraphSource(ANALYTICS_SOURCE_NAME));

Vertex v = gOLTP.V().has("name", "marko").next();
long count = gOLAP.V().count().next();

Important note: there is no interactivity with DSE Graph until a Terminal Step (such as next(), toList(), etc.) is called.

A word on Results

Objects returned after the Remote traversal execution are objects that are detached from the original DSE Graph on the server. A detached element is an element that lives on its own, even though the detached elements contains the complete data, modifications made to a detached element do not affect the data stored in the DSE Graph.

Additional features

Just like when building queries with the Fluent API, using the DSE Java driver allows to use some advanced features from Tinkerpop. For instance one would use the Gremlin Domain Specific Language feature with a remote connected traversal source like this:

// see TinkerPop documentation link for the generation of SocialTraversalSource
SocialTraversalSource gSocial = DseGraph.traversal(dseSession, SocialTraversalSource.class);
List<Vertex> vertices = gSocial.persons("marko").knows("vadas").toList();

DSE Search Text and Geo predicates can also be used with a remote connected traversal source:

GraphTraversalSource g = DseGraph.traversal(dseSession, new GraphOptions().setGraphName("thegraph"));
Vertex v = g.V().has("textProp", Search.tokenPrefix("1")).next();

See this page for more information.