Graph options

You can set default graph options when initializing the cluster. They will be used for all graph statements. For example, to avoid repeating setGraphName("demo") on each statement:

DseCluster dseCluster = DseCluster.builder()
        .addContactPoint("127.0.0.1")
        .withGraphOptions(new GraphOptions().setGraphName("demo"))
        .build();

You can also retrieve and change the options at runtime (be careful about concurrency though, the changes will be visible across all client threads):

GraphOptions graphOptions = dseCluster.getConfiguration().getGraphOptions();
graphOptions.setGraphName("demo2");

If an option is set manually on a GraphStatement, it always takes precedence; otherwise the default option is used. This might be a problem if a default graph name is set, but you explicitly want to execute a statement targeting system, for which no graph name must be set. In that situation, use GraphStatement#setSystemQuery():

GraphStatement s = new SimpleGraphStatement("system.graph('demo').ifNotExists().create()")
        .setSystemQuery();
dseSession.executeGraph(s);

All the different options settable are referenced on the API docs of the GraphOptions class.

Timeouts

The default maximum time limit for executing a graph query is configured server side, in dse.yaml.

By default the Java driver will rely on that server-side configuration. This means that by default, after sending a request, the driver will wait until the server responds with a result or an error message, or times out.

This can be changed if the client needs a lower timeout. A timeout for the client can be set either on the Cluster’s GraphOptions object and will apply to all Graph queries, or individually on each GraphStatement object, through the setReadTimeoutMillis() method. Note that the server will abort a query once the client has stopped waiting for it, so there’s no risk of leaving long-running queries on the server.

Graph sub-protocol

Since DSE driver 1.3.0 it is possible to choose the sub-protocol used for communicating parameters and results with DSE for graph requests, via the GraphOptions.setGraphSubProtocol(GraphProtocol) method.

As of DSE driver 1.x, if the graph protocol is unset, GraphSON1 is the protocol used by default for Gremlin-groovy script queries. The default for Fluent API queries is GraphSON2.

A graph sub-protocol can only be set on the GraphOptions, so only as a global configuration on the DseCluster. If a sub-protocol is explicitly set, it will be applied for all kinds of GraphStatements, whether it is a Gremlin-groovy or Fluent API query, otherwise the defaults explained above will apply.

Example for how to set a graph sub-protocol:

DseCluster cluster = DseCluster.builder()
    .addContactPoints(getContactPoints())
    .withGraphOptions(new GraphOptions().setGraphSubProtocol(GraphProtocol.GRAPHSON_2_0))
    .build();

The GraphSON1 defaults were kept for backward compatibility, however if using DataStax Enterprise 5.0.4+, we highly recommend setting GraphSON2 explicitly for a better handling of results and query parameters. In the next major version of the driver, GraphSON2 will be set by default for all queries.