From 2edd4006d2858fb5055c251c85bab2980a5e2192 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Tue, 8 Nov 2022 21:57:10 +0100 Subject: [PATCH] Change the return type of counting methods in various DAOs from int to long This is required for job repository/explorer implementations that use the Long type to count records in the database. Resolves #4227 --- .../org/springframework/batch/core/explore/JobExplorer.java | 2 +- .../batch/core/explore/support/SimpleJobExplorer.java | 2 +- .../springframework/batch/core/job/flow/JobFlowExecutor.java | 4 ++-- .../springframework/batch/core/repository/JobRepository.java | 2 +- .../batch/core/repository/dao/JdbcJobInstanceDao.java | 4 ++-- .../batch/core/repository/dao/JdbcStepExecutionDao.java | 4 ++-- .../batch/core/repository/dao/JobInstanceDao.java | 2 +- .../batch/core/repository/dao/StepExecutionDao.java | 2 +- .../batch/core/repository/support/SimpleJobRepository.java | 2 +- .../batch/core/configuration/xml/DummyJobRepository.java | 4 ++-- .../xml/TaskletStepAllowStartIfCompleteTests.java | 2 +- .../batch/core/explore/support/SimpleJobExplorerTests.java | 2 +- .../batch/core/launch/support/CommandLineJobRunnerTests.java | 4 ++-- .../batch/core/repository/dao/JdbcStepExecutionDaoTests.java | 2 +- .../core/repository/support/SimpleJobRepositoryTests.java | 4 ++-- .../springframework/batch/core/step/JobRepositorySupport.java | 4 ++-- .../batch/core/step/item/TaskletStepExceptionTests.java | 2 +- .../batch/integration/JobRepositorySupport.java | 4 ++-- 18 files changed, 26 insertions(+), 26 deletions(-) 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 e1dc101eb..4077a4ccb 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 @@ -153,6 +153,6 @@ public interface JobExplorer { * @throws NoSuchJobException thrown when there is no {@link JobInstance} for the * jobName specified. */ - int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException; + long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException; } 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 76d400de3..7893acf42 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 @@ -226,7 +226,7 @@ public class SimpleJobExplorer implements JobExplorer { * String) */ @Override - public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { + public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { return jobInstanceDao.getJobInstanceCount(jobName); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java index e9d8fecb3..982704057 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public class JobFlowExecutor implements FlowExecutor { } private boolean isStepRestart(Step step) { - int count = jobRepository.getStepExecutionCount(execution.getJobInstance(), step.getName()); + long count = jobRepository.getStepExecutionCount(execution.getJobInstance(), step.getName()); return count > 0; } 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 6242116f9..14d8695b5 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 @@ -199,7 +199,7 @@ public interface JobRepository { * @param stepName the name of the step execution that might have run. * @return the execution count of the step within the given job instance. */ - int getStepExecutionCount(JobInstance jobInstance, String stepName); + long getStepExecutionCount(JobInstance jobInstance, String stepName); /** * @param jobName the name of the job that might have run diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index 8e13c9c7c..79aa8e66e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -268,10 +268,10 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements * java.lang.String) */ @Override - public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { + public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { try { - return getJdbcTemplate().queryForObject(getQuery(COUNT_JOBS_WITH_NAME), Integer.class, jobName); + return getJdbcTemplate().queryForObject(getQuery(COUNT_JOBS_WITH_NAME), Long.class, jobName); } catch (EmptyResultDataAccessException e) { throw new NoSuchJobException("No job instances were found for job name " + jobName); 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 04bdaad7d..66bab0fad 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 @@ -358,8 +358,8 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement } @Override - public int countStepExecutions(JobInstance jobInstance, String stepName) { - return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), Integer.class, + public long countStepExecutions(JobInstance jobInstance, String stepName) { + return getJdbcTemplate().queryForObject(getQuery(COUNT_STEP_EXECUTIONS), Long.class, jobInstance.getInstanceId(), stepName); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java index 4c3989947..074e4a187 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java @@ -128,7 +128,7 @@ public interface JobInstanceDao { * repository * @throws NoSuchJobException thrown if no Job has the jobName specified. */ - int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException; + long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException; /** * Delete the job instance. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java index 1dd127e4c..88358521b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java @@ -87,7 +87,7 @@ public interface StepExecutionDao { * @since 4.3 * @return the count of {@link StepExecution}s for a given step */ - default int countStepExecutions(JobInstance jobInstance, String stepName) { + default long countStepExecutions(JobInstance jobInstance, String stepName) { throw new UnsupportedOperationException(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index 9556efac8..a8f81a240 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -242,7 +242,7 @@ public class SimpleJobRepository implements JobRepository { * @return number of executions of the step within given job instance */ @Override - public int getStepExecutionCount(JobInstance jobInstance, String stepName) { + public long getStepExecutionCount(JobInstance jobInstance, String stepName) { return stepExecutionDao.countStepExecutions(jobInstance, stepName); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java index a2f9cfa2d..290fd59f6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/DummyJobRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,7 +70,7 @@ public class DummyJobRepository implements JobRepository, BeanNameAware { } @Override - public int getStepExecutionCount(JobInstance jobInstance, String stepName) { + public long getStepExecutionCount(JobInstance jobInstance, String stepName) { return 0; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests.java index f08f16962..11823defd 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/TaskletStepAllowStartIfCompleteTests.java @@ -63,7 +63,7 @@ class TaskletStepAllowStartIfCompleteTests { jobExecution = jobRepository.createJobExecution(job.getName(), paramBuilder.toJobParameters()); job.execute(jobExecution); - int count = jobRepository.getStepExecutionCount(jobExecution.getJobInstance(), "simpleJob.step1"); + long count = jobRepository.getStepExecutionCount(jobExecution.getJobInstance(), "simpleJob.step1"); assertEquals(2, count); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java index cfecd2606..9844cca56 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java @@ -171,7 +171,7 @@ class SimpleJobExplorerTests { @Test void testGetJobInstanceCount() throws Exception { - when(jobInstanceDao.getJobInstanceCount("myJob")).thenReturn(4); + when(jobInstanceDao.getJobInstanceCount("myJob")).thenReturn(4L); assertEquals(4, jobExplorer.getJobInstanceCount("myJob")); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java index e26e24616..0ebb60aaa 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java @@ -554,8 +554,8 @@ class CommandLineJobRunnerTests { } @Override - public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { - int count = 0; + public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { + long count = 0; for (JobInstance jobInstance : jobInstances) { if (jobInstance.getJobName().equals(jobName)) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java index 4f790a218..36123929e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java @@ -81,7 +81,7 @@ class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests { dao.saveStepExecution(stepExecution); // When - int result = dao.countStepExecutions(jobInstance, stepExecution.getStepName()); + long result = dao.countStepExecutions(jobInstance, stepExecution.getStepName()); // Then assertEquals(1, result); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java index b92c1cd81..bb785f757 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java @@ -277,11 +277,11 @@ class SimpleJobRepositoryTests { @Test void testGetStepExecutionCount() { // Given - int expectedResult = 1; + long expectedResult = 1; when(stepExecutionDao.countStepExecutions(jobInstance, "stepName")).thenReturn(expectedResult); // When - int actualResult = jobRepository.getStepExecutionCount(jobInstance, "stepName"); + long actualResult = jobRepository.getStepExecutionCount(jobInstance, "stepName"); // Then assertEquals(expectedResult, actualResult); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/JobRepositorySupport.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/JobRepositorySupport.java index a2c6bbcea..6209ebe46 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/JobRepositorySupport.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/JobRepositorySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ public class JobRepositorySupport implements JobRepository { } @Override - public int getStepExecutionCount(JobInstance jobInstance, String stepName) { + public long getStepExecutionCount(JobInstance jobInstance, String stepName) { return 0; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java index 44da78b2a..455254800 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/TaskletStepExceptionTests.java @@ -527,7 +527,7 @@ class TaskletStepExceptionTests { } @Override - public int getStepExecutionCount(JobInstance jobInstance, String stepName) { + public long getStepExecutionCount(JobInstance jobInstance, String stepName) { return 0; } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java index 30d2be884..2e23bb5a0 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/JobRepositorySupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ public class JobRepositorySupport implements JobRepository { * org.springframework.batch.core.repository.JobRepository#getStepExecutionCount(org. * springframework.batch.core.JobInstance, org.springframework.batch.core.Step) */ - public int getStepExecutionCount(JobInstance jobInstance, String stepName) { + public long getStepExecutionCount(JobInstance jobInstance, String stepName) { return 0; }