From 74e8caa36836262661db2e270850a9381c8ca542 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Mon, 9 May 2022 10:29:57 +0200 Subject: [PATCH] Add default methods in Job and Step interfaces Default values are consistent with AbstractJob and AbstractStep. Issue #3924 --- .../org/springframework/batch/core/Job.java | 19 +++++++++++++------ .../org/springframework/batch/core/Step.java | 13 ++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/Job.java b/spring-batch-core/src/main/java/org/springframework/batch/core/Job.java index 1a65a1a213..66533ba714 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/Job.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/Job.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core; +import org.springframework.batch.core.job.DefaultJobParametersValidator; import org.springframework.lang.Nullable; /** @@ -33,9 +34,11 @@ public interface Job { /** * Flag to indicate if this job can be restarted, at least in principle. * - * @return true if this job can be restarted after a failure + * @return true if this job can be restarted after a failure. Defaults to {@code true}. */ - boolean isRestartable(); + default boolean isRestartable() { + return true; + } /** * Run the {@link JobExecution} and update the meta information, such as status @@ -52,10 +55,12 @@ public interface Job { * sequence, they can use this incrementer. The return value may be {@code null}, * when this job does not have a natural sequence. * - * @return in incrementer to be used for creating new parameters + * @return an incrementer to be used for creating new parameters. Defaults to {@code null}. */ @Nullable - JobParametersIncrementer getJobParametersIncrementer(); + default JobParametersIncrementer getJobParametersIncrementer() { + return null; + } /** * A validator for the job parameters of a {@link JobExecution}. Clients of @@ -63,8 +68,10 @@ public interface Job { * the execution. * * @return a validator that can be used to check parameter values (never - * {@code null}). + * {@code null}). Defaults to {@link DefaultJobParametersValidator}. */ - JobParametersValidator getJobParametersValidator(); + default JobParametersValidator getJobParametersValidator() { + return new DefaultJobParametersValidator(); + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/Step.java b/spring-batch-core/src/main/java/org/springframework/batch/core/Step.java index 85f8088daa..4190b24a02 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/Step.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/Step.java @@ -20,6 +20,7 @@ * explicitly represent the configuration of a step by a developer but also the ability to execute the step. * * @author Dave Syer + * @author Mahmoud Ben Hassine * */ public interface Step { @@ -36,13 +37,19 @@ public interface Step { /** * @return {@code true} if a step that is already marked as complete can be started again. + * Defaults to {@code false}. */ - boolean isAllowStartIfComplete(); + default boolean isAllowStartIfComplete() { + return false; + } /** - * @return the number of times a job can be started with the same identifier. + * @return the number of times a step can be (re)started for the same job instance. + * Defaults to {@code Integer.MAX_VALUE} */ - int getStartLimit(); + default int getStartLimit() { + return Integer.MAX_VALUE; + } /** * Process the step and assign progress and status meta information to the {@link StepExecution} provided. The