From d173f0c022ea92986b60f7200e4bb4befaf700c7 Mon Sep 17 00:00:00 2001 From: dsyer Date: Mon, 28 Jan 2008 13:17:56 +0000 Subject: [PATCH] Resolved some TODOs. Changed signature of StepDao to use entity instead of ID. --- .../execution/repository/SimpleJobRepository.java | 2 +- .../batch/execution/repository/dao/JdbcStepDao.java | 4 ++-- .../batch/execution/repository/dao/MapStepDao.java | 4 ++-- .../batch/execution/repository/dao/StepDao.java | 7 +++---- .../batch/execution/repository/MockStepDao.java | 2 +- .../repository/SimpleJobRepositoryTests.java | 12 ++++++------ .../repository/dao/AbstractStepDaoTests.java | 6 +++--- .../execution/repository/dao/MapStepDaoTests.java | 6 +++--- .../repeat/support/TaskExecutorRepeatTemplate.java | 1 - 9 files changed, 21 insertions(+), 23 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 08b701a06..e76499b54 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 @@ -322,7 +322,7 @@ public class SimpleJobRepository implements JobRepository { StepInstance step = stepDao.findStep(job, stepConfiguration.getName()); if (step != null) { - step.setStepExecutionCount(stepDao.getStepExecutionCount(step.getId())); + step.setStepExecutionCount(stepDao.getStepExecutionCount(step)); // Ensure valid restart data is being returned. if (step.getRestartData() == null || step.getRestartData().getProperties() == null) { step.setRestartData(new GenericRestartData(new Properties())); diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java index 8ffe84485..88e91415b 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java @@ -276,9 +276,9 @@ public class JdbcStepDao implements StepDao, InitializingBean { return getQuery(SAVE_STEP_EXECUTION); } - public int getStepExecutionCount(Long stepId) { + public int getStepExecutionCount(StepInstance step) { - Object[] parameters = new Object[] { stepId }; + Object[] parameters = new Object[] { step.getId() }; return jdbcTemplate.queryForInt(getStepExecutionCountQuery(), parameters); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java index 04217b44f..46026df6b 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java @@ -84,8 +84,8 @@ public class MapStepDao implements StepDao { return (RestartData) restartsById.get(stepId); } - public int getStepExecutionCount(Long jobId) { - Set executions = (Set) executionsById.get(jobId); + public int getStepExecutionCount(StepInstance stepInstance) { + Set executions = (Set) executionsById.get(stepInstance.getId()); if (executions==null) return 0; return executions.size(); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java index 9c49cf6d7..2f3b296f8 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java @@ -90,11 +90,10 @@ public interface StepDao { /** * Return the count of StepExecutions with the given StepId. * - * @param stepId - * @return the number of step executions for this step TODO: change - * signature to search by {@link StepInstance} + * @param step + * @return the number of step executions for this step */ - public int getStepExecutionCount(Long stepId); + public int getStepExecutionCount(StepInstance step); /** * Return all StepExecutions for the given step. diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java index 218fedf11..c0acbf601 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java @@ -50,7 +50,7 @@ public class MockStepDao implements StepDao { return null; } - public int getStepExecutionCount(Long stepId) { + public int getStepExecutionCount(StepInstance step) { return 1; } 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 64bb9a5d3..821bac1a6 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 @@ -161,11 +161,11 @@ public class SimpleJobRepositoryTests extends TestCase { jobDaoControl.setReturnValue(jobs); stepDao.findStep(databaseJob, "TestStep1"); stepDaoControl.setReturnValue(databaseStep1); - stepDao.getStepExecutionCount(databaseStep1.getId()); + stepDao.getStepExecutionCount(databaseStep1); stepDaoControl.setReturnValue(1); stepDao.findStep(databaseJob, "TestStep2"); stepDaoControl.setReturnValue(databaseStep2); - stepDao.getStepExecutionCount(databaseStep2.getId()); + stepDao.getStepExecutionCount(databaseStep2); stepDaoControl.setReturnValue(1); stepDaoControl.replay(); jobDao.getJobExecutionCount(databaseJob.getId()); @@ -233,11 +233,11 @@ public class SimpleJobRepositoryTests extends TestCase { jobDaoControl.setReturnValue(jobs); stepDao.findStep(databaseJob, "TestStep1"); stepDaoControl.setReturnValue(databaseStep1); - stepDao.getStepExecutionCount(databaseStep1.getId()); + stepDao.getStepExecutionCount(databaseStep1); stepDaoControl.setReturnValue(1); stepDao.findStep(databaseJob, "TestStep2"); stepDaoControl.setReturnValue(databaseStep2); - stepDao.getStepExecutionCount(databaseStep2.getId()); + stepDao.getStepExecutionCount(databaseStep2); stepDaoControl.setReturnValue(1); stepDaoControl.replay(); jobDao.getJobExecutionCount(databaseJob.getId()); @@ -441,12 +441,12 @@ public class SimpleJobRepositoryTests extends TestCase { stepDao.findStep(databaseJob, "TestStep1"); databaseStep1.setRestartData(null); stepDaoControl.setReturnValue(databaseStep1); - stepDao.getStepExecutionCount(databaseStep1.getId()); + stepDao.getStepExecutionCount(databaseStep1); stepDaoControl.setReturnValue(1); stepDao.findStep(databaseJob, "TestStep2"); databaseStep2.setRestartData(new GenericRestartData(null)); stepDaoControl.setReturnValue(databaseStep2); - stepDao.getStepExecutionCount(databaseStep2.getId()); + stepDao.getStepExecutionCount(databaseStep2); stepDaoControl.setReturnValue(1); stepDaoControl.replay(); jobDao.getJobExecutionCount(databaseJob.getId()); 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 b58d4d569..d98f7b26f 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 @@ -207,16 +207,16 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour public void testGetStepExecutionCountForNoExecutions(){ - int executionCount = stepDao.getStepExecutionCount(step2.getId()); + int executionCount = stepDao.getStepExecutionCount(step2); assertEquals(executionCount, 0); } public void testIncrementStepExecutionCount(){ - assertEquals(1, stepDao.getStepExecutionCount(step1.getId())); + assertEquals(1, stepDao.getStepExecutionCount(step1)); StepExecution execution = new StepExecution(step1, new JobExecution(step1.getJobInstance(), new Long(123)), null); stepDao.save(execution); - assertEquals(2, stepDao.getStepExecutionCount(step1.getId())); + assertEquals(2, stepDao.getStepExecutionCount(step1)); } public void testUpdateStepExecutionVersion() throws Exception { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java index 0b46d89fa..753bc010a 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java @@ -85,7 +85,7 @@ public class MapStepDaoTests extends TestCase { } public void testNoExecutionsForNew() throws Exception { - assertEquals(0, dao.getStepExecutionCount(step.getId())); + assertEquals(0, dao.getStepExecutionCount(step)); } public void testSaveExecutionUpdatesId() throws Exception { @@ -97,13 +97,13 @@ public class MapStepDaoTests extends TestCase { public void testCorrectExecutionCountForExisting() throws Exception { dao.save(new StepExecution(step, null, null)); - assertEquals(1, dao.getStepExecutionCount(step.getId())); + assertEquals(1, dao.getStepExecutionCount(step)); } public void testOnlyOneExecutionPerStep() throws Exception { dao.save(new StepExecution(step, null, null)); dao.save(new StepExecution(step, null, null)); - assertEquals(2, dao.getStepExecutionCount(step.getId())); + assertEquals(2, dao.getStepExecutionCount(step)); } public void testSaveRestartData() throws Exception { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java index 1518e973c..055c516cc 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplate.java @@ -160,7 +160,6 @@ public class TaskExecutorRepeatTemplate extends RepeatTemplate { try { value = future.getResult(); } catch (InterruptedException e) { - // TODO: cancel batch? Thread.currentThread().interrupt(); value = e; }