diff --git a/docs/pom.xml b/docs/pom.xml index c1cc17a71..44c493b39 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -1,15 +1,16 @@ - + 4.0.0 - spring-batch-docs - 2.0.0.CI-SNAPSHOT + org.springframework.batch.docs + 2.0.0.CI-SNAPSHOT Documentation pom Spring Batch Documentation - reference guide and user manuals. org.springframework.batch - spring-batch + org.springframework.batch 2.0.0.CI-SNAPSHOT .. @@ -61,7 +62,9 @@ - + pre-site diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/ExitStatus.java b/spring-batch-core/src/main/java/org/springframework/batch/core/ExitStatus.java similarity index 93% rename from spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/ExitStatus.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/ExitStatus.java index ec4098bbb..f8099b95a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/ExitStatus.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/ExitStatus.java @@ -13,10 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.repeat; +package org.springframework.batch.core; import java.io.Serializable; +import org.springframework.batch.repeat.RepeatOperations; import org.springframework.util.StringUtils; /** @@ -66,6 +67,11 @@ public class ExitStatus implements Serializable { */ public static final ExitStatus FAILED = new ExitStatus(false, "FAILED"); + /** + * Convenient constant value representing finished processing with interrupted status. + */ + public static final ExitStatus INTERRUPTED = new ExitStatus(false, "INTERRUPTED"); + private final boolean continuable; private final String exitCode; @@ -138,8 +144,9 @@ public class ExitStatus implements Serializable { * Severity is defined by the exit code: *
    *
  • Codes beginning with NOOP have severity 1
  • - *
  • Codes beginning with FAILED have severity 2
  • - *
  • Codes beginning with UNKNOWN have severity 3
  • + *
  • Codes beginning with INTERRUPTED have severity 2
  • + *
  • Codes beginning with FAILED have severity 3
  • + *
  • Codes beginning with UNKNOWN have severity 4
  • *
* Others have severity 0.
* @@ -173,12 +180,15 @@ public class ExitStatus implements Serializable { if (status.exitCode.startsWith(NOOP.exitCode)) { return 0; } - if (status.exitCode.startsWith(FAILED.exitCode)) { + if (status.exitCode.startsWith(INTERRUPTED.exitCode)) { return 1; } - if (status.exitCode.startsWith(UNKNOWN.exitCode)) { + if (status.exitCode.startsWith(FAILED.exitCode)) { return 2; } + if (status.exitCode.startsWith(UNKNOWN.exitCode)) { + return 3; + } return 0; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java index c88a153d2..f218ac5f2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Set; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; /** * Batch domain object representing the execution of a job. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index 77ef97477..5e7246b63 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -23,7 +23,6 @@ import java.util.Date; import java.util.List; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.Assert; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java index e1e069b89..4af9cf23f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecutionListener.java @@ -15,7 +15,6 @@ */ package org.springframework.batch.core; -import org.springframework.batch.repeat.ExitStatus; /** * Listener interface for the lifecycle of a {@link Step}. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index ae1b9f1a8..71a86db25 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -21,6 +21,7 @@ import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; @@ -35,7 +36,6 @@ import org.springframework.batch.core.listener.CompositeExecutionJobListener; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; 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; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/StateTransition.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/StateTransition.java index 7830b1c38..ec23e85a1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/StateTransition.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/StateTransition.java @@ -15,8 +15,8 @@ */ package org.springframework.batch.core.job.flow.support; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.job.flow.support.util.PatternMatcher; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.StringUtils; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java index 5b2d009cc..4bb4053ce 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobRunner.java @@ -19,6 +19,7 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -26,7 +27,6 @@ import org.springframework.batch.core.configuration.JobLocator; import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.launch.JobLauncher; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.ConfigurableApplicationContext; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapper.java index 36e12f557..d2f8101ab 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapper.java @@ -21,7 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; /** * An implementation of {@link ExitCodeMapper} that can be configured through a diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java index 6989df3d6..0712a0504 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeStepExecutionListener.java @@ -18,9 +18,9 @@ package org.springframework.batch.core.listener; import java.util.Arrays; import java.util.Iterator; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.Ordered; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java index 4d266b679..fc25b32d4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.listener; import java.util.List; import org.springframework.batch.core.ChunkListener; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.ItemProcessListener; import org.springframework.batch.core.ItemReadListener; import org.springframework.batch.core.ItemWriteListener; @@ -26,7 +27,6 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.StepListener; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java index 327a4cdc7..224dd7039 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepExecutionListenerSupport.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.core.listener; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java index f494520c0..b8b809d5d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerSupport.java @@ -18,12 +18,12 @@ package org.springframework.batch.core.listener; import java.util.List; import org.springframework.batch.core.ChunkListener; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.ItemReadListener; import org.springframework.batch.core.ItemWriteListener; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.StepListener; -import org.springframework.batch.repeat.ExitStatus; /** * Basic no-op implementations of all {@link StepListener} implementations. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java index 261a37f70..eda473cb1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/PartitionStep.java @@ -10,7 +10,6 @@ import org.springframework.batch.core.partition.PartitionHandler; import org.springframework.batch.core.partition.StepExecutionSplitter; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.Assert; /** @@ -70,7 +69,7 @@ public class PartitionStep extends AbstractStep { * @see Step#execute(StepExecution) */ @Override - protected ExitStatus doExecute(StepExecution stepExecution) throws Exception { + protected void doExecute(StepExecution stepExecution) throws Exception { // Wait for task completion and then aggregate the results Collection executions = partitionHandler.handle(stepExecutionSplitter, stepExecution); @@ -79,8 +78,6 @@ public class PartitionStep extends AbstractStep { throw new JobExecutionException("Partition handler returned an incomplete step"); } - return stepExecution.getExitStatus(); - } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java index 39a73d557..e5980b490 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/StepExecutionAggregator.java @@ -3,8 +3,8 @@ package org.springframework.batch.core.partition.support; import java.util.Collection; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.Assert; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java index ff0cf8021..8d7824737 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java @@ -8,11 +8,11 @@ import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.partition.PartitionHandler; import org.springframework.batch.core.partition.StepExecutionSplitter; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.core.task.TaskExecutor; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 03ce69068..dbd089e73 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -10,9 +10,9 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.OptimisticLockingFailureException; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index d02b859f8..27e758555 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -8,9 +8,9 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java index 6a974ed00..f05c9c69a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionSimpleCompletionPolicy.java @@ -21,8 +21,8 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.util.Assert; @@ -74,10 +74,9 @@ public class StepExecutionSimpleCompletionPolicy extends StepExecutionListenerSu * @param result * @return true if the commit interval has been reached or the result * indicates completion - * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, - * org.springframework.batch.repeat.ExitStatus) + * @see CompletionPolicy#isComplete(RepeatContext, RepeatStatus) */ - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { Assert.state(delegate != null, "The delegate resource has not been initialised. " + "Remember to register this object as a StepListener."); return delegate.isComplete(context, result); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepContextRepeatCallback.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepContextRepeatCallback.java index 55c7f7bcd..a99af58cd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepContextRepeatCallback.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/StepContextRepeatCallback.java @@ -18,11 +18,12 @@ package org.springframework.batch.core.scope; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; /** * Convenient base class for clients who need to do something in a repeat @@ -52,7 +53,7 @@ public abstract class StepContextRepeatCallback implements RepeatCallback { * * @see RepeatCallback#doInIteration(RepeatContext) */ - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { ChunkContext chunkContext = attributeQueue.poll(); if (chunkContext == null) { @@ -64,7 +65,9 @@ public abstract class StepContextRepeatCallback implements RepeatCallback { // otherwise step-scoped beans will be re-initialised for each chunk. StepSynchronizationManager.register(stepContext); try { - return doInStepContext(context, stepContext); + ExitStatus exitStatus = doInStepContext(context, stepContext); + stepContext.getStepExecution().setExitStatus(exitStatus); + return RepeatStatus.continueIf(exitStatus.isContinuable()); } finally { // Still some stuff to do with the data in this chunk, diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index c0071face..a69bcd369 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -22,6 +22,7 @@ import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; @@ -34,7 +35,6 @@ import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.scope.StepContext; import org.springframework.batch.core.scope.StepSynchronizationManager; 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; @@ -47,12 +47,13 @@ import org.springframework.util.Assert; * @author Ben Hale * @author Robert Kasanicky */ -public abstract class AbstractStep implements Step, InitializingBean, BeanNameAware { +public abstract class AbstractStep implements Step, InitializingBean, + BeanNameAware { /** * Exit code for interrupted status. */ - public static final String JOB_INTERRUPTED = "JOB_INTERRUPTED"; + public static final String JOB_INTERRUPTED = "INTERRUPTED"; private static final Log logger = LogFactory.getLog(AbstractStep.class); @@ -113,7 +114,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Public setter for the startLimit. * - * @param startLimit the startLimit to set + * @param startLimit + * the startLimit to set */ public void setStartLimit(int startLimit) { this.startLimit = startLimit; @@ -127,7 +129,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * Public setter for flag that determines whether the step should start * again if it is already complete. Defaults to false. * - * @param allowStartIfComplete the value of the flag to set + * @param allowStartIfComplete + * the value of the flag to set */ public void setAllowStartIfComplete(boolean allowStartIfComplete) { this.allowStartIfComplete = allowStartIfComplete; @@ -143,21 +146,23 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw } /** - * Extension point for subclasses to execute business logic. + * Extension point for subclasses to execute business logic. Subclasses + * should set the {@link ExitStatus} on the {@link StepExecution} before + * returning. * - * @param stepExecution the current step context - * @return {@link ExitStatus} to show whether the step is finished - * processing. + * @param stepExecution + * the current step context * @throws Exception */ - protected abstract ExitStatus doExecute(StepExecution stepExecution) throws Exception; + protected abstract void doExecute(StepExecution stepExecution) throws Exception; /** * Extension point for subclasses to provide callbacks to their * collaborators at the beginning of a step, to open or acquire resources. * Does nothing by default. * - * @param ctx the {@link ExecutionContext} to use + * @param ctx + * the {@link ExecutionContext} to use * @throws Exception */ protected void open(ExecutionContext ctx) throws Exception { @@ -166,9 +171,10 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Extension point for subclasses to provide callbacks to their * collaborators at the end of a step (right at the end of the finally - * block), to close or release resources. Does nothing by default. + * block), to close or release resources. Does nothing by default. * - * @param ctx the {@link ExecutionContext} to use + * @param ctx + * the {@link ExecutionContext} to use * @throws Exception */ protected void close(ExecutionContext ctx) throws Exception { @@ -177,10 +183,11 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Template method for step execution logic - calls abstract methods for * resource initialization ({@link #open(ExecutionContext)}), execution - * logic ({@link #doExecute(StepExecution)}) and resource closing ({@link #close(ExecutionContext)}). + * logic ({@link #doExecute(StepExecution)}) and resource closing ( + * {@link #close(ExecutionContext)}). */ - public final void execute(StepExecution stepExecution) throws JobInterruptedException, - UnexpectedJobExecutionException { + public final void execute(StepExecution stepExecution) + throws JobInterruptedException, UnexpectedJobExecutionException { stepExecution.setStartTime(new Date()); stepExecution.setStatus(BatchStatus.STARTED); getJobRepository().update(stepExecution); @@ -195,7 +202,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw getCompositeListener().beforeStep(stepExecution); open(stepExecution.getExecutionContext()); - exitStatus = doExecute(stepExecution); + doExecute(stepExecution); + exitStatus = stepExecution.getExitStatus(); // Check if someone is trying to stop us if (stepExecution.isTerminateOnly()) { @@ -208,66 +216,68 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw try { getJobRepository().update(stepExecution); getJobRepository().updateExecutionContext(stepExecution); - } - catch (Exception e) { + } catch (Exception e) { commitException = e; exitStatus = exitStatus.and(ExitStatus.UNKNOWN); } - } - catch (Throwable e) { + } catch (Throwable e) { - logger.error("Encountered an error executing the step: " + e.getClass() + ": " + e.getMessage(), e); + logger.error("Encountered an error executing the step: " + + e.getClass() + ": " + e.getMessage(), e); stepExecution.setStatus(determineBatchStatus(e)); exitStatus = getDefaultExitStatusForFailure(e); stepExecution.addFailureException(e); try { getJobRepository().updateExecutionContext(stepExecution); - } - catch (Exception ex) { - logger.error("Encountered an error on listener error callback.", ex); + } catch (Exception ex) { + logger.error( + "Encountered an error on listener error callback.", ex); stepExecution.addFailureException(ex); } - } - finally { - + } finally { + try { - exitStatus = exitStatus.and(getCompositeListener().afterStep(stepExecution)); - } - catch (Exception e){ + exitStatus = exitStatus.and(getCompositeListener().afterStep( + stepExecution)); + } catch (Exception e) { logger.error("Exception in afterStep callback", e); } - + stepExecution.setExitStatus(exitStatus); stepExecution.setEndTime(new Date()); try { getJobRepository().update(stepExecution); - } - catch (Exception e) { + } catch (Exception e) { if (commitException == null) { commitException = e; - } - else { - logger.error("Exception while updating step execution after commit exception", e); + } else { + logger + .error( + "Exception while updating step execution after commit exception", + e); } } try { close(stepExecution.getExecutionContext()); - } - catch (Exception e) { - logger.error("Exception while closing step execution resources", e); + } catch (Exception e) { + logger.error( + "Exception while closing step execution resources", e); stepExecution.addFailureException(e); } - + StepSynchronizationManager.release(); if (commitException != null) { stepExecution.setStatus(BatchStatus.UNKNOWN); - logger.error("Encountered an error saving batch meta data." - + "This job is now in an unknown state and should not be restarted.", commitException); + logger + .error( + "Encountered an error saving batch meta data." + + "This job is now in an unknown state and should not be restarted.", + commitException); stepExecution.addFailureException(commitException); } } @@ -279,11 +289,10 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw private static BatchStatus determineBatchStatus(Throwable e) { if (e instanceof FatalException) { return BatchStatus.UNKNOWN; - } - else if (e instanceof JobInterruptedException || e.getCause() instanceof JobInterruptedException) { + } else if (e instanceof JobInterruptedException + || e.getCause() instanceof JobInterruptedException) { return BatchStatus.STOPPED; - } - else { + } else { return BatchStatus.FAILED; } } @@ -292,7 +301,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * Register a step listener for callbacks at the appropriate stages in a * step execution. * - * @param listener a {@link StepExecutionListener} + * @param listener + * a {@link StepExecutionListener} */ public void registerStepExecutionListener(StepExecutionListener listener) { this.listener.register(listener); @@ -301,7 +311,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Register each of the objects as listeners. * - * @param listeners an array of listener objects of known types. + * @param listeners + * an array of listener objects of known types. */ public void setStepExecutionListeners(StepExecutionListener[] listeners) { for (int i = 0; i < listeners.length; i++) { @@ -319,7 +330,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Public setter for {@link JobRepository}. * - * @param jobRepository is a mandatory dependence (no default). + * @param jobRepository + * is a mandatory dependence (no default). */ public void setJobRepository(JobRepository jobRepository) { this.jobRepository = jobRepository; @@ -333,18 +345,21 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw * Default mapping from throwable to {@link ExitStatus}. Clients can modify * the exit code using a {@link StepExecutionListener}. * - * @param ex the cause of the failure + * @param ex + * the cause of the failure * @return an {@link ExitStatus} */ private ExitStatus getDefaultExitStatusForFailure(Throwable ex) { ExitStatus exitStatus; - if (ex instanceof JobInterruptedException || ex.getCause() instanceof JobInterruptedException) { - exitStatus = new ExitStatus(false, JOB_INTERRUPTED, JobInterruptedException.class.getName()); - } - else if (ex instanceof NoSuchJobException || ex.getCause() instanceof NoSuchJobException) { - exitStatus = new ExitStatus(false, ExitCodeMapper.NO_SUCH_JOB, ex.getClass().getName()); - } - else { + if (ex instanceof JobInterruptedException + || ex.getCause() instanceof JobInterruptedException) { + exitStatus = new ExitStatus(false, JOB_INTERRUPTED, + JobInterruptedException.class.getName()); + } else if (ex instanceof NoSuchJobException + || ex.getCause() instanceof NoSuchJobException) { + exitStatus = new ExitStatus(false, ExitCodeMapper.NO_SUCH_JOB, ex + .getClass().getName()); + } else { StringWriter writer = new StringWriter(); ex.printStackTrace(new PrintWriter(writer)); String message = writer.toString(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java index 9e19c3330..5098ba3ff 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/NoWorkFoundStepExecutionListener.java @@ -16,10 +16,10 @@ package org.springframework.batch.core.step; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.item.NoWorkFoundException; -import org.springframework.batch.repeat.ExitStatus; /** * Fails the step if no items have been processed ( item count is 0). diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkOrientedTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkOrientedTasklet.java index 4caec4a68..7da3a16d5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkOrientedTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkOrientedTasklet.java @@ -19,16 +19,17 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.skip.ItemSkipPolicy; import org.springframework.batch.core.step.skip.NonSkippableReadException; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -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.RepeatStatus; import org.springframework.batch.retry.RetryOperations; import org.springframework.batch.support.Classifier; import org.springframework.core.AttributeAccessor; @@ -84,18 +85,20 @@ public class FaultTolerantChunkOrientedTasklet extends AbstractFaultTolera if (inputs.isEmpty() && outputs.isEmpty()) { - result = getRepeatOperations().iterate(new RepeatCallback() { - public ExitStatus doInIteration(final RepeatContext context) throws Exception { + RepeatStatus continuable = getRepeatOperations().iterate(new RepeatCallback() { + public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = read(contribution, skippedReads); if (item == null) { - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); + + result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/NonbufferingFaultTolerantChunkOrientedTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/NonbufferingFaultTolerantChunkOrientedTasklet.java index aa70604a6..0c0c5ed1f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/NonbufferingFaultTolerantChunkOrientedTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/NonbufferingFaultTolerantChunkOrientedTasklet.java @@ -6,16 +6,17 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.skip.ItemSkipPolicy; import org.springframework.batch.core.step.skip.SkipListenerFailedException; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -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.RepeatStatus; import org.springframework.batch.retry.RetryOperations; import org.springframework.batch.support.Classifier; import org.springframework.core.AttributeAccessor; @@ -56,19 +57,20 @@ public class NonbufferingFaultTolerantChunkOrientedTasklet extends final List inputs = new ArrayList(); final List skippedReads = getBufferedList(attributes, SKIPPED_READS_KEY); - result = getRepeatOperations().iterate(new RepeatCallback() { - - public ExitStatus doInIteration(final RepeatContext context) throws Exception { + RepeatStatus continuable = getRepeatOperations().iterate(new RepeatCallback() { + public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = read(contribution, skippedReads); if (item == null) { - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); + + result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED; // filter inputs marked for skipping final Map skippedInputs = getBufferedSkips(attributes, SKIPPED_INPUTS_KEY); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkOrientedTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkOrientedTasklet.java index a45e3c2e8..13c408a27 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkOrientedTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkOrientedTasklet.java @@ -3,15 +3,16 @@ package org.springframework.batch.core.step.item; import java.util.ArrayList; import java.util.List; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -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.RepeatStatus; import org.springframework.core.AttributeAccessor; /** @@ -40,20 +41,22 @@ public class SimpleChunkOrientedTasklet extends AbstractItemOrientedTaskle ExitStatus result = ExitStatus.CONTINUABLE; final List inputs = new ArrayList(); - result = repeatOperations.iterate(new RepeatCallback() { + RepeatStatus continuable = repeatOperations.iterate(new RepeatCallback() { - public ExitStatus doInIteration(final RepeatContext context) throws Exception { + public RepeatStatus doInIteration(final RepeatContext context) throws Exception { I item = doRead(); if (item == null) { - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } inputs.add(item); contribution.incrementReadCount(); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); + result = continuable.isContinuable() ? ExitStatus.CONTINUABLE : ExitStatus.FINISHED; + // If there is no input we don't have to do anything more if (inputs.isEmpty()) { return result; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java index 92d5197c0..047ddeb15 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapter.java @@ -17,8 +17,8 @@ package org.springframework.batch.core.step.tasklet; import java.util.concurrent.Callable; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.AttributeAccessor; import org.springframework.util.Assert; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java index 67da87557..74ebd19cf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapper.java @@ -2,11 +2,11 @@ package org.springframework.batch.core.step.tasklet; import java.util.Map; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.util.Assert; /** - * Maps exit codes to {@link org.springframework.batch.repeat.ExitStatus} + * Maps exit codes to {@link org.springframework.batch.core.ExitStatus} * according to injected map. The injected map is required to contain a value * for 'else' key, this value will be returned if the injected map * does not contain value for the exit code returned by the system process. @@ -30,7 +30,7 @@ public class ConfigurableSystemProcessExitCodeMapper implements SystemProcessExi /** * @param mappings Integer exit code keys to - * {@link org.springframework.batch.repeat.ExitStatus} values. + * {@link org.springframework.batch.core.ExitStatus} values. */ public void setMappings(Map mappings) { Assert.notNull(mappings.get(ELSE_KEY)); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/MethodInvokingTaskletAdapter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/MethodInvokingTaskletAdapter.java index 91f260608..552201885 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/MethodInvokingTaskletAdapter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/MethodInvokingTaskletAdapter.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.core.step.tasklet; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapper.java index 7415a38a1..a74409087 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapper.java @@ -1,6 +1,6 @@ package org.springframework.batch.core.step.tasklet; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; /** * Simple {@link SystemProcessExitCodeMapper} implementation that performs following mapping: diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java index c65e3e83b..491b6e934 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemCommandTasklet.java @@ -7,11 +7,11 @@ import java.util.concurrent.FutureTask; import org.apache.commons.lang.time.StopWatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.AttributeAccessor; import org.springframework.core.task.SimpleAsyncTaskExecutor; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemProcessExitCodeMapper.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemProcessExitCodeMapper.java index 47603d2ce..be012a5bf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemProcessExitCodeMapper.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/SystemProcessExitCodeMapper.java @@ -1,7 +1,7 @@ package org.springframework.batch.core.step.tasklet; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.step.tasklet.SystemCommandTasklet; -import org.springframework.batch.repeat.ExitStatus; /** * Maps the exit code of a system process to ExitStatus value diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java index 4be2f89b1..44862a71b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java @@ -15,8 +15,8 @@ */ package org.springframework.batch.core.step.tasklet; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java index 5439753b9..4c346ca6d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.step.tasklet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; @@ -35,7 +36,6 @@ import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.CompositeItemStream; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatOperations; import org.springframework.batch.repeat.support.RepeatTemplate; @@ -100,30 +100,37 @@ public class TaskletStep extends AbstractStep { */ public TaskletStep(String name) { super(name); - synchronizer = new StepExecutionSynchronizerFactory().getStepExecutionSynchronizer(); + synchronizer = new StepExecutionSynchronizerFactory() + .getStepExecutionSynchronizer(); } /** * Public setter for the {@link PlatformTransactionManager}. * - * @param transactionManager the transaction manager to set + * @param transactionManager + * the transaction manager to set */ - public void setTransactionManager(PlatformTransactionManager transactionManager) { + public void setTransactionManager( + PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } /** * Public setter for the {@link TransactionAttribute}. - * @param transactionAttribute the {@link TransactionAttribute} to set + * + * @param transactionAttribute + * the {@link TransactionAttribute} to set */ - public void setTransactionAttribute(TransactionAttribute transactionAttribute) { + public void setTransactionAttribute( + TransactionAttribute transactionAttribute) { this.transactionAttribute = transactionAttribute; } /** * Public setter for the {@link Tasklet}. * - * @param tasklet the {@link Tasklet} to set + * @param tasklet + * the {@link Tasklet} to set */ public void setTasklet(Tasklet tasklet) { this.tasklet = tasklet; @@ -139,7 +146,8 @@ public class TaskletStep extends AbstractStep { * This is a good way to get access to job parameters and execution context * if the tasklet is parameterised. * - * @param listeners an array of listener objects of known types. + * @param listeners + * an array of listener objects of known types. */ public void setStepExecutionListeners(StepExecutionListener[] listeners) { for (int i = 0; i < listeners.length; i++) { @@ -156,7 +164,8 @@ public class TaskletStep extends AbstractStep { * which itself is a {@link ItemStream}, you need to register the delegate * here. * - * @param streams an array of {@link ItemStream} objects. + * @param streams + * an array of {@link ItemStream} objects. */ public void setStreams(ItemStream[] streams) { for (int i = 0; i < streams.length; i++) { @@ -179,7 +188,8 @@ public class TaskletStep extends AbstractStep { * processing. Should be set up by the caller through a factory. Defaults to * a plain {@link RepeatTemplate}. * - * @param stepOperations a {@link RepeatOperations} instance. + * @param stepOperations + * a {@link RepeatOperations} instance. */ public void setStepOperations(RepeatOperations stepOperations) { this.stepOperations = stepOperations; @@ -190,7 +200,8 @@ public class TaskletStep extends AbstractStep { * check whether an external request has been made to interrupt the job * execution. * - * @param interruptionPolicy a {@link StepInterruptionPolicy} + * @param interruptionPolicy + * a {@link StepInterruptionPolicy} */ public void setInterruptionPolicy(StepInterruptionPolicy interruptionPolicy) { this.interruptionPolicy = interruptionPolicy; @@ -201,7 +212,8 @@ public class TaskletStep extends AbstractStep { * backport concurrency utilities. Public setter for the * {@link StepExecutionSynchronizer}. * - * @param synchronizer the {@link StepExecutionSynchronizer} to set + * @param synchronizer + * the {@link StepExecutionSynchronizer} to set */ public void setSynchronizer(StepExecutionSynchronizer synchronizer) { this.synchronizer = synchronizer; @@ -216,26 +228,29 @@ public class TaskletStep extends AbstractStep { * the current context governing the step execution, which would normally be * available to the caller through the step's {@link ExecutionContext}.
* - * @throws JobInterruptedException if the step or a chunk is interrupted - * @throws RuntimeException if there is an exception during a chunk - * execution + * @throws JobInterruptedException + * if the step or a chunk is interrupted + * @throws RuntimeException + * if there is an exception during a chunk execution * */ @Override - protected ExitStatus doExecute(StepExecution stepExecution) throws Exception { + protected void doExecute(StepExecution stepExecution) throws Exception { stream.update(stepExecution.getExecutionContext()); getJobRepository().updateExecutionContext(stepExecution); - return stepOperations.iterate(new StepContextRepeatCallback(stepExecution) { + stepOperations.iterate(new StepContextRepeatCallback(stepExecution) { @Override - public ExitStatus doInStepContext(RepeatContext repeatContext, StepContext stepContext) throws Exception { + public ExitStatus doInStepContext(RepeatContext repeatContext, + StepContext stepContext) throws Exception { StepExecution stepExecution = stepContext.getStepExecution(); ExceptionHolder fatalException = new ExceptionHolder(); - StepContribution contribution = stepExecution.createStepContribution(); + StepContribution contribution = stepExecution + .createStepContribution(); stepExecution.getExecutionContext().clearDirtyFlag(); // Before starting a new transaction, check for @@ -244,7 +259,8 @@ public class TaskletStep extends AbstractStep { ExitStatus exitStatus = ExitStatus.CONTINUABLE; - TransactionStatus transaction = transactionManager.getTransaction(transactionAttribute); + TransactionStatus transaction = transactionManager + .getTransaction(transactionAttribute); boolean locked = false; @@ -252,8 +268,7 @@ public class TaskletStep extends AbstractStep { try { exitStatus = tasklet.execute(contribution, stepContext); - } - finally { + } finally { // Apply the contribution to the step // even if unsuccessful logger.debug("Applying contribution: " + contribution); @@ -269,8 +284,7 @@ public class TaskletStep extends AbstractStep { try { synchronizer.lock(stepExecution); locked = true; - } - catch (InterruptedException e) { + } catch (InterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); Thread.currentThread().interrupt(); } @@ -286,44 +300,45 @@ public class TaskletStep extends AbstractStep { stream.update(stepExecution.getExecutionContext()); try { - getJobRepository().updateExecutionContext(stepExecution); - } - catch (Exception e) { + getJobRepository() + .updateExecutionContext(stepExecution); + } catch (Exception e) { fatalException.setException(e); stepExecution.setStatus(BatchStatus.UNKNOWN); - throw new FatalException("Fatal error detected during save of step execution context", e); + throw new FatalException( + "Fatal error detected during save of step execution context", + e); } try { transactionManager.commit(transaction); - } - catch (Exception e) { + } catch (Exception e) { fatalException.setException(e); stepExecution.setStatus(BatchStatus.UNKNOWN); logger.error("Fatal error detected during commit."); - throw new FatalException("Fatal error detected during commit", e); + throw new FatalException( + "Fatal error detected during commit", e); } try { - logger.debug("Saving step execution after commit: " + stepExecution); + logger.debug("Saving step execution after commit: " + + stepExecution); getJobRepository().update(stepExecution); - } - catch (Exception e) { + } catch (Exception e) { fatalException.setException(e); stepExecution.setStatus(BatchStatus.UNKNOWN); - throw new FatalException("Fatal error detected during update of step execution", e); + throw new FatalException( + "Fatal error detected during update of step execution", + e); } - } - catch (Error e) { + } catch (Error e) { processRollback(stepExecution, fatalException, transaction); throw e; - } - catch (Exception e) { + } catch (Exception e) { processRollback(stepExecution, fatalException, transaction); throw e; - } - finally { + } finally { // only release the lock if we acquired it if (locked) { synchronizer.release(stepExecution); @@ -348,8 +363,8 @@ public class TaskletStep extends AbstractStep { * @param fatalException * @param transaction */ - private void processRollback(final StepExecution stepExecution, final ExceptionHolder fatalException, - TransactionStatus transaction) { + private void processRollback(final StepExecution stepExecution, + final ExceptionHolder fatalException, TransactionStatus transaction) { /* * Any exception thrown within the transaction should automatically @@ -359,8 +374,7 @@ public class TaskletStep extends AbstractStep { try { transactionManager.rollback(transaction); - } - catch (Exception e) { + } catch (Exception e) { /* * If we already failed to commit, it doesn't help to do this again * - it's better to allow the CommitFailedException to propagate diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/ExitStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java similarity index 87% rename from spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/ExitStatusTests.java rename to spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java index e42031a9b..fdb965094 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/ExitStatusTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.repeat; +package org.springframework.batch.core; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue; import org.apache.commons.lang.SerializationUtils; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; /** * @author Dave Syer @@ -30,7 +31,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)} + * {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)} * . */ @Test @@ -42,7 +43,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)} + * {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)} * . */ @Test @@ -54,7 +55,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#ExitStatus(boolean, String)} + * {@link org.springframework.batch.core.ExitStatus#ExitStatus(boolean, String)} * . */ @Test @@ -107,7 +108,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(boolean)}. + * {@link org.springframework.batch.core.ExitStatus#and(boolean)}. */ @Test public void testAndBoolean() { @@ -120,7 +121,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test @@ -133,7 +134,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test @@ -143,7 +144,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test @@ -153,7 +154,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test @@ -164,7 +165,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test @@ -175,7 +176,7 @@ public class ExitStatusTests { /** * Test method for - * {@link org.springframework.batch.repeat.ExitStatus#and(org.springframework.batch.repeat.ExitStatus)} + * {@link org.springframework.batch.core.ExitStatus#and(org.springframework.batch.core.ExitStatus)} * . */ @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java index 7a991db69..6546898b3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.commons.lang.SerializationUtils; import org.junit.Test; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java index 7ac5711f2..d169e666b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestTasklet.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestTasklet.java index 41ba9c50c..d7463db3a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestTasklet.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TestTasklet.java @@ -1,8 +1,8 @@ package org.springframework.batch.core.configuration.xml; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; public class TestTasklet extends AbstractTestComponent implements Tasklet { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index 0953529bb..09c9954e2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -35,6 +35,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; import org.springframework.batch.core.JobExecutionListener; @@ -57,7 +58,6 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao; import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.StepSupport; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; /** * Tests for DefaultJobLifecycle. MapJobDao and MapStepExecutionDao are used diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java index fc0e23490..f884f6415 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/flow/FlowJobTests.java @@ -26,6 +26,7 @@ import java.util.Collections; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.JobParameters; @@ -42,7 +43,6 @@ import org.springframework.batch.core.job.flow.support.state.StepState; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java index 2c242b600..ee37031bc 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/SimpleJobLauncherTests.java @@ -30,6 +30,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; @@ -38,7 +39,6 @@ import org.springframework.batch.core.job.JobSupport; import org.springframework.batch.core.launch.support.SimpleJobLauncher; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.task.TaskExecutor; /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java index 3c733f3ed..ff995e59f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java @@ -23,6 +23,7 @@ import java.util.Properties; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; @@ -30,7 +31,6 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter; import org.springframework.batch.core.converter.JobParametersConverter; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.ClassUtils; /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapperTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapperTests.java index 231288f5d..eb84f088b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapperTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/SimpleJvmExitCodeMapperTests.java @@ -21,9 +21,9 @@ import java.util.Map; import junit.framework.TestCase; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.launch.support.ExitCodeMapper; import org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper; -import org.springframework.batch.repeat.ExitStatus; public class SimpleJvmExitCodeMapperTests extends TestCase { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java index 2dd18caae..51af5d5b4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/CompositeStepExecutionListenerTests.java @@ -20,9 +20,9 @@ import java.util.List; import junit.framework.TestCase; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java index 19e174f4c..8c13ec6d2 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/listener/MulticasterBatchListenerTests.java @@ -23,8 +23,8 @@ import java.util.List; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java index 8ff0e6d78..59dae1241 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/PartitionStepTests.java @@ -23,6 +23,7 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; @@ -31,7 +32,6 @@ import org.springframework.batch.core.partition.StepExecutionSplitter; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean; import org.springframework.batch.core.step.StepSupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java index 4edd8a8e9..2d799bb8a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/StepExecutionAggregatorTests.java @@ -8,9 +8,9 @@ import java.util.Collections; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; public class StepExecutionAggregatorTests { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandlerTests.java index 1e0b33dc0..851a164eb 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandlerTests.java @@ -10,13 +10,13 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobExecutionException; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.partition.StepExecutionSplitter; import org.springframework.batch.core.step.StepSupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; import org.springframework.core.task.TaskRejectedException; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java index 02f6808cb..78aab78db 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobDaoTests.java @@ -31,11 +31,11 @@ import javax.sql.DataSource; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.transaction.annotation.Transactional; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java index 852fe9918..a43578e6e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java @@ -14,11 +14,11 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.transaction.annotation.Transactional; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java index ceff32aa0..8a8e0eb9c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoTests.java @@ -8,7 +8,7 @@ import org.junit.Test; import java.util.List; import java.util.Map; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; import org.springframework.transaction.annotation.Transactional; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java index 2b60a210b..221d5e03b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java @@ -4,9 +4,9 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepContextRepeatCallbackTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepContextRepeatCallbackTests.java index 388ed5906..00c4cf8c5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepContextRepeatCallbackTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepContextRepeatCallbackTests.java @@ -20,10 +20,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; /** * @author Dave Syer @@ -44,7 +45,8 @@ public class StepContextRepeatCallbackTests { return ExitStatus.NOOP; } }; - assertEquals(ExitStatus.NOOP, callback.doInIteration(null)); + assertEquals(RepeatStatus.FINISHED, callback.doInIteration(null)); + assertEquals(ExitStatus.NOOP, stepExecution.getExitStatus()); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/AbstractStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/AbstractStepTests.java index 904bf2299..cf64bd2ef 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/AbstractStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/AbstractStepTests.java @@ -12,13 +12,13 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.Assert; /** @@ -55,10 +55,11 @@ public class AbstractStepTests { events.add("open"); } - protected ExitStatus doExecute(StepExecution context) throws Exception { + @Override + protected void doExecute(StepExecution context) throws Exception { assertSame(execution, context); events.add("doExecute"); - return ExitStatus.FINISHED; + context.setExitStatus(ExitStatus.FINISHED); } protected void close(ExecutionContext ctx) throws Exception { @@ -139,8 +140,7 @@ public class AbstractStepTests { public void testBeanName() throws Exception { AbstractStep step = new AbstractStep() { @Override - protected ExitStatus doExecute(StepExecution stepExecution) throws Exception { - return null; + protected void doExecute(StepExecution stepExecution) throws Exception { } }; assertNull(step.getName()); @@ -152,8 +152,7 @@ public class AbstractStepTests { public void testName() throws Exception { AbstractStep step = new AbstractStep() { @Override - protected ExitStatus doExecute(StepExecution stepExecution) throws Exception { - return null; + protected void doExecute(StepExecution stepExecution) throws Exception { } }; assertNull(step.getName()); @@ -196,7 +195,7 @@ public class AbstractStepTests { public void testFailure() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepExecution context) throws Exception { + protected void doExecute(StepExecution context) throws Exception { super.doExecute(context); throw new RuntimeException("crash!"); } @@ -234,9 +233,9 @@ public class AbstractStepTests { public void testStoppedStep() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepExecution context) throws Exception { + protected void doExecute(StepExecution context) throws Exception { context.setTerminateOnly(); - return super.doExecute(context); + super.doExecute(context); } }; tested.setJobRepository(repository); @@ -257,7 +256,7 @@ public class AbstractStepTests { assertEquals("close", events.get(i++)); assertEquals(7, events.size()); - assertEquals("JOB_INTERRUPTED", execution.getExitStatus().getExitCode()); + assertEquals("INTERRUPTED", execution.getExitStatus().getExitCode()); assertTrue("Execution context modifications made by listener should be persisted", repository.saved .containsKey("afterStep")); @@ -270,9 +269,8 @@ public class AbstractStepTests { public void testFailureInSavingExecutionContext() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepExecution context) throws Exception { + protected void doExecute(StepExecution context) throws Exception { super.doExecute(context); - return ExitStatus.FINISHED; } }; repository = new JobRepositoryStub() { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBeanTests.java index b75f711ff..e8f3fd208 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/RepeatOperationsStepFactoryBeanTests.java @@ -28,9 +28,9 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.launch.EmptyItemWriter; import org.springframework.batch.core.step.JobRepositorySupport; import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatOperations; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; /** @@ -70,10 +70,10 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase { factory.setStepOperations(new RepeatOperations() { - public ExitStatus iterate(RepeatCallback callback) { + public RepeatStatus iterate(RepeatCallback callback) { list = new ArrayList(); list.add("foo"); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java index 10fa309e2..f589b5a9b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java @@ -8,6 +8,7 @@ import static org.springframework.batch.core.BatchStatus.*; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobInterruptedException; @@ -26,7 +27,6 @@ import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamSupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.AttributeAccessor; import org.springframework.transaction.TransactionException; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java index 1f8766491..3272b1f93 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/CallableTaskletAdapterTests.java @@ -21,8 +21,8 @@ import static org.junit.Assert.fail; import java.util.concurrent.Callable; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.step.tasklet.CallableTaskletAdapter; -import org.springframework.batch.repeat.ExitStatus; public class CallableTaskletAdapterTests { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java index c0fc9fbc5..138add1e3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ConfigurableSystemProcessExitCodeMapperTests.java @@ -8,8 +8,8 @@ import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.step.tasklet.ConfigurableSystemProcessExitCodeMapper; -import org.springframework.batch.repeat.ExitStatus; /** * Tests for {@link ConfigurableSystemProcessExitCodeMapper} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapperTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapperTests.java index 36bc2928f..aeb8c7fe1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapperTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SimpleSystemProcessExitCodeMapperTests.java @@ -3,8 +3,8 @@ package org.springframework.batch.core.step.tasklet; import static org.junit.Assert.assertEquals; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.step.tasklet.SimpleSystemProcessExitCodeMapper; -import org.springframework.batch.repeat.ExitStatus; /** * Tests for {@link SimpleSystemProcessExitCodeMapper}. diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepHandlerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepHandlerAdapterTests.java index 265678016..8e208b15f 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepHandlerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepHandlerAdapterTests.java @@ -19,8 +19,8 @@ import static org.junit.Assert.assertEquals; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter; -import org.springframework.batch.repeat.ExitStatus; /** * @author Dave Syer diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java index 95d0c12d5..88e604ff8 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java @@ -10,6 +10,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; import org.junit.Test; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobInterruptedException; @@ -18,7 +19,6 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.step.tasklet.SystemCommandException; import org.springframework.batch.core.step.tasklet.SystemCommandTasklet; import org.springframework.batch.core.step.tasklet.SystemProcessExitCodeMapper; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.util.Assert; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java index 4007f75ee..54e3b717e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java @@ -29,6 +29,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; @@ -54,7 +55,6 @@ import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemStreamSupport; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java index 631ca0a13..5500e6b6a 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java @@ -28,9 +28,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatSynchronizationManager; import org.springframework.batch.repeat.support.RepeatTemplate; @@ -123,12 +123,12 @@ public class ExternalRetryInBatchTests { repeatTemplate.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { final String item = provider.read(); if (item==null) { - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } RetryCallback callback = new RetryCallback() { @@ -154,7 +154,7 @@ public class ExternalRetryInBatchTests { retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(item)); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } diff --git a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java index e4b2b4ae6..4650729b2 100644 --- a/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java +++ b/spring-batch-infrastructure-tests/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java @@ -16,7 +16,8 @@ package org.springframework.batch.repeat.jms; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; @@ -26,27 +27,27 @@ import javax.jms.JMSException; import javax.jms.Session; import javax.sql.DataSource; -import org.springframework.batch.repeat.ExitStatus; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.support.RepeatTemplate; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jms.connection.SessionProxy; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.SessionCallback; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.BeforeTransaction; -import org.springframework.transaction.support.TransactionCallback; -import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.BeansException; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ApplicationContext; -import org.junit.runner.RunWith; -import org.junit.Test; +import org.springframework.transaction.support.TransactionCallback; +import org.springframework.transaction.support.TransactionTemplate; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") @@ -101,11 +102,11 @@ public class SynchronousTests implements ApplicationContextAware { assertInitialState(); repeatTemplate.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); - return new ExitStatus(text != null); + return RepeatStatus.continueIf(text != null); } }); @@ -125,11 +126,11 @@ public class SynchronousTests implements ApplicationContextAware { new TransactionTemplate(transactionManager).execute(new TransactionCallback() { public Object doInTransaction(org.springframework.transaction.TransactionStatus status) { repeatTemplate.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) jmsTemplate.receiveAndConvert("queue"); list.add(text); simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); - return new ExitStatus(text != null); + return RepeatStatus.continueIf(text != null); } }); // force rollback... @@ -170,11 +171,11 @@ public class SynchronousTests implements ApplicationContextAware { public Object doInTransaction(org.springframework.transaction.TransactionStatus status) { repeatTemplate.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { String text = (String) txJmsTemplate.receiveAndConvert("queue"); list.add(text); simpleJdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", list.size(), text); - return new ExitStatus(text != null); + return RepeatStatus.continueIf(text != null); } }); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/CompletionPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/CompletionPolicy.java index 2aab88e0a..f39895e4b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/CompletionPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/CompletionPolicy.java @@ -16,6 +16,7 @@ package org.springframework.batch.repeat; + /** * Interface for batch completion policies, to enable batch operations to * strategise normal completion conditions. Stateful implementations of batch @@ -41,7 +42,7 @@ public interface CompletionPolicy { * * @see #isComplete(RepeatContext) */ - boolean isComplete(RepeatContext context, ExitStatus result); + boolean isComplete(RepeatContext context, RepeatStatus result); /** * Allow policy to signal completion according to internal state, without diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatCallback.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatCallback.java index ea93db4fb..cb72f80c0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatCallback.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatCallback.java @@ -16,6 +16,7 @@ package org.springframework.batch.repeat; + /** * Callback interface for batch operations. Many simple processes will be able * to use off-the-shelf implementations of this interface, enabling the @@ -35,9 +36,9 @@ public interface RepeatCallback { * implementation of the caller. * * @param context the current context passed in by the caller. - * @return an {@link ExitStatus} which is continuable if there is (or may + * @return an {@link RepeatStatus} which is continuable if there is (or may * be) more data to process. * @throws Exception if there is a problem with the processing. */ - ExitStatus doInIteration(RepeatContext context) throws Exception; + RepeatStatus doInIteration(RepeatContext context) throws Exception; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java index 6049173d4..3c42f329c 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatListener.java @@ -16,6 +16,7 @@ package org.springframework.batch.repeat; + /** * Interface for listeners to the batch process. Implementers can provide * enhance the behaviour of a batch in small cross-cutting modules. The @@ -41,7 +42,7 @@ public interface RepeatListener { * @param context the current batch context * @param result the result of the callback */ - void after(RepeatContext context, ExitStatus result); + void after(RepeatContext context, RepeatStatus result); /** * Called once at the start of a complete batch, before any items are diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatOperations.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatOperations.java index 202326d4b..a392de23f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatOperations.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatOperations.java @@ -16,6 +16,7 @@ package org.springframework.batch.repeat; + /** * The main interface providing access to batch operations. The batch client is * the {@link RepeatCallback}, where a single item or record is processed. The @@ -41,6 +42,6 @@ public interface RepeatOperations { * indication of whether the {@link RepeatOperations} can continue * processing if this method is called again. */ - ExitStatus iterate(RepeatCallback callback) throws RepeatException; + RepeatStatus iterate(RepeatCallback callback) throws RepeatException; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatStatus.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatStatus.java new file mode 100644 index 000000000..bdc7231e7 --- /dev/null +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/RepeatStatus.java @@ -0,0 +1,25 @@ +package org.springframework.batch.repeat; + +public enum RepeatStatus { + + UNKNOWN(true), CONTINUABLE(true), FINISHED(false); + + private final boolean continuable; + + private RepeatStatus(boolean continuable) { + this.continuable = continuable; + } + + public static RepeatStatus continueIf(boolean continuable) { + return continuable ? CONTINUABLE : FINISHED; + } + + public boolean isContinuable() { + return this == CONTINUABLE; + } + + public RepeatStatus and(boolean value) { + return value && continuable ? CONTINUABLE : FINISHED; + } + +} diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/callback/NestedRepeatCallback.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/callback/NestedRepeatCallback.java index 69265fbc0..af5d3b9bb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/callback/NestedRepeatCallback.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/callback/NestedRepeatCallback.java @@ -16,7 +16,7 @@ package org.springframework.batch.repeat.callback; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatOperations; @@ -55,7 +55,7 @@ public class NestedRepeatCallback implements RepeatCallback { * * @see org.springframework.batch.repeat.RepeatCallback#doInIteration(RepeatContext) */ - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { return template.iterate(callback); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java index 5dc0e5ce5..e352fc10f 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptor.java @@ -19,7 +19,7 @@ package org.springframework.batch.repeat.interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.ProxyMethodInvocation; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; @@ -75,7 +75,7 @@ public class RepeatOperationsInterceptor implements MethodInterceptor { try { repeatOperations.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { try { MethodInvocation clone = invocation; @@ -89,16 +89,16 @@ public class RepeatOperationsInterceptor implements MethodInterceptor { Object value = clone.proceed(); if (voidReturnType) { - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } if (!isComplete(value)) { // Save the last result result.setValue(value); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } else { result.setFinalValue(value); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } } catch (Throwable e) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java index ddc49e3a2..ed765f0e0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; @@ -54,7 +54,7 @@ public class CompositeRepeatListener implements RepeatListener { /* (non-Javadoc) * @see org.springframework.batch.repeat.RepeatListener#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus) */ - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { for (RepeatListener listener : listeners) { listener.after(context, result); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java index d1a497a23..97229169d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/RepeatListenerSupport.java @@ -16,7 +16,7 @@ package org.springframework.batch.repeat.listener; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; @@ -31,7 +31,7 @@ public class RepeatListenerSupport implements RepeatListener { public void before(RepeatContext context) { } - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { } public void close(RepeatContext context) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java index 0d508b82d..d13a06168 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompletionPolicySupport.java @@ -17,7 +17,7 @@ package org.springframework.batch.repeat.policy; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; @@ -34,9 +34,9 @@ public class CompletionPolicySupport implements CompletionPolicy { * delegate to {@link #isComplete(RepeatContext)}. * * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, - * ExitStatus) + * RepeatStatus) */ - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { if (result != null && !result.isContinuable()) { return true; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java index 87f1b3ca0..0f43d2e7a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicy.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; @@ -48,9 +48,9 @@ public class CompositeCompletionPolicy implements CompletionPolicy { * This policy is complete if any of the composed policies is complete. * * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, - * ExitStatus) + * RepeatStatus) */ - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { RepeatContext[] contexts = ((CompositeBatchContext) context).contexts; CompletionPolicy[] policies = ((CompositeBatchContext) context).policies; for (int i = 0; i < policies.length; i++) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/DefaultResultCompletionPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/DefaultResultCompletionPolicy.java index 2530aa73e..d0a1ad8f7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/DefaultResultCompletionPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/DefaultResultCompletionPolicy.java @@ -17,13 +17,13 @@ package org.springframework.batch.repeat.policy; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; /** * Very simple {@link CompletionPolicy} that bases its decision on the result of * a batch operation. If the result is null or not continuable according to the - * {@link ExitStatus} the batch is complete, otherwise not. + * {@link RepeatStatus} the batch is complete, otherwise not. * * @author Dave Syer * @@ -31,13 +31,13 @@ import org.springframework.batch.repeat.RepeatContext; public class DefaultResultCompletionPolicy extends CompletionPolicySupport { /** - * True if the result is null, or a {@link ExitStatus} indicating + * True if the result is null, or a {@link RepeatStatus} indicating * completion. * * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, - * ExitStatus) + * RepeatStatus) */ - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { return (result == null || !result.isContinuable()); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicy.java index e8e68cf71..22bb1b12e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicy.java @@ -16,7 +16,7 @@ package org.springframework.batch.repeat.policy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; import org.springframework.batch.repeat.support.RepeatTemplate; @@ -64,11 +64,11 @@ public class SimpleCompletionPolicy extends DefaultResultCompletionPolicy { * Terminate if the chunk size has been reached, or the result is null. * * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext, - * ExitStatus) + * RepeatStatus) * @throws RuntimeException (normally terminating the batch) if the result is * itself an exception. */ - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { return super.isComplete(context, result) || ((SimpleTerminationContext) context).isComplete(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java index 594124c87..a70f1c168 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatTemplate.java @@ -24,7 +24,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; @@ -52,7 +52,7 @@ import org.springframework.util.Assert; * the {@link RepeatCallback} can consider using a custom {@link RepeatListener} * instead of trying to customise the {@link CompletionPolicy}. This is * generally a friendlier interface to implement, and the - * {@link RepeatListener#after(RepeatContext, ExitStatus)} method is passed in + * {@link RepeatListener#after(RepeatContext, RepeatStatus)} method is passed in * the result of the callback, which would be an instance of {@link Throwable} * if the business processing had thrown an exception. If the exception is not * to be propagated to the caller, then a non-default {@link CompletionPolicy} @@ -110,7 +110,7 @@ public class RepeatTemplate implements RepeatOperations { /** * Setter for policy to decide when the batch is complete. The default is to - * complete normally when the callback returns a {@link ExitStatus} which is + * complete normally when the callback returns a {@link RepeatStatus} which is * not marked as continuable, and abnormally when the callback throws an * exception (but the decision to re-throw the exception is deferred to the * {@link ExceptionHandler}). @@ -132,11 +132,11 @@ public class RepeatTemplate implements RepeatOperations { * * @see org.springframework.batch.repeat.RepeatOperations#iterate(org.springframework.batch.repeat.RepeatCallback) */ - public ExitStatus iterate(RepeatCallback callback) { + public RepeatStatus iterate(RepeatCallback callback) { RepeatContext outer = RepeatSynchronizationManager.getContext(); - ExitStatus result = ExitStatus.CONTINUABLE; + RepeatStatus result = RepeatStatus.CONTINUABLE; try { // This works with an asynchronous TaskExecutor: the // interceptors have to wait for the child processes. @@ -162,7 +162,7 @@ public class RepeatTemplate implements RepeatOperations { * for all the results from the callback. * */ - private ExitStatus executeInternal(final RepeatCallback callback) { + private RepeatStatus executeInternal(final RepeatCallback callback) { // Reset the termination policy if there is one... RepeatContext context = start(); @@ -180,7 +180,7 @@ public class RepeatTemplate implements RepeatOperations { } // Return value, default is to allow continued processing. - ExitStatus result = ExitStatus.CONTINUABLE; + RepeatStatus result = RepeatStatus.CONTINUABLE; RepeatInternalState state = createInternalState(context); Collection throwables = state.getThrowables(); @@ -346,7 +346,7 @@ public class RepeatTemplate implements RepeatOperations { * @see #isComplete(RepeatContext) * @see #createInternalState(RepeatContext) */ - protected ExitStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) + protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws Throwable { update(context); return callback.doInIteration(context); @@ -358,7 +358,7 @@ public class RepeatTemplate implements RepeatOperations { * processes. By default does nothing and returns true. * * @param state the internal state. - * @return true if {@link #canContinue(ExitStatus)} is true for all results + * @return true if {@link #canContinue(RepeatStatus)} is true for all results * retrieved. */ protected boolean waitForResults(RepeatInternalState state) { @@ -370,10 +370,10 @@ public class RepeatTemplate implements RepeatOperations { * Check return value from batch operation. * * @param value the last callback result. - * @return true if the value is {@link ExitStatus#CONTINUABLE}. + * @return true if the value is {@link RepeatStatus#CONTINUABLE}. */ - protected final boolean canContinue(ExitStatus value) { - return ((ExitStatus) value).isContinuable(); + protected final boolean canContinue(RepeatStatus value) { + return ((RepeatStatus) value).isContinuable(); } private boolean isMarkedComplete(RepeatContext context) { @@ -394,7 +394,7 @@ public class RepeatTemplate implements RepeatOperations { * @param context the current batch context. * @param value the result of the callback to process. */ - protected void executeAfterInterceptors(final RepeatContext context, ExitStatus value) { + protected void executeAfterInterceptors(final RepeatContext context, RepeatStatus value) { // Don't re-throw exceptions here: let the exception handler deal with // that... @@ -413,9 +413,9 @@ public class RepeatTemplate implements RepeatOperations { * Delegate to the {@link CompletionPolicy}. * * @see org.springframework.batch.repeat.CompletionPolicy#isComplete(RepeatContext, - * ExitStatus) + * RepeatStatus) */ - protected boolean isComplete(RepeatContext context, ExitStatus result) { + protected boolean isComplete(RepeatContext context, RepeatStatus result) { boolean complete = completionPolicy.isComplete(context, result); if (complete) { logger.debug("Repeat is complete according to policy and result value."); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ResultHolder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ResultHolder.java index b6ee836fa..413717394 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ResultHolder.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/ResultHolder.java @@ -1,6 +1,6 @@ package org.springframework.batch.repeat.support; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; /** @@ -16,7 +16,7 @@ interface ResultHolder { * @return the result, or null if there is none. * @throws IllegalStateException */ - ExitStatus getResult(); + RepeatStatus getResult(); /** * Get the error for client from this holder if any. Does not block if diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java index a140ebc7e..69537247a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java @@ -16,7 +16,7 @@ package org.springframework.batch.repeat.support; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; @@ -78,7 +78,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { * method so there is no need to synchronize access. * */ - protected ExitStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) + protected RepeatStatus getNextResult(RepeatContext context, RepeatCallback callback, RepeatInternalState state) throws Throwable { ExecutingRunnable runnable = null; @@ -161,7 +161,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { state.getThrowables().add(future.getError()); } else { - ExitStatus status = future.getResult(); + RepeatStatus status = future.getResult(); result = result && canContinue(status); executeAfterInterceptors(future.getContext(), status); } @@ -192,7 +192,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { private final ResultQueue queue; - private volatile ExitStatus result; + private volatile RepeatStatus result; private volatile Throwable error; @@ -241,7 +241,7 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { * Get the result - never blocks because the queue manages waiting for * the task to finish. */ - public ExitStatus getResult() { + public RepeatStatus getResult() { return result; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java index 627d02726..790c57b44 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java @@ -18,7 +18,7 @@ package org.springframework.batch.repeat.callback; import junit.framework.TestCase; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.support.RepeatTemplate; @@ -29,12 +29,12 @@ public class NestedRepeatCallbackTests extends TestCase { public void testExecute() throws Exception { NestedRepeatCallback callback = new NestedRepeatCallback(new RepeatTemplate(), new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return new ExitStatus(count <= 1); + return RepeatStatus.continueIf(count <= 1); } }); - ExitStatus result = callback.doInIteration(null); + RepeatStatus result = callback.doInIteration(null); assertEquals(2, count); assertFalse(result.isContinuable()); // False because processing has finished } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java index 2ca42bef6..9d45a7176 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java @@ -27,7 +27,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatException; import org.springframework.batch.repeat.RepeatOperations; @@ -68,7 +68,7 @@ public class RepeatOperationsInterceptorTests extends TestCase { public void testSetTemplate() throws Exception { final List calls = new ArrayList(); interceptor.setRepeatOperations(new RepeatOperations() { - public ExitStatus iterate(RepeatCallback callback) { + public RepeatStatus iterate(RepeatCallback callback) { try { Object result = callback.doInIteration(null); calls.add(result); @@ -76,7 +76,7 @@ public class RepeatOperationsInterceptorTests extends TestCase { catch (Exception e) { throw new RepeatException("Encountered exception in repeat.", e); } - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); ((Advised) service).addAdvice(interceptor); @@ -87,9 +87,9 @@ public class RepeatOperationsInterceptorTests extends TestCase { public void testCallbackNotExecuted() throws Exception { final List calls = new ArrayList(); interceptor.setRepeatOperations(new RepeatOperations() { - public ExitStatus iterate(RepeatCallback callback) { + public RepeatStatus iterate(RepeatCallback callback) { calls.add(null); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }); ((Advised) service).addAdvice(interceptor); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java index 6ef18e118..659d07f51 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java @@ -21,7 +21,7 @@ import java.util.List; import junit.framework.TestCase; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; @@ -46,9 +46,9 @@ public class RepeatListenerTests extends TestCase { } } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return new ExitStatus(count <= 1); + return RepeatStatus.continueIf(count <= 1); } }); // 2 calls: the second time there is no processing @@ -69,9 +69,9 @@ public class RepeatListenerTests extends TestCase { } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }); assertEquals(0, count); @@ -83,18 +83,18 @@ public class RepeatListenerTests extends TestCase { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList(); template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } }, new RepeatListenerSupport() { - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { calls.add("2"); } } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return new ExitStatus(count <= 1); + return RepeatStatus.continueIf(count <= 1); } }); // 2 calls to the callback, and the second one had no processing... @@ -117,9 +117,9 @@ public class RepeatListenerTests extends TestCase { } } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); assertEquals(0, count); @@ -135,10 +135,10 @@ public class RepeatListenerTests extends TestCase { } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; context.setCompleteOnly(); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }); assertEquals(1, count); @@ -158,9 +158,9 @@ public class RepeatListenerTests extends TestCase { } } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return new ExitStatus(count < 2); + return RepeatStatus.continueIf(count < 2); } }); // Test that more than one call comes in to the callback... @@ -184,7 +184,7 @@ public class RepeatListenerTests extends TestCase { } }); try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { throw new IllegalStateException("Bogus"); } }); @@ -201,7 +201,7 @@ public class RepeatListenerTests extends TestCase { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList(); template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } }, new RepeatListenerSupport() { @@ -211,7 +211,7 @@ public class RepeatListenerTests extends TestCase { } }); try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { throw new IllegalStateException("Bogus"); } }); @@ -231,7 +231,7 @@ public class RepeatListenerTests extends TestCase { final List calls = new ArrayList(); final List fails = new ArrayList(); template.setListeners(new RepeatListener[] { new RepeatListenerSupport() { - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { calls.add("1"); } }, new RepeatListenerSupport() { @@ -242,7 +242,7 @@ public class RepeatListenerTests extends TestCase { } }); try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { throw new IllegalStateException("Bogus"); } }); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java index 7ecfc2a74..1805d584b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java @@ -19,7 +19,7 @@ package org.springframework.batch.repeat.policy; import junit.framework.TestCase; import org.springframework.batch.repeat.CompletionPolicy; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; public class CompositeCompletionPolicyTests extends TestCase { @@ -59,7 +59,7 @@ public class CompositeCompletionPolicyTests extends TestCase { CompositeCompletionPolicy policy = new CompositeCompletionPolicy(); policy.setPolicies(new CompletionPolicy[] { new MockCompletionPolicySupport(), new MockCompletionPolicySupport() { - public boolean isComplete(RepeatContext context, ExitStatus result) { + public boolean isComplete(RepeatContext context, RepeatStatus result) { return true; } } }); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java index 4e4ccdae8..e4ef2623b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java @@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy; import junit.framework.TestCase; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; @@ -53,7 +53,7 @@ public class CountingCompletionPolicyTests extends TestCase { }; policy.setMaxCount(10); RepeatContext context = policy.start(null); - assertTrue(policy.isComplete(context, ExitStatus.FINISHED)); + assertTrue(policy.isComplete(context, RepeatStatus.FINISHED)); } public void testDefaultBehaviourWithUpdate() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java index 241a8fd77..8890aa886 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java @@ -18,7 +18,7 @@ package org.springframework.batch.repeat.policy; import junit.framework.TestCase; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; public class SimpleCompletionPolicyTests extends TestCase { @@ -27,7 +27,7 @@ public class SimpleCompletionPolicyTests extends TestCase { RepeatContext context; - ExitStatus dummy = ExitStatus.CONTINUABLE; + RepeatStatus dummy = RepeatStatus.CONTINUABLE; protected void setUp() throws Exception { super.setUp(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java index fcd4f7184..08318b1ba 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java @@ -16,10 +16,11 @@ package org.springframework.batch.repeat.policy; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.Test; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; public class TimeoutCompletionPolicyTests { @@ -43,7 +44,7 @@ public class TimeoutCompletionPolicyTests { @Test public void testNonContinuableResult() throws Exception { TimeoutTerminationPolicy policy = new TimeoutTerminationPolicy(); - ExitStatus result = new ExitStatus(false, "non-continuable exit status"); + RepeatStatus result = RepeatStatus.FINISHED; assertTrue(policy.isComplete(policy.start(null), result)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AsynchronousRepeatTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AsynchronousRepeatTests.java index 7affd43f8..2481e2cd6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AsynchronousRepeatTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AsynchronousRepeatTests.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.core.task.SimpleAsyncTaskExecutor; @@ -42,7 +42,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests { final Set threadNames = new HashSet(); final RepeatCallback callback = new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertNotSame(threadName, Thread.currentThread().getName()); threadNames.add(Thread.currentThread().getName()); Thread.sleep(100); @@ -50,7 +50,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests { if (item!=null) { processor.write(Collections.singletonList(item)); } - return new ExitStatus(item!=null); + return RepeatStatus.continueIf(item!=null); } }; @@ -78,7 +78,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests { final Set threadNames = new HashSet(); final RepeatCallback stepCallback = new ItemReaderRepeatCallback(provider, processor) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertNotSame(threadName, Thread.currentThread().getName()); threadNames.add(Thread.currentThread().getName()); Thread.sleep(100); @@ -86,9 +86,9 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests { } }; RepeatCallback jobCallback = new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { stepTemplate.iterate(stepCallback); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java index 0a4da508a..13494161a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java @@ -17,7 +17,7 @@ package org.springframework.batch.repeat.support; import org.springframework.batch.item.ItemReader; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.callback.NestedRepeatCallback; @@ -51,9 +51,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { // once chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2)); - ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) { + RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; // for test assertion return super.doInIteration(context); } @@ -86,9 +86,9 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2)); chunkTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor()); - ExitStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) { + RepeatStatus result = repeatTemplate.iterate(new NestedRepeatCallback(chunkTemplate, callback) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; // for test assertion return super.doInIteration(context); } @@ -158,8 +158,8 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests { chunker.reset(); template.iterate(new ItemReaderRepeatCallback(truncated, processor) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { - ExitStatus result = super.doInIteration(context); + public RepeatStatus doInIteration(RepeatContext context) throws Exception { + RepeatStatus result = super.doInIteration(context); if (!result.isContinuable() && chunker.first()) { chunker.set(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ItemReaderRepeatCallback.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ItemReaderRepeatCallback.java index f4137202d..f194e5999 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ItemReaderRepeatCallback.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ItemReaderRepeatCallback.java @@ -19,7 +19,7 @@ import java.util.Collections; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -44,13 +44,13 @@ public class ItemReaderRepeatCallback implements RepeatCallback { /* (non-Javadoc) * @see org.springframework.batch.repeat.RepeatCallback#doInIteration(org.springframework.batch.repeat.RepeatContext) */ - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { T item = reader.read(); if (item==null) { - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } writer.write(Collections.singletonList(item)); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java index de09b76e2..9fbdd380c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java @@ -20,7 +20,6 @@ import junit.framework.TestCase; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; -import org.springframework.batch.repeat.support.RepeatSynchronizationManager; public class RepeatSynchronizationManagerTests extends TestCase { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java index 4ec5d2514..dae99e8dc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java @@ -19,7 +19,7 @@ package org.springframework.batch.repeat.support; import java.util.ArrayList; import java.util.List; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; @@ -73,7 +73,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; throw new IllegalStateException("foo!"); } @@ -109,9 +109,9 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { } }); template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; - return new ExitStatus(count < 1); + return RepeatStatus.continueIf(count < 1); } }); @@ -143,7 +143,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; throw new RuntimeException("foo"); } @@ -176,7 +176,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; throw new RuntimeException("foo"); } @@ -198,10 +198,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { */ public void testEarlyCompletionWithContext() throws Exception { - ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) { + RepeatStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { - ExitStatus result = super.doInIteration(context); + public RepeatStatus doInIteration(RepeatContext context) throws Exception { + RepeatStatus result = super.doInIteration(context); if (processor.count >= 2) { context.setCompleteOnly(); // If we return null the batch will terminate anyway @@ -226,10 +226,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { */ public void testEarlyCompletionWithContextTerminated() throws Exception { - ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) { + RepeatStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { - ExitStatus result = super.doInIteration(context); + public RepeatStatus doInIteration(RepeatContext context) throws Exception { + RepeatStatus result = super.doInIteration(context); if (processor.count >= 2) { context.setTerminateOnly(); // If we return null the batch will terminate anyway @@ -251,15 +251,15 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { RepeatTemplate outer = getRepeatTemplate(); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); assertNotSame("Nested batch should have new session", context, context.getParent()); assertSame(context, RepeatSynchronizationManager.getContext()); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertSame(context, RepeatSynchronizationManager.getContext()); return super.doInIteration(context); @@ -272,14 +272,14 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { RepeatTemplate outer = getRepeatTemplate(); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertEquals(2, count); fail("Nested batch should not have been executed"); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; context.setCompleteOnly(); return super.doInIteration(context); @@ -293,19 +293,19 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { outer.setCompletionPolicy(new SimpleCompletionPolicy(2)); RepeatTemplate inner = getRepeatTemplate(); outer.iterate(new NestedRepeatCallback(inner, new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); assertNotSame("Nested batch should have new session", context, context.getParent()); assertSame(context, RepeatSynchronizationManager.getContext()); - return ExitStatus.FINISHED; + return RepeatStatus.FINISHED; } }) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertSame(context, RepeatSynchronizationManager.getContext()); super.doInIteration(context); - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } }); assertEquals(4, count); @@ -316,7 +316,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { * @throws Exception */ public void testResult() throws Exception { - ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor)); + RepeatStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor)); assertEquals(NUMBER_OF_ITEMS, processor.count); // We are complete - do not expect to be called again assertFalse(result.isContinuable()); @@ -326,10 +326,10 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { template.setCompletionPolicy(new SimpleCompletionPolicy(2)); try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; if (count < 2) { - return ExitStatus.CONTINUABLE; + return RepeatStatus.CONTINUABLE; } throw new RuntimeException("Barf second try count=" + count); } @@ -352,13 +352,13 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { template.setCompletionPolicy(new SimpleCompletionPolicy(4)); - ExitStatus result = ExitStatus.FINISHED; + RepeatStatus result = RepeatStatus.FINISHED; try { result = template.iterate(new ItemReaderRepeatCallback(provider, processor) { - public ExitStatus doInIteration(RepeatContext context) throws Exception { - ExitStatus result = super.doInIteration(context); + public RepeatStatus doInIteration(RepeatContext context) throws Exception { + RepeatStatus result = super.doInIteration(context); if (processor.count >= 2) { context.setCompleteOnly(); throw new RuntimeException("Barf second try count=" + processor.count); @@ -383,20 +383,6 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { } - public void testCustomExitCode() { - - ExitStatus status = template.iterate(new RepeatCallback() { - - public ExitStatus doInIteration(RepeatContext context) throws Exception { - ExitStatus exitStatus = new ExitStatus(false, "CUSTOM_CODE"); - return exitStatus; - } - - }); - - assertEquals("CUSTOM_CODE", status.getExitCode()); - } - /** * Checked exceptions are wrapped into runtime RepeatException. * RepeatException should be unwrapped before before it is passed to @@ -438,7 +424,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests { try { template.iterate(new RepeatCallback() { - public ExitStatus doInIteration(RepeatContext context) throws Exception { + public RepeatStatus doInIteration(RepeatContext context) throws Exception { throw new RepeatException("typically thrown by nested repeat template", exception); } }); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java index 8f542dcd0..e4e4391e4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java @@ -15,7 +15,10 @@ */ package org.springframework.batch.repeat.support; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.NoSuchElementException; diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java index 95aae963a..b6649d361 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkMessageChannelItemWriter.java @@ -5,13 +5,13 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java index abce8c644..dcd211368 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandler.java @@ -2,7 +2,7 @@ package org.springframework.batch.integration.chunk; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkResponse.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkResponse.java index d03ec06aa..e39b39d86 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkResponse.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/chunk/ChunkResponse.java @@ -2,7 +2,7 @@ package org.springframework.batch.integration.chunk; import java.io.Serializable; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; public class ChunkResponse implements Serializable { diff --git a/spring-batch-integration/src/main/java/org/springframework/batch/integration/job/MessageOrientedStep.java b/spring-batch-integration/src/main/java/org/springframework/batch/integration/job/MessageOrientedStep.java index df9077074..338c2d5db 100644 --- a/spring-batch-integration/src/main/java/org/springframework/batch/integration/job/MessageOrientedStep.java +++ b/spring-batch-integration/src/main/java/org/springframework/batch/integration/job/MessageOrientedStep.java @@ -16,12 +16,12 @@ package org.springframework.batch.integration.job; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.annotation.Required; import org.springframework.integration.channel.PollableChannel; import org.springframework.integration.core.Message; @@ -97,10 +97,10 @@ public class MessageOrientedStep extends AbstractStep { * @see AbstractStep#execute(StepExecution) */ @Override - public ExitStatus doExecute(StepExecution stepExecution) throws JobInterruptedException, + protected void doExecute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException { - JobExecutionRequest request = new JobExecutionRequest(stepExecution .getJobExecution()); + JobExecutionRequest request = new JobExecutionRequest(stepExecution.getJobExecution()); ExecutionContext executionContext = stepExecution.getExecutionContext(); @@ -116,7 +116,7 @@ public class MessageOrientedStep extends AbstractStep { waitForReply(request.getJobId()); } - return ExitStatus.FINISHED; + stepExecution.setExitStatus(ExitStatus.FINISHED); } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java index b7b1f7aef..8d9dc73e3 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkMessageItemWriterIntegrationTests.java @@ -10,6 +10,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParametersBuilder; import org.springframework.batch.core.Step; @@ -26,7 +27,6 @@ import org.springframework.batch.core.repository.support.SimpleJobRepository; import org.springframework.batch.core.step.item.SimpleStepFactoryBean; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.support.ListItemReader; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandlerTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandlerTests.java index 36f817cfd..e35b3911a 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandlerTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkProcessorChunkHandlerTests.java @@ -5,7 +5,7 @@ import static org.junit.Assert.assertEquals; import java.util.Collection; import org.junit.Test; -import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.util.StringUtils; public class ChunkProcessorChunkHandlerTests { diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/MessageOrientedStepTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/MessageOrientedStepTests.java index d62e6bd73..9ed3b1868 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/MessageOrientedStepTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/MessageOrientedStepTests.java @@ -25,12 +25,12 @@ import java.lang.reflect.Method; import org.junit.Before; import org.junit.Test; import org.springframework.batch.core.BatchStatus; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.StepExecution; import org.springframework.batch.integration.JobRepositorySupport; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.annotation.Required; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.integration.channel.DirectChannel; diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/TestTasklet.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/TestTasklet.java index ff5917177..94ac1e39a 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/TestTasklet.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/job/TestTasklet.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.integration.job; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java index f8a47faf8..20d7daf80 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java @@ -9,13 +9,13 @@ import java.util.List; import org.apache.commons.lang.SerializationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ReaderNotOpenException; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.RowMapper; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemWriter.java index 4f423c649..3c4d06ca7 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemWriter.java @@ -7,10 +7,10 @@ import java.util.List; import java.util.ListIterator; import org.apache.commons.lang.SerializationUtils; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.StepExecutionListener; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateCreditDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateCreditDao.java index 622c85fe2..950a20567 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateCreditDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/HibernateCreditDao.java @@ -18,9 +18,9 @@ package org.springframework.batch.sample.domain.trade.internal; import java.util.ArrayList; import java.util.List; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; +import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.sample.domain.trade.CustomerCredit; import org.springframework.batch.sample.domain.trade.CustomerCreditDao; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; @@ -89,7 +89,7 @@ public class HibernateCreditDao extends HibernateDaoSupport implements /* (non-Javadoc) * @see org.springframework.batch.repeat.RepeatInterceptor#after(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.ExitStatus) */ - public void after(RepeatContext context, ExitStatus result) { + public void after(RepeatContext context, RepeatStatus result) { } /* (non-Javadoc) diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java index 543b17815..121fb3d01 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageReceivingTasklet.java @@ -2,12 +2,12 @@ package org.springframework.batch.sample.tasklet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java index 2122a341a..aa15e81d3 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/DummyMessageSendingTasklet.java @@ -2,12 +2,12 @@ package org.springframework.batch.sample.tasklet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.listener.StepExecutionListenerSupport; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.core.AttributeAccessor; /** diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java index f4a8c942b..73b1a81e4 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/FileDeletingTasklet.java @@ -1,9 +1,9 @@ package org.springframework.batch.sample.tasklet; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.UnexpectedJobExecutionException; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.AttributeAccessor; import org.springframework.core.io.Resource; diff --git a/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java b/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java index 663f5e6a2..fe49ff8e9 100755 --- a/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java +++ b/spring-batch-test/src/test/java/org/springframework/batch/test/sample/SampleTasklet.java @@ -1,8 +1,8 @@ package org.springframework.batch.test.sample; +import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.AttributeAccessor; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;