如何在Datastax DSE 5.0 Graph中提交和回滚图形操作?

时间:2016-12-19 22:35:00

标签: java datastax datastax-java-driver datastax-enterprise-graph

我试着做

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();
    }

因为这是在TitanDB被Datastax收购之前允许的,但我得到了#34; Graph不支持交易"

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)

除了提到Datastax DSE Graph作为交易之外,我在文档中找不到任何内容。

谢谢!

1 个答案:

答案 0 :(得分:2)

Michail,在Andy回答的另一篇文章中,他提供了一些有关DSE如何“做”交易的见解。我们不会将Tinkerpop事务API直接暴露给最终用户。事务当前是隐式的,每个executestatement调用将触发DSE Graph Server中的Tinkerpop事务机制。这是一个快速而又脏的GitHub示例,显示了事务如何与DSE Graph一起使用 - https://github.com/jlacefie/GraphTransactionExample