RESOLVED - BATCH-654: Transactions when commit fails

ItemOrientedStep now detects failed commit and dies asap instead of trying to rollback
This commit is contained in:
robokaso
2008-06-06 12:49:32 +00:00
parent 7df20a9902
commit 61c21ed663
3 changed files with 21 additions and 7 deletions

View File

@@ -326,7 +326,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
* {@link BatchStatus#UNKNOWN} as step's status.
*/
protected static class FatalException extends RuntimeException {
public FatalException(String string, Exception e) {
public FatalException(String string, Throwable e) {
super(string, e);
}
}

View File

@@ -265,18 +265,23 @@ public class ItemOrientedStep extends AbstractStep {
throw new FatalException("Fatal error detected during save of step execution context", e);
}
itemHandler.mark();
try {
itemHandler.mark();
transactionManager.commit(transaction);
}
catch (Exception e) {
fatalException.setException(e);
stepExecution.setStatus(BatchStatus.UNKNOWN);
logger.error("Fatal error detected during commit.");
throw new FatalException("Fatal error detected during commit", e);
throw new CommitException("Fatal error detected during commit - "
+ "the execution is in undefined state and restart will not be possible", e);
}
}
catch (CommitException e) {
// trying to rollback after failed commit would just be
// asking for more trouble - die ASAP
throw e;
}
catch (Error e) {
processRollback(stepExecution, contribution, fatalException, transaction);
throw e;
@@ -382,6 +387,15 @@ public class ItemOrientedStep extends AbstractStep {
}
/**
* Encapsulates exception thrown while committing transaction.
*/
private static class CommitException extends FatalException {
public CommitException(String msg, Throwable cause) {
super(msg, cause);
}
}
protected void close(ExecutionContext ctx) throws Exception {
stream.close(ctx);
}