Added additional menthod to ItemSkipPolicy to determine if a step should fail. Also added a small prototype of domain-specific interceptors.

This commit is contained in:
lucasward
2008-02-28 05:23:49 +00:00
parent 52ccced24a
commit db46104307
4 changed files with 37 additions and 5 deletions

View File

@@ -328,12 +328,20 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
fatalException.setException(e);
stepExecution.setStatus(BatchStatus.UNKNOWN);
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
if(itemSkipPolicy.shouldFail(t)){
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
else {
throw new RuntimeException(t);
}
}
else {
throw new RuntimeException(t);
else{
logger.error("Exception should not cause step to fail", t);
}
result = ExitStatus.CONTINUABLE;
}
// Check for interruption after transaction as well, so that

View File

@@ -29,4 +29,8 @@ public class AlwaysSkipItemSkipPolicy implements ItemSkipPolicy {
public boolean shouldSkip(Exception ex, int skipCount) {
return true;
}
public boolean shouldFail(Throwable t) {
return true;
}
}

View File

@@ -57,6 +57,7 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
private final int skipLimit;
private ExceptionClassifier exceptionClassifier;
private List failurePreventingExceptions = new ArrayList();
public LimitCheckingItemSkipPolicy(int skipLimit) {
this(skipLimit, new ArrayList(0));
@@ -95,5 +96,22 @@ public class LimitCheckingItemSkipPolicy implements ItemSkipPolicy {
return false;
}
}
public boolean shouldFail(Throwable t) {
if(failurePreventingExceptions.contains(t)){
return false;
}
else{
return true;
}
}
/**
* Set the list of exceptions that will prevent step execution from failing.
*
* @param failurePreventingExceptions
*/
public void setFailurePreventingExceptions(List failurePreventingExceptions) {
this.failurePreventingExceptions = failurePreventingExceptions;
}
}

View File

@@ -29,5 +29,7 @@ public class NeverSkipItemSkipPolicy implements ItemSkipPolicy{
return false;
}
public boolean shouldFail(Throwable t) {
return true;
}
}