I have written a web script that searches for a set of nodes of a particular type that were created in a specified date range, then deletes each node and recreates it with the same data (this is intended to fix a problem that is out of the scope of this question). The code that re-creates the node does a search first to confirm that the node does not exist.
I have each delete and create enclosed in a transaction. When I run in the debugger and trace through the code, everything works because the deleted node is not found. If run without the debugger, the search for the existing node returns a result, with all the fields marked as "missing". Because the node already (incompletely) exists, the new node is not created.
The web script definition has <transaction>none</transaction>.
Here is some stripped-down code minus things like error handling, try/catch, rollbacks, etc.:
UserTransaction trxDelete = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction(false); trxDelete.begin();
retBi = deleteBundle(bundleId);
trxDelete.commit();
UserTransaction trxCreate = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction(false); trxCreate.begin();
retBi = createBundle(bundleId, bundleInfo.getBundledSubmissions());
trxCreate.commit();
createBundle() does the search on bundleId before creating the node, and is finding the deleted node IFF I don't run in the debugger. If run in the debugger, it doesn't find the deleted node. This makes me think that the commit is taking some time to actually complete and is returning before it's complete.
What is the best way to handle this situation?
Thanks,
Bill