IN PROGRESS - BATCH-712: Upgrade ItemReaders to use Parameterized types

This commit is contained in:
robokaso
2008-07-18 12:42:22 +00:00
parent 44ee192ee4
commit 77c8f4600e
8 changed files with 66 additions and 54 deletions

View File

@@ -18,13 +18,13 @@ import org.springframework.util.Assert;
public abstract class AbstractDataSourceItemReaderIntegrationTests extends
AbstractTransactionalDataSourceSpringContextTests {
protected ItemReader reader;
protected ItemReader<Foo> reader;
protected ExecutionContext executionContext;
/**
* @return configured input source ready for use
*/
protected abstract ItemReader createItemReader() throws Exception;
protected abstract ItemReader<Foo> createItemReader() throws Exception;
protected String[] getConfigLocations() {
return new String[] { "org/springframework/batch/item/database/data-source-context.xml" };
@@ -245,11 +245,11 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends
reader.reset();
}
private ItemStream getAsItemStream(ItemReader source) {
private ItemStream getAsItemStream(ItemReader<Foo> source) {
return (ItemStream) source;
}
private InitializingBean getAsInitializingBean(ItemReader source) {
private InitializingBean getAsInitializingBean(ItemReader<Foo> source) {
return (InitializingBean) source;
}

View File

@@ -17,14 +17,14 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
protected ItemReader itemReader;
protected ItemReader<Foo> itemReader;
protected ExecutionContext executionContext;
/**
* @return input source with all necessary dependencies set
*/
protected abstract ItemReader createItemReader() throws Exception;
protected abstract ItemReader<Foo> createItemReader() throws Exception;
protected String[] getConfigLocations(){
return new String[] { "org/springframework/batch/item/database/data-source-context.xml"};
@@ -160,15 +160,15 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
itemReader.reset();
}
private ItemStream getAsItemStream(ItemReader source) {
private ItemStream getAsItemStream(ItemReader<Foo> source) {
return (ItemStream) source;
}
private InitializingBean getAsInitializingBean(ItemReader source) {
private InitializingBean getAsInitializingBean(ItemReader<Foo> source) {
return (InitializingBean) source;
}
private DisposableBean getAsDisposableBean(ItemReader source) {
private DisposableBean getAsDisposableBean(ItemReader<Foo> source) {
return (DisposableBean) source;
}

View File

@@ -15,7 +15,7 @@ import org.springframework.util.Assert;
public class DrivingQueryItemReaderTests extends TestCase {
DrivingQueryItemReader itemReader;
DrivingQueryItemReader<Foo> itemReader;
static {
TransactionSynchronizationManager.initSynchronization();
@@ -27,9 +27,9 @@ public class DrivingQueryItemReaderTests extends TestCase {
itemReader = createItemReader();
}
private DrivingQueryItemReader createItemReader() throws Exception {
private DrivingQueryItemReader<Foo> createItemReader() throws Exception {
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
DrivingQueryItemReader<Foo> inputSource = new DrivingQueryItemReader<Foo>();
inputSource.setKeyCollector(new MockKeyGenerator());
inputSource.setSaveState(true);
@@ -159,10 +159,10 @@ public class DrivingQueryItemReaderTests extends TestCase {
public void testRetriveZeroKeys() {
itemReader.setKeyCollector(new KeyCollector() {
itemReader.setKeyCollector(new KeyCollector<Foo>() {
public List<Object> retrieveKeys(ExecutionContext executionContext) {
return new ArrayList<Object>();
public List<Foo> retrieveKeys(ExecutionContext executionContext) {
return new ArrayList<Foo>();
}
public void updateContext(Object key,
@@ -184,19 +184,19 @@ public class DrivingQueryItemReaderTests extends TestCase {
itemReader.reset();
}
private InitializingBean getAsInitializingBean(ItemReader source) {
private InitializingBean getAsInitializingBean(ItemReader<Foo> source) {
return (InitializingBean) source;
}
private ItemStream getAsItemStream(ItemReader source) {
private ItemStream getAsItemStream(ItemReader<Foo> source) {
return (ItemStream) source;
}
private static class MockKeyGenerator implements KeyCollector {
private static class MockKeyGenerator implements KeyCollector<Foo> {
static ExecutionContext streamContext;
List<Object> keys;
List<Object> restartKeys;
List<Foo> keys;
List<Foo> restartKeys;
static final String RESTART_KEY = "restart.keys";
static {
@@ -207,14 +207,14 @@ public class DrivingQueryItemReaderTests extends TestCase {
public MockKeyGenerator() {
keys = new ArrayList<Object>();
keys = new ArrayList<Foo>();
keys.add(new Foo(1, "1", 1));
keys.add(new Foo(2, "2", 2));
keys.add(new Foo(3, "3", 3));
keys.add(new Foo(4, "4", 4));
keys.add(new Foo(5, "5", 5));
restartKeys = new ArrayList<Object>();
restartKeys = new ArrayList<Foo>();
restartKeys.add(new Foo(3, "3", 3));
restartKeys.add(new Foo(4, "4", 4));
restartKeys.add(new Foo(5, "5", 5));
@@ -224,7 +224,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
return streamContext;
}
public List<Object> retrieveKeys(ExecutionContext executionContext) {
public List<Foo> retrieveKeys(ExecutionContext executionContext) {
if (executionContext.containsKey(RESTART_KEY)) {
return restartKeys;
} else {

View File

@@ -3,26 +3,27 @@ package org.springframework.batch.item.database;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.sample.Foo;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
class FooItemReader implements ItemStream, ItemReader, DisposableBean, InitializingBean {
class FooItemReader implements ItemStream, ItemReader<Foo>, DisposableBean, InitializingBean {
DrivingQueryItemReader itemReader;
DrivingQueryItemReader<Foo> itemReader;
public void setItemReader(DrivingQueryItemReader itemReader) {
public void setItemReader(DrivingQueryItemReader<Foo> itemReader) {
this.itemReader = itemReader;
}
FooDao fooDao = new SingleKeyFooDao();
public FooItemReader(DrivingQueryItemReader inputSource, JdbcTemplate jdbcTemplate) {
public FooItemReader(DrivingQueryItemReader<Foo> inputSource, JdbcTemplate jdbcTemplate) {
this.itemReader = inputSource;
fooDao.setJdbcTemplate(jdbcTemplate);
}
public Object read() {
public Foo read() {
Object key = itemReader.read();
if (key != null) {
return fooDao.getFoo(key);

View File

@@ -3,13 +3,14 @@ package org.springframework.batch.item.database;
import org.hibernate.SessionFactory;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.sample.Foo;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
public class HibernateCursorItemReaderCommonTests extends CommonDatabaseItemStreamItemReaderTests {
protected ItemReader getItemReader() throws Exception {
protected ItemReader<Foo> getItemReader() throws Exception {
SessionFactory sessionFactory = createSessionFactory();