Search code examples
cassandradatastax-java-driverdatastax-enterprise-graph

How to commit and rollback graph operations in Datastax DSE 5.0 Graph?


I tried to do

DseCluster dseCluster = null;

    try {
        dseCluster = DseCluster.builder()
                .addContactPoint("192.168.1.43")
                .build();
        DseSession dseSession = dseCluster.connect();
        GraphTraversalSource g = DseGraph.traversal(dseSession, new GraphOptions().setGraphName("graph"));
        GraphStatement graphStatement =  DseGraph.statementFromTraversal(g.addV("test"));
        GraphResultSet grs = dseSession.executeGraph(graphStatement.setGraphName("graph"));
        System.out.println(grs.one().asVertex());

        g.tx().commit();

    } finally {
        if (dseCluster != null) dseCluster.close();
    }

since this was allowed in TitanDB before it was acquired by Datastax but I get "Graph does not support transactions"

Exception in thread "main" java.lang.UnsupportedOperationException: Graph does not support transactions
00:27:52.420 [cluster1-nio-worker-0] DEBUG io.netty.buffer.PoolThreadCache - Freed 26 thread-local buffer(s) from thread: cluster1-nio-worker-0
    at org.apache.tinkerpop.gremlin.structure.Graph$Exceptions.transactionsNotSupported(Graph.java:1127)
    at org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.tx(EmptyGraph.java:75)
    at org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource.tx(GraphTraversalSource.java:320)
    at testbed.TestBed.main(TestBed.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

I couldn't find anything in the documentation other than mentions Datastax DSE Graph as transactional.

Thanks!


Solution

  • Michail, in your other post in which Andy answered, he provided some insight into how DSE "does" transactions at the moment. We do not expose the Tinkerpop transaction API directly to end users. Transactions are currently implicit, each executestatement call will trigger the Tinkerpop transaction mechanisms within DSE Graph Server. Here's a quick and dirty GitHub example showing how transactions work with DSE Graph - https://github.com/jlacefie/GraphTransactionExample