From 600c68aa0271d216d2e818968197f9256de5756d Mon Sep 17 00:00:00 2001 From: robokaso Date: Thu, 14 Feb 2008 14:52:35 +0000 Subject: [PATCH] IN PROGRESS - issue BATCH-340: Refactor JobRepository for greater clarity and consistency. http://jira.springframework.org/browse/BATCH-340 JdbcStepExecutionDao no longer has JobExecutionDao dependency - repository coordinates the daos now --- .../repository/SimpleJobRepository.java | 4 ++++ .../repository/dao/JdbcStepExecutionDao.java | 17 ----------------- .../repository/SimpleJobRepositoryTests.java | 2 +- .../repository/dao/AbstractStepDaoTests.java | 7 +++++++ .../repository/dao/JdbcStepDaoPrefixTests.java | 1 - .../execution/repository/dao/sql-dao-test.xml | 1 - .../resources/simple-container-definition.xml | 1 - 7 files changed, 12 insertions(+), 21 deletions(-) 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 b938eed6a..4e93e67bf 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 @@ -259,6 +259,10 @@ public class SimpleJobRepository implements JobRepository { if (stepExecution.getId() == null) { // new execution, obtain id and insert + JobExecution jobExecution = stepExecution.getJobExecution(); + if (jobExecution.getId() == null) { + jobExecutionDao.saveJobExecution(jobExecution); + } stepExecutionDao.saveStepExecution(stepExecution); stepExecutionDao.saveExecutionAttributes(stepExecution.getId(), stepExecution.getExecutionAttributes()); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java index 81ea2d30c..5a1138eaa 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java @@ -96,8 +96,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao private DataFieldMaxValueIncrementer stepExecutionIncrementer; - private JobExecutionDao jobExecutionDao; - public ExecutionAttributes findExecutionAttributes(final Long executionId) { Assert.notNull(executionId, "ExecutionId must not be null."); @@ -281,8 +279,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao validateStepExecution(stepExecution); - cascadeJobExecution(stepExecution.getJobExecution()); - stepExecution.setId(new Long(stepExecutionIncrementer.nextLongValue())); stepExecution.incrementVersion(); // should be 0 now Object[] parameters = new Object[] { stepExecution.getId(), stepExecution.getVersion(), @@ -297,14 +293,6 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao Types.INTEGER, Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR }); } - private void cascadeJobExecution(JobExecution jobExecution) { - if (jobExecution.getId() != null) { - // assume already saved... - return; - } - jobExecutionDao.saveJobExecution(jobExecution); - } - /** * Validate StepExecution. At a minimum, JobId, StartTime, and Status cannot * be null. EndTime can be null for an unfinished job. @@ -478,13 +466,8 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao this.stepExecutionIncrementer = stepExecutionIncrementer; } - public void setJobExecutionDao(JobExecutionDao jobExecutionDao) { - this.jobExecutionDao = jobExecutionDao; - } - public void afterPropertiesSet() throws Exception { Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer cannot be null."); - Assert.notNull(jobExecutionDao, "JobDao cannot be null"); } public static class AttributeType { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index ed4cfab33..5f6c11c7f 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -369,7 +369,7 @@ public class SimpleJobRepositoryTests extends TestCase { } public void testSaveExistingStepExecution() { - StepExecution stepExecution = new StepExecution(new StepInstance(new Long(10L)), null, null); + StepExecution stepExecution = new StepExecution(new StepInstance(new Long(10L)), new JobExecution(null), null); ExecutionAttributes executionAttributes = new ExecutionAttributes(); stepExecution.setExecutionAttributes(executionAttributes); stepDao.saveStepExecution(stepExecution); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java index 1fbcb4177..f40950638 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java @@ -49,6 +49,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour protected StepInstanceDao stepInstanceDao; protected StepExecutionDao stepExecutionDao; + + protected JobExecutionDao jobExecutionDao; protected JobInstance jobInstance; @@ -76,6 +78,10 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour this.stepExecutionDao = stepExecutionDao; } + public void setJobExecutionDao(JobExecutionDao jobExecutionDao) { + this.jobExecutionDao = jobExecutionDao; + } + /* * (non-Javadoc) * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigLocations() @@ -94,6 +100,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour step1 = stepInstanceDao.createStepInstance(jobInstance, "TestStep1"); step2 = stepInstanceDao.createStepInstance(jobInstance, "TestStep2"); jobExecution = new JobExecution(step2.getJobInstance()); + jobExecutionDao.saveJobExecution(jobExecution); stepExecution = new StepExecution(step1, jobExecution, null); stepExecution.setStatus(BatchStatus.STARTED); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java index 73c9daa11..aafe6ced7 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/JdbcStepDaoPrefixTests.java @@ -46,7 +46,6 @@ public class JdbcStepDaoPrefixTests extends TestCase { stepInstanceDao = new JdbcStepInstanceDao(); stepExecutionDao = new JdbcStepExecutionDao(); - stepExecutionDao.setJobExecutionDao(new MapJobDao()); stepExecutionIncrementer = (DataFieldMaxValueIncrementer)stepExecutionIncrementerControl.getMock(); stepIncrementer = (DataFieldMaxValueIncrementer)stepIncrementerControl.getMock(); diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml index 53f76ec9a..6dcc97db1 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml @@ -23,7 +23,6 @@ - diff --git a/spring-batch-samples/src/main/resources/simple-container-definition.xml b/spring-batch-samples/src/main/resources/simple-container-definition.xml index f0471f3ba..6e73bd522 100644 --- a/spring-batch-samples/src/main/resources/simple-container-definition.xml +++ b/spring-batch-samples/src/main/resources/simple-container-definition.xml @@ -73,7 +73,6 @@ class="org.springframework.batch.execution.repository.dao.JdbcStepExecutionDao"> -