OPEN - issue BATCH-404: FactoryBeans for step configuration

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

New flag on DefaultStepFactoryBean for item skip policy (alwaysSkip=false is the default).
This commit is contained in:
dsyer
2008-03-02 12:04:12 +00:00
parent df0c615ff8
commit 108c21b187
4 changed files with 60 additions and 43 deletions

View File

@@ -16,17 +16,20 @@
package org.springframework.batch.execution.step.support;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
/**
* @author Dave Syer
*
*
*/
public class SimpleStepFactoryBean extends AbstractStepFactoryBean {
private int commitInterval = 0;
private boolean alwaysSkip = false;
/**
* Set the commit interval.
*
@@ -36,19 +39,45 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean {
this.commitInterval = commitInterval;
}
/**
* Public setter for the flag that determines skip policy. If this flag is
* true then an exception in chunk processing will cause the item to be
* skipped and no exceptions propagated. If it is false then all exceptions
* will be propagated from the chunk and cause the step to abort.
*
* @param alwaysSkip the value to set. Default is false.
*/
public void setAlwaysSkip(boolean alwaysSkip) {
this.alwaysSkip = alwaysSkip;
}
/**
* @param step
*
*/
protected void applyConfiguration(ItemOrientedStep step) {
super.applyConfiguration(step);
if (commitInterval > 0) {
RepeatTemplate chunkOperations = new RepeatTemplate();
chunkOperations.setCompletionPolicy(new SimpleCompletionPolicy(commitInterval));
step.setChunkOperations(chunkOperations);
}
if (alwaysSkip) {
// If we always skip (not the default) then we are prepared to
// absorb all exceptions at the step level because the failed items
// will never re-appear after a rollback.
step.setItemSkipPolicy(new AlwaysSkipItemSkipPolicy());
RepeatTemplate stepOperations = new RepeatTemplate();
stepOperations.setExceptionHandler(new SimpleLimitExceptionHandler(Integer.MAX_VALUE));
step.setStepOperations(stepOperations);
}
else {
// This is the default in ItemOrientedStep anyway...
step.setItemSkipPolicy(new NeverSkipItemSkipPolicy());
}
}
}