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

skip configuration moved to separate step factory subclass
This commit is contained in:
robokaso
2008-03-12 10:30:24 +00:00
parent 19aea73481
commit 56174c7d32
3 changed files with 59 additions and 37 deletions

View File

@@ -23,7 +23,6 @@ import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.exception.ExceptionHandler;
import org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate;
@@ -38,8 +37,6 @@ import org.springframework.core.task.TaskExecutor;
*/
public class DefaultStepFactoryBean extends AbstractStepFactoryBean {
private int skipLimit = 0;
private int commitInterval = 0;
private ItemStream[] streams = new ItemStream[0];
@@ -75,19 +72,6 @@ public class DefaultStepFactoryBean extends AbstractStepFactoryBean {
public void setStreams(ItemStream[] streams) {
this.streams = streams;
}
/**
* 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
* skipped and no exception propagated until the limit is reached. If it is
* zero then all exceptions will be propagated from the chunk and cause the
* step to abort.
*
* @param skipLimit the value to set. Default is 0 (never skip).
*/
public void setSkipLimit(int skipLimit) {
this.skipLimit = skipLimit;
}
/**
* The listeners to inject into the {@link Step}. Any instance of
@@ -221,26 +205,10 @@ public class DefaultStepFactoryBean extends AbstractStepFactoryBean {
step.setStepOperations(stepOperations);
ItemSkipPolicyItemHandler itemProcessor = new ItemSkipPolicyItemHandler(itemReader, itemWriter);
ItemSkipPolicyItemHandler itemHandler = new ItemSkipPolicyItemHandler(itemReader, itemWriter);
if (skipLimit > 0) {
/*
* If there is a skip limit (not the default) then we are prepared
* to absorb exceptions at the step level because the failed items
* will never re-appear after a rollback.
*/
itemProcessor.setItemSkipPolicy(new LimitCheckingItemSkipPolicy(skipLimit));
setExceptionHandler(new SimpleLimitExceptionHandler(skipLimit));
stepOperations.setExceptionHandler(getExceptionHandler());
step.setStepOperations(stepOperations);
}
else {
// This is the default in ItemOrientedStep anyway...
itemProcessor.setItemSkipPolicy(new NeverSkipItemSkipPolicy());
}
setItemHandler(itemProcessor);
step.setItemHandler(itemProcessor);
setItemHandler(itemHandler);
step.setItemHandler(itemHandler);
}

View File

@@ -0,0 +1,54 @@
package org.springframework.batch.core.step;
import org.springframework.batch.repeat.exception.SimpleLimitExceptionHandler;
/**
* Factory bean for step that allows configuring skip limit.
*
*/
public class SkipLimitStepFactoryBean extends DefaultStepFactoryBean {
private int skipLimit = 0;
/**
* 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
* skipped and no exception propagated until the limit is reached. If it is
* zero then all exceptions will be propagated from the chunk and cause the
* step to abort.
*
* @param skipLimit the value to set. Default is 0 (never skip).
*/
public void setSkipLimit(int skipLimit) {
this.skipLimit = skipLimit;
}
/**
* Uses the {@link #skipLimit} value to configure item handler and
* and exception handler.
*/
protected void applyConfiguration(ItemOrientedStep step) {
super.applyConfiguration(step);
ItemSkipPolicyItemHandler itemHandler = new ItemSkipPolicyItemHandler(getItemReader(), getItemWriter());
if (skipLimit > 0) {
/*
* If there is a skip limit (not the default) then we are prepared
* to absorb exceptions at the step level because the failed items
* will never re-appear after a rollback.
*/
itemHandler.setItemSkipPolicy(new LimitCheckingItemSkipPolicy(skipLimit));
setExceptionHandler(new SimpleLimitExceptionHandler(skipLimit));
getStepOperations().setExceptionHandler(getExceptionHandler());
}
else {
// This is the default in ItemOrientedStep anyway...
itemHandler.setItemSkipPolicy(new NeverSkipItemSkipPolicy());
}
step.setItemHandler(itemHandler);
}
}

View File

@@ -153,10 +153,10 @@ public class StatefulRetryStepFactoryBean extends DefaultStepFactoryBean {
retryTemplate.setBackOffPolicy(backOffPolicy);
}
StatefulRetryItemHandler itemProcessor = new StatefulRetryItemHandler(getItemReader(), getItemWriter(),
StatefulRetryItemHandler itemHandler = new StatefulRetryItemHandler(getItemReader(), getItemWriter(),
retryTemplate, retryCallback);
step.setItemHandler(itemProcessor);
step.setItemHandler(itemHandler);
}