From a35a9d79dc12d57d3110218d826554d80ab3087a Mon Sep 17 00:00:00 2001 From: dsyer Date: Wed, 27 Feb 2008 16:44:52 +0000 Subject: [PATCH] OPEN - issue BATCH-368: StepExecution attributes can overflow and cause spurious OptimisticLockingException http://jira.springframework.org/browse/BATCH-368 Split the save of a StepExecution into two parts at the JobRepository level, that way we can see if the failure was in saving context or just the step execution. Lots of exception handling and tests in step implementations. --- .../batch/core/repository/JobRepository.java | 26 +- .../batch/execution/job/AbstractJob.java | 2 - .../repository/SimpleJobRepository.java | 19 +- .../repository/dao/JdbcStepExecutionDao.java | 42 +-- .../execution/repository/dao/MapStepDao.java | 7 +- .../repository/dao/StepExecutionDao.java | 14 +- .../execution/step/ItemOrientedStep.java | 134 ++++++-- .../batch/execution/step/TaskletStep.java | 26 +- .../execution/repository/MockStepDao.java | 11 +- .../repository/SimpleJobRepositoryTests.java | 25 +- .../repository/dao/AbstractStepDaoTests.java | 8 +- .../execution/step/ItemOrientedStepTests.java | 293 +++++++++++++----- .../execution/step/TaskletStepTests.java | 28 +- .../step/support/JobRepositorySupport.java | 6 + .../item/exception/CommitFailedException.java | 46 +++ 15 files changed, 489 insertions(+), 198 deletions(-) create mode 100644 spring-batch-infrastructure/src/main/java/org/springframework/batch/item/exception/CommitFailedException.java diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java index 986015051..af8e01484 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java @@ -81,18 +81,31 @@ public interface JobRepository { public void saveOrUpdate(JobExecution jobExecution); /** - * Save or Update a StepExecution. If no ID is found a new instance will be - * created. (saved). If an ID does exist it will be updated. It is not - * advisable that an ID be assigned to a JobExecution before calling this - * method. Instead, it should be left blank, to be assigned by a - * JobRepository. + * Save or update a {@link StepExecution}. If no ID is found a new instance + * will be created (and saved). If an ID does exist it will be updated. It + * is not advisable that an ID be assigned before calling this method. + * Instead, it should be left blank, to be assigned by a + * {@link JobRepository}. The {@link ExecutionContext} of the + * {@link StepExecution} is not saved: see + * {@link #saveExecutionContext(StepExecution)}. * - * Preconditions: StepExecution must have a valid StepId. + * Preconditions: {@link StepExecution} must have a valid {@link Step}. * * @param jobInstance */ public void saveOrUpdate(StepExecution stepExecution); + /** + * Save the {@link ExecutionContext} of the given {@link StepExecution}. + * Implementations are allowed to ensure that the {@link StepExecution} is + * already saved by calling {@link #saveOrUpdate(StepExecution)} before + * saving the {@link ExecutionContext}. + * + * @param stepExecution the {@link StepExecution} containing the + * {@link ExecutionContext} to be saved. + */ + void saveOrUpdateExecutionContext(StepExecution stepExecution); + /** * @return the last execution of step for the given job instance. */ @@ -103,5 +116,4 @@ public interface JobRepository { */ public int getStepExecutionCount(JobInstance jobInstance, Step step); - } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/AbstractJob.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/AbstractJob.java index 21ef40067..6de446cb5 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/AbstractJob.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/job/AbstractJob.java @@ -20,9 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.batch.core.domain.Job; -import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.Step; -import org.springframework.batch.io.exception.BatchCriticalException; import org.springframework.beans.factory.BeanNameAware; import org.springframework.util.ClassUtils; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java index 9db70a515..27ad8ab33 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java @@ -108,8 +108,8 @@ public class SimpleJobRepository implements JobRepository { *