BATCH-711:Modified ItemWriter interface to use parameterized types. Updated a portion of classes using ItemWriter as well.
This commit is contained in:
@@ -50,9 +50,9 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
|
||||
private boolean allowStartIfComplete;
|
||||
|
||||
private ItemReader itemReader;
|
||||
private ItemReader<?> itemReader;
|
||||
|
||||
private ItemWriter itemWriter;
|
||||
private ItemWriter<?> itemWriter;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@@ -114,14 +114,14 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
/**
|
||||
* @param itemReader the itemReader to set
|
||||
*/
|
||||
public void setItemReader(ItemReader itemReader) {
|
||||
public void setItemReader(ItemReader<?> itemReader) {
|
||||
this.itemReader = itemReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemWriter the itemWriter to set
|
||||
*/
|
||||
public void setItemWriter(ItemWriter itemWriter) {
|
||||
public void setItemWriter(ItemWriter<?> itemWriter) {
|
||||
this.itemWriter = itemWriter;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
* Protected getter for the {@link ItemReader} for subclasses to use.
|
||||
* @return the itemReader
|
||||
*/
|
||||
protected ItemReader getItemReader() {
|
||||
protected ItemReader<?> getItemReader() {
|
||||
return itemReader;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
* Protected getter for the {@link ItemWriter} for subclasses to use
|
||||
* @return the itemWriter
|
||||
*/
|
||||
protected ItemWriter getItemWriter() {
|
||||
protected ItemWriter<?> getItemWriter() {
|
||||
return itemWriter;
|
||||
}
|
||||
|
||||
@@ -238,8 +238,8 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
|
||||
step.setStreams(streams);
|
||||
|
||||
ItemReader itemReader = getItemReader();
|
||||
ItemWriter itemWriter = getItemWriter();
|
||||
ItemReader<?> itemReader = getItemReader();
|
||||
ItemWriter<?> itemWriter = getItemWriter();
|
||||
|
||||
// Since we are going to wrap these things with listener callbacks we
|
||||
// need to register them here because the step will not know we did
|
||||
@@ -266,6 +266,7 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
setItemWriter(itemWriter);
|
||||
|
||||
step.setStepExecutionListeners(stepListeners);
|
||||
//TODO: Why is setItemHandler called twice?
|
||||
step.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
|
||||
|
||||
}
|
||||
|
||||
@@ -38,19 +38,19 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class SimpleItemHandler implements ItemHandler {
|
||||
public class SimpleItemHandler<T> implements ItemHandler {
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private ItemReader itemReader;
|
||||
private ItemReader<T> itemReader;
|
||||
|
||||
private ItemWriter itemWriter;
|
||||
private ItemWriter<T> itemWriter;
|
||||
|
||||
/**
|
||||
* @param itemReader
|
||||
* @param itemWriter
|
||||
*/
|
||||
public SimpleItemHandler(ItemReader itemReader, ItemWriter itemWriter) {
|
||||
public SimpleItemHandler(ItemReader<T> itemReader, ItemWriter<T> itemWriter) {
|
||||
super();
|
||||
this.itemReader = itemReader;
|
||||
this.itemWriter = itemWriter;
|
||||
@@ -63,7 +63,7 @@ public class SimpleItemHandler implements ItemHandler {
|
||||
* @see org.springframework.batch.core.step.item.ItemHandler#handle(org.springframework.batch.core.StepContribution)
|
||||
*/
|
||||
public ExitStatus handle(StepContribution contribution) throws Exception {
|
||||
Object item = read(contribution);
|
||||
T item = read(contribution);
|
||||
if (item == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class SimpleItemHandler implements ItemHandler {
|
||||
* @param contribution current context
|
||||
* @return next item for writing
|
||||
*/
|
||||
protected Object read(StepContribution contribution) throws Exception {
|
||||
protected T read(StepContribution contribution) throws Exception {
|
||||
return doRead();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SimpleItemHandler implements ItemHandler {
|
||||
* @return item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final Object doRead() throws Exception {
|
||||
protected final T doRead() throws Exception {
|
||||
return itemReader.read();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class SimpleItemHandler implements ItemHandler {
|
||||
* @param item the item to write
|
||||
* @param contribution current context
|
||||
*/
|
||||
protected void write(Object item, StepContribution contribution) throws Exception {
|
||||
protected void write(T item, StepContribution contribution) throws Exception {
|
||||
doWrite(item);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SimpleItemHandler implements ItemHandler {
|
||||
* @param item
|
||||
* @throws Exception
|
||||
*/
|
||||
protected final void doWrite(Object item) throws Exception {
|
||||
protected final void doWrite(T item) throws Exception {
|
||||
itemWriter.write(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
/**
|
||||
* Simple item reader that supports skip functionality.
|
||||
*/
|
||||
private static class SkipReaderStub implements ItemReader {
|
||||
private static class SkipReaderStub implements ItemReader<Holder> {
|
||||
|
||||
final String[] values = { "1", "2", "3", "4", "5" };
|
||||
|
||||
@@ -281,7 +281,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
|
||||
int marked = 0;
|
||||
|
||||
public Object read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
public Holder read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
counter++;
|
||||
if (counter == 1) {
|
||||
throw new SkippableException("exception in reader");
|
||||
@@ -289,7 +289,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
if (counter >= values.length) {
|
||||
return null;
|
||||
}
|
||||
Object item = new Holder(values[counter]);
|
||||
Holder item = new Holder(values[counter]);
|
||||
processed.add(item);
|
||||
return item;
|
||||
}
|
||||
@@ -307,7 +307,7 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
/**
|
||||
* Simple item writer that supports skip functionality.
|
||||
*/
|
||||
private static class SkipWriterStub implements ItemWriter {
|
||||
private static class SkipWriterStub implements ItemWriter<Holder> {
|
||||
|
||||
boolean mutate = false;
|
||||
|
||||
@@ -325,11 +325,11 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
flushIndex = written.size() - 1;
|
||||
}
|
||||
|
||||
public void write(Object item) throws Exception {
|
||||
String value = ((Holder) item).value;
|
||||
public void write(Holder item) throws Exception {
|
||||
String value = item.value;
|
||||
written.add(item);
|
||||
if (mutate) {
|
||||
((Holder) item).value = "done";
|
||||
item.value = "done";
|
||||
}
|
||||
if (value.equals("4")) {
|
||||
throw new SkippableException("exception in writer");
|
||||
@@ -364,5 +364,4 @@ public class ItemSkipPolicyItemHandlerTests extends TestCase {
|
||||
return "[holder:" + value + "]";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user