IN PROGRESS - BATCH-712: Upgrade ItemReaders to use Parameterized types
parameterized MRIR
This commit is contained in:
@@ -34,7 +34,7 @@ import org.springframework.util.ClassUtils;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class MultiResourceItemReader extends ExecutionContextUserSupport implements ItemReader, ItemStream,
|
||||
public class MultiResourceItemReader<T> extends ExecutionContextUserSupport implements ItemReader<T>, ItemStream,
|
||||
InitializingBean {
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
*/
|
||||
private static final Object END_OF_RESOURCE_MARKER = new Object();
|
||||
|
||||
private ResourceAwareItemReaderItemStream delegate;
|
||||
private ResourceAwareItemReaderItemStream<T> delegate;
|
||||
|
||||
private Resource[] resources;
|
||||
|
||||
@@ -74,9 +74,9 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
/**
|
||||
* Reads the next item, jumping to next resource if necessary.
|
||||
*/
|
||||
public Object read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
public T read() throws Exception, UnexpectedInputException, NoWorkFoundException, ParseException {
|
||||
|
||||
Object item;
|
||||
T item;
|
||||
if (shouldReadBuffer) {
|
||||
item = readBufferedItem();
|
||||
}
|
||||
@@ -94,9 +94,9 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
* one is exhausted. Items are appended to the buffer.
|
||||
* @return next item from input
|
||||
*/
|
||||
private Object readNextItem() throws Exception {
|
||||
private T readNextItem() throws Exception {
|
||||
|
||||
Object item = delegate.read();
|
||||
T item = delegate.read();
|
||||
|
||||
while (item == null) {
|
||||
|
||||
@@ -124,7 +124,8 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
* input for possible restart.
|
||||
* @return next item from buffer
|
||||
*/
|
||||
private Object readBufferedItem() {
|
||||
@SuppressWarnings("unchecked")
|
||||
private T readBufferedItem() {
|
||||
|
||||
Object buffered = itemBufferIterator.next();
|
||||
while (buffered == END_OF_RESOURCE_MARKER) {
|
||||
@@ -137,7 +138,7 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
shouldReadBuffer = false;
|
||||
itemBufferIterator = null;
|
||||
}
|
||||
return buffered;
|
||||
return (T) buffered;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +229,7 @@ public class MultiResourceItemReader extends ExecutionContextUserSupport impleme
|
||||
/**
|
||||
* @param delegate reads items from single {@link Resource}.
|
||||
*/
|
||||
public void setDelegate(ResourceAwareItemReaderItemStream delegate) {
|
||||
public void setDelegate(ResourceAwareItemReaderItemStream<T> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ import org.springframework.core.io.Resource;
|
||||
public class MultiResourceItemReaderFlatFileTests extends
|
||||
CommonItemStreamItemReaderTests {
|
||||
|
||||
protected ItemReader getItemReader() throws Exception {
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
MultiResourceItemReader multiReader = new MultiResourceItemReader();
|
||||
FlatFileItemReader fileReader = new FlatFileItemReader();
|
||||
MultiResourceItemReader<Foo> multiReader = new MultiResourceItemReader<Foo>();
|
||||
FlatFileItemReader<Foo> fileReader = new FlatFileItemReader<Foo>();
|
||||
|
||||
fileReader.setFieldSetMapper(new FieldSetMapper() {
|
||||
public Object mapLine(FieldSet fs, int lineNum) {
|
||||
fileReader.setFieldSetMapper(new FieldSetMapper<Foo>() {
|
||||
public Foo mapLine(FieldSet fs, int lineNum) {
|
||||
Foo foo = new Foo();
|
||||
foo.setValue(fs.readInt(0));
|
||||
return foo;
|
||||
@@ -48,8 +48,8 @@ public class MultiResourceItemReaderFlatFileTests extends
|
||||
return multiReader;
|
||||
}
|
||||
|
||||
protected void pointToEmptyInput(ItemReader tested) throws Exception {
|
||||
MultiResourceItemReader multiReader = (MultiResourceItemReader) tested;
|
||||
protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
|
||||
MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested;
|
||||
multiReader.close(new ExecutionContext());
|
||||
multiReader.setResources(new Resource[] { new ByteArrayResource(""
|
||||
.getBytes()) });
|
||||
|
||||
@@ -15,9 +15,9 @@ import org.springframework.core.io.Resource;
|
||||
*/
|
||||
public class MultiResourceItemReaderIntegrationTests extends TestCase {
|
||||
|
||||
private MultiResourceItemReader tested = new MultiResourceItemReader();
|
||||
private MultiResourceItemReader<FieldSet> tested = new MultiResourceItemReader<FieldSet>();
|
||||
|
||||
private FlatFileItemReader itemReader = new FlatFileItemReader();
|
||||
private FlatFileItemReader<FieldSet> itemReader = new FlatFileItemReader<FieldSet>();
|
||||
|
||||
private ExecutionContext ctx = new ExecutionContext();
|
||||
|
||||
|
||||
@@ -18,14 +18,14 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderTests {
|
||||
|
||||
protected ItemReader getItemReader() throws Exception {
|
||||
MultiResourceItemReader multiReader = new MultiResourceItemReader();
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
MultiResourceItemReader<Foo> multiReader = new MultiResourceItemReader<Foo>();
|
||||
|
||||
StaxEventItemReader reader = new StaxEventItemReader();
|
||||
StaxEventItemReader<Foo> reader = new StaxEventItemReader<Foo>();
|
||||
|
||||
reader.setFragmentRootElementName("foo");
|
||||
reader.setFragmentDeserializer(new EventReaderDeserializer() {
|
||||
public Object deserializeFragment(XMLEventReader eventReader) {
|
||||
reader.setFragmentDeserializer(new EventReaderDeserializer<Foo>() {
|
||||
public Foo deserializeFragment(XMLEventReader eventReader) {
|
||||
Attribute attr;
|
||||
try {
|
||||
assertTrue(eventReader.nextEvent().isStartDocument());
|
||||
@@ -61,8 +61,8 @@ public class MultiResourceItemReaderXmlTests extends CommonItemStreamItemReaderT
|
||||
return multiReader;
|
||||
}
|
||||
|
||||
protected void pointToEmptyInput(ItemReader tested) throws Exception {
|
||||
MultiResourceItemReader multiReader = (MultiResourceItemReader) tested;
|
||||
protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
|
||||
MultiResourceItemReader<Foo> multiReader = (MultiResourceItemReader<Foo>) tested;
|
||||
multiReader.close(new ExecutionContext());
|
||||
multiReader.setResources(new Resource[] { new ByteArrayResource("<foos />"
|
||||
.getBytes()) });
|
||||
|
||||
Reference in New Issue
Block a user