Im writing a backgroundtask that execute procedure my batch written in my oracle database by calling in the public Void run(TaskLifeCycle taskLifeCycle) throws Exception
public void execute(int i) {
systemAuthenticator.withSystem(() -> {
String storeProcedure = "BO.PKG_HANDLE_BATCH.SP_HANDLE";
StoredProcedureQuery query = entityManager.createStoredProcedureQuery(storeProcedure);
return query.execute();
});
}
I have an entity called StepBatch and it have
boolean isSuccess; // (Yes/No)
after that, I want to update the status of the batch if the procedure executed successfully. I try to force-close the browser while the procedure are running.
PROCEDURE SP_HANDLE
IS
BEGIN
DBMS_LOCK.SLEEP(5); -- sleep 5 seconds
INSERT INTO test_table
VALUES(1,1); -- insert into a dummy table to test
END;
But the procedure still executed successfully but the service doesnt update the success status from No to Yes into my entity.
@Override
public Void run(TaskLifeCycle<Integer> taskLifeCycle) throws Exception {
for (int i = 0; i < 10; i++) {
if (taskLifeCycle.isCancelled()) {
break;
}
beforeRun(i); // update some bla bla information
running(i); // calling my public void execute(int i) in my running method and handle exception
afterRun(i); // call dataManager.load to get the StepBatch entity and update StepBatch.isSuccess to Yes then dataManager.save(stepBatch);
i++;
taskLifeCycle.publish(i);
}
return null;
}
My beforeRun just update some neccessary things
My running tried to execute store procedure in my database. I let the procedure sleep 5 second then insert into a dummy table, but while the procedure is sleeping, i try to close the browser
My procedure still commit the work.
but my afterRun doesnt update the status.
How to let my afterRun work?