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
This commit is contained in:
Mahmoud Ben Hassine
2022-11-08 21:57:10 +01:00
parent 919f73e78c
commit 2edd4006d2
18 changed files with 26 additions and 26 deletions

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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.

View File

@@ -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();
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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"));
}

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -527,7 +527,7 @@ class TaskletStepExceptionTests {
}
@Override
public int getStepExecutionCount(JobInstance jobInstance, String stepName) {
public long getStepExecutionCount(JobInstance jobInstance, String stepName) {
return 0;
}

View File

@@ -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;
}