BATCH-711:Modified ItemWriter interface to use parameterized types. Updated a portion of classes using ItemWriter as well.
This commit is contained in:
@@ -35,7 +35,7 @@ package org.springframework.batch.item;
|
||||
* @author Dave Syer
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public interface ItemWriter {
|
||||
public interface ItemWriter<T> {
|
||||
|
||||
/**
|
||||
* Process the supplied data element. Will be called multiple times during a
|
||||
@@ -46,7 +46,7 @@ public interface ItemWriter {
|
||||
* retry or a batch the framework will catch the exception and convert or
|
||||
* rethrow it as appropriate.
|
||||
*/
|
||||
void write(Object item) throws Exception;
|
||||
void write(T item) throws Exception;
|
||||
|
||||
/**
|
||||
* Flush any buffers that are being held. This will usually be performed
|
||||
|
||||
@@ -29,9 +29,9 @@ import org.springframework.batch.item.ItemWriter;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator<Object> implements ItemWriter {
|
||||
public class ItemWriterAdapter<T> extends AbstractMethodInvokingDelegator<T> implements ItemWriter<T> {
|
||||
|
||||
public void write(Object item) throws Exception {
|
||||
public void write(T item) throws Exception {
|
||||
invokeDelegateMethodWithArgument(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator<Object> implements ItemWriter {
|
||||
public class PropertyExtractingDelegatingItemWriter<T> extends AbstractMethodInvokingDelegator<T> implements ItemWriter<T> {
|
||||
|
||||
private String[] fieldsUsedAsTargetMethodArguments;
|
||||
|
||||
@@ -39,7 +39,7 @@ public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvoki
|
||||
* Extracts values from item's fields named in fieldsUsedAsTargetMethodArguments
|
||||
* and passes them as arguments to the delegate method.
|
||||
*/
|
||||
public void write(Object item) throws Exception {
|
||||
public void write(T item) throws Exception {
|
||||
// helper for extracting property values from a bean
|
||||
BeanWrapper beanWrapper = new BeanWrapperImpl(item);
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HibernateCursorItemReader extends AbstractBufferedItemReaderItemStream implements ItemStream,
|
||||
public class HibernateCursorItemReader<T> extends AbstractBufferedItemReaderItemStream<T> implements ItemStream,
|
||||
InitializingBean {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
@@ -150,7 +150,8 @@ public class HibernateCursorItemReader extends AbstractBufferedItemReaderItemStr
|
||||
this.fetchSize = fetchSize;
|
||||
}
|
||||
|
||||
protected Object doRead() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T doRead() throws Exception {
|
||||
if (cursor.next()) {
|
||||
Object[] data = cursor.get();
|
||||
Object item;
|
||||
@@ -162,7 +163,7 @@ public class HibernateCursorItemReader extends AbstractBufferedItemReaderItemStr
|
||||
item = data[0];
|
||||
}
|
||||
|
||||
return item;
|
||||
return (T)item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ import org.springframework.batch.item.ItemWriter;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractItemStreamItemWriter extends ItemStreamSupport implements ItemWriter {
|
||||
public abstract class AbstractItemStreamItemWriter<T> extends ItemStreamSupport implements ItemWriter<T> {
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.batch.item.ItemWriter;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public abstract class AbstractItemWriter implements ItemWriter {
|
||||
public abstract class AbstractItemWriter<T> implements ItemWriter<T> {
|
||||
|
||||
public void flush() throws FlushFailedException {
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
*/
|
||||
public class ItemWriterAdapterTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private ItemWriter processor;
|
||||
private ItemWriter<Foo> processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ItemWriterAdapterTests extends AbstractDependencyInjectionSpringCon
|
||||
}
|
||||
|
||||
// setter for auto-injection
|
||||
public void setProcessor(ItemWriter processor) {
|
||||
public void setProcessor(ItemWriter<Foo> processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
public class PropertyExtractingDelegatingItemProccessorIntegrationTests extends
|
||||
AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private PropertyExtractingDelegatingItemWriter processor;
|
||||
private PropertyExtractingDelegatingItemWriter<Foo> processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PropertyExtractingDelegatingItemProccessorIntegrationTests extends
|
||||
|
||||
}
|
||||
|
||||
public void setProcessor(PropertyExtractingDelegatingItemWriter processor) {
|
||||
public void setProcessor(PropertyExtractingDelegatingItemWriter<Foo> processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class HibernateCursorItemReaderIntegrationTests extends AbstractDataSourc
|
||||
|
||||
String hsqlQuery = "from Foo";
|
||||
|
||||
HibernateCursorItemReader inputSource = new HibernateCursorItemReader();
|
||||
HibernateCursorItemReader<Foo> inputSource = new HibernateCursorItemReader<Foo>();
|
||||
inputSource.setQueryString(hsqlQuery);
|
||||
inputSource.setSessionFactory(sessionFactory);
|
||||
inputSource.setUseStatelessSession(isUseStatelessSession());
|
||||
@@ -47,7 +47,7 @@ public class HibernateCursorItemReaderIntegrationTests extends AbstractDataSourc
|
||||
* called only in uninitialized state.
|
||||
*/
|
||||
public void testSetUseStatelessSession() {
|
||||
HibernateCursorItemReader inputSource = ((HibernateCursorItemReader) reader);
|
||||
HibernateCursorItemReader<Foo> inputSource = (HibernateCursorItemReader<Foo>)reader;
|
||||
|
||||
// initialize and call setter => error
|
||||
inputSource.open(new ExecutionContext());
|
||||
|
||||
@@ -85,9 +85,9 @@ public class ItemTransformerItemWriterFunctionalTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static class BarWriter implements ItemWriter{
|
||||
private static class BarWriter implements ItemWriter<Bar>{
|
||||
|
||||
public void write(Object item) throws Exception {
|
||||
public void write(Bar item) throws Exception {
|
||||
assertTrue(item instanceof Bar);
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ public class ItemTransformerItemWriterFunctionalTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private static class FoobarWriter implements ItemWriter{
|
||||
private static class FoobarWriter implements ItemWriter<Foobar>{
|
||||
|
||||
public void write(Object item) throws Exception {
|
||||
public void write(Foobar item) throws Exception {
|
||||
assertTrue(item instanceof Foobar);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ public class ItemTransformerItemWriterTests extends TestCase {
|
||||
private ItemTransformerItemWriter processor = new ItemTransformerItemWriter();
|
||||
|
||||
private ItemTransformer transformer;
|
||||
private ItemWriter itemWriter;
|
||||
private ItemWriter<Object> itemWriter;
|
||||
|
||||
private MockControl tControl = MockControl.createControl(ItemTransformer.class);
|
||||
private MockControl outControl = MockControl.createControl(ItemWriter.class);
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
transformer = (ItemTransformer) tControl.getMock();
|
||||
itemWriter = (ItemWriter) outControl.getMock();
|
||||
itemWriter = (ItemWriter<Object>) outControl.getMock();
|
||||
|
||||
processor.setItemTransformer(transformer);
|
||||
processor.setDelegate(itemWriter);
|
||||
|
||||
@@ -65,12 +65,12 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class TradeWriter extends AbstractItemWriter {
|
||||
protected static class TradeWriter extends AbstractItemWriter<Trade> {
|
||||
int count = 0;
|
||||
|
||||
// This has to be synchronized because we are going to test the state
|
||||
// (count) at the end of a concurrent batch run.
|
||||
public synchronized void write(Object data) {
|
||||
public synchronized void write(Trade data) {
|
||||
count++;
|
||||
System.out.println("Executing trade '" + data + "'");
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
Thread.sleep(100);
|
||||
Object item = provider.read();
|
||||
Trade item = provider.read();
|
||||
if (item!=null) {
|
||||
processor.write(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user