BATCH-711:Modified ItemWriter interface to use parameterized types. Updated a portion of classes using ItemWriter as well.

This commit is contained in:
lucasward
2008-07-21 04:22:02 +00:00
parent 0ef196d578
commit 4c1af572da
13 changed files with 27 additions and 26 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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