Skip to content

Commit bf53794

Browse files
committed
Deprecate redundant methods in JobExplorer/JobInstanceDao APIs
Resolves #4821
1 parent b9fc0e7 commit bf53794

File tree

5 files changed

+26
-40
lines changed

5 files changed

+26
-40
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java

+3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ public interface JobExplorer {
7676
* @param start The start index of the instances to return.
7777
* @param count The maximum number of instances to return.
7878
* @return a list of {@link JobInstance} for the requested job name.
79+
* @deprecated Since v6.0 and scheduled for removal in v6.2. Use
80+
* {@link #getJobInstances(String, int, int)}
7981
*/
82+
@Deprecated(forRemoval = true)
8083
List<JobInstance> findJobInstancesByJobName(String jobName, int start, int count);
8184

8285
/**

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,14 @@ private void getStepExecutionDependencies(StepExecution stepExecution) {
230230
}
231231
}
232232

233+
/**
234+
* @deprecated since v6.0 and scheduled for removal in v6.2. Use
235+
* {@link #getJobInstances(String, int, int)} instead.
236+
*/
237+
@Deprecated(forRemoval = true)
233238
@Override
234239
public List<JobInstance> findJobInstancesByJobName(String jobName, int start, int count) {
235-
return jobInstanceDao.findJobInstancesByName(jobName, start, count);
240+
return getJobInstances(jobName, start, count);
236241
}
237242

238243
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java

+6-25
Original file line numberDiff line numberDiff line change
@@ -332,33 +332,14 @@ public JobInstance mapRow(ResultSet rs, int rowNum) throws SQLException {
332332

333333
}
334334

335+
/**
336+
* @deprecated since v6.0 and scheduled for removal in v6.2. Use
337+
* {@link #getJobInstances(String, int, int)} instead.
338+
*/
339+
@Deprecated(forRemoval = true)
335340
@Override
336-
@SuppressWarnings({ "rawtypes", "unchecked" })
337341
public List<JobInstance> findJobInstancesByName(String jobName, final int start, final int count) {
338-
ResultSetExtractor extractor = new ResultSetExtractor() {
339-
private final List<JobInstance> list = new ArrayList<>();
340-
341-
@Override
342-
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
343-
int rowNum = 0;
344-
while (rowNum < start && rs.next()) {
345-
rowNum++;
346-
}
347-
while (rowNum < start + count && rs.next()) {
348-
RowMapper<JobInstance> rowMapper = new JobInstanceRowMapper();
349-
list.add(rowMapper.mapRow(rs, rowNum));
350-
rowNum++;
351-
}
352-
return list;
353-
}
354-
};
355-
356-
if (jobName.contains(STAR_WILDCARD)) {
357-
jobName = jobName.replaceAll("\\" + STAR_WILDCARD, SQL_WILDCARD);
358-
}
359-
360-
return (List<JobInstance>) getJdbcTemplate().query(getQuery(FIND_LAST_JOBS_LIKE_NAME), extractor, jobName);
361-
342+
return getJobInstances(jobName, start, count);
362343
}
363344

364345
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,7 +117,10 @@ default JobInstance getLastJobInstance(String jobName) {
117117
* should begin.
118118
* @param count int containing the number of job instances to return.
119119
* @return a list of {@link JobInstance} for the job name requested.
120+
* @deprecated Since v6.0 and scheduled for removal in v6.2. Use
121+
* {@link #getJobInstances(String, int, int)}
120122
*/
123+
@Deprecated(forRemoval = true)
121124
List<JobInstance> findJobInstancesByName(String jobName, int start, int count);
122125

123126
/**

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MongoJobInstanceDao.java

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 the original author or authors.
2+
* Copyright 2024-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -143,20 +143,14 @@ public List<String> getJobNames() {
143143
.toList();
144144
}
145145

146+
/**
147+
* @deprecated since v6.0 and scheduled for removal in v6.2. Use
148+
* {@link #getJobInstances(String, int, int)} instead.
149+
*/
150+
@Deprecated(forRemoval = true)
146151
@Override
147152
public List<JobInstance> findJobInstancesByName(String jobName, int start, int count) {
148-
Query query = query(where("jobName").alike(Example.of(jobName)));
149-
Sort.Order sortOrder = Sort.Order.desc("jobInstanceId");
150-
List<org.springframework.batch.core.repository.persistence.JobInstance> jobInstances = this.mongoOperations
151-
.find(query.with(Sort.by(sortOrder)),
152-
org.springframework.batch.core.repository.persistence.JobInstance.class, COLLECTION_NAME)
153-
.stream()
154-
.toList();
155-
return jobInstances.subList(start, jobInstances.size())
156-
.stream()
157-
.map(this.jobInstanceConverter::toJobInstance)
158-
.limit(count)
159-
.toList();
153+
return getJobInstances(jobName, start, count);
160154
}
161155

162156
@Override

0 commit comments

Comments
 (0)