Skip to content

Commit e6c0321

Browse files
committed
Deprecate JobRepository#getStepExecution(long, long)
Resolves #5007
1 parent 03497b3 commit e6c0321

File tree

8 files changed

+54
-10
lines changed

8 files changed

+54
-10
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ default JobExecution getJobExecution(long executionId) {
166166
/**
167167
* Retrieve job executions by their job instance. The corresponding step executions
168168
* may not be fully hydrated (for example, their execution context may be missing),
169-
* depending on the implementation. In that case, use
170-
* {@link #getStepExecution(long, long)} to hydrate them.
169+
* depending on the implementation. In that case, use {@link #getStepExecution(long)}
170+
* to hydrate them.
171171
* @param jobInstance The {@link JobInstance} to query.
172172
* @return the list of all executions for the specified {@link JobInstance}.
173173
*/
@@ -203,8 +203,7 @@ default JobExecution getLastJobExecution(String jobName, JobParameters jobParame
203203
/**
204204
* Retrieve running job executions. The corresponding step executions may not be fully
205205
* hydrated (for example, their execution context may be missing), depending on the
206-
* implementation. In that case, use {@link #getStepExecution(long, long)} to hydrate
207-
* them.
206+
* implementation. In that case, use {@link #getStepExecution(long)} to hydrate them.
208207
* @param jobName The name of the job.
209208
* @return the set of running executions for jobs with the specified name.
210209
*/
@@ -228,14 +227,27 @@ default Set<JobExecution> findRunningJobExecutions(@Nullable String jobName) {
228227
* @return the {@link StepExecution} that has this ID or {@code null} if not found.
229228
*
230229
* @see #getJobExecution(long)
230+
* @deprecated since 6.0 in favor of {@link #getStepExecution(long)}
231231
*/
232-
// FIXME incorrect contract: stepExecutionId is globally unique, no need for
233-
// jobExecutionId
232+
@Deprecated(since = "6.0", forRemoval = true)
234233
@Nullable
235234
default StepExecution getStepExecution(long jobExecutionId, long stepExecutionId) {
236235
throw new UnsupportedOperationException();
237236
}
238237

238+
/**
239+
* Retrieve a {@link StepExecution} by its ID. The execution context for the step
240+
* should be available in the result, and the parent job execution should have its
241+
* primitive properties, but it may not contain the job instance information.
242+
* @param stepExecutionId The step execution ID.
243+
* @return the {@link StepExecution} that has this ID or {@code null} if not found.
244+
* @since 6.0
245+
*/
246+
@Nullable
247+
default StepExecution getStepExecution(long stepExecutionId) {
248+
throw new UnsupportedOperationException();
249+
}
250+
239251
/**
240252
* @param jobInstance {@link JobInstance} instance containing the step executions.
241253
* @param stepName the name of the step execution that might have run.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
package org.springframework.batch.core.repository.dao.mongodb;
1717

1818
import java.util.ArrayList;
19-
import java.util.Collection;
2019
import java.util.Comparator;
2120
import java.util.List;
2221
import java.util.Optional;
2322

23+
import org.jspecify.annotations.Nullable;
24+
2425
import org.springframework.batch.core.job.JobExecution;
2526
import org.springframework.batch.core.job.JobInstance;
2627
import org.springframework.batch.core.step.StepExecution;
@@ -88,6 +89,8 @@ public void updateStepExecution(StepExecution stepExecution) {
8889
this.mongoOperations.findAndReplace(query, stepExecutionToUpdate, STEP_EXECUTIONS_COLLECTION_NAME);
8990
}
9091

92+
@Nullable
93+
@Override
9194
public StepExecution getStepExecution(long stepExecutionId) {
9295
Query query = query(where("stepExecutionId").is(stepExecutionId));
9396
org.springframework.batch.core.repository.persistence.StepExecution stepExecution = this.mongoOperations

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ private void getJobExecutionDependencies(JobExecution jobExecution) {
249249
* ===================================================================================
250250
*/
251251

252+
@Deprecated(since = "6.0", forRemoval = true)
252253
@Nullable
253254
@Override
254255
public StepExecution getStepExecution(long jobExecutionId, long executionId) {

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/ResourcelessJobRepository.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public StepExecution createStepExecution(String stepName, JobExecution jobExecut
201201
return stepExecution;
202202
}
203203

204+
@Deprecated(since = "6.0", forRemoval = true)
204205
@Override
205206
@Nullable
206207
public StepExecution getStepExecution(long jobExecutionId, long stepExecutionId) {
@@ -214,6 +215,25 @@ public StepExecution getStepExecution(long jobExecutionId, long stepExecutionId)
214215
.orElse(null);
215216
}
216217

218+
/**
219+
* Retrieve a {@link StepExecution} by its id.
220+
* @param stepExecutionId the id of the step execution to retrieve
221+
* @return the {@link StepExecution} with the given id if it exists, null otherwise.
222+
* @since 6.0
223+
*/
224+
@Override
225+
@Nullable
226+
public StepExecution getStepExecution(long stepExecutionId) {
227+
if (this.jobExecution == null) {
228+
return null;
229+
}
230+
return this.jobExecution.getStepExecutions()
231+
.stream()
232+
.filter(stepExecution -> stepExecution.getId() == stepExecutionId)
233+
.findFirst()
234+
.orElse(null);
235+
}
236+
217237
@Override
218238
@Nullable
219239
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.batch.core.BatchStatus;
2224
import org.springframework.batch.core.job.JobExecution;
2325
import org.springframework.batch.core.job.JobInstance;
@@ -80,6 +82,12 @@ public List<JobInstance> findJobInstances(String jobName) {
8082
return this.jobInstanceDao.getJobInstances(jobName);
8183
}
8284

85+
@Nullable
86+
@Override
87+
public StepExecution getStepExecution(long executionId) {
88+
return this.stepExecutionDao.getStepExecution(executionId);
89+
}
90+
8391
/**
8492
* Create a new {@link JobExecution} for the given {@link JobInstance} and
8593
* {@link JobParameters}, and associate the provided {@link ExecutionContext} with the

spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/StepExecutionRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class StepExecutionRequest implements Serializable {
3232

3333
private String stepName;
3434

35+
// FIXME not used on the remote side, can we remove it?
3536
private Long jobExecutionId;
3637

3738
private StepExecutionRequest() {

spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/StepExecutionRequestHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ public void setJobRepository(JobRepository jobRepository) {
4545
@ServiceActivator
4646
public StepExecution handle(StepExecutionRequest request) {
4747

48-
Long jobExecutionId = request.getJobExecutionId();
4948
Long stepExecutionId = request.getStepExecutionId();
50-
StepExecution stepExecution = jobRepository.getStepExecution(jobExecutionId, stepExecutionId);
49+
StepExecution stepExecution = jobRepository.getStepExecution(stepExecutionId);
5150
if (stepExecution == null) {
5251
throw new NoSuchStepException("No StepExecution could be located for this request: " + request);
5352
}

spring-batch-integration/src/test/java/org/springframework/batch/integration/partition/JmsIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void testLaunchJob() throws Exception {
7373
// BATCH-1703: we are using a map dao so the step executions in the job
7474
// execution are old and we need to
7575
// pull them back out of the repository...
76-
stepExecution = jobRepository.getStepExecution(jobExecution.getId(), stepExecution.getId());
76+
stepExecution = jobRepository.getStepExecution(stepExecution.getId());
7777
logger.debug(String.valueOf(stepExecution));
7878
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
7979
}

0 commit comments

Comments
 (0)