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

This commit is contained in:
robokaso
2008-07-18 12:56:32 +00:00
parent 77c8f4600e
commit 09a21fb95c
8 changed files with 24 additions and 21 deletions

View File

@@ -31,7 +31,7 @@ import org.springframework.util.MethodInvoker;
*
* @author Robert Kasanicky
*/
public class AbstractMethodInvokingDelegator implements InitializingBean {
public class AbstractMethodInvokingDelegator<T> implements InitializingBean {
private Object targetObject;
@@ -44,7 +44,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
* @return object returned by invoked method
* @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception
*/
protected Object invokeDelegateMethod() {
protected T invokeDelegateMethod() {
MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod);
invoker.setArguments(arguments);
return doInvoke(invoker);
@@ -56,7 +56,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
* @return object returned by target method
* @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception
*/
protected Object invokeDelegateMethodWithArgument(Object object) {
protected T invokeDelegateMethodWithArgument(Object object) {
MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod);
invoker.setArguments(new Object[]{object});
return doInvoke(invoker);
@@ -68,7 +68,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
* @return object returned by invoked method
* @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception
*/
protected Object invokeDelegateMethodWithArguments(Object[] args) {
protected T invokeDelegateMethodWithArguments(Object[] args) {
MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod);
invoker.setArguments(args);
return doInvoke(invoker);
@@ -90,7 +90,8 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
* @param invoker configured invoker
* @return return value of the invoked method
*/
private Object doInvoke(MethodInvoker invoker) {
@SuppressWarnings("unchecked")
private T doInvoke(MethodInvoker invoker) {
try {
invoker.prepare();
}
@@ -102,7 +103,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean {
}
try {
return invoker.invoke();
return (T) invoker.invoke();
}
catch (InvocationTargetException e) {
throw new DynamicMethodInvocationException(e);

View File

@@ -26,12 +26,12 @@ import org.springframework.batch.item.ResetFailedException;
*
* @author Robert Kasanicky
*/
public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implements ItemReader {
public class ItemReaderAdapter<T> extends AbstractMethodInvokingDelegator<T> implements ItemReader<T> {
/**
* @return return value of the target method.
*/
public Object read() throws Exception {
public T read() throws Exception {
return invokeDelegateMethod();
}

View File

@@ -29,7 +29,7 @@ import org.springframework.batch.item.ItemWriter;
*
* @author Robert Kasanicky
*/
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter {
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator<Object> implements ItemWriter {
public void write(Object item) throws Exception {
invokeDelegateMethodWithArgument(item);

View File

@@ -31,7 +31,7 @@ import org.springframework.util.Assert;
*
* @author Robert Kasanicky
*/
public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator implements ItemWriter {
public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator<Object> implements ItemWriter {
private String[] fieldsUsedAsTargetMethodArguments;

View File

@@ -15,10 +15,10 @@ import org.springframework.util.Assert;
*/
public class AbstractDelegatorTests extends TestCase {
private static class ConcreteDelegator extends AbstractMethodInvokingDelegator {
private static class ConcreteDelegator extends AbstractMethodInvokingDelegator<Foo> {
}
private AbstractMethodInvokingDelegator delegator = new ConcreteDelegator();
private AbstractMethodInvokingDelegator<Foo> delegator = new ConcreteDelegator();
private Foo foo = new Foo(0, "foo", 1);

View File

@@ -14,7 +14,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
*/
public class ItemReaderAdapterTests extends AbstractDependencyInjectionSpringContextTests {
private ItemReaderAdapter provider;
private ItemReaderAdapter<Foo> provider;
private FooService fooService;
@@ -41,7 +41,7 @@ public class ItemReaderAdapterTests extends AbstractDependencyInjectionSpringCon
}
}
public void setProvider(ItemReaderAdapter provider) {
public void setProvider(ItemReaderAdapter<Foo> provider) {
this.provider = provider;
}

View File

@@ -2,12 +2,13 @@ package org.springframework.batch.item.database;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.sample.Foo;
public class JdbcCursorItemReaderCommonTests extends CommonDatabaseItemStreamItemReaderTests {
protected ItemReader getItemReader() throws Exception {
protected ItemReader<Foo> getItemReader() throws Exception {
JdbcCursorItemReader result = new JdbcCursorItemReader();
JdbcCursorItemReader<Foo> result = new JdbcCursorItemReader<Foo>();
result.setDataSource(getDataSource());
result.setSql("select ID, NAME, VALUE from T_FOOS");
result.setIgnoreWarnings(true);
@@ -25,14 +26,14 @@ public class JdbcCursorItemReaderCommonTests extends CommonDatabaseItemStreamIte
public void testRestartWithDriverSupportsAbsolute() throws Exception {
tested = getItemReader();
((JdbcCursorItemReader) tested).setDriverSupportsAbsolute(true);
((JdbcCursorItemReader<Foo>) tested).setDriverSupportsAbsolute(true);
testedAsStream().open(executionContext);
testRestart();
}
protected void pointToEmptyInput(ItemReader tested) throws Exception {
JdbcCursorItemReader reader = (JdbcCursorItemReader) tested;
protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception {
JdbcCursorItemReader<Foo> reader = (JdbcCursorItemReader<Foo>) tested;
reader.close(new ExecutionContext());
reader.setSql("select ID from T_FOOS where ID < 0");
reader.afterPropertiesSet();

View File

@@ -1,6 +1,7 @@
package org.springframework.batch.item.database;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.sample.Foo;
/**
* Tests for {@link JdbcCursorItemReader}
@@ -9,8 +10,8 @@ import org.springframework.batch.item.ItemReader;
*/
public class JdbcCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
protected ItemReader createItemReader() throws Exception {
JdbcCursorItemReader result = new JdbcCursorItemReader();
protected ItemReader<Foo> createItemReader() throws Exception {
JdbcCursorItemReader<Foo> result = new JdbcCursorItemReader<Foo>();
result.setDataSource(super.getJdbcTemplate().getDataSource());
result.setSql("select ID, NAME, VALUE from T_FOOS");
result.setIgnoreWarnings(true);