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:
Mahmoud Ben Hassine
2022-08-17 21:06:09 +02:00
parent bf2e6ab0e5
commit e67c0069f1
175 changed files with 1077 additions and 763 deletions

View File

@@ -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 {
// ...
}

View File

@@ -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
}
}

View File

@@ -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);
}