Graph

The driver provides full support for DSE graph, the distributed graph database available in DataStax Enterprise. The DseSession interface extends GraphSession, which adds specialized methods to execute requests expressed in the Gremlin graph traversal language.

This manual only covers driver usage; for more information about server-side configuration and data modeling, refer to the DSE developer guide.

There are 3 ways to execute graph requests:

  1. Passing a Gremlin script directly in a plain Java string. We’ll refer to this as the script API:

    DseSession session = DseSession.builder().build();
    
    String script = "g.V().has('name', name)";
    ScriptGraphStatement statement =
        ScriptGraphStatement.builder(script)
            .withQueryParam("name", "marko")
            .build();
    
    GraphResultSet result = session.execute(statement);
    for (GraphNode node : result) {
      System.out.println(node.asVertex());
    }
    
  2. Building a traversal with the TinkerPop fluent API, and executing it explicitly with the session:

    import static com.datastax.dse.driver.api.core.graph.DseGraph.g;
    
    GraphTraversal<Vertex, Vertex> traversal = g.V().has("name", "marko");
    FluentGraphStatement statement = FluentGraphStatement.newInstance(traversal);
    
    GraphResultSet result = session.execute(statement);
    for (GraphNode node : result) {
      System.out.println(node.asVertex());
    }
    
  3. Building a connected traversal with the fluent API, and executing it implicitly by invoking a terminal step:

    GraphTraversalSource g = DseGraph.g
        .withRemote(DseGraph.remoteConnectionBuilder(session).build());
    
    List<Vertex> vertices = g.V().has("name", "marko").toList();
    

All executions modes rely on the same set of configuration options.

The script and explicit fluent API return driver-specific result sets. The implicit fluent API returns Apache TinkerPop™ types directly.