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;
}
}