From a547fe5b0a8c72ffbb6349485478a5c104db99e9 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Fri, 17 Feb 2023 17:11:23 +0100 Subject: [PATCH] Deprecate JobOperator#start(String, String) This method accepts job parameters as a string, which can cause parsing issues. Resolves #4304 --- .../batch/core/launch/JobOperator.java | 24 +++++++++++++++++-- .../launch/support/SimpleJobOperator.java | 17 +++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java index 8f747458d..768947859 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 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. @@ -17,6 +17,7 @@ package org.springframework.batch.core.launch; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.springframework.batch.core.Job; @@ -111,10 +112,29 @@ public interface JobOperator { * parameters already exists * @throws JobParametersInvalidException thrown if any of the job parameters are * invalid. + * @deprecated use {@link #start(String, Properties)} instead. Will be removed in + * v5.2. */ + @Deprecated(since = "5.0.1", forRemoval = true) Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException; + /** + * Start a new instance of a job with the parameters specified. + * @param jobName the name of the {@link Job} to launch + * @param parameters the parameters to launch it with + * @return the id of the {@link JobExecution} that is launched + * @throws NoSuchJobException if there is no {@link Job} with the specified name + * @throws JobInstanceAlreadyExistsException if a job instance with this name and + * parameters already exists + * @throws JobParametersInvalidException thrown if any of the job parameters are + * invalid. + */ + default Long start(String jobName, Properties parameters) + throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { + throw new UnsupportedOperationException(); + } + /** * Restart a failed or stopped {@link JobExecution}. Fails with an exception if the id * provided does not exist or corresponds to a {@link JobInstance} that in normal @@ -199,7 +219,7 @@ public interface JobOperator { /** * List the available job names that can be launched with - * {@link #start(String, String)}. + * {@link #start(String, Properties)}. * @return a set of job names */ Set getJobNames(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index b73811aa1..810568f52 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -309,14 +309,27 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { * java.lang.String) */ @Override + @Deprecated(since = "5.0.1", forRemoval = true) public Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { + Properties properties = PropertiesConverter.stringToProperties(parameters); + return start(jobName, properties); + } + + /* + * (non-Javadoc) + * + * @see org.springframework.batch.core.launch.JobOperator#start(java.lang.String, + * java.util.Properties) + */ + @Override + public Long start(String jobName, Properties parameters) + throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { if (logger.isInfoEnabled()) { logger.info("Checking status of job with name=" + jobName); } - Properties properties = PropertiesConverter.stringToProperties(parameters); - JobParameters jobParameters = jobParametersConverter.getJobParameters(properties); + JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters); if (jobRepository.isJobInstanceExists(jobName, jobParameters)) { throw new JobInstanceAlreadyExistsException(