RESOLVED - issue BATCH-546: pull duplicates from TaskletStep and ItemOrientedStep into AbstractStep
Tidied up by changing visibility of some methods and fields.
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.NoSuchJobException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -44,7 +45,7 @@ import org.springframework.util.Assert;
|
||||
* @author Ben Hale
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractStep implements Step, InitializingBean {
|
||||
public abstract class AbstractStep implements Step, InitializingBean, BeanNameAware {
|
||||
|
||||
/**
|
||||
* Exit code for interrupted status.
|
||||
@@ -53,11 +54,11 @@ public abstract class AbstractStep implements Step, InitializingBean {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(AbstractStep.class);
|
||||
|
||||
protected String name;
|
||||
private String name;
|
||||
|
||||
protected int startLimit = Integer.MAX_VALUE;
|
||||
private int startLimit = Integer.MAX_VALUE;
|
||||
|
||||
protected boolean allowStartIfComplete;
|
||||
private boolean allowStartIfComplete;
|
||||
|
||||
private CompositeStepExecutionListener listener = new CompositeStepExecutionListener();
|
||||
|
||||
@@ -88,6 +89,21 @@ public abstract class AbstractStep implements Step, InitializingBean {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name property if it is not already set. Because of the order of
|
||||
* the callbacks in a Spring container the name property will be set first
|
||||
* if it is present. Care is needed with bean definition inheritance - if a
|
||||
* parent bean has a name, then its children need an explicit name as well,
|
||||
* otherwise they will not be unique.
|
||||
*
|
||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||
*/
|
||||
public void setBeanName(String name) {
|
||||
if (this.name == null) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public int getStartLimit() {
|
||||
return this.startLimit;
|
||||
}
|
||||
@@ -134,7 +150,7 @@ public abstract class AbstractStep implements Step, InitializingBean {
|
||||
* resource initialization ({@link #open(ExecutionContext)}), execution
|
||||
* logic ({@link #doExecute(StepExecution)}) and resource closing ({@link #close(ExecutionContext)}).
|
||||
*/
|
||||
public void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException {
|
||||
public final void execute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException {
|
||||
stepExecution.setStartTime(new Date());
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
* execution
|
||||
*
|
||||
*/
|
||||
public ExitStatus doExecute(final StepExecution stepExecution) throws Exception {
|
||||
protected ExitStatus doExecute(final StepExecution stepExecution) throws Exception {
|
||||
stream.update(stepExecution.getExecutionContext());
|
||||
getJobRepository().saveOrUpdateExecutionContext(stepExecution);
|
||||
itemHandler.mark();
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -38,25 +37,10 @@ import org.springframework.util.Assert;
|
||||
* @author Ben Hale
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class TaskletStep extends AbstractStep implements BeanNameAware {
|
||||
public class TaskletStep extends AbstractStep {
|
||||
|
||||
private Tasklet tasklet;
|
||||
|
||||
/**
|
||||
* Set the name property if it is not already set. Because of the order of
|
||||
* the callbacks in a Spring container the name property will be set first
|
||||
* if it is present. Care is needed with bean definition inheritance - if a
|
||||
* parent bean has a name, then its children need an explicit name as well,
|
||||
* otherwise they will not be unique.
|
||||
*
|
||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||
*/
|
||||
public void setBeanName(String name) {
|
||||
if (this.name == null) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register each of the objects as listeners.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user