Use the Chunk API consistently
This commit replaces the usage of List with Chunk where appropriate. Summary of changes: - The Chunk class was moved from the `org.springframework.batch.core.step.item` package to the `org.springframework.batch.item` package - The signature of the method `ItemWriter#write(List)` was changed to `ItemWriter#write(Chunk)` - All implementations of `ItemWriter` were updated to use the Chunk API instead of List - All methods in the `ItemWriteListener` interface were updated to use the Chunk API instead of List - All implementations of `ItemWriteListener` were updated to use the Chunk API instead of List - The constructor of `ChunkRequest` was changed to accept a Chunk instead of a Collection of items - The return type of `ChunkRequest#getItems()` was changed from List to Chunk Resolves #3954
This commit is contained in:
@@ -18,12 +18,13 @@ package org.springframework.batch.core;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
@@ -42,19 +43,18 @@ import org.springframework.batch.item.ItemWriter;
|
||||
public interface ItemWriteListener<S> 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<S> 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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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).<br>
|
||||
* this annotation takes a {@link org.springframework.batch.item.Chunk} because Spring
|
||||
* Batch generally processes a group of items (for the sake of efficiency).<br>
|
||||
* <br>
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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}. <br>
|
||||
* Marks a method to be called before a chunk is passed to an {@link ItemWriter}. <br>
|
||||
* <br>
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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).<br>
|
||||
* 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).<br>
|
||||
* <br>
|
||||
* 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
|
||||
*/
|
||||
|
||||
@@ -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<S> implements ItemWriteListener<S> {
|
||||
@@ -50,10 +52,10 @@ public class CompositeItemWriteListener<S> implements ItemWriteListener<S> {
|
||||
/**
|
||||
* 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<ItemWriteListener<? super S>> iterator = listeners.reverse(); iterator.hasNext();) {
|
||||
ItemWriteListener<? super S> listener = iterator.next();
|
||||
listener.afterWrite(items);
|
||||
@@ -63,10 +65,10 @@ public class CompositeItemWriteListener<S> implements ItemWriteListener<S> {
|
||||
/**
|
||||
* 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<ItemWriteListener<? super S>> iterator = listeners.iterator(); iterator.hasNext();) {
|
||||
ItemWriteListener<? super S> listener = iterator.next();
|
||||
listener.beforeWrite(items);
|
||||
@@ -76,10 +78,10 @@ public class CompositeItemWriteListener<S> implements ItemWriteListener<S> {
|
||||
/**
|
||||
* 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<ItemWriteListener<? super S>> iterator = listeners.reverse(); iterator.hasNext();) {
|
||||
ItemWriteListener<? super S> listener = iterator.next();
|
||||
listener.onWriteError(ex, items);
|
||||
|
||||
@@ -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<T, S> 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<T, S> 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<T, S> 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);
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 <I> input item type
|
||||
*/
|
||||
public class ChunkOrientedTasklet<I> implements Tasklet {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Object, Object> {
|
||||
@@ -45,7 +47,7 @@ public class DefaultItemFailureHandler extends ItemListenerSupport<Object, Objec
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(Exception ex, List<? extends Object> item) {
|
||||
public void onWriteError(Exception ex, Chunk<? extends Object> item) {
|
||||
try {
|
||||
logger.error("Error encountered while writing item: [ " + item + "]", ex);
|
||||
}
|
||||
|
||||
@@ -34,8 +34,10 @@ import org.springframework.batch.core.step.skip.NonSkippableProcessException;
|
||||
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
|
||||
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
|
||||
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.ItemWriter;
|
||||
import org.springframework.batch.item.SkipWrapper;
|
||||
import org.springframework.classify.BinaryExceptionClassifier;
|
||||
import org.springframework.classify.Classifier;
|
||||
import org.springframework.retry.ExhaustedRetryException;
|
||||
@@ -337,7 +339,7 @@ public class FaultTolerantChunkProcessor<I, O> extends SimpleChunkProcessor<I, O
|
||||
Timer.Sample sample = BatchMetrics.createTimerSample();
|
||||
String status = BatchMetrics.STATUS_SUCCESS;
|
||||
try {
|
||||
doWrite(outputs.getItems());
|
||||
doWrite(outputs);
|
||||
}
|
||||
catch (Exception e) {
|
||||
status = BatchMetrics.STATUS_FAILURE;
|
||||
@@ -590,7 +592,7 @@ public class FaultTolerantChunkProcessor<I, O> extends SimpleChunkProcessor<I, O
|
||||
}
|
||||
}
|
||||
|
||||
List<O> items = Collections.singletonList(outputIterator.next());
|
||||
Chunk<O> items = Chunk.of(outputIterator.next());
|
||||
inputIterator.next();
|
||||
try {
|
||||
writeItems(items);
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.batch.core.step.skip.SkipException;
|
||||
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
|
||||
import org.springframework.batch.core.step.skip.SkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.SkipPolicyFailedException;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.classify.BinaryExceptionClassifier;
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.listener.MulticasterBatchListener;
|
||||
import org.springframework.batch.core.observability.BatchMetrics;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -145,7 +146,7 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
* @param items list of items to be written.
|
||||
* @throws Exception thrown if error occurs.
|
||||
*/
|
||||
protected final void doWrite(List<O> items) throws Exception {
|
||||
protected final void doWrite(Chunk<O> items) throws Exception {
|
||||
|
||||
if (itemWriter == null) {
|
||||
return;
|
||||
@@ -167,7 +168,7 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
* Call the listener's after write method.
|
||||
* @param items list of items that were just written.
|
||||
*/
|
||||
protected final void doAfterWrite(List<O> items) {
|
||||
protected final void doAfterWrite(Chunk<O> items) {
|
||||
listener.afterWrite(items);
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
* @param e exception that occurred.
|
||||
* @param items list of items that failed to be written.
|
||||
*/
|
||||
protected final void doOnWriteError(Exception e, List<O> items) {
|
||||
protected final void doOnWriteError(Exception e, Chunk<O> items) {
|
||||
listener.onWriteError(e, items);
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
* @param items list of items to be written.
|
||||
* @throws Exception thrown if error occurs.
|
||||
*/
|
||||
protected void writeItems(List<O> items) throws Exception {
|
||||
protected void writeItems(Chunk<O> items) throws Exception {
|
||||
if (itemWriter != null) {
|
||||
itemWriter.write(items);
|
||||
}
|
||||
@@ -267,10 +268,10 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple implementation delegates to the {@link #doWrite(List)} method and increments
|
||||
* the write count in the contribution. Subclasses can handle more complicated
|
||||
* scenarios, e.g.with fault tolerance. If output items are skipped they should be
|
||||
* removed from the inputs as well.
|
||||
* Simple implementation delegates to the {@link #doWrite(Chunk)} method and
|
||||
* increments the write count in the contribution. Subclasses can handle more
|
||||
* complicated scenarios, e.g.with fault tolerance. If output items are skipped they
|
||||
* should be removed from the inputs as well.
|
||||
* @param contribution the current step contribution
|
||||
* @param inputs the inputs that gave rise to the outputs
|
||||
* @param outputs the outputs to write
|
||||
@@ -280,7 +281,7 @@ public class SimpleChunkProcessor<I, O> implements ChunkProcessor<I>, Initializi
|
||||
Timer.Sample sample = BatchMetrics.createTimerSample();
|
||||
String status = BatchMetrics.STATUS_SUCCESS;
|
||||
try {
|
||||
doWrite(outputs.getItems());
|
||||
doWrite(outputs);
|
||||
}
|
||||
catch (Exception e) {
|
||||
/*
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.listener.MulticasterBatchListener;
|
||||
import org.springframework.batch.core.observability.BatchMetrics;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2012 the original author or authors.
|
||||
* Copyright 2009-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,16 +17,18 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* @author Dan Garrette
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DummyItemWriter implements ItemWriter<Object> {
|
||||
|
||||
@Override
|
||||
public void write(List<? extends Object> items) throws Exception {
|
||||
public void write(Chunk<? extends Object> items) throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010 the original author or authors.
|
||||
* Copyright 2010-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,11 +18,12 @@ package org.springframework.batch.core.configuration.xml;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.annotation.AfterWrite;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
|
||||
public class TestPojoListener extends AbstractTestComponent {
|
||||
|
||||
@AfterWrite
|
||||
public void after(List<Object> items) {
|
||||
public void after(Chunk<Object> items) {
|
||||
executed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-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,12 +17,13 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
public class TestWriter extends AbstractTestComponent implements ItemWriter<String> {
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
executed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -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.support.transaction.TransactionAwareProxyFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -49,7 +51,7 @@ public class EmptyItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<? extends T> items) {
|
||||
public void write(Chunk<? extends T> items) {
|
||||
for (T data : items) {
|
||||
if (!failed && list.size() == failurePoint) {
|
||||
failed = true;
|
||||
|
||||
@@ -24,10 +24,12 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.ItemWriteListener;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
class CompositeItemWriteListenerTests {
|
||||
@@ -46,21 +48,21 @@ class CompositeItemWriteListenerTests {
|
||||
|
||||
@Test
|
||||
void testBeforeWrite() {
|
||||
List<Object> item = Collections.singletonList(new Object());
|
||||
Chunk<Object> item = Chunk.of(new Object());
|
||||
listener.beforeWrite(item);
|
||||
compositeListener.beforeWrite(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAfterWrite() {
|
||||
List<Object> item = Collections.singletonList(new Object());
|
||||
Chunk<Object> item = Chunk.of(new Object());
|
||||
listener.afterWrite(item);
|
||||
compositeListener.afterWrite(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOnWriteError() {
|
||||
List<Object> item = Collections.singletonList(new Object());
|
||||
Chunk<Object> item = Chunk.of(new Object());
|
||||
Exception ex = new Exception();
|
||||
listener.onWriteError(ex, item);
|
||||
compositeListener.onWriteError(ex, item);
|
||||
@@ -73,7 +75,7 @@ class CompositeItemWriteListenerTests {
|
||||
add(listener);
|
||||
}
|
||||
});
|
||||
List<Object> item = Collections.singletonList(new Object());
|
||||
Chunk<Object> item = Chunk.of(new Object());
|
||||
listener.beforeWrite(item);
|
||||
compositeListener.beforeWrite(item);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.batch.core.configuration.annotation.JobBuilderFactory
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.support.RunIdIncrementer;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -175,7 +176,7 @@ class ItemListenerErrorTests {
|
||||
private boolean goingToFail = false;
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
if (goingToFail) {
|
||||
throw new RuntimeException("failure in the writer");
|
||||
}
|
||||
@@ -294,21 +295,21 @@ class ItemListenerErrorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeWrite(List<? extends String> items) {
|
||||
public void beforeWrite(Chunk<? extends String> items) {
|
||||
if (methodToThrowExceptionFrom.equals("beforeWrite")) {
|
||||
throw new RuntimeException("beforeWrite caused this Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> items) {
|
||||
public void afterWrite(Chunk<? extends String> items) {
|
||||
if (methodToThrowExceptionFrom.equals("afterWrite")) {
|
||||
throw new RuntimeException("afterWrite caused this Exception");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(Exception ex, List<? extends String> item) {
|
||||
public void onWriteError(Exception ex, Chunk<? extends String> item) {
|
||||
if (methodToThrowExceptionFrom.equals("onWriteError")) {
|
||||
throw new RuntimeException("onWriteError caused this Exception");
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.batch.core.annotation.BeforeProcess;
|
||||
import org.springframework.batch.core.annotation.BeforeRead;
|
||||
import org.springframework.batch.core.annotation.BeforeWrite;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
@@ -703,7 +704,7 @@ class MulticasterBatchListenerTests {
|
||||
* (java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> items) {
|
||||
public void afterWrite(Chunk<? extends String> items) {
|
||||
count++;
|
||||
if (error) {
|
||||
throw new RuntimeException("listener error");
|
||||
@@ -718,7 +719,7 @@ class MulticasterBatchListenerTests {
|
||||
* (java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void beforeWrite(List<? extends String> items) {
|
||||
public void beforeWrite(Chunk<? extends String> items) {
|
||||
count++;
|
||||
if (error) {
|
||||
throw new RuntimeException("listener error");
|
||||
@@ -733,7 +734,7 @@ class MulticasterBatchListenerTests {
|
||||
* (java.lang.Exception, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
public void onWriteError(Exception exception, List<? extends String> items) {
|
||||
public void onWriteError(Exception exception, Chunk<? extends String> items) {
|
||||
count++;
|
||||
if (error) {
|
||||
throw new RuntimeException("listener error");
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.springframework.batch.core.annotation.OnReadError;
|
||||
import org.springframework.batch.core.annotation.OnWriteError;
|
||||
import org.springframework.batch.core.configuration.xml.AbstractTestComponent;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -66,6 +67,7 @@ import static org.springframework.batch.core.listener.StepListenerMetaData.AFTER
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
class StepListenerFactoryBeanTests {
|
||||
@@ -87,7 +89,7 @@ class StepListenerFactoryBeanTests {
|
||||
// factoryBean.setMetaDataMap(metaDataMap);
|
||||
String readItem = "item";
|
||||
Integer writeItem = 2;
|
||||
List<Integer> writeItems = Arrays.asList(writeItem);
|
||||
Chunk<Integer> writeItems = Chunk.of(writeItem);
|
||||
StepListener listener = (StepListener) factoryBean.getObject();
|
||||
((StepExecutionListener) listener).beforeStep(stepExecution);
|
||||
((StepExecutionListener) listener).afterStep(stepExecution);
|
||||
@@ -283,7 +285,7 @@ class StepListenerFactoryBeanTests {
|
||||
factoryBean.setDelegate(delegate);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
|
||||
listener.afterWrite(Arrays.asList("foo", "bar"));
|
||||
listener.afterWrite(Chunk.of("foo", "bar"));
|
||||
assertTrue(delegate.isExecuted());
|
||||
}
|
||||
|
||||
@@ -291,16 +293,16 @@ class StepListenerFactoryBeanTests {
|
||||
void testRightSignatureAnnotation() {
|
||||
AbstractTestComponent delegate = new AbstractTestComponent() {
|
||||
@AfterWrite
|
||||
public void aMethod(List<String> items) {
|
||||
public void aMethod(Chunk<String> chunk) {
|
||||
executed = true;
|
||||
assertEquals("foo", items.get(0));
|
||||
assertEquals("bar", items.get(1));
|
||||
assertEquals("foo", chunk.getItems().get(0));
|
||||
assertEquals("bar", chunk.getItems().get(1));
|
||||
}
|
||||
};
|
||||
factoryBean.setDelegate(delegate);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
|
||||
listener.afterWrite(Arrays.asList("foo", "bar"));
|
||||
listener.afterWrite(Chunk.of("foo", "bar"));
|
||||
assertTrue(delegate.isExecuted());
|
||||
}
|
||||
|
||||
@@ -330,7 +332,7 @@ class StepListenerFactoryBeanTests {
|
||||
factoryBean.setMetaDataMap(metaDataMap);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
|
||||
listener.afterWrite(Arrays.asList("foo", "bar"));
|
||||
listener.afterWrite(Chunk.of("foo", "bar"));
|
||||
assertTrue(delegate.isExecuted());
|
||||
}
|
||||
|
||||
@@ -338,19 +340,18 @@ class StepListenerFactoryBeanTests {
|
||||
void testRightSignatureNamedMethod() {
|
||||
AbstractTestComponent delegate = new AbstractTestComponent() {
|
||||
@SuppressWarnings("unused")
|
||||
public void aMethod(List<String> items) {
|
||||
public void aMethod(Chunk<String> chunk) {
|
||||
executed = true;
|
||||
assertEquals("foo", items.get(0));
|
||||
assertEquals("bar", items.get(1));
|
||||
assertEquals("foo", chunk.getItems().get(0));
|
||||
assertEquals("bar", chunk.getItems().get(1));
|
||||
}
|
||||
};
|
||||
factoryBean.setDelegate(delegate);
|
||||
Map<String, String> metaDataMap = new HashMap<>();
|
||||
metaDataMap.put(AFTER_WRITE.getPropertyName(), "aMethod");
|
||||
factoryBean.setMetaDataMap(metaDataMap);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriteListener<String> listener = (ItemWriteListener<String>) factoryBean.getObject();
|
||||
listener.afterWrite(Arrays.asList("foo", "bar"));
|
||||
listener.afterWrite(Chunk.of("foo", "bar"));
|
||||
assertTrue(delegate.isExecuted());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-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;
|
||||
|
||||
/**
|
||||
@@ -40,12 +42,12 @@ public class ExampleItemWriter implements ItemWriter<String> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ItemWriter#write(List)
|
||||
* @see ItemWriter#write(Chunk)
|
||||
*/
|
||||
@Override
|
||||
public void write(List<? extends String> data) throws Exception {
|
||||
public void write(Chunk<? extends String> data) throws Exception {
|
||||
log.info(data);
|
||||
items.addAll(data);
|
||||
items.addAll(data.getItems());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
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.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -109,7 +110,7 @@ class OptimisticLockingFailureTests {
|
||||
public static class Writer implements ItemWriter<String> {
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
for (String item : items) {
|
||||
System.out.println(item);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.batch.core.configuration.annotation.JobBuilderFactory
|
||||
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.NonTransientResourceException;
|
||||
@@ -61,6 +62,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
*
|
||||
* @author Tobias Flohre
|
||||
* @author Michael Minella
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
class RegisterMultiListenerTests {
|
||||
|
||||
@@ -174,8 +176,8 @@ class RegisterMultiListenerTests {
|
||||
return new ItemWriter<String>() {
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
if (items.contains("item2")) {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
if (chunk.getItems().contains("item2")) {
|
||||
throw new MySkippableException();
|
||||
}
|
||||
}
|
||||
@@ -267,16 +269,16 @@ class RegisterMultiListenerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeWrite(List<? extends String> items) {
|
||||
public void beforeWrite(Chunk<? extends String> items) {
|
||||
callChecker.beforeWriteCalled++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> items) {
|
||||
public void afterWrite(Chunk<? extends String> items) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(Exception exception, List<? extends String> items) {
|
||||
public void onWriteError(Exception exception, Chunk<? extends String> items) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,12 +26,15 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.batch.item.Chunk;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
class AlmostStatefulRetryChunkTests {
|
||||
|
||||
@@ -27,9 +27,11 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
class ChunkOrientedTaskletTests {
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.listener.ItemListenerSupport;
|
||||
import org.springframework.batch.core.step.skip.AlwaysSkipItemSkipPolicy;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.PassThroughItemProcessor;
|
||||
@@ -66,11 +67,11 @@ class FaultTolerantChunkProcessorTests {
|
||||
batchRetryTemplate = new BatchRetryTemplate();
|
||||
processor = new FaultTolerantChunkProcessor<>(new PassThroughItemProcessor<>(), new ItemWriter<String>() {
|
||||
@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());
|
||||
}
|
||||
}, batchRetryTemplate);
|
||||
batchRetryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
@@ -193,8 +194,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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")) {
|
||||
fail("Expected Error!");
|
||||
}
|
||||
}
|
||||
@@ -210,8 +211,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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("Expected Exception!");
|
||||
}
|
||||
}
|
||||
@@ -232,8 +233,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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("Expected Exception!");
|
||||
}
|
||||
}
|
||||
@@ -276,8 +277,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
Chunk<String> chunk = new Chunk<>(Arrays.asList("foo", "fail", "bar"));
|
||||
processor.setListeners(Arrays.asList(new ItemListenerSupport<String, String>() {
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> item) {
|
||||
after.addAll(item);
|
||||
public void afterWrite(Chunk<? extends String> chunk) {
|
||||
after.addAll(chunk.getItems());
|
||||
}
|
||||
}));
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
@@ -301,18 +302,18 @@ class FaultTolerantChunkProcessorTests {
|
||||
Chunk<String> chunk = new Chunk<>(Arrays.asList("foo", "bar"));
|
||||
processor = new FaultTolerantChunkProcessor<>(new PassThroughItemProcessor<>(), new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
// Fail if there is more than one item
|
||||
if (items.size() > 1) {
|
||||
if (chunk.size() > 1) {
|
||||
throw new RuntimeException("Planned failure!");
|
||||
}
|
||||
list.addAll(items);
|
||||
list.addAll(chunk.getItems());
|
||||
}
|
||||
}, batchRetryTemplate);
|
||||
processor.setListeners(Arrays.asList(new ItemListenerSupport<String, String>() {
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> item) {
|
||||
after.addAll(item);
|
||||
public void afterWrite(Chunk<? extends String> chunk) {
|
||||
after.addAll(chunk.getItems());
|
||||
}
|
||||
}));
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
@@ -330,8 +331,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
Chunk<String> chunk = new Chunk<>(Arrays.asList("foo", "fail"));
|
||||
processor.setListeners(Arrays.asList(new ItemListenerSupport<String, String>() {
|
||||
@Override
|
||||
public void onWriteError(Exception e, List<? extends String> item) {
|
||||
writeError.addAll(item);
|
||||
public void onWriteError(Exception e, Chunk<? extends String> chunk) {
|
||||
writeError.addAll(chunk.getItems());
|
||||
}
|
||||
}));
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
@@ -348,15 +349,15 @@ class FaultTolerantChunkProcessorTests {
|
||||
Chunk<String> chunk = new Chunk<>(Arrays.asList("foo", "bar"));
|
||||
processor = new FaultTolerantChunkProcessor<>(new PassThroughItemProcessor<>(), new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
// Always fail in writer
|
||||
throw new RuntimeException("Planned failure!");
|
||||
}
|
||||
}, batchRetryTemplate);
|
||||
processor.setListeners(Arrays.asList(new ItemListenerSupport<String, String>() {
|
||||
@Override
|
||||
public void onWriteError(Exception e, List<? extends String> item) {
|
||||
writeError.addAll(item);
|
||||
public void onWriteError(Exception e, Chunk<? extends String> chunk) {
|
||||
writeError.addAll(chunk.getItems());
|
||||
}
|
||||
}));
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
@@ -376,8 +377,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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 IllegalArgumentException("Expected Exception!");
|
||||
}
|
||||
}
|
||||
@@ -408,8 +409,8 @@ class FaultTolerantChunkProcessorTests {
|
||||
processor.setWriteSkipPolicy(new AlwaysSkipItemSkipPolicy());
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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 IllegalArgumentException("Expected Exception!");
|
||||
}
|
||||
}
|
||||
@@ -445,11 +446,11 @@ class FaultTolerantChunkProcessorTests {
|
||||
Collections.<Class<? extends Throwable>, Boolean>singletonMap(IllegalArgumentException.class, true)));
|
||||
processor.setItemWriter(new ItemWriter<String>() {
|
||||
@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 IllegalArgumentException("Expected Exception!");
|
||||
}
|
||||
if (items.contains("2")) {
|
||||
if (chunk.getItems().contains("2")) {
|
||||
throw new RuntimeException("Expected Non-Skippable Exception!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.batch.item.UnexpectedInputException;
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
@@ -141,7 +142,7 @@ class FaultTolerantStepFactoryBeanNonBufferingTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
public void write(Chunk<? extends String> items) throws Exception {
|
||||
logger.debug("Writing: " + items);
|
||||
for (String item : items) {
|
||||
if (failures.contains(item)) {
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
|
||||
import org.springframework.batch.core.step.AbstractStep;
|
||||
import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
@@ -91,8 +92,8 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
|
||||
private ItemWriter<String> writer = new ItemWriter<String>() {
|
||||
@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());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -152,7 +153,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
factory.setTransactionManager(new ResourcelessTransactionManager());
|
||||
ItemWriter<Integer> failingWriter = new ItemWriter<Integer>() {
|
||||
@Override
|
||||
public void write(List<? extends Integer> data) throws Exception {
|
||||
public void write(Chunk<? extends Integer> data) throws Exception {
|
||||
int count = 0;
|
||||
for (Integer item : data) {
|
||||
if (count++ == 2) {
|
||||
@@ -202,7 +203,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
final List<String> ITEM_LIST = Arrays.asList("a", "b", "c");
|
||||
ItemWriter<String> failingWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> data) throws Exception {
|
||||
public void write(Chunk<? extends String> data) throws Exception {
|
||||
int count = 0;
|
||||
for (String item : data) {
|
||||
if (count++ == 2) {
|
||||
@@ -248,7 +249,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
void testNoItemsReprocessedWhenErrorInWriterAndProcessorNotTransactional() throws Exception {
|
||||
ItemWriter<String> failingWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> data) throws Exception {
|
||||
public void write(Chunk<? extends String> data) throws Exception {
|
||||
int count = 0;
|
||||
for (String item : data) {
|
||||
if (count++ == 2) {
|
||||
@@ -358,11 +359,11 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
factory.setStreams(new ItemStream[] { reader });
|
||||
factory.setItemWriter(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
if (fail && items.contains("e")) {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
if (fail && chunk.getItems().contains("e")) {
|
||||
throw new RuntimeException("Planned failure");
|
||||
}
|
||||
processed.addAll(items);
|
||||
processed.addAll(chunk.getItems());
|
||||
}
|
||||
});
|
||||
factory.setRetryLimit(0);
|
||||
@@ -445,11 +446,11 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
processed.addAll(item);
|
||||
written.addAll(item);
|
||||
if (item.contains("b") || item.contains("d")) {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
logger.debug("Write Called! Item: [" + chunk.getItems() + "]");
|
||||
processed.addAll(chunk.getItems());
|
||||
written.addAll(chunk.getItems());
|
||||
if (chunk.getItems().contains("b") || chunk.getItems().contains("d")) {
|
||||
throw new RuntimeException("Write error - planned but recoverable.");
|
||||
}
|
||||
}
|
||||
@@ -503,11 +504,11 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
processed.addAll(item);
|
||||
written.addAll(item);
|
||||
if (item.contains("b") || item.contains("d")) {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
logger.debug("Write Called! Item: [" + chunk + "]");
|
||||
processed.addAll(chunk.getItems());
|
||||
written.addAll(chunk.getItems());
|
||||
if (chunk.getItems().contains("b") || chunk.getItems().contains("d")) {
|
||||
throw new RuntimeException("Write error - planned but recoverable.");
|
||||
}
|
||||
}
|
||||
@@ -556,10 +557,10 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
};
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
processed.addAll(item);
|
||||
written.addAll(item);
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
processed.addAll(chunk.getItems());
|
||||
written.addAll(chunk.getItems());
|
||||
logger.debug("Write Called! Item: [" + chunk.getItems() + "]");
|
||||
throw new RuntimeException("Write error - planned but retryable.");
|
||||
}
|
||||
};
|
||||
@@ -608,10 +609,10 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
};
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
processed.addAll(item);
|
||||
written.addAll(item);
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
processed.addAll(chunk.getItems());
|
||||
written.addAll(chunk.getItems());
|
||||
logger.debug("Write Called! Item: [" + chunk.getItems() + "]");
|
||||
throw new RuntimeException("Write error - planned but not skippable.");
|
||||
}
|
||||
};
|
||||
@@ -655,10 +656,10 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
};
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
processed.addAll(item);
|
||||
written.addAll(item);
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
processed.addAll(chunk.getItems());
|
||||
written.addAll(chunk.getItems());
|
||||
logger.debug("Write Called! Item: [" + chunk.getItems() + "]");
|
||||
throw new RuntimeException("Write error - planned but retryable.");
|
||||
}
|
||||
};
|
||||
@@ -707,9 +708,9 @@ class FaultTolerantStepFactoryBeanRetryTests {
|
||||
};
|
||||
ItemWriter<String> itemWriter = new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> item) throws Exception {
|
||||
processed.addAll(item);
|
||||
logger.debug("Write Called! Item: [" + item + "]");
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
processed.addAll(chunk.getItems());
|
||||
logger.debug("Write Called! Item: [" + chunk.getItems() + "]");
|
||||
throw new RuntimeException("Write error - planned but retryable.");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean;
|
||||
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
|
||||
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.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
@@ -451,7 +452,7 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
factory.setSkippableExceptionClasses(map);
|
||||
factory.setItemWriter(new ItemWriter<String>() {
|
||||
@Override
|
||||
public void write(List<? extends String> items) {
|
||||
public void write(Chunk<? extends String> items) {
|
||||
throw new FatalRuntimeException("Ouch!");
|
||||
}
|
||||
});
|
||||
@@ -766,8 +767,8 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
ItemProcessListener<String, String>, SkipListener<String, String>, ChunkListener {
|
||||
|
||||
@Override
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
if (items.contains("4")) {
|
||||
public void write(Chunk<? extends String> chunk) throws Exception {
|
||||
if (chunk.getItems().contains("4")) {
|
||||
throw new SkippableException("skippable");
|
||||
}
|
||||
}
|
||||
@@ -786,16 +787,16 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List<? extends String> items) {
|
||||
public void afterWrite(Chunk<? extends String> items) {
|
||||
listenerCalls.add(2);
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
@@ -33,6 +34,7 @@ import java.util.List;
|
||||
* </p>
|
||||
*
|
||||
* @author Chris Schaefer
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 3.1
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@@ -52,12 +54,12 @@ class ScriptItemProcessorTests {
|
||||
public static class TestItemWriter implements ItemWriter<String> {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>() {
|
||||
@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());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<String> writer = new ItemWriter<String>() {
|
||||
@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<String>() {
|
||||
@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<String>() {
|
||||
@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<String>, ItemProcessListener<String, String>, 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<String>, ItemWriteListener<String> {
|
||||
|
||||
@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) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<T> extends AbstractExceptionThrowingItemHandlerStub<T> implements ItemWriter<T> {
|
||||
@@ -49,7 +51,7 @@ public class SkipWriterStub<T> 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);
|
||||
|
||||
@@ -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<Person> {
|
||||
|
||||
@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")) {
|
||||
|
||||
@@ -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<String>() {
|
||||
@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));
|
||||
|
||||
|
||||
@@ -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<String> itemWriter = new ItemWriter<String>() {
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Object>() {
|
||||
@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);
|
||||
|
||||
@@ -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<String> itemWriter = new ItemWriter<String>() {
|
||||
@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());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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<Game> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<? extends Game> games) {
|
||||
public void write(Chunk<? extends Game> games) {
|
||||
|
||||
for (Game game : games) {
|
||||
|
||||
|
||||
@@ -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<PlayerSummary> {
|
||||
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
|
||||
|
||||
@Override
|
||||
public void write(List<? extends PlayerSummary> summaries) {
|
||||
public void write(Chunk<? extends PlayerSummary> summaries) {
|
||||
|
||||
for (PlayerSummary summary : summaries) {
|
||||
|
||||
|
||||
@@ -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<Player> {
|
||||
@@ -27,7 +28,7 @@ public class PlayerItemWriter implements ItemWriter<Player> {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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<Integer> itemReader = new ListItemReader<>(createItems());
|
||||
ItemWriter<Integer> 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<Integer> itemWriter = new ItemWriter<Integer>() {
|
||||
@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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T> implements ItemWriter<T> {
|
||||
@@ -26,7 +28,7 @@ public class LoggingItemWriter<T> implements ItemWriter<T> {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ public class TradeItemWriter implements ItemWriter<Trade>,
|
||||
|
||||
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<Object> {
|
||||
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<Object> {
|
||||
private Object someObject;
|
||||
|
||||
public void write(List<? extends Object> items) throws Exception {
|
||||
public void write(Chunk<? extends Object> items) throws Exception {
|
||||
// ...
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public class CompositeItemWriter<T> implements ItemWriter<T> {
|
||||
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<Foo, Bar> {
|
||||
}
|
||||
|
||||
public class BarWriter implements ItemWriter<Bar> {
|
||||
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<Bar, Foobar> {
|
||||
}
|
||||
|
||||
public class FoobarWriter implements ItemWriter<Foobar>{
|
||||
public void write(List<? extends Foobar> items) throws Exception {
|
||||
public void write(Chunk<? extends Foobar> items) throws Exception {
|
||||
//write items
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ As with `ItemReader`,
|
||||
----
|
||||
public interface ItemWriter<T> {
|
||||
|
||||
void write(List<? extends T> items) throws Exception;
|
||||
void write(Chunk<? extends T> items) throws Exception;
|
||||
|
||||
}
|
||||
----
|
||||
@@ -2732,7 +2732,7 @@ public class CustomItemWriter<T> implements ItemWriter<T> {
|
||||
|
||||
List<T> output = TransactionAwareProxyFactory.createTransactionalList();
|
||||
|
||||
public void write(List<? extends T> items) throws Exception {
|
||||
public void write(Chunk<? extends T> items) throws Exception {
|
||||
output.addAll(items);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<W> implements Iterable<W> {
|
||||
public class Chunk<W> implements Iterable<W>, Serializable {
|
||||
|
||||
private List<W> items = new ArrayList<>();
|
||||
|
||||
@@ -46,15 +49,19 @@ public class Chunk<W> implements Iterable<W> {
|
||||
|
||||
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 <W> Chunk<W> of(W... items) {
|
||||
return new Chunk<>(items);
|
||||
}
|
||||
|
||||
public Chunk(List<? extends W> items) {
|
||||
this(items, null);
|
||||
}
|
||||
|
||||
public Chunk(Collection<? extends W> items, List<SkipWrapper<W>> skips) {
|
||||
public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips) {
|
||||
super();
|
||||
if (items != null) {
|
||||
this.items = new ArrayList<>(items);
|
||||
@@ -72,6 +79,14 @@ public class Chunk<W> implements Iterable<W> {
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all items to the chunk.
|
||||
* @param items the items to add
|
||||
*/
|
||||
public void addAll(List<W> items) {
|
||||
this.items.addAll(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the items down to signal that we are done.
|
||||
*/
|
||||
@@ -18,6 +18,8 @@ package org.springframework.batch.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 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<T> {
|
||||
@@ -43,10 +46,10 @@ public interface ItemWriter<T> {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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<K, V> implements ItemWriter<V>, 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<T> extends AbstractMethodInvokingDelegator<T> implements ItemWriter<T> {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@@ -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<T> extends AbstractMethodInvokingDelegator<T>
|
||||
implements ItemWriter<T> {
|
||||
@@ -41,7 +43,7 @@ public class PropertyExtractingDelegatingItemWriter<T> 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
|
||||
|
||||
@@ -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<T> implements ItemWriter<T> {
|
||||
}
|
||||
|
||||
@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.");
|
||||
}
|
||||
|
||||
@@ -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<T> extends AbstractItemStreamItemWriter<T> {
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
@@ -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<T> implements ItemWriter<T>, 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<T> 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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, InitializingBean {
|
||||
return TransactionSynchronizationManager.isActualTransactionActive();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<T> getCurrentBuffer() {
|
||||
private Chunk<T> getCurrentBuffer() {
|
||||
if (!TransactionSynchronizationManager.hasResource(bufferKey)) {
|
||||
TransactionSynchronizationManager.bindResource(bufferKey, new ArrayList<T>());
|
||||
TransactionSynchronizationManager.bindResource(bufferKey, new Chunk<T>());
|
||||
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void beforeCommit(boolean readOnly) {
|
||||
List<T> items = (List<T>) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
Chunk<T> chunk = (Chunk<T>) 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<T> implements ItemWriter<T>, InitializingBean {
|
||||
});
|
||||
}
|
||||
|
||||
return (List<T>) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
return (Chunk<T>) TransactionSynchronizationManager.getResource(bufferKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, InitializingBean {
|
||||
}
|
||||
}
|
||||
|
||||
private void save(List<? extends T> items) {
|
||||
private void save(Chunk<? extends T> items) {
|
||||
Session session = this.sessionFactory.openSession();
|
||||
|
||||
for (T item : items) {
|
||||
|
||||
@@ -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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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.");
|
||||
}
|
||||
|
||||
@@ -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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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.");
|
||||
}
|
||||
|
||||
@@ -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.<br>
|
||||
*
|
||||
* It is expected that {@link #write(List)} is called inside a transaction.<br>
|
||||
* It is expected that {@link #write(Chunk)} is called inside a transaction.<br>
|
||||
*
|
||||
* 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<T> implements ItemWriter<T>, InitializingBean {
|
||||
@@ -164,24 +166,25 @@ public class JdbcBatchItemWriter<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.<br>
|
||||
* It is required that {@link #write(Chunk)} is called inside a transaction.<br>
|
||||
*
|
||||
* 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<T> implements ItemWriter<T>, 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<T> implements ItemWriter<T>, 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.");
|
||||
|
||||
@@ -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<T> extends AbstractFileItemWriter<T> {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
@@ -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 <T> item type
|
||||
* @author Robert Kasanicky
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class MultiResourceItemWriter<T> extends AbstractItemStreamItemWriter<T> {
|
||||
|
||||
@@ -67,7 +70,7 @@ public class MultiResourceItemWriter<T> extends AbstractItemStreamItemWriter<T>
|
||||
}
|
||||
|
||||
@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
|
||||
|
||||
@@ -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)}.<br>
|
||||
* default destination, which will be used to send items in {@link #write(Chunk)}.<br>
|
||||
* <br>
|
||||
*
|
||||
* The implementation is thread-safe after its properties are set (normal singleton
|
||||
* behavior).
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public class JmsItemWriter<T> implements ItemWriter<T> {
|
||||
@@ -58,10 +61,10 @@ public class JmsItemWriter<T> implements ItemWriter<T> {
|
||||
/**
|
||||
* 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.");
|
||||
|
||||
@@ -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<T> extends AbstractFileItemWriter<T> {
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
@@ -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;
|
||||
* </p>
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
@@ -60,7 +62,7 @@ public class SimpleMailMessageItemWriter implements ItemWriter<SimpleMailMessage
|
||||
private MailErrorHandler mailErrorHandler = new DefaultMailErrorHandler();
|
||||
|
||||
/**
|
||||
* A {@link MailSender} to be used to send messages in {@link #write(List)}.
|
||||
* A {@link MailSender} to be used to send messages in {@link #write(Chunk)}.
|
||||
* @param mailSender The {@link MailSender} to be used.
|
||||
*/
|
||||
public void setMailSender(MailSender mailSender) {
|
||||
@@ -87,13 +89,13 @@ public class SimpleMailMessageItemWriter implements ItemWriter<SimpleMailMessage
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 SimpleMailMessage> 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<Object, Exception> failedMessages = e.getFailedMessages();
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<MimeMessage> {
|
||||
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<MimeMessage> {
|
||||
}
|
||||
|
||||
/**
|
||||
* @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<Object, Exception> failedMessages = e.getFailedMessages();
|
||||
|
||||
@@ -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<T> 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<T> 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()
|
||||
|
||||
@@ -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<T> implements ItemWriter<T> {
|
||||
@@ -53,14 +55,14 @@ public class ClassifierCompositeItemWriter<T> implements ItemWriter<T> {
|
||||
* 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<ItemWriter<? super T>, List<T>> map = new LinkedHashMap<>();
|
||||
Map<ItemWriter<? super T>, Chunk<T>> 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);
|
||||
}
|
||||
|
||||
@@ -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<T> implements ItemStreamWriter<T>, InitializingBean {
|
||||
|
||||
@@ -78,9 +80,9 @@ public class CompositeItemWriter<T> implements ItemStreamWriter<T>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T> implements ItemWriter<T> {
|
||||
|
||||
private List<T> 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() {
|
||||
|
||||
@@ -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<T> implements ItemStreamWriter<T>, 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<T> extends AbstractItemStreamItemWriter<T>
|
||||
* @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");
|
||||
|
||||
@@ -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<Foo> foos = new ArrayList<>();
|
||||
Chunk<Foo> foos = new Chunk<>();
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
foos.add(foo);
|
||||
}
|
||||
|
||||
@@ -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<Foo> input = fooService.getGeneratedFoos();
|
||||
|
||||
@@ -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<String> amqpItemWriter = new AmqpItemWriter<>(amqpTemplate);
|
||||
amqpItemWriter.write(Arrays.asList("foo", "bar"));
|
||||
amqpItemWriter.write(Chunk.of("foo", "bar"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> amqpItemWriter = new AmqpItemWriterBuilder<String>().amqpTemplate(amqpTemplate).build();
|
||||
amqpItemWriter.write(Arrays.asList("foo", "bar"));
|
||||
amqpItemWriter.write(Chunk.of("foo", "bar"));
|
||||
verify(amqpTemplate).convertAndSend("foo");
|
||||
verify(amqpTemplate).convertAndSend("bar");
|
||||
}
|
||||
|
||||
@@ -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 <T> void verify(AvroItemReader<T> avroItemReader, List<T> actual) throws Exception {
|
||||
protected <T> void verify(AvroItemReader<T> avroItemReader, Chunk<T> actual) throws Exception {
|
||||
|
||||
avroItemReader.open(new ExecutionContext());
|
||||
List<T> 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<T> actualItems = actual.getItems();
|
||||
assertThat(users).containsExactlyInAnyOrder(actualItems.get(0), actualItems.get(1), actualItems.get(2),
|
||||
actualItems.get(3));
|
||||
|
||||
avroItemReader.close();
|
||||
}
|
||||
|
||||
@@ -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 <T> void verifyRecords(byte[] bytes, List<T> actual, Class<T> clazz, boolean embeddedSchema)
|
||||
protected <T> void verifyRecords(byte[] bytes, Chunk<T> actual, Class<T> clazz, boolean embeddedSchema)
|
||||
throws Exception {
|
||||
doVerify(bytes, clazz, actual, embeddedSchema);
|
||||
}
|
||||
|
||||
protected <T> void verifyRecordsWithEmbeddedHeader(byte[] bytes, List<T> actual, Class<T> clazz) throws Exception {
|
||||
protected <T> void verifyRecordsWithEmbeddedHeader(byte[] bytes, Chunk<T> actual, Class<T> clazz) throws Exception {
|
||||
doVerify(bytes, clazz, actual, true);
|
||||
}
|
||||
|
||||
private <T> void doVerify(byte[] bytes, Class<T> clazz, List<T> actual, boolean embeddedSchema) throws Exception {
|
||||
private <T> void doVerify(byte[] bytes, Class<T> clazz, Chunk<T> actual, boolean embeddedSchema) throws Exception {
|
||||
AvroItemReader<T> avroItemReader = new AvroItemReaderBuilder<T>().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<T> actualItems = actual.getItems();
|
||||
assertThat(records).containsExactlyInAnyOrder(actualItems.get(0), actualItems.get(1), actualItems.get(2),
|
||||
actualItems.get(3));
|
||||
}
|
||||
|
||||
protected static class OutputStreamResource implements WritableResource {
|
||||
|
||||
@@ -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<User> avroGeneratedUsers = Arrays.asList(
|
||||
private final Chunk<User> 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<PlainOldUser> plainOldUsers = Arrays.asList(
|
||||
private Chunk<PlainOldUser> 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<User> avroGeneratedUsers() {
|
||||
protected Chunk<User> avroGeneratedUsers() {
|
||||
return this.avroGeneratedUsers;
|
||||
}
|
||||
|
||||
protected List<GenericRecord> genericAvroGeneratedUsers() {
|
||||
return this.avroGeneratedUsers.stream().map(u -> {
|
||||
protected Chunk<GenericRecord> 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<PlainOldUser> plainOldUsers() {
|
||||
protected Chunk<PlainOldUser> plainOldUsers() {
|
||||
return this.plainOldUsers;
|
||||
}
|
||||
|
||||
protected List<GenericRecord> genericPlainOldUsers() {
|
||||
return this.plainOldUsers.stream().map(PlainOldUser::toGenericRecord).collect(Collectors.toList());
|
||||
protected Chunk<GenericRecord> genericPlainOldUsers() {
|
||||
return new Chunk(
|
||||
this.plainOldUsers.getItems().stream().map(PlainOldUser::toGenericRecord).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
protected static class PlainOldUser {
|
||||
|
||||
@@ -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<Foo> items = new ArrayList<Foo>() {
|
||||
Chunk<Foo> chunk = new Chunk<Foo>() {
|
||||
{
|
||||
add(new Foo(new Bar("val1")));
|
||||
add(new Foo(new Bar("val2")));
|
||||
}
|
||||
};
|
||||
|
||||
writer.write(items);
|
||||
writer.write(chunk);
|
||||
|
||||
List<Foo> items = chunk.getItems();
|
||||
verify(template).put("val1", items.get(0));
|
||||
verify(template).put("val2", items.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBasicDelete() throws Exception {
|
||||
List<Foo> items = new ArrayList<Foo>() {
|
||||
Chunk<Foo> chunk = new Chunk<Foo>() {
|
||||
{
|
||||
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<Foo> items = new ArrayList<Foo>() {
|
||||
Chunk<Foo> chunk = new Chunk<Foo>() {
|
||||
{
|
||||
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<Foo> items = chunk.getItems();
|
||||
verify(template).put("item1", items.get(0));
|
||||
verify(template).put("item2", items.get(1));
|
||||
}
|
||||
|
||||
@@ -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<Item> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
Chunk<Item> items = Chunk.of(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.write(items);
|
||||
|
||||
@@ -114,7 +116,7 @@ class MongoItemWriterTests {
|
||||
|
||||
@Test
|
||||
void testWriteNoTransactionWithCollection() throws Exception {
|
||||
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
Chunk<Object> 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<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
final Chunk<Object> items = Chunk.of(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
assertDoesNotThrow(() -> writer.write(items));
|
||||
@@ -147,7 +149,7 @@ class MongoItemWriterTests {
|
||||
|
||||
@Test
|
||||
void testWriteTransactionWithCollection() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
final Chunk<Object> items = Chunk.of(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
@@ -162,7 +164,7 @@ class MongoItemWriterTests {
|
||||
|
||||
@Test
|
||||
void testWriteTransactionFails() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
final Chunk<Object> items = Chunk.of(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
@@ -183,7 +185,7 @@ class MongoItemWriterTests {
|
||||
*/
|
||||
@Test
|
||||
void testWriteTransactionReadOnly() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
final Chunk<Object> 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<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
Chunk<Object> 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<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
Chunk<Object> 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<Object> items = Arrays.asList(new Item(1), new Item(2));
|
||||
Chunk<Object> 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<Object> items = Arrays.asList(new Item(1), new Item(2));
|
||||
Chunk<Object> items = Chunk.of(new Item(1), new Item(2));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
@@ -285,7 +287,7 @@ class MongoItemWriterTests {
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) 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) {
|
||||
|
||||
@@ -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<String> items = new ArrayList<>();
|
||||
Chunk<String> items = new Chunk<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
@@ -126,7 +102,7 @@ class Neo4jItemWriterTests {
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
Chunk<String> items = new Chunk<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
|
||||
@@ -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<String> items = Collections.singletonList("foo");
|
||||
Chunk<String> items = Chunk.of("foo");
|
||||
|
||||
writer.write(items);
|
||||
|
||||
@@ -83,7 +83,7 @@ class RepositoryItemWriterTests {
|
||||
|
||||
@Test
|
||||
void testWriteItemsWithDefaultMethodName() throws Exception {
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
Chunk<String> items = Chunk.of("foo");
|
||||
|
||||
writer.setMethodName(null);
|
||||
writer.write(items);
|
||||
|
||||
@@ -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<String, GemfireItemWriterBuilderTests.Foo> itemKeyMapper;
|
||||
|
||||
private List<GemfireItemWriterBuilderTests.Foo> items;
|
||||
private Chunk<Foo> 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
|
||||
|
||||
@@ -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<Item> saveItems;
|
||||
private Chunk<Item> saveItems;
|
||||
|
||||
private List<Item> removeItems;
|
||||
private Chunk<Item> 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));
|
||||
}
|
||||
|
||||
@@ -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<String> writer = new Neo4jItemWriterBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.build();
|
||||
List<String> items = new ArrayList<>();
|
||||
Chunk<String> items = new Chunk<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
@@ -68,7 +70,7 @@ class Neo4jItemWriterBuilderTests {
|
||||
void testBasicDelete() throws Exception {
|
||||
Neo4jItemWriter<String> writer = new Neo4jItemWriterBuilder<String>().delete(true)
|
||||
.sessionFactory(this.sessionFactory).build();
|
||||
List<String> items = new ArrayList<>();
|
||||
Chunk<String> items = new Chunk<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
|
||||
@@ -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<String> writer = new RepositoryItemWriterBuilder<String>().methodName("save")
|
||||
.repository(this.repository).build();
|
||||
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
Chunk<String> items = Chunk.of("foo");
|
||||
|
||||
writer.write(items);
|
||||
|
||||
@@ -72,7 +74,7 @@ class RepositoryItemWriterBuilderTests {
|
||||
RepositoryItemWriter<String> writer = new RepositoryItemWriterBuilder<String>().methodName("foo")
|
||||
.repository(this.repository).build();
|
||||
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
Chunk<String> items = Chunk.of("foo");
|
||||
|
||||
writer.write(items);
|
||||
|
||||
@@ -88,7 +90,7 @@ class RepositoryItemWriterBuilderTests {
|
||||
RepositoryItemWriter<String> writer = new RepositoryItemWriterBuilder<String>().methodName("foo")
|
||||
.repository(repositoryMethodReference).build();
|
||||
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
Chunk<String> items = Chunk.of("foo");
|
||||
|
||||
writer.write(items);
|
||||
|
||||
|
||||
@@ -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<String> items = Arrays.asList(new String[] { "foo", "bar" });
|
||||
Chunk<String> 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<String> items = Arrays.asList(new String[] { "foo", "bar" });
|
||||
Chunk<String> 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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>() {
|
||||
@@ -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"));
|
||||
|
||||
@@ -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<Map[]> captor = ArgumentCaptor.forClass(Map[].class);
|
||||
|
||||
when(namedParameterJdbcOperations.batchUpdate(eq(sql), captor.capture())).thenReturn(new int[] { 1 });
|
||||
mapWriter.write(List.of(Map.of("foo", "bar")));
|
||||
mapWriter.write(Chunk.of(Map.of("foo", "bar")));
|
||||
|
||||
assertEquals(1, captor.getValue().length);
|
||||
Map<String, Object> results = captor.getValue()[0];
|
||||
@@ -158,7 +160,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
ArgumentCaptor<SqlParameterSource[]> captor = ArgumentCaptor.forClass(SqlParameterSource[].class);
|
||||
|
||||
when(namedParameterJdbcOperations.batchUpdate(any(String.class), captor.capture())).thenReturn(new int[] { 1 });
|
||||
mapWriter.write(List.of(Map.of("foo", "bar")));
|
||||
mapWriter.write(Chunk.of(Map.of("foo", "bar")));
|
||||
|
||||
assertEquals(1, captor.getValue().length);
|
||||
SqlParameterSource results = captor.getValue()[0];
|
||||
@@ -172,7 +174,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
|
||||
.thenReturn(new int[] { 0 });
|
||||
Exception exception = assertThrows(EmptyResultDataAccessException.class,
|
||||
() -> writer.write(List.of(new Foo("bar"))));
|
||||
() -> writer.write(Chunk.of(new Foo("bar"))));
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("did not update"), "Wrong message: " + message);
|
||||
}
|
||||
@@ -184,7 +186,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
eqSqlParameterSourceArray(
|
||||
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
|
||||
.thenThrow(ex);
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of(new Foo("bar"))));
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(Chunk.of(new Foo("bar"))));
|
||||
assertEquals("ERROR", exception.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.item.Chunk;
|
||||
import org.springframework.batch.item.sample.Person;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -71,7 +72,7 @@ class JpaItemWriterIntegrationTests {
|
||||
JpaItemWriter<Person> writer = new JpaItemWriter<>();
|
||||
writer.setEntityManagerFactory(this.entityManagerFactory);
|
||||
writer.afterPropertiesSet();
|
||||
List<Person> items = Arrays.asList(new Person(1, "foo"), new Person(2, "bar"));
|
||||
Chunk<Person> items = Chunk.of(new Person(1, "foo"), new Person(2, "bar"));
|
||||
|
||||
// when
|
||||
writer.write(items);
|
||||
@@ -87,7 +88,7 @@ class JpaItemWriterIntegrationTests {
|
||||
writer.setEntityManagerFactory(this.entityManagerFactory);
|
||||
writer.setUsePersist(true);
|
||||
writer.afterPropertiesSet();
|
||||
List<Person> items = Arrays.asList(new Person(1, "foo"), new Person(2, "bar"));
|
||||
Chunk<Person> items = Chunk.of(new Person(1, "foo"), new Person(2, "bar"));
|
||||
|
||||
// when
|
||||
writer.write(items);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user