java-rest-binding
java-rest-binding copied to clipboard
Cannot call batchRestApi.getNodeById() inside BatchCallback
This won't work:
graphDb.getRestAPI().executeBatch(new BatchCallback<Void>() {
@Override
public Void recordBatch(RestAPI batchRestApi) {
Node node = batchRestApi.getNodeById(nodeId);
for (Relationship rel : node.getRelationships()) {
rel.delete();
}
node.delete();
return null;
}
});
The workaround is: (for this specific case only)
graphDb.getRestAPI().executeBatch(new BatchCallback<Void>() {
@Override
public Void recordBatch(RestAPI batchRestApi) {
batchRestApi.deleteEntity(new RestEntity("/node/" + nodeId, batchRestApi));
return null;
}
});
This is by intent as the batch-requests are all deferred.
So best way to do it is to pull the node before the batch-request. At least it should. Might run into the same issue as #11
Even the getRelationships is deferred so it also has to be called before the batch operation.
This will work with the next snapshot:
final Node node1 = restAPI.createNode(map("name","node1"));
node1.createRelationshipTo(restAPI.createNode(map("name","node2")),RELATIONSHIP_TYPE);
node1.createRelationshipTo(restAPI.createNode(map("name","node3")),RELATIONSHIP_TYPE);
final Iterable<Relationship> rels = node1.getRelationships();
Integer deleted = restAPI.executeBatch(new BatchCallback<Integer>() {
@Override
public Integer recordBatch(RestAPI batchRestApi) {
int count = 0;
for (Relationship rel : rels) {
rel.delete();
count++;
}
node1.delete();
count++;
return count;
}
});
assertEquals(3, deleted.intValue());