我正在开发一个REST API.我在Orientdb中遇到各种各样的问题.在当前设置中,我们有一个包装ODatabaseDocumentPool的单例.我们通过此设置检索所有实例.每个api调用都是从池中获取实例并使用ODatabaseDocumentTx实例创建OrientGraph的新实例开始的.后面的代码使用ODatabaseDocumentTx和OrientGraph中的方法.在代码的最后,我们在写操作上调用graph.commit(),在所有操作上调用graph.shutdown().
我有一份问题清单.
为了验证,我仍然可以使用我用来创建OrientGraph的ODatabaseDocumentTx实例?或者我应该使用OrientGraph.getRawGraph()?
使用OrientGraph时,执行读取操作的最佳方法是什么?即使在读取操作期间,我也会在检索记录时获得OConcurrentModificationExceptions,锁定异常或错误.这是因为OrientGraph是事务性的,即使在检索记录时也会修改版本吗?我应该提一下,我也使用索引管理器并在这些读操作中迭代顶点的边.
当我通过索引管理器获取记录时,这是否更新了数据库上的版本?
graph.shutdown()是否将ODatabaseDocumentTx实例释放回池中?
v1.78是否仍然要求我们锁定交易中的记录?
如果在OrientGraph上将autoStartTx设置为false,我是否必须手动启动事务,还是在访问数据库时自动启动?
示例代码:
ODatabaseDocumentTx db = pool.acquire();
// READ
OrientGraph graph = new OrientGraph(db);
ODocument doc = (ODocument) oidentifialbe.getRecord() // I use Java API to a get record from index
if( ((String) doc.field("field")).equals('name') )
//code
OrientVertex v = graph.getVertex(doc);
for(OrientVertex vv : v.getVertices()) {
//code
}
// OR WRITE
doc.field('d',val);
doc = doc.save();
OrientVertex v = v.getVertex(doc);
graph.addEdge(null, v, otherVertex);
graph.addEdge(null, v, anotherVertex) // do I have to reload the record in v?
// End Transaction
// if write
graph.commit();
// then
graph.shutdown();
Run Code Online (Sandbox Code Playgroud)
我使用 ODatabaseSession,从这个角度来看,我注意到我对您的一些观点的观察:
使用 OrientGraph 时执行读取操作的最佳方式是什么?即使在读取操作期间,我也会遇到 OConcurrentModificationExceptions、锁定异常或检索记录时出错。这是因为 OrientGraph 是事务性的,即使在检索记录时版本也会被修改?我应该提到,我还使用索引管理器并在这些读取操作中迭代顶点的边缘。
请参阅OrientDB 并发。您收到并发异常是因为,在您检索信息(例如顶点)的时间和您更新的时间,其他部分已经更新了记录。可以通过重新加载记录来避免这种情况
Run Code Online (Sandbox Code Playgroud)When I get a record through the Index Manager, does this update the version on the database?
读取操作不会更新记录版本,只有修改操作才会更新。
v1.78还要求我们在交易中锁定记录吗?
如果在 OrientGraph 上将 autoStartTx 设置为 false,我是否必须手动启动事务,还是在访问数据库时自动启动事务?
请参阅OrientDB 事务。请参阅图 API。如果 autoStartTx 关闭,则需要显式启动事务。