Skip to content

Commit a547fe5

Browse files
committed
Deprecate JobOperator#start(String, String)
This method accepts job parameters as a string, which can cause parsing issues. Resolves #4304
1 parent e4efa24 commit a547fe5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 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.
@@ -17,6 +17,7 @@
1717

1818
import java.util.List;
1919
import java.util.Map;
20+
import java.util.Properties;
2021
import java.util.Set;
2122

2223
import org.springframework.batch.core.Job;
@@ -111,10 +112,29 @@ default JobInstance getJobInstance(String jobName, JobParameters jobParameters)
111112
* parameters already exists
112113
* @throws JobParametersInvalidException thrown if any of the job parameters are
113114
* invalid.
115+
* @deprecated use {@link #start(String, Properties)} instead. Will be removed in
116+
* v5.2.
114117
*/
118+
@Deprecated(since = "5.0.1", forRemoval = true)
115119
Long start(String jobName, String parameters)
116120
throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException;
117121

122+
/**
123+
* Start a new instance of a job with the parameters specified.
124+
* @param jobName the name of the {@link Job} to launch
125+
* @param parameters the parameters to launch it with
126+
* @return the id of the {@link JobExecution} that is launched
127+
* @throws NoSuchJobException if there is no {@link Job} with the specified name
128+
* @throws JobInstanceAlreadyExistsException if a job instance with this name and
129+
* parameters already exists
130+
* @throws JobParametersInvalidException thrown if any of the job parameters are
131+
* invalid.
132+
*/
133+
default Long start(String jobName, Properties parameters)
134+
throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException {
135+
throw new UnsupportedOperationException();
136+
}
137+
118138
/**
119139
* Restart a failed or stopped {@link JobExecution}. Fails with an exception if the id
120140
* provided does not exist or corresponds to a {@link JobInstance} that in normal
@@ -199,7 +219,7 @@ Long startNextInstance(String jobName) throws NoSuchJobException, JobParametersN
199219

200220
/**
201221
* List the available job names that can be launched with
202-
* {@link #start(String, String)}.
222+
* {@link #start(String, Properties)}.
203223
* @return a set of job names
204224
*/
205225
Set<String> getJobNames();

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,14 +309,27 @@ public Long restart(long executionId) throws JobInstanceAlreadyCompleteException
309309
* java.lang.String)
310310
*/
311311
@Override
312+
@Deprecated(since = "5.0.1", forRemoval = true)
312313
public Long start(String jobName, String parameters)
313314
throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException {
315+
Properties properties = PropertiesConverter.stringToProperties(parameters);
316+
return start(jobName, properties);
317+
}
318+
319+
/*
320+
* (non-Javadoc)
321+
*
322+
* @see org.springframework.batch.core.launch.JobOperator#start(java.lang.String,
323+
* java.util.Properties)
324+
*/
325+
@Override
326+
public Long start(String jobName, Properties parameters)
327+
throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException {
314328
if (logger.isInfoEnabled()) {
315329
logger.info("Checking status of job with name=" + jobName);
316330
}
317331

318-
Properties properties = PropertiesConverter.stringToProperties(parameters);
319-
JobParameters jobParameters = jobParametersConverter.getJobParameters(properties);
332+
JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters);
320333

321334
if (jobRepository.isJobInstanceExists(jobName, jobParameters)) {
322335
throw new JobInstanceAlreadyExistsException(

0 commit comments

Comments
 (0)