Skip to content

Commit 74e8caa

Browse files
committed
Add default methods in Job and Step interfaces
Default values are consistent with AbstractJob and AbstractStep. Issue #3924
1 parent 9f4424f commit 74e8caa

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/Job.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.batch.core;
1717

18+
import org.springframework.batch.core.job.DefaultJobParametersValidator;
1819
import org.springframework.lang.Nullable;
1920

2021
/**
@@ -33,9 +34,11 @@ public interface Job {
3334
/**
3435
* Flag to indicate if this job can be restarted, at least in principle.
3536
*
36-
* @return true if this job can be restarted after a failure
37+
* @return true if this job can be restarted after a failure. Defaults to {@code true}.
3738
*/
38-
boolean isRestartable();
39+
default boolean isRestartable() {
40+
return true;
41+
}
3942

4043
/**
4144
* Run the {@link JobExecution} and update the meta information, such as status
@@ -52,19 +55,23 @@ public interface Job {
5255
* sequence, they can use this incrementer. The return value may be {@code null},
5356
* when this job does not have a natural sequence.
5457
*
55-
* @return in incrementer to be used for creating new parameters
58+
* @return an incrementer to be used for creating new parameters. Defaults to {@code null}.
5659
*/
5760
@Nullable
58-
JobParametersIncrementer getJobParametersIncrementer();
61+
default JobParametersIncrementer getJobParametersIncrementer() {
62+
return null;
63+
}
5964

6065
/**
6166
* A validator for the job parameters of a {@link JobExecution}. Clients of
6267
* a {@code Job} may need to validate the parameters for a launch or before or during
6368
* the execution.
6469
*
6570
* @return a validator that can be used to check parameter values (never
66-
* {@code null}).
71+
* {@code null}). Defaults to {@link DefaultJobParametersValidator}.
6772
*/
68-
JobParametersValidator getJobParametersValidator();
73+
default JobParametersValidator getJobParametersValidator() {
74+
return new DefaultJobParametersValidator();
75+
}
6976

7077
}

spring-batch-core/src/main/java/org/springframework/batch/core/Step.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* explicitly represent the configuration of a step by a developer but also the ability to execute the step.
2121
*
2222
* @author Dave Syer
23+
* @author Mahmoud Ben Hassine
2324
*
2425
*/
2526
public interface Step {
@@ -36,13 +37,19 @@ public interface Step {
3637

3738
/**
3839
* @return {@code true} if a step that is already marked as complete can be started again.
40+
* Defaults to {@code false}.
3941
*/
40-
boolean isAllowStartIfComplete();
42+
default boolean isAllowStartIfComplete() {
43+
return false;
44+
}
4145

4246
/**
43-
* @return the number of times a job can be started with the same identifier.
47+
* @return the number of times a step can be (re)started for the same job instance.
48+
* Defaults to {@code Integer.MAX_VALUE}
4449
*/
45-
int getStartLimit();
50+
default int getStartLimit() {
51+
return Integer.MAX_VALUE;
52+
}
4653

4754
/**
4855
* Process the step and assign progress and status meta information to the {@link StepExecution} provided. The

0 commit comments

Comments
 (0)