* Listener interface for the writing of items. Implementations of this interface are
- * notified before, after, and in case of any exception thrown while writing a list of
+ * notified before, after, and in case of any exception thrown while writing a chunk of
* items.
*
*
@@ -42,19 +43,18 @@ import org.springframework.batch.item.ItemWriter;
public interface ItemWriteListener extends StepListener {
/**
- * Called before {@link ItemWriter#write(java.util.List)}
+ * Called before {@link ItemWriter#write(Chunk)}
* @param items to be written
*/
- default void beforeWrite(List extends S> items) {
+ default void beforeWrite(Chunk extends S> items) {
}
/**
- * Called after {@link ItemWriter#write(java.util.List)}. This is called before any
- * transaction is committed, and before
- * {@link ChunkListener#afterChunk(ChunkContext)}.
+ * Called after {@link ItemWriter#write(Chunk)}. This is called before any transaction
+ * is committed, and before {@link ChunkListener#afterChunk(ChunkContext)}.
* @param items written items
*/
- default void afterWrite(List extends S> items) {
+ default void afterWrite(Chunk extends S> items) {
}
/**
@@ -64,7 +64,7 @@ public interface ItemWriteListener extends StepListener {
* @param exception thrown from {@link ItemWriter}
* @param items attempted to be written.
*/
- default void onWriteError(Exception exception, List extends S> items) {
+ default void onWriteError(Exception exception, Chunk extends S> items) {
}
}
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/AfterWrite.java b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/AfterWrite.java
index 9d8bda813..8a15a1739 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/AfterWrite.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/AfterWrite.java
@@ -27,12 +27,14 @@ import org.springframework.batch.item.ItemWriter;
/**
* Marks a method to be called after an item is passed to an {@link ItemWriter}. Note that
- * this annotation takes a {@link List} because Spring Batch generally processes a group
- * of items (for the sake of efficiency).
+ * this annotation takes a {@link org.springframework.batch.item.Chunk} because Spring
+ * Batch generally processes a group of items (for the sake of efficiency).
*
- * Expected signature: void afterWrite({@link List}<? extends S> items)
+ * Expected signature: void afterWrite({@link org.springframework.batch.item.Chunk}<?
+ * extends S> items)
*
* @author Lucas Ward
+ * @author Mahmoud Ben Hassine
* @since 2.0
* @see ItemWriteListener
*/
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/BeforeWrite.java b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/BeforeWrite.java
index 7c5eb1ce8..58812a540 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/BeforeWrite.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/BeforeWrite.java
@@ -26,11 +26,13 @@ import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.item.ItemWriter;
/**
- * Marks a method to be called before an item is passed to an {@link ItemWriter}.
+ * Marks a method to be called before a chunk is passed to an {@link ItemWriter}.
*
- * Expected signature: void beforeWrite({@link List}<? extends S> items)
+ * Expected signature: void beforeWrite({@link org.springframework.batch.item.Chunk}<?
+ * extends S> items)
*
* @author Lucas Ward
+ * @author Mahmoud Ben Hassine
* @since 2.0
* @see ItemWriteListener
*/
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/OnWriteError.java b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/OnWriteError.java
index 7d8283ba0..fe71f0870 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/OnWriteError.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/annotation/OnWriteError.java
@@ -27,13 +27,14 @@ import org.springframework.batch.item.ItemWriter;
/**
* Marks a method to be called if an exception is thrown by an {@link ItemWriter}. Note
- * that this annotation takes a {@link List} because Spring Batch generally processes a
- * group of items (for the sake of efficiency).
+ * that this annotation takes a {@link org.springframework.batch.item.Chunk} because
+ * Spring Batch generally processes a group of items (for the sake of efficiency).
*
- * Expected signature: void onWriteError({@link Exception} exception, {@link List}<?
- * extends S> items)
+ * Expected signature: void onWriteError({@link Exception} exception,
+ * {@link org.springframework.batch.item.Chunk}<? extends S> items)
*
* @author Lucas Ward
+ * @author Mahmoud Ben Hassine
* @since 2.0
* @see ItemWriteListener
*/
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeItemWriteListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeItemWriteListener.java
index de28c07e6..9c00e4ae5 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeItemWriteListener.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeItemWriteListener.java
@@ -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.
@@ -19,11 +19,13 @@ import java.util.Iterator;
import java.util.List;
import org.springframework.batch.core.ItemWriteListener;
+import org.springframework.batch.item.Chunk;
import org.springframework.core.Ordered;
/**
* @author Lucas Ward
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
*
*/
public class CompositeItemWriteListener implements ItemWriteListener {
@@ -50,10 +52,10 @@ public class CompositeItemWriteListener implements ItemWriteListener {
/**
* Call the registered listeners in reverse order, respecting and prioritising those
* that implement {@link Ordered}.
- * @see ItemWriteListener#afterWrite(java.util.List)
+ * @see ItemWriteListener#afterWrite(Chunk)
*/
@Override
- public void afterWrite(List extends S> items) {
+ public void afterWrite(Chunk extends S> items) {
for (Iterator> iterator = listeners.reverse(); iterator.hasNext();) {
ItemWriteListener super S> listener = iterator.next();
listener.afterWrite(items);
@@ -63,10 +65,10 @@ public class CompositeItemWriteListener implements ItemWriteListener {
/**
* Call the registered listeners in order, respecting and prioritising those that
* implement {@link Ordered}.
- * @see ItemWriteListener#beforeWrite(List)
+ * @see ItemWriteListener#beforeWrite(Chunk)
*/
@Override
- public void beforeWrite(List extends S> items) {
+ public void beforeWrite(Chunk extends S> items) {
for (Iterator> iterator = listeners.iterator(); iterator.hasNext();) {
ItemWriteListener super S> listener = iterator.next();
listener.beforeWrite(items);
@@ -76,10 +78,10 @@ public class CompositeItemWriteListener implements ItemWriteListener {
/**
* Call the registered listeners in reverse order, respecting and prioritising those
* that implement {@link Ordered}.
- * @see ItemWriteListener#onWriteError(Exception, List)
+ * @see ItemWriteListener#onWriteError(Exception, Chunk)
*/
@Override
- public void onWriteError(Exception ex, List extends S> items) {
+ public void onWriteError(Exception ex, Chunk extends S> items) {
for (Iterator> iterator = listeners.reverse(); iterator.hasNext();) {
ItemWriteListener super S> listener = iterator.next();
listener.onWriteError(ex, items);
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java
index 90170a4a7..fe517bebe 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/MulticasterBatchListener.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.
@@ -28,6 +28,7 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemStream;
import org.springframework.lang.Nullable;
@@ -241,10 +242,10 @@ public class MulticasterBatchListener implements StepExecutionListener, Ch
}
/**
- * @see ItemWriteListener#afterWrite(List)
+ * @see ItemWriteListener#afterWrite(Chunk)
*/
@Override
- public void afterWrite(List extends S> items) {
+ public void afterWrite(Chunk extends S> items) {
try {
itemWriteListener.afterWrite(items);
}
@@ -254,10 +255,10 @@ public class MulticasterBatchListener implements StepExecutionListener, Ch
}
/**
- * @see ItemWriteListener#beforeWrite(List)
+ * @see ItemWriteListener#beforeWrite(Chunk)
*/
@Override
- public void beforeWrite(List extends S> items) {
+ public void beforeWrite(Chunk extends S> items) {
try {
itemWriteListener.beforeWrite(items);
}
@@ -267,10 +268,10 @@ public class MulticasterBatchListener implements StepExecutionListener, Ch
}
/**
- * @see ItemWriteListener#onWriteError(Exception, List)
+ * @see ItemWriteListener#onWriteError(Exception, Chunk)
*/
@Override
- public void onWriteError(Exception ex, List extends S> items) {
+ public void onWriteError(Exception ex, Chunk extends S> items) {
try {
itemWriteListener.onWriteError(ex, items);
}
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerMetaData.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerMetaData.java
index df4b988a2..4ef713a61 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerMetaData.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/StepListenerMetaData.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-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.
@@ -46,6 +46,7 @@ import org.springframework.batch.core.annotation.OnSkipInRead;
import org.springframework.batch.core.annotation.OnSkipInWrite;
import org.springframework.batch.core.annotation.OnWriteError;
import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.item.Chunk;
/**
* Enumeration for {@link StepListener} meta data, which ties together the names of
@@ -72,10 +73,10 @@ public enum StepListenerMetaData implements ListenerMetaData {
Object.class),
ON_PROCESS_ERROR("onProcessError", "on-process-error-method", OnProcessError.class, ItemProcessListener.class,
Object.class, Exception.class),
- BEFORE_WRITE("beforeWrite", "before-write-method", BeforeWrite.class, ItemWriteListener.class, List.class),
- AFTER_WRITE("afterWrite", "after-write-method", AfterWrite.class, ItemWriteListener.class, List.class),
+ BEFORE_WRITE("beforeWrite", "before-write-method", BeforeWrite.class, ItemWriteListener.class, Chunk.class),
+ AFTER_WRITE("afterWrite", "after-write-method", AfterWrite.class, ItemWriteListener.class, Chunk.class),
ON_WRITE_ERROR("onWriteError", "on-write-error-method", OnWriteError.class, ItemWriteListener.class,
- Exception.class, List.class),
+ Exception.class, Chunk.class),
ON_SKIP_IN_READ("onSkipInRead", "on-skip-in-read-method", OnSkipInRead.class, SkipListener.class, Throwable.class),
ON_SKIP_IN_PROCESS("onSkipInProcess", "on-skip-in-process-method", OnSkipInProcess.class, SkipListener.class,
Object.class, Throwable.class),
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java
index 1a7fc7d0a..fbeb0425b 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkOrientedTasklet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2019 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.
@@ -21,6 +21,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.lang.Nullable;
@@ -28,6 +29,7 @@ import org.springframework.lang.Nullable;
* A {@link Tasklet} implementing variations on read-process-write item handling.
*
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
* @param input item type
*/
public class ChunkOrientedTasklet implements Tasklet {
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProcessor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProcessor.java
index 5ca36744d..3bab818b8 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProcessor.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -17,9 +17,10 @@
package org.springframework.batch.core.step.item;
import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.item.Chunk;
/**
- * Interface defined for processing {@link Chunk}s.
+ * Interface defined for processing {@link org.springframework.batch.item.Chunk}s.
*
* @since 2.0
*/
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProvider.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProvider.java
index 36b778d2c..f713af61f 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProvider.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -17,10 +17,11 @@
package org.springframework.batch.core.step.item;
import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.item.Chunk;
/**
- * Interface for providing {@link Chunk}s to be processed, used by the
- * {@link ChunkOrientedTasklet}
+ * Interface for providing {@link org.springframework.batch.item.Chunk}s to be processed,
+ * used by the {@link ChunkOrientedTasklet}
*
* @since 2.0
* @see ChunkOrientedTasklet
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/DefaultItemFailureHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/DefaultItemFailureHandler.java
index 77c5c5225..d43dd1b20 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/DefaultItemFailureHandler.java
+++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/DefaultItemFailureHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2008 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,6 +20,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.listener.ItemListenerSupport;
+import org.springframework.batch.item.Chunk;
/**
* Default implementation of the {@link ItemListenerSupport} class that writes all
@@ -28,6 +29,7 @@ import org.springframework.batch.core.listener.ItemListenerSupport;
* object.
*
* @author Lucas Ward
+ * @author Mahmoud Ben Hassine
*
*/
public class DefaultItemFailureHandler extends ItemListenerSupport
*
* @author Chris Schaefer
+ * @author Mahmoud Ben Hassine
* @since 3.1
*/
@SpringJUnitConfig
@@ -52,12 +54,12 @@ class ScriptItemProcessorTests {
public static class TestItemWriter implements ItemWriter {
@Override
- public void write(List extends String> items) throws Exception {
- Assert.notNull(items, "Items cannot be null");
- Assert.isTrue(!items.isEmpty(), "Items cannot be empty");
- Assert.isTrue(items.size() == 1, "Items should only contain one entry");
+ public void write(Chunk extends String> chunk) throws Exception {
+ Assert.notNull(chunk.getItems(), "Items cannot be null");
+ Assert.isTrue(!chunk.getItems().isEmpty(), "Items cannot be empty");
+ Assert.isTrue(chunk.getItems().size() == 1, "Items should only contain one entry");
- String item = items.get(0);
+ String item = chunk.getItems().get(0);
Assert.isTrue("BLAH".equals(item), "Transformed item to write should have been: BLAH but got: " + item);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProcessorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProcessorTests.java
index 7b1f48779..85b92b857 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProcessorTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProcessorTests.java
@@ -28,6 +28,7 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.lang.Nullable;
@@ -46,11 +47,11 @@ class SimpleChunkProcessorTests {
}
}, new ItemWriter() {
@Override
- public void write(List extends String> items) throws Exception {
- if (items.contains("fail")) {
+ public void write(Chunk extends String> chunk) throws Exception {
+ if (chunk.getItems().contains("fail")) {
throw new RuntimeException("Planned failure!");
}
- list.addAll(items);
+ list.addAll(chunk.getItems());
}
});
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProviderTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProviderTests.java
index b4161133c..eb5f4196d 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProviderTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleChunkProviderTests.java
@@ -26,6 +26,7 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.support.RepeatTemplate;
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java
index 0e2a3ef56..a85f0c043 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleStepFactoryBeanTests.java
@@ -46,6 +46,7 @@ import org.springframework.batch.core.repository.support.JobRepositoryFactoryBea
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.factory.SimpleStepFactoryBean;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
@@ -72,8 +73,8 @@ class SimpleStepFactoryBeanTests {
private final ItemWriter writer = new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
- written.addAll(data);
+ public void write(Chunk extends String> data) throws Exception {
+ written.addAll(data.getItems());
}
};
@@ -174,7 +175,7 @@ class SimpleStepFactoryBeanTests {
factory.setItemWriter(new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
+ public void write(Chunk extends String> data) throws Exception {
throw new RuntimeException("Error!");
}
});
@@ -185,7 +186,7 @@ class SimpleStepFactoryBeanTests {
}
@Override
- public void onWriteError(Exception ex, List extends String> item) {
+ public void onWriteError(Exception ex, Chunk extends String> item) {
listened.add(ex);
}
} });
@@ -212,7 +213,7 @@ class SimpleStepFactoryBeanTests {
factory.setBeanName("exceptionStep");
factory.setItemWriter(new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
+ public void write(Chunk extends String> data) throws Exception {
throw new RuntimeException("Foo");
}
});
@@ -237,7 +238,7 @@ class SimpleStepFactoryBeanTests {
int count = 0;
@Override
- public void write(List extends String> data) throws Exception {
+ public void write(Chunk extends String> data) throws Exception {
if (count++ == 0) {
throw new RuntimeException("Foo");
}
@@ -264,8 +265,8 @@ class SimpleStepFactoryBeanTests {
String trail = "";
@Override
- public void beforeWrite(List extends Object> items) {
- if (items.contains("error")) {
+ public void beforeWrite(Chunk extends Object> chunk) {
+ if (chunk.getItems().contains("error")) {
throw new RuntimeException("rollback the last chunk");
}
@@ -273,7 +274,7 @@ class SimpleStepFactoryBeanTests {
}
@Override
- public void afterWrite(List extends Object> items) {
+ public void afterWrite(Chunk extends Object> items) {
trail = trail + "3";
}
@@ -379,7 +380,7 @@ class SimpleStepFactoryBeanTests {
ItemWriteListener, ItemProcessListener, ChunkListener {
@Override
- public void write(List extends String> items) throws Exception {
+ public void write(Chunk extends String> items) throws Exception {
}
@Nullable
@@ -402,16 +403,16 @@ class SimpleStepFactoryBeanTests {
}
@Override
- public void afterWrite(List extends String> items) {
+ public void afterWrite(Chunk extends String> items) {
listenerCalls.add("write");
}
@Override
- public void beforeWrite(List extends String> items) {
+ public void beforeWrite(Chunk extends String> items) {
}
@Override
- public void onWriteError(Exception exception, List extends String> items) {
+ public void onWriteError(Exception exception, Chunk extends String> items) {
}
@Override
@@ -470,20 +471,20 @@ class SimpleStepFactoryBeanTests {
class TestItemListenerWriter implements ItemWriter, ItemWriteListener {
@Override
- public void write(List extends String> items) throws Exception {
+ public void write(Chunk extends String> items) throws Exception {
}
@Override
- public void afterWrite(List extends String> items) {
+ public void afterWrite(Chunk extends String> items) {
listenerCalls.add("write");
}
@Override
- public void beforeWrite(List extends String> items) {
+ public void beforeWrite(Chunk extends String> items) {
}
@Override
- public void onWriteError(Exception exception, List extends String> items) {
+ public void onWriteError(Exception exception, Chunk extends String> items) {
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWrapperTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWrapperTests.java
index 32a3cf667..9b024669b 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWrapperTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWrapperTests.java
@@ -21,8 +21,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
+import org.springframework.batch.item.SkipWrapper;
+
/**
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
*
*/
class SkipWrapperTests {
@@ -41,7 +44,7 @@ class SkipWrapperTests {
/**
* Test method for
- * {@link org.springframework.batch.core.step.item.SkipWrapper#SkipWrapper(java.lang.Object, java.lang.Throwable)}.
+ * {@link SkipWrapper#SkipWrapper(java.lang.Object, java.lang.Throwable)}.
*/
@Test
void testItemWrapperTException() {
@@ -51,8 +54,7 @@ class SkipWrapperTests {
}
/**
- * Test method for
- * {@link org.springframework.batch.core.step.item.SkipWrapper#toString()}.
+ * Test method for {@link SkipWrapper#toString()}.
*/
@Test
void testToString() {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWriterStub.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWriterStub.java
index f02d2c777..aafad502c 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWriterStub.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SkipWriterStub.java
@@ -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.
@@ -18,11 +18,13 @@ package org.springframework.batch.core.step.item;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
/**
* @author Dan Garrette
+ * @author Mahmoud Ben Hassine
* @since 2.0.1
*/
public class SkipWriterStub extends AbstractExceptionThrowingItemHandlerStub implements ItemWriter {
@@ -49,7 +51,7 @@ public class SkipWriterStub extends AbstractExceptionThrowingItemHandlerStub<
}
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
logger.debug("Writing: " + items);
for (T item : items) {
written.add(item);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/skip/ReprocessExceptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/skip/ReprocessExceptionTests.java
index ea4bce0a5..d5dd29b9e 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/skip/ReprocessExceptionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/skip/ReprocessExceptionTests.java
@@ -21,6 +21,7 @@ import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author mminella
+ * @author Mahmoud Ben Hassine
*/
@SpringJUnitConfig
public class ReprocessExceptionTests {
@@ -77,7 +79,7 @@ public class ReprocessExceptionTests {
public static class PersonItemWriter implements ItemWriter {
@Override
- public void write(List extends Person> persons) throws Exception {
+ public void write(Chunk extends Person> persons) throws Exception {
for (Person person : persons) {
System.out.println(person.getFirstName() + " " + person.getLastName());
if (person.getFirstName().equals("JANE")) {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java
index f117d7395..ab36006e0 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncChunkOrientedStepIntegrationTests.java
@@ -34,6 +34,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.batch.core.repository.JobRepository;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.ListItemReader;
@@ -53,6 +54,7 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
/**
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
*
*/
@SpringJUnitConfig(locations = "/org/springframework/batch/core/repository/dao/sql-dao-test.xml")
@@ -125,8 +127,8 @@ class AsyncChunkOrientedStepIntegrationTests {
getReader(new String[] { "a", "b", "c", "a", "b", "c", "a", "b", "c", "a", "b", "c" }),
new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
- written.addAll(data);
+ public void write(Chunk extends String> data) throws Exception {
+ written.addAll(data.getItems());
}
}, chunkOperations));
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java
index f81e3d23b..949701941 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/AsyncTaskletStepTests.java
@@ -33,6 +33,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.JobRepositorySupport;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemStreamSupport;
@@ -59,11 +60,11 @@ class AsyncTaskletStepTests {
ItemWriter itemWriter = new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
+ public void write(Chunk extends String> data) throws Exception {
// Thread.sleep(100L);
logger.info("Items: " + data);
- processed.addAll(data);
- if (data.contains("fail")) {
+ processed.addAll(data.getItems());
+ if (data.getItems().contains("fail")) {
throw new RuntimeException("Planned");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java
index 384b89f6f..ee82396cf 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java
@@ -37,6 +37,7 @@ import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
@@ -88,7 +89,7 @@ class StepExecutorInterruptionTests {
step.setTransactionManager(this.transactionManager);
itemWriter = new ItemWriter() {
@Override
- public void write(List extends Object> item) throws Exception {
+ public void write(Chunk extends Object> item) throws Exception {
}
};
stepExecution = new StepExecution(step.getName(), jobExecution);
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java
index 36492f980..ca57da591 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/TaskletStepTests.java
@@ -45,6 +45,7 @@ import org.springframework.batch.core.repository.support.JobRepositoryFactoryBea
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.JobRepositorySupport;
import org.springframework.batch.core.step.StepInterruptionPolicy;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
@@ -75,8 +76,8 @@ class TaskletStepTests {
ItemWriter itemWriter = new ItemWriter() {
@Override
- public void write(List extends String> data) throws Exception {
- processed.addAll(data);
+ public void write(Chunk extends String> data) throws Exception {
+ processed.addAll(data.getItems());
}
};
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcGameDao.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcGameDao.java
index 7bdbd9e65..ad0bcb9bd 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcGameDao.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcGameDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -19,6 +19,7 @@ package org.springframework.batch.core.test.football.internal;
import java.util.List;
import org.springframework.batch.core.test.football.domain.Game;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
@@ -38,7 +39,7 @@ public class JdbcGameDao extends JdbcDaoSupport implements ItemWriter {
}
@Override
- public void write(List extends Game> games) {
+ public void write(Chunk extends Game> games) {
for (Game game : games) {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcPlayerSummaryDao.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcPlayerSummaryDao.java
index 062e058fd..83948e099 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcPlayerSummaryDao.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/JdbcPlayerSummaryDao.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -19,6 +19,7 @@ package org.springframework.batch.core.test.football.internal;
import java.util.List;
import org.springframework.batch.core.test.football.domain.PlayerSummary;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -35,7 +36,7 @@ public class JdbcPlayerSummaryDao implements ItemWriter {
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Override
- public void write(List extends PlayerSummary> summaries) {
+ public void write(Chunk extends PlayerSummary> summaries) {
for (PlayerSummary summary : summaries) {
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/PlayerItemWriter.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/PlayerItemWriter.java
index fd83d6ea2..38df58995 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/PlayerItemWriter.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/football/internal/PlayerItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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,6 +20,7 @@ import java.util.List;
import org.springframework.batch.core.test.football.domain.Player;
import org.springframework.batch.core.test.football.domain.PlayerDao;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
public class PlayerItemWriter implements ItemWriter {
@@ -27,7 +28,7 @@ public class PlayerItemWriter implements ItemWriter {
private PlayerDao playerDao;
@Override
- public void write(List extends Player> players) throws Exception {
+ public void write(Chunk extends Player> players) throws Exception {
for (Player player : players) {
playerDao.savePlayer(player);
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanIntegrationTests.java
index 946f578b0..16201a713 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanIntegrationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanIntegrationTests.java
@@ -39,6 +39,7 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
@@ -111,7 +112,7 @@ class FaultTolerantStepFactoryBeanIntegrationTests {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
- writer.write(Arrays.asList("foo", "bar"));
+ writer.write(Chunk.of("foo", "bar"));
processor.process("spam");
assertEquals(3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
@@ -228,7 +229,7 @@ class FaultTolerantStepFactoryBeanIntegrationTests {
}
@Override
- public void write(List extends String> items) throws Exception {
+ public void write(Chunk extends String> items) throws Exception {
for (String item : items) {
written.add(item);
jdbcTemplate.update("INSERT INTO ERROR_LOG (MESSAGE, STEP_NAME) VALUES (?, ?)", item, "written");
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanRollbackIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanRollbackIntegrationTests.java
index ddffda568..080d6e053 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanRollbackIntegrationTests.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/FaultTolerantStepFactoryBeanRollbackIntegrationTests.java
@@ -39,6 +39,7 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
@@ -108,7 +109,7 @@ class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
- writer.write(Arrays.asList("foo", "bar"));
+ writer.write(Chunk.of("foo", "bar"));
processor.process("spam");
assertEquals(3, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG"));
@@ -253,7 +254,7 @@ class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
}
@Override
- public void write(List extends String> items) throws Exception {
+ public void write(Chunk extends String> items) throws Exception {
for (String item : items) {
written.add(item);
jdbcTemplate.update("INSERT INTO ERROR_LOG (MESSAGE, STEP_NAME) VALUES (?, ?)", item, "written");
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 08513018f..14611d328 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
@@ -35,6 +35,7 @@ import org.springframework.batch.core.step.builder.FaultTolerantStepBuilder;
import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.skip.SkipPolicy;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
@@ -71,7 +72,7 @@ class FaultTolerantStepIntegrationTests {
void setUp() {
ItemReader itemReader = new ListItemReader<>(createItems());
ItemWriter itemWriter = chunk -> {
- if (chunk.contains(1)) {
+ if (chunk.getItems().contains(1)) {
throw new IllegalArgumentException();
}
};
@@ -169,7 +170,7 @@ class FaultTolerantStepIntegrationTests {
private int cpt;
@Override
- public void write(List extends Integer> items) throws Exception {
+ public void write(Chunk extends Integer> items) throws Exception {
cpt++;
if (cpt == 1) {
throw new Exception("Error during write");
@@ -210,8 +211,8 @@ class FaultTolerantStepIntegrationTests {
ItemWriter itemWriter = new ItemWriter() {
@Override
- public void write(List extends Integer> items) throws Exception {
- if (items.contains(3)) {
+ public void write(Chunk extends Integer> chunk) throws Exception {
+ if (chunk.getItems().contains(3)) {
throw new Exception("Error during write");
}
}
diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/LoggingItemWriter.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/LoggingItemWriter.java
index 43904fc25..3a4ef2de3 100644
--- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/LoggingItemWriter.java
+++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/timeout/LoggingItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 the original author or authors.
+ * Copyright 2014-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.
@@ -19,6 +19,8 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
public class LoggingItemWriter implements ItemWriter {
@@ -26,7 +28,7 @@ public class LoggingItemWriter implements ItemWriter {
protected Log logger = LogFactory.getLog(LoggingItemWriter.class);
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
logger.info(items);
}
diff --git a/spring-batch-docs/src/main/asciidoc/common-patterns.adoc b/spring-batch-docs/src/main/asciidoc/common-patterns.adoc
index 30a116a64..f59e840bd 100644
--- a/spring-batch-docs/src/main/asciidoc/common-patterns.adoc
+++ b/spring-batch-docs/src/main/asciidoc/common-patterns.adoc
@@ -277,7 +277,7 @@ public class TradeItemWriter implements ItemWriter,
private BigDecimal totalAmount = BigDecimal.ZERO;
- public void write(List extends Trade> items) throws Exception {
+ public void write(Chunk extends Trade> items) throws Exception {
BigDecimal chunkTotal = BigDecimal.ZERO;
for (Trade trade : items) {
chunkTotal = chunkTotal.add(trade.getAmount());
@@ -665,7 +665,7 @@ then it is not persisted during `Step` execution. If the `Step` fails, that data
public class SavingItemWriter implements ItemWriter {
private StepExecution stepExecution;
- public void write(List extends Object> items) throws Exception {
+ public void write(Chunk extends Object> items) throws Exception {
// ...
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
@@ -759,7 +759,7 @@ in the following example:
public class RetrievingItemWriter implements ItemWriter {
private Object someObject;
- public void write(List extends Object> items) throws Exception {
+ public void write(Chunk extends Object> items) throws Exception {
// ...
}
diff --git a/spring-batch-docs/src/main/asciidoc/processor.adoc b/spring-batch-docs/src/main/asciidoc/processor.adoc
index 8c3351241..c4e08f1fd 100644
--- a/spring-batch-docs/src/main/asciidoc/processor.adoc
+++ b/spring-batch-docs/src/main/asciidoc/processor.adoc
@@ -25,7 +25,7 @@ public class CompositeItemWriter implements ItemWriter {
this.itemWriter = itemWriter;
}
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
//Add business logic here
itemWriter.write(items);
}
@@ -77,7 +77,7 @@ public class FooProcessor implements ItemProcessor {
}
public class BarWriter implements ItemWriter {
- public void write(List extends Bar> bars) throws Exception {
+ public void write(Chunk extends Bar> bars) throws Exception {
//write bars
}
}
@@ -162,7 +162,7 @@ public class BarProcessor implements ItemProcessor {
}
public class FoobarWriter implements ItemWriter{
- public void write(List extends Foobar> items) throws Exception {
+ public void write(Chunk extends Foobar> items) throws Exception {
//write items
}
}
diff --git a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc
index ce60b65e0..d2d0cbceb 100644
--- a/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc
+++ b/spring-batch-docs/src/main/asciidoc/readersAndWriters.adoc
@@ -78,7 +78,7 @@ As with `ItemReader`,
----
public interface ItemWriter {
- void write(List extends T> items) throws Exception;
+ void write(Chunk extends T> items) throws Exception;
}
----
@@ -2732,7 +2732,7 @@ public class CustomItemWriter implements ItemWriter {
List output = TransactionAwareProxyFactory.createTransactionalList();
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
output.addAll(items);
}
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java
similarity index 86%
rename from spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java
rename to spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java
index 9fa7f4682..5e778ac62 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/Chunk.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java
@@ -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.
@@ -14,9 +14,11 @@
* limitations under the License.
*/
-package org.springframework.batch.core.step.item;
+package org.springframework.batch.item;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -26,13 +28,14 @@ import java.util.List;
* Encapsulation of a list of items to be processed and possibly a list of failed items to
* be skipped. To mark an item as skipped clients should iterate over the chunk using the
* {@link #iterator()} method, and if there is a failure call
- * {@link org.springframework.batch.core.step.item.Chunk.ChunkIterator#remove()} on the
- * iterator. The skipped items are then available through the chunk.
+ * {@link Chunk.ChunkIterator#remove()} on the iterator. The skipped items are then
+ * available through the chunk.
*
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
* @since 2.0
*/
-public class Chunk implements Iterable {
+public class Chunk implements Iterable, Serializable {
private List items = new ArrayList<>();
@@ -46,15 +49,19 @@ public class Chunk implements Iterable {
private boolean busy;
- public Chunk() {
- this(null, null);
+ public Chunk(W... items) {
+ this(Arrays.stream(items).toList());
}
- public Chunk(Collection extends W> items) {
+ public static Chunk of(W... items) {
+ return new Chunk<>(items);
+ }
+
+ public Chunk(List extends W> items) {
this(items, null);
}
- public Chunk(Collection extends W> items, List> skips) {
+ public Chunk(List extends W> items, List> skips) {
super();
if (items != null) {
this.items = new ArrayList<>(items);
@@ -72,6 +79,14 @@ public class Chunk implements Iterable {
items.add(item);
}
+ /**
+ * Add all items to the chunk.
+ * @param items the items to add
+ */
+ public void addAll(List items) {
+ this.items.addAll(items);
+ }
+
/**
* Clear the items down to signal that we are done.
*/
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java
index c5af2028d..005535103 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemWriter.java
@@ -18,6 +18,8 @@ package org.springframework.batch.item;
import java.util.List;
+import org.springframework.lang.NonNull;
+
/**
*
* Basic interface for generic output operations. Class implementing this interface will
@@ -36,6 +38,7 @@ import java.util.List;
* @author Dave Syer
* @author Lucas Ward
* @author Taeik Lim
+ * @author Mahmoud Ben Hassine
*/
@FunctionalInterface
public interface ItemWriter {
@@ -43,10 +46,10 @@ public interface ItemWriter {
/**
* Process the supplied data element. Will not be called with any null items in normal
* operation.
- * @param items items to be written
+ * @param chunk of items to be written. Must not be {@code null}.
* @throws Exception if there are errors. The framework will catch the exception and
* convert or rethrow it as appropriate.
*/
- void write(List extends T> items) throws Exception;
+ void write(@NonNull Chunk extends T> chunk) throws Exception;
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java
index ecf42abf2..1b5997f13 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/KeyValueItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2021 the original author or authors.
+ * Copyright 2002-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. You may obtain a copy of the License at
@@ -23,6 +23,7 @@ import org.springframework.util.Assert;
* a {@link Converter} to derive a key from an item
*
* @author David Turanski
+ * @author Mahmoud Ben Hassine
* @since 2.2
*
*/
@@ -38,7 +39,7 @@ public abstract class KeyValueItemWriter implements ItemWriter, Initial
* @see org.springframework.batch.item.ItemWriter#write(java.util.List)
*/
@Override
- public void write(List extends V> items) throws Exception {
+ public void write(Chunk extends V> items) throws Exception {
if (items == null) {
return;
}
diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipWrapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/SkipWrapper.java
similarity index 93%
rename from spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipWrapper.java
rename to spring-batch-infrastructure/src/main/java/org/springframework/batch/item/SkipWrapper.java
index 2ad4eac4b..41b5dd977 100644
--- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SkipWrapper.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/SkipWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2018 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.batch.core.step.item;
+package org.springframework.batch.item;
import org.springframework.lang.Nullable;
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java
index 384065e21..3abd77124 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java
@@ -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.
@@ -18,6 +18,7 @@ package org.springframework.batch.item.adapter;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
/**
@@ -26,11 +27,12 @@ import org.springframework.batch.item.ItemWriter;
*
* @see PropertyExtractingDelegatingItemWriter
* @author Robert Kasanicky
+ * @author Mahmoud Ben Hassine
*/
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter {
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
for (T item : items) {
invokeDelegateMethodWithArgument(item);
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java
index 58da807d1..609d6f3d0 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java
@@ -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.
@@ -19,6 +19,7 @@ package org.springframework.batch.item.adapter;
import java.util.Arrays;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
@@ -30,6 +31,7 @@ import org.springframework.util.Assert;
*
* @see ItemWriterAdapter
* @author Robert Kasanicky
+ * @author Mahmoud Ben Hassine
*/
public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator
implements ItemWriter {
@@ -41,7 +43,7 @@ public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInv
* passes them as arguments to the delegate method.
*/
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
for (T item : items) {
// helper for extracting property values from a bean
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/amqp/AmqpItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/amqp/AmqpItemWriter.java
index 399040de2..9a2b8f975 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/amqp/AmqpItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/amqp/AmqpItemWriter.java
@@ -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.
@@ -19,6 +19,7 @@ package org.springframework.batch.item.amqp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.util.Assert;
@@ -47,7 +48,7 @@ public class AmqpItemWriter implements ItemWriter {
}
@Override
- public void write(final List extends T> items) throws Exception {
+ public void write(final Chunk extends T> items) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Writing to AMQP with " + items.size() + " items.");
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/AvroItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/AvroItemWriter.java
index 66ade7282..1e791bd22 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/AvroItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/avro/AvroItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019-2021 the original author or authors.
+ * Copyright 2019-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.
@@ -31,6 +31,7 @@ import org.apache.avro.reflect.ReflectDatumWriter;
import org.apache.avro.specific.SpecificDatumWriter;
import org.apache.avro.specific.SpecificRecordBase;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
@@ -84,7 +85,7 @@ public class AvroItemWriter extends AbstractItemStreamItemWriter {
}
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
items.forEach(item -> {
try {
if (this.dataFileWriter != null) {
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java
index 85fff8b46..cff4fce4b 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.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.
@@ -22,6 +22,7 @@ import java.util.List;
import org.bson.Document;
import org.bson.types.ObjectId;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.data.mongodb.core.BulkOperations;
@@ -113,39 +114,39 @@ public class MongoItemWriter implements ItemWriter, InitializingBean {
* If a transaction is active, buffer items to be written just before commit.
* Otherwise write items using the provided template.
*
- * @see org.springframework.batch.item.ItemWriter#write(List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> chunk) throws Exception {
if (!transactionActive()) {
- doWrite(items);
+ doWrite(chunk);
return;
}
- List bufferedItems = getCurrentBuffer();
- bufferedItems.addAll(items);
+ Chunk bufferedItems = getCurrentBuffer();
+ bufferedItems.addAll(chunk.getItems());
}
/**
* Performs the actual write to the store via the template. This can be overridden by
* a subclass if necessary.
- * @param items the list of items to be persisted.
+ * @param chunk the chunk of items to be persisted.
*/
- protected void doWrite(List extends T> items) {
- if (!CollectionUtils.isEmpty(items)) {
+ protected void doWrite(Chunk extends T> chunk) {
+ if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (this.delete) {
- delete(items);
+ delete(chunk);
}
else {
- saveOrUpdate(items);
+ saveOrUpdate(chunk);
}
}
}
- private void delete(List extends T> items) {
- BulkOperations bulkOperations = initBulkOperations(BulkMode.ORDERED, items.get(0));
+ private void delete(Chunk extends T> chunk) {
+ BulkOperations bulkOperations = initBulkOperations(BulkMode.ORDERED, chunk.getItems().get(0));
MongoConverter mongoConverter = this.template.getConverter();
- for (Object item : items) {
+ for (Object item : chunk) {
Document document = new Document();
mongoConverter.write(item, document);
Object objectId = document.get(ID_KEY);
@@ -157,11 +158,11 @@ public class MongoItemWriter implements ItemWriter, InitializingBean {
bulkOperations.execute();
}
- private void saveOrUpdate(List extends T> items) {
- BulkOperations bulkOperations = initBulkOperations(BulkMode.ORDERED, items.get(0));
+ private void saveOrUpdate(Chunk extends T> chunk) {
+ BulkOperations bulkOperations = initBulkOperations(BulkMode.ORDERED, chunk.getItems().get(0));
MongoConverter mongoConverter = this.template.getConverter();
FindAndReplaceOptions upsert = new FindAndReplaceOptions().upsert();
- for (Object item : items) {
+ for (Object item : chunk) {
Document document = new Document();
mongoConverter.write(item, document);
Object objectId = document.get(ID_KEY) != null ? document.get(ID_KEY) : new ObjectId();
@@ -186,19 +187,18 @@ public class MongoItemWriter implements ItemWriter, InitializingBean {
return TransactionSynchronizationManager.isActualTransactionActive();
}
- @SuppressWarnings("unchecked")
- private List getCurrentBuffer() {
+ private Chunk getCurrentBuffer() {
if (!TransactionSynchronizationManager.hasResource(bufferKey)) {
- TransactionSynchronizationManager.bindResource(bufferKey, new ArrayList());
+ TransactionSynchronizationManager.bindResource(bufferKey, new Chunk());
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void beforeCommit(boolean readOnly) {
- List items = (List) TransactionSynchronizationManager.getResource(bufferKey);
+ Chunk chunk = (Chunk) TransactionSynchronizationManager.getResource(bufferKey);
- if (!CollectionUtils.isEmpty(items)) {
+ if (!CollectionUtils.isEmpty(chunk.getItems())) {
if (!readOnly) {
- doWrite(items);
+ doWrite(chunk);
}
}
}
@@ -212,7 +212,7 @@ public class MongoItemWriter implements ItemWriter, InitializingBean {
});
}
- return (List) TransactionSynchronizationManager.getResource(bufferKey);
+ return (Chunk) TransactionSynchronizationManager.getResource(bufferKey);
}
@Override
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemWriter.java
index 6d6f826f9..75316655d 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/Neo4jItemWriter.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.
@@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
@@ -86,12 +87,12 @@ public class Neo4jItemWriter implements ItemWriter, InitializingBean {
/**
* Write all items to the data store.
*
- * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) throws Exception {
- if (!CollectionUtils.isEmpty(items)) {
- doWrite(items);
+ public void write(Chunk extends T> chunk) throws Exception {
+ if (!CollectionUtils.isEmpty(chunk.getItems())) {
+ doWrite(chunk);
}
}
@@ -100,7 +101,7 @@ public class Neo4jItemWriter implements ItemWriter, InitializingBean {
* if necessary.
* @param items the list of items to be persisted.
*/
- protected void doWrite(List extends T> items) {
+ protected void doWrite(Chunk extends T> items) {
if (delete) {
delete(items);
}
@@ -109,7 +110,7 @@ public class Neo4jItemWriter implements ItemWriter, InitializingBean {
}
}
- private void delete(List extends T> items) {
+ private void delete(Chunk extends T> items) {
Session session = this.sessionFactory.openSession();
for (T item : items) {
@@ -117,7 +118,7 @@ public class Neo4jItemWriter implements ItemWriter, InitializingBean {
}
}
- private void save(List extends T> items) {
+ private void save(Chunk extends T> items) {
Session session = this.sessionFactory.openSession();
for (T item : items) {
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java
index 808b33270..4ce7c96e4 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/RepositoryItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 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.
@@ -20,6 +20,8 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper;
import org.springframework.batch.item.adapter.DynamicMethodInvocationException;
@@ -87,12 +89,12 @@ public class RepositoryItemWriter implements ItemWriter, InitializingBean
/**
* Write all items to the data store via a Spring Data repository.
*
- * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) throws Exception {
- if (!CollectionUtils.isEmpty(items)) {
- doWrite(items);
+ public void write(Chunk extends T> chunk) throws Exception {
+ if (!CollectionUtils.isEmpty(chunk.getItems())) {
+ doWrite(chunk);
}
}
@@ -102,7 +104,7 @@ public class RepositoryItemWriter implements ItemWriter, InitializingBean
* @param items the list of items to be persisted.
* @throws Exception thrown if error occurs during writing.
*/
- protected void doWrite(List extends T> items) throws Exception {
+ protected void doWrite(Chunk extends T> items) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Writing to the repository with " + items.size() + " items.");
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemWriter.java
index f9b621804..4ca03a6cb 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/HibernateItemWriter.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.
@@ -23,6 +23,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.context.spi.CurrentSessionContext;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
@@ -81,10 +82,10 @@ public class HibernateItemWriter implements ItemWriter, InitializingBean {
* Save or update any entities not in the current hibernate session and then flush the
* hibernate session.
*
- * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) {
+ public void write(Chunk extends T> items) {
doWrite(sessionFactory, items);
sessionFactory.getCurrentSession().flush();
if (clearSession) {
@@ -98,7 +99,7 @@ public class HibernateItemWriter implements ItemWriter, InitializingBean {
* @param sessionFactory Hibernate SessionFactory to be used
* @param items the list of items to use for the write
*/
- protected void doWrite(SessionFactory sessionFactory, List extends T> items) {
+ protected void doWrite(SessionFactory sessionFactory, Chunk extends T> items) {
if (logger.isDebugEnabled()) {
logger.debug("Writing to Hibernate with " + items.size() + " items.");
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java
index 9e19791f6..d98e950bb 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JdbcBatchItemWriter.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.
@@ -25,6 +25,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessException;
@@ -51,7 +52,7 @@ import org.springframework.util.Assert;
* be responsible for mapping the item to the parameters needed to execute the SQL
* statement.
*
- * It is expected that {@link #write(List)} is called inside a transaction.
+ * It is expected that {@link #write(Chunk)} is called inside a transaction.
*
* The writer is thread-safe after its properties are set (normal singleton behavior), so
* it can be used to write in multiple concurrent transactions.
@@ -59,6 +60,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
* @author Thomas Risberg
* @author Michael Minella
+ * @author Mahmoud Ben Hassine
* @since 2.0
*/
public class JdbcBatchItemWriter implements ItemWriter, InitializingBean {
@@ -164,24 +166,25 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean {
*/
@SuppressWarnings("unchecked")
@Override
- public void write(final List extends T> items) throws Exception {
+ public void write(final Chunk extends T> chunk) throws Exception {
- if (!items.isEmpty()) {
+ if (!chunk.isEmpty()) {
if (logger.isDebugEnabled()) {
- logger.debug("Executing batch with " + items.size() + " items.");
+ logger.debug("Executing batch with " + chunk.size() + " items.");
}
int[] updateCounts;
if (usingNamedParameters) {
- if (items.get(0) instanceof Map && this.itemSqlParameterSourceProvider == null) {
- updateCounts = namedParameterJdbcTemplate.batchUpdate(sql, items.toArray(new Map[items.size()]));
+ if (chunk.getItems().get(0) instanceof Map && this.itemSqlParameterSourceProvider == null) {
+ updateCounts = namedParameterJdbcTemplate.batchUpdate(sql,
+ chunk.getItems().toArray(new Map[chunk.size()]));
}
else {
- SqlParameterSource[] batchArgs = new SqlParameterSource[items.size()];
+ SqlParameterSource[] batchArgs = new SqlParameterSource[chunk.size()];
int i = 0;
- for (T item : items) {
+ for (T item : chunk) {
batchArgs[i++] = itemSqlParameterSourceProvider.createSqlParameterSource(item);
}
updateCounts = namedParameterJdbcTemplate.batchUpdate(sql, batchArgs);
@@ -193,7 +196,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean {
@Override
public int[] doInPreparedStatement(PreparedStatement ps)
throws SQLException, DataAccessException {
- for (T item : items) {
+ for (T item : chunk) {
itemPreparedStatementSetter.setValues(item, ps);
ps.addBatch();
}
@@ -207,7 +210,7 @@ public class JdbcBatchItemWriter implements ItemWriter, InitializingBean {
int value = updateCounts[i];
if (value == 0) {
throw new EmptyResultDataAccessException("Item " + i + " of " + updateCounts.length
- + " did not update any rows: [" + items.get(i) + "]", 1);
+ + " did not update any rows: [" + chunk.getItems().get(i) + "]", 1);
}
}
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java
index 8ca7b0c01..d526af59a 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/database/JpaItemWriter.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.
@@ -18,6 +18,8 @@ package org.springframework.batch.item.database;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessResourceFailureException;
@@ -32,7 +34,7 @@ import java.util.List;
* {@link org.springframework.batch.item.ItemWriter} that is using a JPA
* EntityManagerFactory to merge any Entities that aren't part of the persistence context.
*
- * It is required that {@link #write(List)} is called inside a transaction.
+ * It is required that {@link #write(Chunk)} is called inside a transaction.
*
* The reader must be configured with an {@link jakarta.persistence.EntityManagerFactory}
* that is capable of participating in Spring managed transactions.
@@ -80,10 +82,10 @@ public class JpaItemWriter implements ItemWriter, InitializingBean {
* Merge all provided items that aren't already in the persistence context and then
* flush the entity manager.
*
- * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) {
+ public void write(Chunk extends T> items) {
EntityManager entityManager = EntityManagerFactoryUtils.getTransactionalEntityManager(entityManagerFactory);
if (entityManager == null) {
throw new DataAccessResourceFailureException("Unable to obtain a transactional EntityManager");
@@ -98,7 +100,7 @@ public class JpaItemWriter implements ItemWriter, InitializingBean {
* @param entityManager the EntityManager to use for the operation
* @param items the list of items to use for the write
*/
- protected void doWrite(EntityManager entityManager, List extends T> items) {
+ protected void doWrite(EntityManager entityManager, Chunk extends T> items) {
if (logger.isDebugEnabled()) {
logger.debug("Writing to JPA with " + items.size() + " items.");
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java
index 2202d52af..520b41d31 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2018 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.
@@ -18,6 +18,7 @@ package org.springframework.batch.item.file;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.batch.item.support.AbstractFileItemWriter;
import org.springframework.core.io.Resource;
@@ -71,7 +72,7 @@ public class FlatFileItemWriter extends AbstractFileItemWriter {
}
@Override
- public String doWrite(List extends T> items) {
+ public String doWrite(Chunk extends T> items) {
StringBuilder lines = new StringBuilder();
for (T item : items) {
lines.append(this.lineAggregator.aggregate(item)).append(this.lineSeparator);
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemWriter.java
index 776dd217b..65f72a925 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/MultiResourceItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2017 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.
@@ -19,6 +19,8 @@ package org.springframework.batch.item.file;
import java.io.File;
import java.io.IOException;
import java.util.List;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.support.AbstractItemStreamItemWriter;
@@ -39,6 +41,7 @@ import org.springframework.util.ClassUtils;
*
* @param item type
* @author Robert Kasanicky
+ * @author Mahmoud Ben Hassine
*/
public class MultiResourceItemWriter extends AbstractItemStreamItemWriter {
@@ -67,7 +70,7 @@ public class MultiResourceItemWriter extends AbstractItemStreamItemWriter
}
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
if (!opened) {
File file = setResourceToDelegate();
// create only if write is called
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java
index 934963e95..90f95cff5 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/jms/JmsItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -18,6 +18,8 @@ package org.springframework.batch.item.jms;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
@@ -27,13 +29,14 @@ import java.util.List;
/**
* An {@link ItemWriter} for JMS using a {@link JmsTemplate}. The template should have a
- * default destination, which will be used to send items in {@link #write(List)}.
+ * default destination, which will be used to send items in {@link #write(Chunk)}.
*
*
* The implementation is thread-safe after its properties are set (normal singleton
* behavior).
*
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
*
*/
public class JmsItemWriter implements ItemWriter {
@@ -58,10 +61,10 @@ public class JmsItemWriter implements ItemWriter {
/**
* Send the items one-by-one to the default destination of the JMS template.
*
- * @see org.springframework.batch.item.ItemWriter#write(java.util.List)
+ * @see org.springframework.batch.item.ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Writing to JMS with " + items.size() + " items.");
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/JsonFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/JsonFileItemWriter.java
index d41e8d015..b08aaa20f 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/JsonFileItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/json/JsonFileItemWriter.java
@@ -19,6 +19,7 @@ package org.springframework.batch.item.json;
import java.util.Iterator;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.support.AbstractFileItemWriter;
import org.springframework.core.io.WritableResource;
import org.springframework.util.Assert;
@@ -94,7 +95,7 @@ public class JsonFileItemWriter extends AbstractFileItemWriter {
}
@Override
- public String doWrite(List extends T> items) {
+ public String doWrite(Chunk extends T> items) {
StringBuilder lines = new StringBuilder();
Iterator extends T> iterator = items.iterator();
if (!items.isEmpty() && state.getLinesWritten() > 0) {
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriter.java
index b9df93a2c..24b0ead87 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2010 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.
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.mail.MailException;
@@ -50,6 +51,7 @@ import org.springframework.util.Assert;
*
*
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
* @since 2.1
*
*/
@@ -60,7 +62,7 @@ public class SimpleMailMessageItemWriter implements ItemWriter items) throws MailException {
+ public void write(Chunk extends SimpleMailMessage> chunk) throws MailException {
try {
- mailSender.send(items.toArray(new SimpleMailMessage[items.size()]));
+ mailSender.send(chunk.getItems().toArray(new SimpleMailMessage[chunk.size()]));
}
catch (MailSendException e) {
Map failedMessages = e.getFailedMessages();
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilder.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilder.java
index d8e1fee7f..8f8d7dcce 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilder.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 the original author or authors.
+ * Copyright 2017-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.
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* Creates a fully qualified SimpleMailMessageItemWriter.
*
* @author Glenn Renfro
+ * @author Mahmoud Ben Hassine
* @since 4.0
*/
@@ -39,7 +40,7 @@ public class SimpleMailMessageItemWriterBuilder {
/**
* A {@link MailSender} to be used to send messages in
- * {@link SimpleMailMessageItemWriter#write(List)}.
+ * {@link SimpleMailMessageItemWriter#write(Chunk)}.
* @param mailSender strategy for sending simple mails.
* @return this instance for method chaining.
* @see SimpleMailMessageItemWriter#setMailSender(MailSender)
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriter.java
index ae3d2f955..8fa531032 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriter.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.
@@ -15,6 +15,7 @@
*/
package org.springframework.batch.item.mail.javamail;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.mail.DefaultMailErrorHandler;
import org.springframework.batch.item.mail.MailErrorHandler;
@@ -64,7 +65,7 @@ public class MimeMessageItemWriter implements ItemWriter {
private MailErrorHandler mailErrorHandler = new DefaultMailErrorHandler();
/**
- * A {@link JavaMailSender} to be used to send messages in {@link #write(List)}.
+ * A {@link JavaMailSender} to be used to send messages in {@link #write(Chunk)}.
* @param mailSender service for doing the work of sending a MIME message
*/
public void setJavaMailSender(JavaMailSender mailSender) {
@@ -90,13 +91,13 @@ public class MimeMessageItemWriter implements ItemWriter {
}
/**
- * @param items the items to send
- * @see ItemWriter#write(List)
+ * @param chunk the chunk of items to send
+ * @see ItemWriter#write(Chunk)
*/
@Override
- public void write(List extends MimeMessage> items) throws MailException {
+ public void write(Chunk extends MimeMessage> chunk) throws MailException {
try {
- mailSender.send(items.toArray(new MimeMessage[items.size()]));
+ mailSender.send(chunk.getItems().toArray(new MimeMessage[chunk.size()]));
}
catch (MailSendException e) {
Map failedMessages = e.getFailedMessages();
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java
index dd376307c..cf04d21eb 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractFileItemWriter.java
@@ -31,6 +31,7 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
@@ -220,7 +221,7 @@ public abstract class AbstractFileItemWriter extends AbstractItemStreamItemWr
* @throws Exception if an error occurs while writing items to the output stream
*/
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
if (!getOutputState().isInitialized()) {
throw new WriterNotOpenException("Writer must be open before it can be written to");
}
@@ -247,7 +248,7 @@ public abstract class AbstractFileItemWriter extends AbstractItemStreamItemWr
* @param items to be written
* @return written lines
*/
- protected abstract String doWrite(List extends T> items);
+ protected abstract String doWrite(Chunk extends T> items);
/**
* @see ItemStream#close()
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java
index 4b3f243fa..17f818544 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ClassifierCompositeItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 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.
@@ -21,6 +21,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import org.springframework.batch.item.Chunk;
import org.springframework.classify.Classifier;
import org.springframework.classify.ClassifierSupport;
import org.springframework.batch.item.ItemWriter;
@@ -34,6 +35,7 @@ import org.springframework.util.Assert;
*
* @author Dave Syer
* @author Glenn Renfro
+ * @author Mahmoud Ben Hassine
* @since 2.0
*/
public class ClassifierCompositeItemWriter implements ItemWriter {
@@ -53,14 +55,14 @@ public class ClassifierCompositeItemWriter implements ItemWriter {
* classification by the {@link Classifier}.
*/
@Override
- public void write(List extends T> items) throws Exception {
+ public void write(Chunk extends T> items) throws Exception {
- Map, List> map = new LinkedHashMap<>();
+ Map, Chunk> map = new LinkedHashMap<>();
for (T item : items) {
ItemWriter super T> key = classifier.classify(item);
if (!map.containsKey(key)) {
- map.put(key, new ArrayList<>());
+ map.put(key, new Chunk<>());
}
map.get(key).add(item);
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java
index 73051efe7..5613f16a6 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java
@@ -16,6 +16,7 @@
package org.springframework.batch.item.support;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
@@ -35,6 +36,7 @@ import java.util.List;
*
* @author Robert Kasanicky
* @author Dave Syer
+ * @author Mahmoud Ben Hassine
*/
public class CompositeItemWriter implements ItemStreamWriter, InitializingBean {
@@ -78,9 +80,9 @@ public class CompositeItemWriter implements ItemStreamWriter, Initializing
}
@Override
- public void write(List extends T> item) throws Exception {
+ public void write(Chunk extends T> chunk) throws Exception {
for (ItemWriter super T> writer : delegates) {
- writer.write(item);
+ writer.write(chunk);
}
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ListItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ListItemWriter.java
index c51e892ed..7f3ff2626 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ListItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/ListItemWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2019 the original author or authors.
+ * Copyright 2014-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.
@@ -15,6 +15,7 @@
*/
package org.springframework.batch.item.support;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import java.util.ArrayList;
@@ -22,14 +23,15 @@ import java.util.List;
/**
* @author mminella
+ * @author Mahmoud Ben Hassine
*/
public class ListItemWriter implements ItemWriter {
private List writtenItems = new ArrayList<>();
@Override
- public void write(List extends T> items) throws Exception {
- writtenItems.addAll(items);
+ public void write(Chunk extends T> chunk) throws Exception {
+ writtenItems.addAll(chunk.getItems());
}
public List extends T> getWrittenItems() {
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java
index e61853a13..2cfe6fc3f 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/SynchronizedItemStreamWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 the original author or authors.
+ * Copyright 2020-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.
@@ -15,6 +15,7 @@
*/
package org.springframework.batch.item.support;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamWriter;
@@ -60,7 +61,7 @@ public class SynchronizedItemStreamWriter implements ItemStreamWriter, Ini
* This method delegates to the {@code write} method of the {@code delegate}.
*/
@Override
- public synchronized void write(List extends T> items) throws Exception {
+ public synchronized void write(Chunk extends T> items) throws Exception {
this.delegate.write(items);
}
diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java
index 6579fdc3e..8bf4ce9f3 100644
--- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java
+++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java
@@ -38,6 +38,7 @@ import javax.xml.transform.Result;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemWriter;
@@ -761,7 +762,7 @@ public class StaxEventItemWriter extends AbstractItemStreamItemWriter
* @throws XmlMappingException thrown if error occurs during XML Mapping.
*/
@Override
- public void write(List extends T> items) throws XmlMappingException, IOException {
+ public void write(Chunk extends T> items) throws XmlMappingException, IOException {
if (!this.initialized) {
throw new WriterNotOpenException("Writer must be open before it can be written to");
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemWriterAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemWriterAdapterTests.java
index bc42e35eb..66c5d660f 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemWriterAdapterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemWriterAdapterTests.java
@@ -23,6 +23,8 @@ import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.sample.Foo;
import org.springframework.batch.item.sample.FooService;
@@ -33,6 +35,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
* Tests for {@link ItemWriterAdapter}.
*
* @author Robert Kasanicky
+ * @author Mahmoud Ben Hassine
*/
@SpringJUnitConfig(locations = "delegating-item-writer.xml")
class ItemWriterAdapterTests {
@@ -50,7 +53,7 @@ class ItemWriterAdapterTests {
@Test
void testProcess() throws Exception {
Foo foo;
- List foos = new ArrayList<>();
+ Chunk foos = new Chunk<>();
while ((foo = fooService.generateFoo()) != null) {
foos.add(foo);
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemProcessorIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemProcessorIntegrationTests.java
index 2d2f9e482..c943ec4a7 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemProcessorIntegrationTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemProcessorIntegrationTests.java
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.sample.Foo;
import org.springframework.batch.item.sample.FooService;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -49,7 +50,7 @@ class PropertyExtractingDelegatingItemProcessorIntegrationTests {
void testProcess() throws Exception {
Foo foo;
while ((foo = fooService.generateFoo()) != null) {
- processor.write(Collections.singletonList(foo));
+ processor.write(Chunk.of(foo));
}
List input = fooService.getGeneratedFoos();
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java
index 816eb0e95..ac79bd7a3 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.batch.item.Chunk;
import java.util.Arrays;
@@ -31,6 +32,7 @@ import java.util.Arrays;
*
* @author Chris Schaefer
* @author Will Schipp
+ * @author Mahmoud Ben Hassine
*/
class AmqpItemWriterTests {
@@ -48,7 +50,7 @@ class AmqpItemWriterTests {
amqpTemplate.convertAndSend("bar");
AmqpItemWriter amqpItemWriter = new AmqpItemWriter<>(amqpTemplate);
- amqpItemWriter.write(Arrays.asList("foo", "bar"));
+ amqpItemWriter.write(Chunk.of("foo", "bar"));
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java
index 8e53b3d8c..2618a6cba 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.amqp.AmqpItemWriter;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -31,6 +32,7 @@ import static org.mockito.Mockito.verify;
/**
* @author Glenn Renfro
+ * @author Mahmoud Ben Hassine
*/
class AmqpItemWriterBuilderTests {
@@ -46,7 +48,7 @@ class AmqpItemWriterBuilderTests {
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
AmqpItemWriter amqpItemWriter = new AmqpItemWriterBuilder().amqpTemplate(amqpTemplate).build();
- amqpItemWriter.write(Arrays.asList("foo", "bar"));
+ amqpItemWriter.write(Chunk.of("foo", "bar"));
verify(amqpTemplate).convertAndSend("foo");
verify(amqpTemplate).convertAndSend("bar");
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemReaderTestSupport.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemReaderTestSupport.java
index 76dc7e4b3..9618b7d1b 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemReaderTestSupport.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemReaderTestSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 the original author or authors.
+ * Copyright 2019-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.
@@ -19,6 +19,7 @@ package org.springframework.batch.item.avro.support;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.avro.AvroItemReader;
@@ -26,10 +27,11 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author David Turanski
+ * @author Mahmoud Ben Hassine
*/
public abstract class AvroItemReaderTestSupport extends AvroTestFixtures {
- protected void verify(AvroItemReader avroItemReader, List actual) throws Exception {
+ protected void verify(AvroItemReader avroItemReader, Chunk actual) throws Exception {
avroItemReader.open(new ExecutionContext());
List users = new ArrayList<>();
@@ -40,7 +42,9 @@ public abstract class AvroItemReaderTestSupport extends AvroTestFixtures {
}
assertThat(users).hasSize(4);
- assertThat(users).containsExactlyInAnyOrder(actual.get(0), actual.get(1), actual.get(2), actual.get(3));
+ List actualItems = actual.getItems();
+ assertThat(users).containsExactlyInAnyOrder(actualItems.get(0), actualItems.get(1), actualItems.get(2),
+ actualItems.get(3));
avroItemReader.close();
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemWriterTestSupport.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemWriterTestSupport.java
index 4586b0f87..eb1275f31 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemWriterTestSupport.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroItemWriterTestSupport.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 the original author or authors.
+ * Copyright 2019-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.
@@ -25,6 +25,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.avro.AvroItemReader;
import org.springframework.batch.item.avro.builder.AvroItemReaderBuilder;
@@ -36,22 +37,23 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author David Turanski
+ * @author Mahmoud Ben Hassine
*/
public abstract class AvroItemWriterTestSupport extends AvroTestFixtures {
/*
* This item reader configured for Specific Avro types.
*/
- protected void verifyRecords(byte[] bytes, List actual, Class clazz, boolean embeddedSchema)
+ protected void verifyRecords(byte[] bytes, Chunk actual, Class clazz, boolean embeddedSchema)
throws Exception {
doVerify(bytes, clazz, actual, embeddedSchema);
}
- protected void verifyRecordsWithEmbeddedHeader(byte[] bytes, List actual, Class clazz) throws Exception {
+ protected void verifyRecordsWithEmbeddedHeader(byte[] bytes, Chunk actual, Class clazz) throws Exception {
doVerify(bytes, clazz, actual, true);
}
- private void doVerify(byte[] bytes, Class clazz, List actual, boolean embeddedSchema) throws Exception {
+ private void doVerify(byte[] bytes, Class clazz, Chunk actual, boolean embeddedSchema) throws Exception {
AvroItemReader avroItemReader = new AvroItemReaderBuilder().type(clazz)
.resource(new ByteArrayResource(bytes)).embeddedSchema(embeddedSchema).build();
@@ -63,7 +65,9 @@ public abstract class AvroItemWriterTestSupport extends AvroTestFixtures {
records.add(record);
}
assertThat(records).hasSize(4);
- assertThat(records).containsExactlyInAnyOrder(actual.get(0), actual.get(1), actual.get(2), actual.get(3));
+ List actualItems = actual.getItems();
+ assertThat(records).containsExactlyInAnyOrder(actualItems.get(0), actualItems.get(1), actualItems.get(2),
+ actualItems.get(3));
}
protected static class OutputStreamResource implements WritableResource {
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroTestFixtures.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroTestFixtures.java
index 968cd84f6..cf1958d39 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroTestFixtures.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/support/AvroTestFixtures.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 the original author or authors.
+ * Copyright 2019-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.
@@ -33,6 +33,8 @@ import org.apache.avro.io.Encoder;
import org.apache.avro.io.EncoderFactory;
import org.apache.avro.reflect.ReflectData;
import org.apache.avro.reflect.ReflectDatumWriter;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.avro.example.User;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
@@ -45,13 +47,13 @@ import org.springframework.core.io.Resource;
public abstract class AvroTestFixtures {
//@formatter:off
- private final List avroGeneratedUsers = Arrays.asList(
+ private final Chunk avroGeneratedUsers = Chunk.of(
new User("David", 20, "blue"),
new User("Sue", 4, "red"),
new User("Alana", 13, "yellow"),
new User("Joe", 1, "pink"));
- private List plainOldUsers = Arrays.asList(
+ private Chunk plainOldUsers = Chunk.of(
new PlainOldUser("David", 20, "blue"),
new PlainOldUser("Sue", 4, "red"),
new PlainOldUser("Alana", 13, "yellow"),
@@ -86,27 +88,28 @@ public abstract class AvroTestFixtures {
}
}
- protected List avroGeneratedUsers() {
+ protected Chunk avroGeneratedUsers() {
return this.avroGeneratedUsers;
}
- protected List genericAvroGeneratedUsers() {
- return this.avroGeneratedUsers.stream().map(u -> {
+ protected Chunk genericAvroGeneratedUsers() {
+ return new Chunk(this.avroGeneratedUsers.getItems().stream().map(u -> {
GenericData.Record avroRecord;
avroRecord = new GenericData.Record(u.getSchema());
avroRecord.put("name", u.getName());
avroRecord.put("favorite_number", u.getFavoriteNumber());
avroRecord.put("favorite_color", u.getFavoriteColor());
return avroRecord;
- }).collect(Collectors.toList());
+ }).collect(Collectors.toList()));
}
- protected List plainOldUsers() {
+ protected Chunk plainOldUsers() {
return this.plainOldUsers;
}
- protected List genericPlainOldUsers() {
- return this.plainOldUsers.stream().map(PlainOldUser::toGenericRecord).collect(Collectors.toList());
+ protected Chunk genericPlainOldUsers() {
+ return new Chunk(
+ this.plainOldUsers.getItems().stream().map(PlainOldUser::toGenericRecord).collect(Collectors.toList()));
}
protected static class PlainOldUser {
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java
index 68bad56ea..651627e56 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java
@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.SpELItemKeyMapper;
import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.core.convert.converter.Converter;
@@ -61,29 +63,30 @@ class GemfireItemWriterTests {
@Test
void testBasicWrite() throws Exception {
- List items = new ArrayList() {
+ Chunk chunk = new Chunk() {
{
add(new Foo(new Bar("val1")));
add(new Foo(new Bar("val2")));
}
};
- writer.write(items);
+ writer.write(chunk);
+ List items = chunk.getItems();
verify(template).put("val1", items.get(0));
verify(template).put("val2", items.get(1));
}
@Test
void testBasicDelete() throws Exception {
- List items = new ArrayList() {
+ Chunk chunk = new Chunk() {
{
add(new Foo(new Bar("val1")));
add(new Foo(new Bar("val2")));
}
};
writer.setDelete(true);
- writer.write(items);
+ writer.write(chunk);
verify(template).remove("val1");
verify(template).remove("val2");
@@ -91,7 +94,7 @@ class GemfireItemWriterTests {
@Test
void testWriteWithCustomItemKeyMapper() throws Exception {
- List items = new ArrayList() {
+ Chunk chunk = new Chunk() {
{
add(new Foo(new Bar("val1")));
add(new Foo(new Bar("val2")));
@@ -108,8 +111,9 @@ class GemfireItemWriterTests {
}
});
writer.afterPropertiesSet();
- writer.write(items);
+ writer.write(chunk);
+ List items = chunk.getItems();
verify(template).put("item1", items.get(0));
verify(template).put("item2", items.get(1));
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java
index ccb54fdc6..00636da4c 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java
@@ -38,6 +38,8 @@ import static org.mockito.Mockito.never;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.BulkOperations;
@@ -104,7 +106,7 @@ class MongoItemWriterTests {
@Test
void testWriteNoTransactionNoCollection() throws Exception {
- List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.write(items);
@@ -114,7 +116,7 @@ class MongoItemWriterTests {
@Test
void testWriteNoTransactionWithCollection() throws Exception {
- List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.setCollection("collection");
@@ -126,7 +128,7 @@ class MongoItemWriterTests {
@Test
void testWriteNoTransactionNoItems() throws Exception {
- writer.write(null);
+ writer.write(new Chunk<>());
verifyNoInteractions(template);
verifyNoInteractions(bulkOperations);
@@ -134,7 +136,7 @@ class MongoItemWriterTests {
@Test
void testWriteTransactionNoCollection() {
- final List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ final Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
new TransactionTemplate(transactionManager).execute((TransactionCallback) status -> {
assertDoesNotThrow(() -> writer.write(items));
@@ -147,7 +149,7 @@ class MongoItemWriterTests {
@Test
void testWriteTransactionWithCollection() {
- final List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ final Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.setCollection("collection");
@@ -162,7 +164,7 @@ class MongoItemWriterTests {
@Test
void testWriteTransactionFails() {
- final List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ final Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.setCollection("collection");
@@ -183,7 +185,7 @@ class MongoItemWriterTests {
*/
@Test
void testWriteTransactionReadOnly() {
- final List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ final Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.setCollection("collection");
@@ -201,7 +203,7 @@ class MongoItemWriterTests {
@Test
void testRemoveNoObjectIdNoCollection() throws Exception {
writer.setDelete(true);
- List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.write(items);
@@ -212,7 +214,7 @@ class MongoItemWriterTests {
@Test
void testRemoveNoObjectIdWithCollection() throws Exception {
writer.setDelete(true);
- List items = Arrays.asList(new Item("Foo"), new Item("Bar"));
+ Chunk items = Chunk.of(new Item("Foo"), new Item("Bar"));
writer.setCollection("collection");
writer.write(items);
@@ -224,7 +226,7 @@ class MongoItemWriterTests {
@Test
void testRemoveNoTransactionNoCollection() throws Exception {
writer.setDelete(true);
- List items = Arrays.asList(new Item(1), new Item(2));
+ Chunk items = Chunk.of(new Item(1), new Item(2));
writer.write(items);
@@ -235,7 +237,7 @@ class MongoItemWriterTests {
@Test
void testRemoveNoTransactionWithCollection() throws Exception {
writer.setDelete(true);
- List items = Arrays.asList(new Item(1), new Item(2));
+ Chunk items = Chunk.of(new Item(1), new Item(2));
writer.setCollection("collection");
@@ -285,7 +287,7 @@ class MongoItemWriterTests {
new TransactionTemplate(transactionManager).execute((TransactionCallback) status -> {
try {
for (int i = 0; i < limit; i++) {
- writers.get(i).write(Collections.singletonList(String.valueOf(i)));
+ writers.get(i).write(Chunk.of(String.valueOf(i)));
}
}
catch (Exception e) {
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java
index 0a9584a48..d727b1343 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java
@@ -25,6 +25,8 @@ import org.mockito.quality.Strictness;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
+import org.springframework.batch.item.Chunk;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
@@ -62,32 +64,6 @@ class Neo4jItemWriterTests {
writer.afterPropertiesSet();
}
- @Test
- void testWriteNullSession() throws Exception {
-
- writer = new Neo4jItemWriter<>();
-
- writer.setSessionFactory(this.sessionFactory);
- writer.afterPropertiesSet();
-
- writer.write(null);
-
- verifyNoInteractions(this.session);
- }
-
- @Test
- void testWriteNullWithSession() throws Exception {
- writer = new Neo4jItemWriter<>();
-
- writer.setSessionFactory(this.sessionFactory);
- writer.afterPropertiesSet();
-
- when(this.sessionFactory.openSession()).thenReturn(this.session);
- writer.write(null);
-
- verifyNoInteractions(this.session);
- }
-
@Test
void testWriteNoItemsWithSession() throws Exception {
writer = new Neo4jItemWriter<>();
@@ -96,7 +72,7 @@ class Neo4jItemWriterTests {
writer.afterPropertiesSet();
when(this.sessionFactory.openSession()).thenReturn(this.session);
- writer.write(new ArrayList<>());
+ writer.write(new Chunk<>());
verifyNoInteractions(this.session);
}
@@ -108,7 +84,7 @@ class Neo4jItemWriterTests {
writer.setSessionFactory(this.sessionFactory);
writer.afterPropertiesSet();
- List items = new ArrayList<>();
+ Chunk items = new Chunk<>();
items.add("foo");
items.add("bar");
@@ -126,7 +102,7 @@ class Neo4jItemWriterTests {
writer.setSessionFactory(this.sessionFactory);
writer.afterPropertiesSet();
- List items = new ArrayList<>();
+ Chunk items = new Chunk<>();
items.add("foo");
items.add("bar");
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java
index 11cdbceee..d62f06ab0 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java
@@ -31,6 +31,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.data.repository.CrudRepository;
@ExtendWith(MockitoExtension.class)
@@ -64,16 +66,14 @@ class RepositoryItemWriterTests {
@Test
void testWriteNoItems() throws Exception {
- writer.write(null);
-
- writer.write(new ArrayList<>());
+ writer.write(new Chunk<>());
verifyNoInteractions(repository);
}
@Test
void testWriteItems() throws Exception {
- List items = Collections.singletonList("foo");
+ Chunk items = Chunk.of("foo");
writer.write(items);
@@ -83,7 +83,7 @@ class RepositoryItemWriterTests {
@Test
void testWriteItemsWithDefaultMethodName() throws Exception {
- List items = Collections.singletonList("foo");
+ Chunk items = Chunk.of("foo");
writer.setMethodName(null);
writer.write(items);
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java
index d451f05e5..0ffe43a52 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java
@@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.SpELItemKeyMapper;
import org.springframework.batch.item.data.GemfireItemWriter;
import org.springframework.data.gemfire.GemfireTemplate;
@@ -35,6 +37,7 @@ import static org.mockito.Mockito.verify;
/**
* @author Glenn Renfro
+ * @author Mahmoud Ben Hassine
*/
@ExtendWith(MockitoExtension.class)
class GemfireItemWriterBuilderTests {
@@ -44,11 +47,11 @@ class GemfireItemWriterBuilderTests {
private SpELItemKeyMapper itemKeyMapper;
- private List items;
+ private Chunk items;
@BeforeEach
void setUp() {
- this.items = Arrays.asList(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")),
+ this.items = Chunk.of(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")),
new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val2")));
this.itemKeyMapper = new SpELItemKeyMapper<>("bar.val");
}
@@ -60,8 +63,8 @@ class GemfireItemWriterBuilderTests {
writer.write(this.items);
- verify(this.template).put("val1", items.get(0));
- verify(this.template).put("val2", items.get(1));
+ verify(this.template).put("val1", items.getItems().get(0));
+ verify(this.template).put("val2", items.getItems().get(1));
verify(this.template, never()).remove("val1");
verify(this.template, never()).remove("val2");
}
@@ -75,8 +78,8 @@ class GemfireItemWriterBuilderTests {
verify(this.template).remove("val1");
verify(this.template).remove("val2");
- verify(this.template, never()).put("val1", items.get(0));
- verify(this.template, never()).put("val2", items.get(1));
+ verify(this.template, never()).put("val1", items.getItems().get(0));
+ verify(this.template, never()).put("val2", items.getItems().get(1));
}
@Test
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java
index 7dbf19815..08c1fa34a 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java
@@ -31,6 +31,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.data.MongoItemWriter;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.BulkOperations;
@@ -68,9 +70,9 @@ class MongoItemWriterBuilderTests {
private MongoConverter mongoConverter;
- private List saveItems;
+ private Chunk saveItems;
- private List removeItems;
+ private Chunk removeItems;
@BeforeEach
void setUp() {
@@ -81,8 +83,8 @@ class MongoItemWriterBuilderTests {
mongoConverter = spy(new MappingMongoConverter(this.dbRefResolver, mappingContext));
when(this.template.getConverter()).thenReturn(mongoConverter);
- this.saveItems = Arrays.asList(new Item("Foo"), new Item("Bar"));
- this.removeItems = Arrays.asList(new Item(1), new Item(2));
+ this.saveItems = Chunk.of(new Item("Foo"), new Item("Bar"));
+ this.removeItems = Chunk.of(new Item(1), new Item(2));
}
@Test
@@ -91,8 +93,8 @@ class MongoItemWriterBuilderTests {
writer.write(this.saveItems);
verify(this.template).bulkOps(any(), any(Class.class));
- verify(this.mongoConverter).write(eq(this.saveItems.get(0)), any(Document.class));
- verify(this.mongoConverter).write(eq(this.saveItems.get(1)), any(Document.class));
+ verify(this.mongoConverter).write(eq(this.saveItems.getItems().get(0)), any(Document.class));
+ verify(this.mongoConverter).write(eq(this.saveItems.getItems().get(1)), any(Document.class));
verify(this.bulkOperations, times(2)).replaceOne(any(Query.class), any(Object.class), any());
verify(this.bulkOperations, never()).remove(any(Query.class));
}
@@ -105,8 +107,8 @@ class MongoItemWriterBuilderTests {
writer.write(this.saveItems);
verify(this.template).bulkOps(any(), eq("collection"));
- verify(this.mongoConverter).write(eq(this.saveItems.get(0)), any(Document.class));
- verify(this.mongoConverter).write(eq(this.saveItems.get(1)), any(Document.class));
+ verify(this.mongoConverter).write(eq(this.saveItems.getItems().get(0)), any(Document.class));
+ verify(this.mongoConverter).write(eq(this.saveItems.getItems().get(1)), any(Document.class));
verify(this.bulkOperations, times(2)).replaceOne(any(Query.class), any(Object.class), any());
verify(this.bulkOperations, never()).remove(any(Query.class));
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java
index 34546077c..897277745 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java
@@ -26,6 +26,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.data.Neo4jItemWriter;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -36,6 +37,7 @@ import static org.mockito.Mockito.when;
/**
* @author Glenn Renfro
+ * @author Mahmoud Ben Hassine
*/
@SuppressWarnings("deprecation")
@ExtendWith(MockitoExtension.class)
@@ -51,7 +53,7 @@ class Neo4jItemWriterBuilderTests {
void testBasicWriter() throws Exception {
Neo4jItemWriter writer = new Neo4jItemWriterBuilder().sessionFactory(this.sessionFactory)
.build();
- List items = new ArrayList<>();
+ Chunk items = new Chunk<>();
items.add("foo");
items.add("bar");
@@ -68,7 +70,7 @@ class Neo4jItemWriterBuilderTests {
void testBasicDelete() throws Exception {
Neo4jItemWriter writer = new Neo4jItemWriterBuilder().delete(true)
.sessionFactory(this.sessionFactory).build();
- List items = new ArrayList<>();
+ Chunk items = new Chunk<>();
items.add("foo");
items.add("bar");
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java
index 3c8c2ffe4..0a419e6fb 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java
@@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.batch.item.data.RepositoryItemWriter;
import org.springframework.data.repository.CrudRepository;
@@ -60,7 +62,7 @@ class RepositoryItemWriterBuilderTests {
RepositoryItemWriter writer = new RepositoryItemWriterBuilder().methodName("save")
.repository(this.repository).build();
- List items = Collections.singletonList("foo");
+ Chunk items = Chunk.of("foo");
writer.write(items);
@@ -72,7 +74,7 @@ class RepositoryItemWriterBuilderTests {
RepositoryItemWriter writer = new RepositoryItemWriterBuilder().methodName("foo")
.repository(this.repository).build();
- List items = Collections.singletonList("foo");
+ Chunk items = Chunk.of("foo");
writer.write(items);
@@ -88,7 +90,7 @@ class RepositoryItemWriterBuilderTests {
RepositoryItemWriter writer = new RepositoryItemWriterBuilder().methodName("foo")
.repository(repositoryMethodReference).build();
- List items = Collections.singletonList("foo");
+ Chunk items = Chunk.of("foo");
writer.write(items);
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java
index ef214c5ac..470f6b4f6 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java
@@ -23,6 +23,8 @@ import org.hibernate.SessionFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.springframework.batch.item.Chunk;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -84,7 +86,7 @@ class HibernateItemWriterTests {
this.currentSession.flush();
this.currentSession.clear();
- List items = Arrays.asList(new String[] { "foo", "bar" });
+ Chunk items = Chunk.of("foo", "bar");
writer.write(items);
}
@@ -95,7 +97,7 @@ class HibernateItemWriterTests {
final RuntimeException ex = new RuntimeException("ERROR");
when(this.currentSession.contains("foo")).thenThrow(ex);
- Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
+ Exception exception = assertThrows(RuntimeException.class, () -> writer.write(Chunk.of("foo")));
assertEquals("ERROR", exception.getMessage());
}
@@ -109,7 +111,7 @@ class HibernateItemWriterTests {
currentSession.flush();
currentSession.clear();
- List items = Arrays.asList(new String[] { "foo", "bar" });
+ Chunk items = Chunk.of("foo", "bar");
writer.write(items);
}
@@ -121,7 +123,7 @@ class HibernateItemWriterTests {
when(factory.getCurrentSession()).thenReturn(currentSession);
when(currentSession.contains("foo")).thenThrow(ex);
- Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
+ Exception exception = assertThrows(RuntimeException.class, () -> writer.write(Chunk.of("foo")));
assertEquals("ERROR", exception.getMessage());
}
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java
index c2bb97dce..21e375a9c 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java
@@ -27,6 +27,8 @@ import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+
+import org.springframework.batch.item.Chunk;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException;
@@ -38,6 +40,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
* @author Dave Syer
* @author Thomas Risberg
* @author Will Schipp
+ * @author Mahmoud Ben Hassine
*/
class JdbcBatchItemWriterClassicTests {
@@ -105,7 +108,7 @@ class JdbcBatchItemWriterClassicTests {
void testWriteAndFlush() throws Exception {
ps.addBatch();
when(ps.executeBatch()).thenReturn(new int[] { 123 });
- writer.write(Collections.singletonList("bar"));
+ writer.write(Chunk.of("bar"));
assertEquals(2, list.size());
assertTrue(list.contains("SQL"));
}
@@ -114,7 +117,7 @@ class JdbcBatchItemWriterClassicTests {
void testWriteAndFlushWithEmptyUpdate() throws Exception {
ps.addBatch();
when(ps.executeBatch()).thenReturn(new int[] { 0 });
- Exception exception = assertThrows(EmptyResultDataAccessException.class, () -> writer.write(List.of("bar")));
+ Exception exception = assertThrows(EmptyResultDataAccessException.class, () -> writer.write(Chunk.of("bar")));
String message = exception.getMessage();
assertTrue(message.contains("did not update"), "Wrong message: " + message);
assertEquals(2, list.size());
@@ -133,7 +136,7 @@ class JdbcBatchItemWriterClassicTests {
});
ps.addBatch();
when(ps.executeBatch()).thenReturn(new int[] { 123 });
- Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
+ Exception exception = assertThrows(RuntimeException.class, () -> writer.write(Chunk.of("foo")));
assertEquals("bar", exception.getMessage());
assertEquals(2, list.size());
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter() {
@@ -142,7 +145,7 @@ class JdbcBatchItemWriterClassicTests {
list.add(item);
}
});
- writer.write(Collections.singletonList("foo"));
+ writer.write(Chunk.of("foo"));
assertEquals(4, list.size());
assertTrue(list.contains("SQL"));
assertTrue(list.contains("foo"));
diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java
index 7062a6fef..b117604c9 100644
--- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java
+++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
+import org.springframework.batch.item.Chunk;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -43,6 +44,7 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
* @author Thomas Risberg
* @author Will Schipp
* @author Michael Minella
+ * @author Mahmoud Ben Hassine
*/
public class JdbcBatchItemWriterNamedParameterTests {
@@ -119,7 +121,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
eqSqlParameterSourceArray(
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
.thenReturn(new int[] { 1 });
- writer.write(List.of(new Foo("bar")));
+ writer.write(Chunk.of(new Foo("bar")));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -134,7 +136,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
ArgumentCaptor