Executing graph queries

DseSession has dedicated methods to execute graph queries.

A graph query can be executed either via the executeGraph() method which accepts a string Gremlin-groovy script in parameter, or the recommended executeGraph() method that accepts a GraphStatement. The recommended way to create GraphStatements to execute is via the Fluent API module.

The following snippet is a fully functional example. It creates a new DSE Graph and sets the graph schema to development mode, which allows to bypass the schema creation phase of DSE Graph in order to learn how to use DSE Graph and experiment, but this setting is not recommended for production and is just a guide to get started quickly:

// -- DSE Graph setup --
dseSession.executeGraph("system.graph('demo').ifNotExists().create()");
dseSession.getCluster().getConfiguration().getGraphOptions().setGraphName("demo");

// WARNING: these settings are not recommended for Production! These are only used here
// for demonstration purposes. Check the DSE Graph Schema documentation for more information.
dseSession.executeGraph("schema.config().option('graph.allow_scan').set(true)");
dseSession.executeGraph("schema.config().option('graph.schema_mode').set('Development')");
// -- end DSE Graph setup --

GraphTraversalSource g = DseGraph.traversal();

GraphStatement s1 = DseGraph.statementFromTraversal(g.addV("testLabel"));
dseSession.executeGraph(s1);

GraphStatement s2 = DseGraph.statementFromTraversal(g.V());
GraphResultSet grs = dseSession.executeGraph(s2);
System.out.println(grs.one().asVertex());
Asynchronous execution

GraphStatement can also be executed asynchronously via the executeGraphAsync() methods.