Hi,
I have a requirement where a list of requests which can add , delete or edit vertex in orient db need to be executed in batch. If any of the operation fails the system should rollback all the transactions.
I am using orientdb.
Below is the pseudocode -
public void changeData(List reqs)
{
Graph graph = OrientGraph.open(dbName , url , password);
graph.tx().open();
for(Req req: reqs)
{
try{
createVertex(req, graph);
graph.tx().commit();
}catch(Exception e)
{
graph.tx().rollback();
}
}
}
public void createVertex(Req req , Graph g)
{
Vertex v = g.addVertex(req.getName());
Map<String , Object> attributes = req.getProperties();
attributes.forEach((key,val)->{
v.property(key ,val);
});
//do some more processing logical processing which can throw error. When error is thrown after this line the vertex is created in dbName
throw new Exception();
}
The above code executes creation of vertex successfully , but after the error is thrown because of further processing the transaction is not rolled back. The vertex get created in db.
Please can you tell me how can i fix this issue.
Regards
Smita