diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java index a23baebd3..af9bf7b2f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/Entity.java @@ -63,9 +63,17 @@ public class Entity implements Serializable { public Integer getVersion() { return version; } + + /** + * Public setter for the version needed only by repository methods. + * @param version the version to set + */ + public void setVersion(Integer version) { + this.version = version; + } /** - * + * Increment the version number */ public void incrementVersion() { if (version == null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java index 90b4e8f8b..9b411f889 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java @@ -20,6 +20,7 @@ import java.util.Set; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; +import org.springframework.batch.core.StepExecution; /** * @author Dave Syer @@ -35,11 +36,18 @@ public interface JobExplorer { List getLastJobInstances(String jobName, int count); /** - * @param executionId + * @param executionId the job execution id * @return the {@link JobExecution} with this id, or null if not found */ JobExecution getJobExecution(Long executionId); + /** + * @param jobExecutionId the parent job execution id + * @param stepName the step name identifier for the required {@link StepExecution} + * @return the {@link StepExecution} with this id, or null if not found + */ + StepExecution getStepExecution(Long jobExecutionId, String stepName); + /** * @param instanceId * @return the {@link JobInstance} with this id, or null diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java index c480d6e51..a7fb940d0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java @@ -21,6 +21,7 @@ import java.util.Set; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; +import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.core.repository.dao.JobExecutionDao; import org.springframework.batch.core.repository.dao.JobInstanceDao; @@ -93,6 +94,14 @@ public class SimpleJobExplorer implements JobExplorer { getJobExecutionDependencies(jobExecution); return jobExecution; } + + /* (non-Javadoc) + * @see org.springframework.batch.core.explore.JobExplorer#getStepExecution(java.lang.Long) + */ + public StepExecution getStepExecution(Long executionId, String stepName) { + JobExecution jobExecution = jobExecutionDao.getJobExecution(executionId); + return stepExecutionDao.getStepExecution(jobExecution, stepName); + } /* (non-Javadoc) * @see org.springframework.batch.core.explore.JobExplorer#getJobInstance(java.lang.Long) 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 e6637ab27..bdd8890e6 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 @@ -50,7 +50,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement + " where STEP_EXECUTION_ID = ? and VERSION = ?"; private static final String GET_RAW_STEP_EXECUTIONS = "SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT," - + " READ_COUNT, FILTER_COUNT, WRITE_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED from %PREFIX%STEP_EXECUTION where JOB_EXECUTION_ID = ?"; + + " READ_COUNT, FILTER_COUNT, WRITE_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from %PREFIX%STEP_EXECUTION where JOB_EXECUTION_ID = ?"; private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS + " order by STEP_EXECUTION_ID"; @@ -243,6 +243,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement stepExecution.setProcessSkipCount(rs.getInt(15)); stepExecution.setRollbackCount(rs.getInt(16)); stepExecution.setLastUpdated(rs.getTimestamp(17)); + stepExecution.setVersion(rs.getInt(18)); return stepExecution; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java index 68aa55b23..8e1406cc0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java @@ -72,6 +72,15 @@ public class SimpleJobExplorerTests extends TestCase { verify(jobExecutionDao, jobInstanceDao, stepExecutionDao); } + @Test + public void testGetStepExecution() throws Exception { + expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); + expect(stepExecutionDao.getStepExecution(jobExecution, "foo")).andReturn(null); + replay(jobExecutionDao, stepExecutionDao); + jobExplorer.getStepExecution(123L,"foo"); + verify(jobExecutionDao, stepExecutionDao); + } + @Test public void testFindRunningJobExecutions() throws Exception { expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn(Collections.singleton(jobExecution)); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java index 88e38a66a..fb38e56c3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java @@ -88,7 +88,7 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona } @Transactional @Test - public void testSaveAndFindExecution() { + public void testSaveAndGetExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7); @@ -104,12 +104,13 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona StepExecution retrieved = dao.getStepExecution(jobExecution, step.getName()); assertStepExecutionsAreEqual(stepExecution, retrieved); + assertNotNull(retrieved.getVersion()); assertNull(dao.getStepExecution(jobExecution, "not-existing step")); } @Transactional @Test - public void testSaveAndGetExecution() { + public void testSaveAndFindExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7);