diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobExecutionDao.java index 3ca18a19d8..ca0471de5d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobExecutionDao.java @@ -77,6 +77,7 @@ * @author Dimitrios Liapis * @author Philippe Marschall * @author Jinwoo Bae + * @author Yanming Zhou */ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean { @@ -322,11 +323,8 @@ public void updateJobExecution(JobExecution jobExecution) { // Avoid concurrent modifications... if (count == 0) { - int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_JOB_EXECUTION), - Integer.class, new Object[] { jobExecution.getId() }); - throw new OptimisticLockingFailureException( - "Attempt to update job execution id=" + jobExecution.getId() + " with wrong version (" - + jobExecution.getVersion() + "), where current version is " + currentVersion); + throw new OptimisticLockingFailureException("Attempt to update job execution id=" + jobExecution.getId() + + " with wrong version (" + jobExecution.getVersion() + ")"); } jobExecution.incrementVersion(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java index 11363eaa59..a48c27155c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java @@ -68,6 +68,7 @@ * @author Mahmoud Ben Hassine * @author Baris Cubukcuoglu * @author Minsoo Kim + * @author Yanming Zhou * @see StepExecutionDao */ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implements StepExecutionDao, InitializingBean { @@ -102,11 +103,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement WHERE JE.JOB_INSTANCE_ID = ? AND SE.STEP_NAME = ? """; - private static final String CURRENT_VERSION_STEP_EXECUTION = """ - SELECT VERSION FROM %PREFIX%STEP_EXECUTION - WHERE STEP_EXECUTION_ID=? - """; - private static final String COUNT_STEP_EXECUTIONS = """ SELECT COUNT(*) FROM %PREFIX%JOB_EXECUTION JE @@ -289,11 +285,8 @@ public void updateStepExecution(StepExecution stepExecution) { // Avoid concurrent modifications... if (count == 0) { - int currentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION), - Integer.class, stepExecution.getId()); - throw new OptimisticLockingFailureException( - "Attempt to update step execution id=" + stepExecution.getId() + " with wrong version (" - + stepExecution.getVersion() + "), where current version is " + currentVersion); + throw new OptimisticLockingFailureException("Attempt to update step execution id=" + + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + ")"); } stepExecution.incrementVersion();