BATCH-836: added ItemStream interface to CompositeItemWriter

This commit is contained in:
dsyer
2010-09-07 11:34:10 +00:00
parent 45a1982dfe
commit 4c25159040
2 changed files with 75 additions and 5 deletions

View File

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