【问题标题】:How to commit and rollback graph operations in Datastax DSE 5.0 Graph?如何在 Datastax DSE 5.0 Graph 中提交和回滚图形操作?
【发布时间】:2017-05-05 01:34:52
【问题描述】:

我试过了

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

因为在被 Datastax 收购之前,TitanDB 允许这样做,但我得到“图形不支持事务”

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 作为事务性之外,我在文档中找不到任何内容。

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 对于某些上下文:stackoverflow.com/a/41232259/986160@jilacefie 谢谢!我还想知道这是否也考虑了一个事务(当没有通过 executeGraph() 完成时):Vertex v = g.addV("User").property("uuid","testuuid231").next(); 似乎当我执行 .next() 时它实际上存储了直到那时的所有内容,所以它是一个事务,对吧?.. 如果我v.property("someotherprop","testprop") 之后它是另一笔交易吗?再次感谢并保持良好的工作:)
    • 实际上我尝试了上面所说的内容,当我使用 .next() 从数据库中获取顶点后尝试对其进行变异时,它显示java.lang.IllegalStateException: Property addition is not supported
    • Michail,根据此处的 beta 文档:github.com/datastax/java-dse-graph/tree/1.0.0-beta1/manual 看起来我们还不支持通过新的 Fluent API 进行突变。字符串传递机制是目前要走的路。我已经要求我们的一位司机团队成员也审查这篇文章,并在必要时进行更正。谢谢你的反馈顺便说一句。请随时加入 datastax academy graph slack room 进行更直接的互动。
    • 根据这篇文章,我能够通过 Gremlin Fluent API(使用两种方法)很好地进行突变:stackoverflow.com/questions/41231912/…
    猜你喜欢
    • 2017-05-05
    • 2017-05-05
    • 2017-08-29
    • 1970-01-01
    • 2023-03-28
    • 2017-05-21
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多