IN PROGRESS - issue BATCH-422: Provide ability to specify exception types as well as skip limit in DefaultStepFactoryBean

http://jira.springframework.org/browse/BATCH-422

The desired functionality should now be there, but needs better tests
This commit is contained in:
robokaso
2008-03-12 13:43:39 +00:00
parent 64a4e53a99
commit 8fff682219
3 changed files with 34 additions and 13 deletions

View File

@@ -37,7 +37,7 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
private RethrowOnThresholdExceptionHandler delegate = new RethrowOnThresholdExceptionHandler();
private Class type = Exception.class;
private Class[] exceptionClasses = new Class[] { Exception.class };
/**
* Flag to indicate the the exception counters should be shared between
@@ -68,8 +68,10 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
super();
delegate.setExceptionClassifier(new ExceptionClassifierSupport() {
public Object classify(Throwable throwable) {
if (type.isAssignableFrom(throwable.getClass())) {
return TX_INVALID;
for (int i = 0; i < exceptionClasses.length; i++) {
if (exceptionClasses[i].isAssignableFrom(throwable.getClass())) {
return TX_INVALID;
}
}
return super.classify(throwable);
}
@@ -106,13 +108,15 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler {
}
/**
* Setter for the Throwable type that this handler counts. Defaults to
* {@link Exception}.
* Setter for the Throwable exceptionClasses that this handler counts. Defaults to
* {@link Exception}. If more exceptionClasses are specified handler uses single
* counter that is incremented when one of the recognized exception
* exceptionClasses is handled.
*
* @param type
*/
public void setType(Class type) {
this.type = type;
public void setExceptionClasses(Class[] classes) {
this.exceptionClasses = classes;
}
}