BATCH-836: added ItemStream interface to CompositeItemWriter
This commit is contained in:
@@ -18,6 +18,10 @@ package org.springframework.batch.item.support;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemStreamException;
|
||||
import org.springframework.batch.item.ItemStreamWriter;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -31,10 +35,16 @@ import org.springframework.util.Assert;
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class CompositeItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
public class CompositeItemWriter<T> implements ItemStreamWriter<T>, InitializingBean {
|
||||
|
||||
private List<ItemWriter<? super T>> delegates;
|
||||
|
||||
private boolean ignoreItemStream = false;
|
||||
|
||||
public void setIgnoreItemStream(boolean ignoreItemStream) {
|
||||
this.ignoreItemStream = ignoreItemStream;
|
||||
}
|
||||
|
||||
public void write(List<? extends T> item) throws Exception {
|
||||
for (ItemWriter<? super T> writer : delegates) {
|
||||
writer.write(item);
|
||||
@@ -50,4 +60,28 @@ public class CompositeItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
this.delegates = delegates;
|
||||
}
|
||||
|
||||
public void close() throws ItemStreamException {
|
||||
for (ItemWriter<? super T> writer : delegates) {
|
||||
if (!ignoreItemStream && (writer instanceof ItemStream)) {
|
||||
((ItemStream) writer).close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void open(ExecutionContext executionContext) throws ItemStreamException {
|
||||
for (ItemWriter<? super T> writer : delegates) {
|
||||
if (!ignoreItemStream && (writer instanceof ItemStream)) {
|
||||
((ItemStream) writer).open(executionContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ExecutionContext executionContext) throws ItemStreamException {
|
||||
for (ItemWriter<? super T> writer : delegates) {
|
||||
if (!ignoreItemStream && (writer instanceof ItemStream)) {
|
||||
((ItemStream) writer).update(executionContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user