IN PROGRESS - issue BATCH-212: Merge InputSource with ItemProvider

http://opensource.atlassian.com/projects/spring/browse/BATCH-212

Merge InputSource/ItemProvider -> ItemReader.
This commit is contained in:
dsyer
2007-12-17 13:13:39 +00:00
parent ddc4a48de1
commit ab98d1ebe6
107 changed files with 828 additions and 826 deletions

View File

@@ -20,12 +20,12 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemProvider;
import org.springframework.batch.item.ItemReader;
/**
* Custom class that contains logic that would normally be
* be contained in {@link ItemProvider} (<code>getData()</code>) and
* be contained in {@link ItemReader} (<code>getData()</code>) and
* {@link ItemProcessor} (<code>processData(..)</code>).
*
* @author tomas.slanina

View File

@@ -22,10 +22,10 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.io.InputSource;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.item.provider.AbstractItemProvider;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.provider.AbstractItemReader;
import org.springframework.batch.item.validator.Validator;
import org.springframework.batch.sample.domain.Address;
import org.springframework.batch.sample.domain.BillingInfo;
@@ -40,9 +40,9 @@ import org.springframework.batch.sample.domain.ShippingInfo;
* @author peter.zozom
*
*/
public class OrderItemProvider extends AbstractItemProvider {
private static Log log = LogFactory.getLog(OrderItemProvider.class);
private InputSource inputSource;
public class OrderItemReader extends AbstractItemReader {
private static Log log = LogFactory.getLog(OrderItemReader.class);
private ItemReader inputSource;
private Order order;
private boolean recordFinished;
private FieldSetMapper headerMapper;
@@ -54,9 +54,10 @@ public class OrderItemProvider extends AbstractItemProvider {
private Validator validator;
/**
* @see org.springframework.batch.item.ItemProvider#next()
* @throws Exception
* @see org.springframework.batch.item.ItemReader#read()
*/
public Object next() {
public Object read() throws Exception {
recordFinished = false;
while (!recordFinished) {
@@ -190,7 +191,7 @@ public class OrderItemProvider extends AbstractItemProvider {
this.headerMapper = headerMapper;
}
public void setInputSource(InputSource inputSource) {
public void setItemReader(ItemReader inputSource) {
this.inputSource = inputSource;
}

View File

@@ -11,7 +11,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.execution.scope.StepContext;
import org.springframework.batch.execution.scope.StepContextAware;
import org.springframework.batch.item.ItemProvider;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ResourceLifecycle;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
import org.springframework.batch.sample.item.processor.StagingItemProcessor;
@@ -26,14 +26,14 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
public class StagingItemProvider extends JdbcDaoSupport implements
ItemProvider, ResourceLifecycle, DisposableBean,
public class StagingItemReader extends JdbcDaoSupport implements
ItemReader, ResourceLifecycle, DisposableBean,
StepContextAware {
// Key for buffer in transaction synchronization manager
private static final String BUFFER_KEY = StagingItemProvider.class.getName()+".BUFFER";
private static final String BUFFER_KEY = StagingItemReader.class.getName()+".BUFFER";
private static Log logger = LogFactory.getLog(StagingItemProvider.class);
private static Log logger = LogFactory.getLog(StagingItemReader.class);
private StepContext stepContext;
@@ -49,7 +49,7 @@ public class StagingItemProvider extends JdbcDaoSupport implements
/**
*
* @see org.springframework.batch.io.driving.DrivingQueryInputSource#close()
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#close()
*/
public void close() {
initialized = false;
@@ -61,7 +61,7 @@ public class StagingItemProvider extends JdbcDaoSupport implements
/**
* @throws Exception
* @see org.springframework.batch.io.driving.DrivingQueryInputSource#destroy()
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#destroy()
*/
public void destroy() throws Exception {
close();
@@ -69,7 +69,7 @@ public class StagingItemProvider extends JdbcDaoSupport implements
/**
*
* @see org.springframework.batch.io.driving.DrivingQueryInputSource#open()
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#open()
*/
public void open() {
Assert.state(keys == null || initialized,
@@ -122,8 +122,8 @@ public class StagingItemProvider extends JdbcDaoSupport implements
return item;
}
public Object next() throws Exception {
Long id = read();
public Object read() throws Exception {
Long id = doRead();
if (id == null) {
return null;
@@ -152,7 +152,7 @@ public class StagingItemProvider extends JdbcDaoSupport implements
return result;
}
private Long read() {
private Long doRead() {
if (!initialized) {
open();
}

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.sample.tasklet;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet;
import org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
@@ -29,7 +29,7 @@ import org.springframework.batch.repeat.ExitStatus;
* @author Robert Kasanicky
*
*/
public class ExceptionRestartableTasklet extends RestartableItemProviderTasklet {
public class ExceptionRestartableTasklet extends RestartableItemOrientedTasklet {
private int counter = 0;
private int throwExceptionOnRecordNumber = 4;

View File

@@ -19,8 +19,8 @@ package org.springframework.batch.sample.tasklet;
import java.util.Properties;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet;
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
import org.springframework.batch.io.file.support.DefaultFlatFileItemReader;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.sample.dao.TradeWriter;
import org.springframework.batch.sample.domain.Trade;
@@ -31,7 +31,7 @@ import org.springframework.batch.statistics.StatisticsProvider;
* and processing of input data. This can be viable in cases, when the input
* reading and processing logic need not to be reused in different contexts. In
* general it is recommended to separate these two concerns using an
* {@link ItemProviderProcessTasklet}.
* {@link ItemOrientedTasklet}.
*
* Note this class is thread-safe, as per the 'standard' module implementations
* provided by the framework.
@@ -45,7 +45,7 @@ public class SimpleTradeTasklet implements Tasklet, StatisticsProvider {
/*
* reads the data from input file
*/
private DefaultFlatFileInputSource inputSource;
private DefaultFlatFileItemReader inputSource;
/*
* writes a Trade object to output
@@ -76,7 +76,7 @@ public class SimpleTradeTasklet implements Tasklet, StatisticsProvider {
return ExitStatus.CONTINUABLE;
}
public void setInputSource(DefaultFlatFileInputSource inputTemplate) {
public void setItemReader(DefaultFlatFileItemReader inputTemplate) {
this.inputSource = inputTemplate;
}