From 234e28a1e8bfe257e0789fd15b5f2ad514be75aa Mon Sep 17 00:00:00 2001 From: Henning Poettker Date: Fri, 29 Apr 2022 13:27:03 +0200 Subject: [PATCH] Allow lambdas to be passed as item processors Resolves #4061 --- .../core/step/builder/SimpleStepBuilder.java | 24 +------------------ .../core/step/builder/StepBuilderTests.java | 5 ++-- .../FaultTolerantStepIntegrationTests.java | 5 ++-- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java index 40aa86f21..091f22468 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/SimpleStepBuilder.java @@ -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. @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; -import java.util.function.Function; import org.springframework.batch.core.ChunkListener; import org.springframework.batch.core.ItemProcessListener; @@ -47,7 +46,6 @@ import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.function.FunctionItemProcessor; import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.RepeatOperations; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; @@ -78,8 +76,6 @@ public class SimpleStepBuilder extends AbstractTaskletStepBuilder processor; - private Function itemProcessorFunction; - private int chunkSize = 0; private RepeatOperations chunkOperations; @@ -112,7 +108,6 @@ public class SimpleStepBuilder extends AbstractTaskletStepBuilder extends AbstractTaskletStepBuilder processor(Function function) { - this.itemProcessorFunction = function; - return this; - } - /** * Sets a flag to say that the reader is transactional (usually a queue), which is to say that failed items might be * rolled back and re-presented in a subsequent transaction. Default is false, meaning that the items are read @@ -359,10 +341,6 @@ public class SimpleStepBuilder extends AbstractTaskletStepBuilder getProcessor() { - if(this.itemProcessorFunction != null) { - this.processor = new FunctionItemProcessor<>(this.itemProcessorFunction); - } - return processor; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java index 8ad0e6c91..f80dd2a02 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/builder/StepBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 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. @@ -17,7 +17,6 @@ package org.springframework.batch.core.step.builder; import java.util.Arrays; import java.util.List; -import java.util.function.Function; import org.junit.Before; import org.junit.Test; @@ -245,7 +244,7 @@ public class StepBuilderTests { .transactionManager(transactionManager) .chunk(3) .reader(reader) - .processor((Function) s -> s.toString()) + .processor(Object::toString) .writer(itemWriter) .listener(new AnnotationBasedStepExecutionListener()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java index a3f7844bb..e9f806f77 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2021 the original author or authors. + * Copyright 2010-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. @@ -70,7 +70,6 @@ public class FaultTolerantStepIntegrationTests { @Before public void setUp() { ItemReader itemReader = new ListItemReader<>(createItems()); - ItemProcessor itemProcessor = item -> item > 20 ? null : item; ItemWriter itemWriter = chunk -> { if (chunk.contains(1)) { throw new IllegalArgumentException(); @@ -80,7 +79,7 @@ public class FaultTolerantStepIntegrationTests { stepBuilder = new StepBuilderFactory(jobRepository, transactionManager).get("step") .chunk(CHUNK_SIZE) .reader(itemReader) - .processor(itemProcessor) + .processor(item -> item > 20 ? null : item) .writer(itemWriter) .faultTolerant(); }