diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java index f5650fd4b..3dbdabd5d 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/AbstractStep.java @@ -15,21 +15,11 @@ */ package org.springframework.batch.execution.step; -import org.springframework.batch.core.domain.ItemSkipPolicy; import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; -import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.execution.step.support.NeverSkipItemSkipPolicy; import org.springframework.batch.io.exception.InfrastructureException; -import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.repeat.exception.handler.ExceptionHandler; -import org.springframework.batch.retry.RetryPolicy; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.util.Assert; /** * A {@link Step} implementation that provides common behaviour to subclasses. @@ -37,21 +27,7 @@ import org.springframework.util.Assert; * @author Dave Syer * @author Ben Hale */ -public abstract class AbstractStep implements Step, InitializingBean, BeanNameAware { - - protected ExceptionHandler exceptionHandler; - - protected RetryPolicy retryPolicy; - - protected JobRepository jobRepository; - - protected PlatformTransactionManager transactionManager; - - protected ItemReader itemReader; - - protected ItemWriter itemWriter; - - protected ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy(); +public abstract class AbstractStep implements Step, BeanNameAware { protected String name; @@ -130,70 +106,5 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw this.name = name; } - /** - * Public setter for the {@link RetryPolicy}. - * @param retryPolicy the {@link RetryPolicy} to set - */ - public void setRetryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - } - - public void setExceptionHandler(ExceptionHandler exceptionHandler) { - this.exceptionHandler = exceptionHandler; - } - - /** - * Public setter for {@link JobRepository}. - * - * @param jobRepository is a mandatory dependence (no default). - */ - public void setJobRepository(JobRepository jobRepository) { - this.jobRepository = jobRepository; - } - - /** - * Public setter for the {@link PlatformTransactionManager}. - * - * @param transactionManager the transaction manager to set - */ - public void setTransactionManager(PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - - /** - * @param itemReader the itemReader to set - */ - public void setItemReader(ItemReader itemReader) { - this.itemReader = itemReader; - } - - /** - * @param itemWriter the itemWriter to set - */ - public void setItemWriter(ItemWriter itemWriter) { - this.itemWriter = itemWriter; - } - - public void setItemSkipPolicy(ItemSkipPolicy itemSkipPolicy) { - this.itemSkipPolicy = itemSkipPolicy; - } - - /** - * Assert that all mandatory properties are set (the {@link JobRepository}). - * - * @throws Exception - */ - public void afterPropertiesSet() throws Exception { - assertMandatoryProperties(); - } - - protected void assertMandatoryProperties() { - Assert.notNull(jobRepository, "JobRepository is mandatory"); - Assert.notNull(transactionManager, "TransactionManager must be set"); - Assert.notNull(itemReader, "ItemReader must be provided"); - Assert.notNull(itemWriter, "ItemWriter must be provided"); - - } - public abstract void execute(StepExecution stepExecution) throws JobInterruptedException, InfrastructureException; } \ No newline at end of file diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java index b645c1ca2..5483fccee 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/ItemOrientedStep.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.domain.BatchListener; import org.springframework.batch.core.domain.BatchStatus; +import org.springframework.batch.core.domain.ItemSkipPolicy; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobInterruptedException; import org.springframework.batch.core.domain.StepContribution; @@ -29,6 +30,7 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier; import org.springframework.batch.core.tasklet.Tasklet; import org.springframework.batch.execution.step.support.ListenerMulticaster; +import org.springframework.batch.execution.step.support.NeverSkipItemSkipPolicy; import org.springframework.batch.execution.step.support.SimpleExitStatusExceptionClassifier; import org.springframework.batch.execution.step.support.StepInterruptionPolicy; import org.springframework.batch.execution.step.support.ThreadStepInterruptionPolicy; @@ -45,6 +47,7 @@ import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatOperations; +import org.springframework.batch.repeat.exception.handler.ExceptionHandler; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.batch.retry.RetryPolicy; @@ -52,6 +55,7 @@ import org.springframework.batch.retry.callback.ItemReaderRetryCallback; import org.springframework.batch.retry.policy.ItemReaderRetryPolicy; import org.springframework.batch.retry.support.RetryTemplate; import org.springframework.beans.factory.InitializingBean; +import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.Assert; @@ -107,6 +111,18 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { } }; + private ExceptionHandler exceptionHandler; + + private JobRepository jobRepository; + + private PlatformTransactionManager transactionManager; + + private ItemReader itemReader; + + protected ItemWriter itemWriter; + + private ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy(); + /** * Public setter for the {@link ItemKeyGenerator}. If it is not injected * but the reader or writer implement {@link ItemKeyGenerator}, one of @@ -180,15 +196,6 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { this.exceptionClassifier = exceptionClassifier; } - /** - * Public setter for the retryPolicy. - * - * @param retyPolicy the retryPolicy to set - */ - public void setRetryPolicy(RetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - } - public void setCommitInterval(int commitInterval) { this.commitInterval = commitInterval; } @@ -642,6 +649,64 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean { } + /** + * Set the name property. Always overrides the default value if this object + * is a Spring bean. + * + * @see #setBeanName(java.lang.String) + */ + public void setName(String name) { + this.name = name; + } + + /** + * Public setter for the {@link RetryPolicy}. + * @param retryPolicy the {@link RetryPolicy} to set + */ + public void setRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + } + + public void setExceptionHandler(ExceptionHandler exceptionHandler) { + this.exceptionHandler = exceptionHandler; + } + + /** + * Public setter for {@link JobRepository}. + * + * @param jobRepository is a mandatory dependence (no default). + */ + public void setJobRepository(JobRepository jobRepository) { + this.jobRepository = jobRepository; + } + + /** + * Public setter for the {@link PlatformTransactionManager}. + * + * @param transactionManager the transaction manager to set + */ + public void setTransactionManager(PlatformTransactionManager transactionManager) { + this.transactionManager = transactionManager; + } + + /** + * @param itemReader the itemReader to set + */ + public void setItemReader(ItemReader itemReader) { + this.itemReader = itemReader; + } + + /** + * @param itemWriter the itemWriter to set + */ + public void setItemWriter(ItemWriter itemWriter) { + this.itemWriter = itemWriter; + } + + public void setItemSkipPolicy(ItemSkipPolicy itemSkipPolicy) { + this.itemSkipPolicy = itemSkipPolicy; + } + /** * @author Dave Syer * diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java index f29efdf74..ca8babfa9 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/step/TaskletStep.java @@ -40,83 +40,13 @@ import org.springframework.util.Assert; * * @author Ben Hale */ -public class TaskletStep implements Step, InitializingBean, BeanNameAware { +public class TaskletStep extends AbstractStep implements Step, InitializingBean, BeanNameAware { private static final Log logger = LogFactory.getLog(TaskletStep.class); private Tasklet tasklet; private JobRepository jobRepository; - - private String name; - - private int startLimit = Integer.MAX_VALUE; - - private boolean allowStartIfComplete; - - public String getName() { - return this.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; - } - } - - /** - * Set the name property. Always overrides the default value if this object - * is a Spring bean. - * - * @see #setBeanName(java.lang.String) - */ - public void setName(String name) { - this.name = name; - } - - /* - * (non-Javadoc) - * @see org.springframework.batch.core.domain.Step#getStartLimit() - */ - public int getStartLimit() { - return this.startLimit; - } - - /** - * Public setter for the startLimit. - * - * @param startLimit the startLimit to set - */ - public void setStartLimit(int startLimit) { - this.startLimit = startLimit; - } - - /* - * (non-Javadoc) - * @see org.springframework.batch.core.domain.Step#isAllowStartIfComplete() - */ - public boolean isAllowStartIfComplete() { - return this.allowStartIfComplete; - } - - /** - * Public setter for the shouldAllowStartIfComplete. - * - * @param allowStartIfComplete the shouldAllowStartIfComplete to set - */ - public void setAllowStartIfComplete(boolean allowStartIfComplete) { - this.allowStartIfComplete = allowStartIfComplete; - } - private CompositeStepListener listener = new CompositeStepListener(); /** diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java index c58ccacd8..bd9db3c21 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/job/SimpleJobTests.java @@ -22,6 +22,7 @@ import java.util.List; import junit.framework.TestCase; import org.springframework.batch.core.domain.BatchStatus; +import org.springframework.batch.core.domain.ItemSkipPolicy; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobInterruptedException; @@ -39,9 +40,15 @@ import org.springframework.batch.execution.repository.dao.MapJobInstanceDao; import org.springframework.batch.execution.repository.dao.MapStepExecutionDao; import org.springframework.batch.execution.repository.dao.StepExecutionDao; import org.springframework.batch.execution.step.AbstractStep; +import org.springframework.batch.execution.step.support.NeverSkipItemSkipPolicy; import org.springframework.batch.io.exception.InfrastructureException; +import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.reader.AbstractItemReader; import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.exception.handler.ExceptionHandler; +import org.springframework.batch.retry.RetryPolicy; +import org.springframework.transaction.PlatformTransactionManager; /** * Tests for DefaultJobLifecycle. MapJobDao and MapStepExecutionDao are used instead of a @@ -288,6 +295,13 @@ public class SimpleJobTests extends TestCase { private Runnable runnable; private Exception exception; + protected ExceptionHandler exceptionHandler; + protected RetryPolicy retryPolicy; + protected JobRepository jobRepository; + protected PlatformTransactionManager transactionManager; + protected ItemReader itemReader; + protected ItemWriter itemWriter; + protected ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy(); /** * @param string @@ -323,5 +337,63 @@ public class SimpleJobTests extends TestCase { stepExecution.setExitStatus(ExitStatus.FINISHED); } + /** + * Set the name property. Always overrides the default value if this object + * is a Spring bean. + * + * @see #setBeanName(java.lang.String) + */ + public void setName(String name) { + this.name = name; + } + + /** + * Public setter for the {@link RetryPolicy}. + * @param retryPolicy the {@link RetryPolicy} to set + */ + public void setRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + } + + public void setExceptionHandler(ExceptionHandler exceptionHandler) { + this.exceptionHandler = exceptionHandler; + } + + /** + * Public setter for {@link JobRepository}. + * + * @param jobRepository is a mandatory dependence (no default). + */ + public void setJobRepository(JobRepository jobRepository) { + this.jobRepository = jobRepository; + } + + /** + * Public setter for the {@link PlatformTransactionManager}. + * + * @param transactionManager the transaction manager to set + */ + public void setTransactionManager(PlatformTransactionManager transactionManager) { + this.transactionManager = transactionManager; + } + + /** + * @param itemReader the itemReader to set + */ + public void setItemReader(ItemReader itemReader) { + this.itemReader = itemReader; + } + + /** + * @param itemWriter the itemWriter to set + */ + public void setItemWriter(ItemWriter itemWriter) { + this.itemWriter = itemWriter; + } + + public void setItemSkipPolicy(ItemSkipPolicy itemSkipPolicy) { + this.itemSkipPolicy = itemSkipPolicy; + } + } } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java index aa1b3e2ec..fa3d4fd8e 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/launch/SimpleJobTests.java @@ -177,7 +177,7 @@ public class SimpleJobTests extends TestCase { } public void testExceptionTerminates() throws Exception { - AbstractStep step = getStep(new String[] { "foo", "bar", "spam" }); + ItemOrientedStep step = getStep(new String[] { "foo", "bar", "spam" }); step.setName("exceptionStep"); step.setItemWriter(new AbstractItemWriter() { public void write(Object data) throws Exception {