From fa4a690cda8aea4ac35b173d1e4ece6e543c7e5a Mon Sep 17 00:00:00 2001 From: dsyer Date: Thu, 16 Oct 2008 11:08:59 +0000 Subject: [PATCH] OPEN - issue BATCH-282: Make input parameters easier to access from ItemReaders, etc. Revert change to method signature in AbstractStep --- .../batch/core/scope/StepContextRepeatCallback.java | 3 ++- .../batch/core/step/AbstractStep.java | 8 ++++---- .../batch/core/step/tasklet/TaskletStep.java | 4 ++-- .../batch/core/step/AbstractStepTests.java | 13 ++++++------- .../batch/integration/job/MessageOrientedStep.java | 4 +--- 5 files changed, 15 insertions(+), 17 deletions(-) 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 a4314cc92..f1cb6ce7e 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 @@ -41,7 +41,8 @@ public abstract class StepContextRepeatCallback implements RepeatCallback { /** * Manage the {@link StepContext} lifecycle to ensure that the current * thread has a reference to the context, even if the callback is executed - * in a pooled thread. + * in a pooled thread. Handles the registration and de-registration of the + * step context, so clients should not duplicate those calls. * * @see RepeatCallback#doInIteration(RepeatContext) */ 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 601e04c16..6dafa5bf3 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 @@ -145,12 +145,12 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw /** * Extension point for subclasses to execute business logic. * - * @param stepContext the current step context + * @param stepExecution the current step context * @return {@link ExitStatus} to show whether the step is finished * processing. * @throws Exception */ - protected abstract ExitStatus doExecute(StepContext stepContext) throws Exception; + protected abstract ExitStatus doExecute(StepExecution stepExecution) throws Exception; /** * Extension point for subclasses to provide callbacks to their @@ -177,7 +177,7 @@ 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(StepContext)}) 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 { @@ -195,7 +195,7 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw getCompositeListener().beforeStep(stepExecution); open(stepExecution.getExecutionContext()); - exitStatus = doExecute(stepContext); + exitStatus = doExecute(stepExecution); // Check if someone is trying to stop us if (stepExecution.isTerminateOnly()) { 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 d2b175cc8..75d6b56bf 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 @@ -227,8 +227,8 @@ public class TaskletStep extends AbstractStep { * */ @Override - protected ExitStatus doExecute(StepContext stepContext) throws Exception { - StepExecution stepExecution = stepContext.getStepExecution(); + protected ExitStatus doExecute(StepExecution stepExecution) throws Exception { + StepContext stepContext = new StepContext(stepExecution); stream.update(stepExecution.getExecutionContext()); getJobRepository().updateExecutionContext(stepExecution); 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 5d45acc29..3c8bfa56a 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 @@ -16,7 +16,6 @@ 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.core.scope.StepContext; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.ExitStatus; import org.springframework.util.Assert; @@ -55,8 +54,8 @@ public class AbstractStepTests { events.add("open"); } - protected ExitStatus doExecute(StepContext context) throws Exception { - assertSame(execution, context.getStepExecution()); + protected ExitStatus doExecute(StepExecution context) throws Exception { + assertSame(execution, context); events.add("doExecute"); return ExitStatus.FINISHED; } @@ -167,7 +166,7 @@ public class AbstractStepTests { public void testFailure() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepContext context) throws Exception { + protected ExitStatus doExecute(StepExecution context) throws Exception { super.doExecute(context); throw new RuntimeException("crash!"); } @@ -205,8 +204,8 @@ public class AbstractStepTests { public void testStoppedStep() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepContext context) throws Exception { - context.getStepExecution().setTerminateOnly(); + protected ExitStatus doExecute(StepExecution context) throws Exception { + context.setTerminateOnly(); return super.doExecute(context); } }; @@ -241,7 +240,7 @@ public class AbstractStepTests { public void testFailureInSavingExecutionContext() throws Exception { tested = new EventTrackingStep() { @Override - protected ExitStatus doExecute(StepContext context) throws Exception { + protected ExitStatus doExecute(StepExecution context) throws Exception { super.doExecute(context); return ExitStatus.FINISHED; } 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 94c983c85..3bdfe1ff7 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 @@ -19,7 +19,6 @@ import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobInterruptedException; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.UnexpectedJobExecutionException; -import org.springframework.batch.core.scope.StepContext; import org.springframework.batch.core.step.AbstractStep; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.ExitStatus; @@ -98,10 +97,9 @@ public class MessageOrientedStep extends AbstractStep { * @see AbstractStep#execute(StepExecution) */ @Override - public ExitStatus doExecute(StepContext stepContext) throws JobInterruptedException, + public ExitStatus doExecute(StepExecution stepExecution) throws JobInterruptedException, UnexpectedJobExecutionException { - StepExecution stepExecution = stepContext.getStepExecution(); JobExecutionRequest request = new JobExecutionRequest(stepExecution .getJobExecution()); ExecutionContext executionContext = stepExecution.getExecutionContext();