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

@@ -1,5 +1,7 @@
package org.springframework.batch.core.step;
import java.util.Arrays;
import org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler;
/**
@@ -10,6 +12,8 @@ public class SkipLimitStepFactoryBean extends DefaultStepFactoryBean {
private int skipLimit = 0;
private Class[] skippableExceptionClasses = new Class[]{ Exception.class };
/**
* Public setter for a limit that determines skip policy. If this value is
* positive then an exception in chunk processing will cause the item to be
@@ -22,6 +26,17 @@ public class SkipLimitStepFactoryBean extends DefaultStepFactoryBean {
public void setSkipLimit(int skipLimit) {
this.skipLimit = skipLimit;
}
/**
* Public setter for exception classes that when raised won't crash the job
* but will result in transaction rollback and the item which handling caused
* the exception will be skipped.
*
* @param skippableExceptionClasses defaults to <code>Exception</code>
*/
public void setSkippableExceptionClasses(Class[] exceptionClasses) {
this.skippableExceptionClasses = exceptionClasses;
}
/**
* Uses the {@link #skipLimit} value to configure item handler and
@@ -38,7 +53,10 @@ public class SkipLimitStepFactoryBean extends DefaultStepFactoryBean {
* to absorb exceptions at the step level because the failed items
* will never re-appear after a rollback.
*/
itemHandler.setItemSkipPolicy(new LimitCheckingItemSkipPolicy(skipLimit));
itemHandler.setItemSkipPolicy(new LimitCheckingItemSkipPolicy(skipLimit, Arrays.asList(skippableExceptionClasses)));
SimpleLimitExceptionHandler exceptionHandler = new SimpleLimitExceptionHandler();
exceptionHandler.setLimit(skipLimit);
exceptionHandler.setExceptionClasses(skippableExceptionClasses);
setExceptionHandler(new SimpleLimitExceptionHandler(skipLimit));
getStepOperations().setExceptionHandler(getExceptionHandler());
}
@@ -50,5 +68,4 @@ public class SkipLimitStepFactoryBean extends DefaultStepFactoryBean {
step.setItemHandler(itemHandler);
}
}