Let fluent setters of SimpleStepBuilder return proper type
Let fluent setters of `SimpleStepBuilder` return `this` with type `SimpleStepBuilder`. This makes the required order of some fluent setters a bit more lenient and prevents that `AbstractTaskletStepBuilder::listener` for parameters of type `Object` is invoked although an overloaded method specific for `SimpleStepBuilder` is intended. Fixes #773 and #1098.
This commit is contained in:
committed by
Fadhel Mahmoud Ben Hassine
parent
8fef41bd76
commit
d280556d02
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -51,8 +51,7 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
* @since 2.2
|
||||
* @param <B> the type of builder represented
|
||||
*/
|
||||
public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBuilder<B>>
|
||||
extends StepBuilderHelper<AbstractTaskletStepBuilder<B>> {
|
||||
public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBuilder<B>> extends StepBuilderHelper<B> {
|
||||
|
||||
protected Set<ChunkListener> chunkListeners = new LinkedHashSet<>();
|
||||
|
||||
@@ -137,9 +136,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param listener the listener to register
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> listener(ChunkListener listener) {
|
||||
public B listener(ChunkListener listener) {
|
||||
chunkListeners.add(listener);
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,9 +161,7 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
this.listener((ChunkListener) factory.getObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,9 +169,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param stream the stream to register
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> stream(ItemStream stream) {
|
||||
public B stream(ItemStream stream) {
|
||||
streams.add(stream);
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,9 +180,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param taskExecutor the task executor to register
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> taskExecutor(TaskExecutor taskExecutor) {
|
||||
public B taskExecutor(TaskExecutor taskExecutor) {
|
||||
this.taskExecutor = taskExecutor;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,9 +193,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param throttleLimit maximum number of concurrent tasklet executions allowed
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> throttleLimit(int throttleLimit) {
|
||||
public B throttleLimit(int throttleLimit) {
|
||||
this.throttleLimit = throttleLimit;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,9 +204,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param exceptionHandler the exception handler
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> exceptionHandler(ExceptionHandler exceptionHandler) {
|
||||
public B exceptionHandler(ExceptionHandler exceptionHandler) {
|
||||
this.exceptionHandler = exceptionHandler;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,9 +215,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param repeatTemplate a repeat template with rules for iterating
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> stepOperations(RepeatOperations repeatTemplate) {
|
||||
public B stepOperations(RepeatOperations repeatTemplate) {
|
||||
this.stepOperations = repeatTemplate;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,9 +227,9 @@ public abstract class AbstractTaskletStepBuilder<B extends AbstractTaskletStepBu
|
||||
* @param transactionAttribute a transaction attribute set
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
public AbstractTaskletStepBuilder<B> transactionAttribute(TransactionAttribute transactionAttribute) {
|
||||
public B transactionAttribute(TransactionAttribute transactionAttribute) {
|
||||
this.transactionAttribute = transactionAttribute;
|
||||
return this;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,8 +224,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTaskletStepBuilder<SimpleStepBuilder<I, O>> transactionAttribute(
|
||||
TransactionAttribute transactionAttribute) {
|
||||
public SimpleStepBuilder<I, O> transactionAttribute(TransactionAttribute transactionAttribute) {
|
||||
return super.transactionAttribute(getTransactionAttribute(transactionAttribute));
|
||||
}
|
||||
|
||||
@@ -394,7 +393,7 @@ public class FaultTolerantStepBuilder<I, O> extends SimpleStepBuilder<I, O> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTaskletStepBuilder<SimpleStepBuilder<I, O>> stream(ItemStream stream) {
|
||||
public SimpleStepBuilder<I, O> stream(ItemStream stream) {
|
||||
if (stream instanceof ItemReader<?>) {
|
||||
if (!streamIsReader) {
|
||||
streamIsReader = true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2011 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -69,4 +69,9 @@ public class FlowStepBuilder extends StepBuilderHelper<FlowStepBuilder> {
|
||||
return step;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FlowStepBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2011 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -114,4 +114,9 @@ public class JobStepBuilder extends StepBuilderHelper<JobStepBuilder> {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JobStepBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2021 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -222,6 +222,11 @@ public class PartitionStepBuilder extends StepBuilderHelper<PartitionStepBuilder
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PartitionStepBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected TaskExecutor getTaskExecutor() {
|
||||
return taskExecutor;
|
||||
}
|
||||
|
||||
@@ -246,7 +246,6 @@ public class SimpleStepBuilder<I, O> extends AbstractTaskletStepBuilder<SimpleSt
|
||||
* @param listener the object that has a method configured with listener annotation
|
||||
* @return this for fluent chaining
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public SimpleStepBuilder<I, O> listener(Object listener) {
|
||||
super.listener(listener);
|
||||
@@ -268,9 +267,7 @@ public class SimpleStepBuilder<I, O> extends AbstractTaskletStepBuilder<SimpleSt
|
||||
itemListeners.add((StepListener) factory.getObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
SimpleStepBuilder<I, O> result = this;
|
||||
return result;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,6 +312,11 @@ public class SimpleStepBuilder<I, O> extends AbstractTaskletStepBuilder<SimpleSt
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleStepBuilder<I, O> self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected RepeatOperations createChunkOperations() {
|
||||
RepeatOperations repeatOperations = chunkOperations;
|
||||
if (repeatOperations == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -124,4 +124,9 @@ public class StepBuilder extends StepBuilderHelper<StepBuilder> {
|
||||
return new FlowStepBuilder(this).flow(flow);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StepBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2014 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -64,23 +64,17 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
|
||||
public B repository(JobRepository jobRepository) {
|
||||
properties.jobRepository = jobRepository;
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B transactionManager(PlatformTransactionManager transactionManager) {
|
||||
properties.transactionManager = transactionManager;
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B startLimit(int startLimit) {
|
||||
properties.startLimit = startLimit;
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,25 +93,21 @@ public abstract class StepBuilderHelper<B extends StepBuilderHelper<B>> {
|
||||
properties.addStepExecutionListener((StepExecutionListener) factory.getObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B listener(StepExecutionListener listener) {
|
||||
properties.addStepExecutionListener(listener);
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
public B allowStartIfComplete(boolean allowStartIfComplete) {
|
||||
properties.allowStartIfComplete = allowStartIfComplete;
|
||||
@SuppressWarnings("unchecked")
|
||||
B result = (B) this;
|
||||
return result;
|
||||
return self();
|
||||
}
|
||||
|
||||
protected abstract B self();
|
||||
|
||||
protected String getName() {
|
||||
return properties.name;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2011 the original author or authors.
|
||||
* Copyright 2006-2022 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.
|
||||
@@ -45,6 +45,11 @@ public class TaskletStepBuilder extends AbstractTaskletStepBuilder<TaskletStepBu
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskletStepBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Tasklet createTasklet() {
|
||||
return tasklet;
|
||||
|
||||
Reference in New Issue
Block a user