IN PROGRESS - BATCH-830: DelegatingItemReader should be removed

removed DelegatingItemReader
This commit is contained in:
robokaso
2008-09-25 14:10:46 +00:00
parent 963e924bc6
commit cbbf2e5b92
5 changed files with 19 additions and 192 deletions

View File

@@ -16,10 +16,8 @@
package org.springframework.batch.sample.support;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.support.DelegatingItemReader;
/**
* Hacked {@link ItemReader} that throws exception on a given record number
@@ -27,28 +25,36 @@ import org.springframework.batch.item.support.DelegatingItemReader;
*
* @author Robert Kasanicky
* @author Lucas Ward
*
*
*/
public class ExceptionThrowingItemReaderProxy<T> extends DelegatingItemReader<T> {
public class ExceptionThrowingItemReaderProxy<T> implements ItemReader<T> {
private int counter = 0;
private int throwExceptionOnRecordNumber = 4;
private ItemReader<T> delegate;
/**
* @param throwExceptionOnRecordNumber The number of record on which exception should be thrown
* @param throwExceptionOnRecordNumber The number of record on which
* exception should be thrown
*/
public void setThrowExceptionOnRecordNumber(int throwExceptionOnRecordNumber) {
this.throwExceptionOnRecordNumber = throwExceptionOnRecordNumber;
}
public T read() throws Exception {
counter++;
if (counter == throwExceptionOnRecordNumber) {
throw new UnexpectedJobExecutionException("Planned failure on count="+counter);
throw new UnexpectedJobExecutionException("Planned failure on count=" + counter);
}
return super.read();
return delegate.read();
}
public void setDelegate(ItemReader<T> delegate) {
this.delegate = delegate;
}
}

View File

@@ -34,7 +34,7 @@
<bean id="itemReader"
class="org.springframework.batch.sample.support.ExceptionThrowingItemReaderProxy">
<property name="itemReader" ref="fileItemReader" />
<property name="delegate" ref="fileItemReader" />
</bean>
<bean id="fileItemReader"

View File

@@ -28,7 +28,7 @@ public class ExceptionThrowingItemReaderProxyTests {
//create module and set item processor and iteration count
ExceptionThrowingItemReaderProxy<String> itemReader = new ExceptionThrowingItemReaderProxy<String>();
itemReader.setItemReader(new ListItemReader<String>(new ArrayList<String>() {{
itemReader.setDelegate(new ListItemReader<String>(new ArrayList<String>() {{
add("a");
add("b");
add("c");