我正在阅读《泰坦》的这篇文章。他们在这里谈论泰坦图中的交易
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
是“新”图实例,因此也需要对其进行包装以装饰IdGraph
特征。请注意,在解决此问题之前,以上代码将不起作用:
https://github.com/thinkaurelius/titan/issues/592
直到提出这个问题,我才意识到不可能进行这种包装。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句