我正在经历这个Titan article 。这里他们谈论的是泰坦图中的交易
Vertex v1 = g.addVertex(null);
//Do many other things
TransactionalGraph tx = g.newTransaction();
Vertex v2 = tx.addVertex(null);
v2.setProperty("uniqueName","foo");
tx.commit();
g.addEdge(null,v1,g.getVertex(v2),"related"); //Need to load v2 into outer transaction
//Do many other things
g.commit(); // Likely to fail due to lock congestion
如果我使用 TitanGraph
就可以了,但是使用 IdGraph
时应该如何处理事务?我应该做如下的事情吗:
// baseGraph is TitanGraph, g is IdGraph
TransactionalGraph tx = baseGraph.newTransaction();
Vertex v = g.addVertex(pageId);
v.setProperty("prop1", prop1);
v.setProperty("prop2", prop2);
v.setProperty("prop3", prop3);
tx.commit();
.....create some edges here
g.commit();
最佳答案
有趣的问题。如果我这样做,我的本能是使用 baseGraph
启动新交易,然后将创建的 tx
包装在 IdGraph
中,如下所示:
// baseGraph is TitanGraph, g is IdGraph
TransactionalGraph tx = baseGraph.newTransaction();
IdGraph txId = new IdGraph(tx);
Vertex v = txId.addVertex(pageId);
v.setProperty("prop1", prop1);
v.setProperty("prop2", prop2);
v.setProperty("prop3", prop3);
txId.commit();
.....create some edges here using txId
txId.commit();
将 baseGraph
包装在 IdGraph
中仅用该功能装饰 g
。由于 tx 是一个"new"图形实例,因此也需要对其进行包装以使用 IdGraph 功能进行装饰。请注意,在解决此问题之前,上述代码将不起作用:
https://github.com/thinkaurelius/titan/issues/592
直到这个问题出现之前,我才意识到这样的包装是不可能的。
关于graph-databases - 泰坦图数据库 : handling Transaction in IdGraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21658776/