IN PROGRESS - BATCH-830: DelegatingItemReader should be removed
removed DelegatingItemReader
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user