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:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user