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:
@@ -25,12 +25,12 @@ import java.util.Set;
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemProviderRetryPolicy;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemReaderRetryPolicy;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.util.Assert;
|
||||
* the reading and processing of batch data into two separate classes:
|
||||
* ItemProvider and ItemProcessor. The ItemProvider class provides a solid means
|
||||
* for re-usability and enforces good architecture practices. Because an object
|
||||
* <em>must</em> be returned by the {@link ItemProvider} to continue
|
||||
* <em>must</em> be returned by the {@link ItemReader} to continue
|
||||
* processing, (returning null indicates processing should end) a developer is
|
||||
* forced to read in all relevant data, place it into a domain object, and
|
||||
* return that object. The {@link ItemProcessor} will then use this object for
|
||||
@@ -50,12 +50,12 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* If a {@link RetryPolicy} is provided it will be used to construct a stateful
|
||||
* retry around the {@link ItemProcessor}, delegating identity concerns to the
|
||||
* {@link ItemProvider} and recovery concerns to the {@link ItemRecoverer} (if
|
||||
* {@link ItemReader} and recovery concerns to the {@link ItemRecoverer} (if
|
||||
* present). In this case clients of this class do not need to take any
|
||||
* additional action at runtime to take advantage of the retry and recovery,
|
||||
* provided that when the {@link #execute()} method is called again the same
|
||||
* item is eventually re-presented (normally this would be the case because a
|
||||
* transaction would have rolled back and the {@link ItemProvider} would go back
|
||||
* transaction would have rolled back and the {@link ItemReader} would go back
|
||||
* to its previous state).<br/>
|
||||
*
|
||||
* If a {@link RetryPolicy} is not provided then the {@link ItemRecoverer} can
|
||||
@@ -65,7 +65,7 @@ import org.springframework.util.Assert;
|
||||
* can be achieved by injecting an {@link ItemRecoverer} that has a
|
||||
* transactional recover method.
|
||||
*
|
||||
* @see ItemProvider
|
||||
* @see ItemReader
|
||||
* @see ItemProcessor
|
||||
* @see RetryPolicy
|
||||
* @see Recoverable
|
||||
@@ -75,7 +75,7 @@ import org.springframework.util.Assert;
|
||||
* @author Robert Kasanicky
|
||||
*
|
||||
*/
|
||||
public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
public class ItemOrientedTasklet implements Tasklet, Skippable,
|
||||
StatisticsProvider, InitializingBean {
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
|
||||
private RetryPolicy retryPolicy = null;
|
||||
|
||||
protected ItemProvider itemProvider;
|
||||
protected ItemReader itemProvider;
|
||||
|
||||
protected ItemProcessor itemProcessor;
|
||||
|
||||
@@ -100,7 +100,7 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
|
||||
private RetryTemplate template = new RetryTemplate();
|
||||
|
||||
private ItemProviderRetryCallback retryCallback;
|
||||
private ItemReaderRetryCallback retryCallback;
|
||||
|
||||
/**
|
||||
* Check mandatory properties (provider and processor).
|
||||
@@ -115,12 +115,12 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
itemRecoverer = (ItemRecoverer) itemProvider;
|
||||
}
|
||||
|
||||
ItemProviderRetryPolicy itemProviderRetryPolicy = new ItemProviderRetryPolicy(
|
||||
ItemReaderRetryPolicy itemProviderRetryPolicy = new ItemReaderRetryPolicy(
|
||||
retryPolicy);
|
||||
template.setRetryPolicy(itemProviderRetryPolicy);
|
||||
|
||||
if (retryPolicy != null) {
|
||||
retryCallback = new ItemProviderRetryCallback(itemProvider,
|
||||
retryCallback = new ItemReaderRetryCallback(itemProvider,
|
||||
itemProcessor);
|
||||
retryCallback.setRecoverer(itemRecoverer);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the {@link ItemProvider} and process (if not null) with the
|
||||
* Read from the {@link ItemReader} and process (if not null) with the
|
||||
* {@link ItemProcessor}. The call to {@link ItemProcessor} is wrapped in a
|
||||
* stateful retry, if a {@link RetryPolicy} is provided. The
|
||||
* {@link ItemRecoverer} is used (if provided) in the case of an exception
|
||||
@@ -144,7 +144,7 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
public ExitStatus execute() throws Exception {
|
||||
|
||||
if (retryCallback == null) {
|
||||
Object item = itemProvider.next();
|
||||
Object item = itemProvider.read();
|
||||
if (item == null) {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class ItemProviderProcessTasklet implements Tasklet, Skippable,
|
||||
/**
|
||||
* @param itemProvider
|
||||
*/
|
||||
public void setItemProvider(ItemProvider itemProvider) {
|
||||
public void setItemProvider(ItemReader itemProvider) {
|
||||
this.itemProvider = itemProvider;
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ package org.springframework.batch.execution.tasklet;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* An extension of {@link ItemProviderProcessTasklet} that delegates calls to
|
||||
* An extension of {@link ItemOrientedTasklet} that delegates calls to
|
||||
* {@link Restartable} to the provider and processor.
|
||||
*
|
||||
* @see ItemProvider
|
||||
* @see ItemReader
|
||||
* @see ItemProcessor
|
||||
* @see Restartable
|
||||
*
|
||||
@@ -37,7 +37,7 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class RestartableItemProviderTasklet extends ItemProviderProcessTasklet implements Restartable {
|
||||
public class RestartableItemOrientedTasklet extends ItemOrientedTasklet implements Restartable {
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
@@ -55,7 +55,7 @@ public class RestartableItemProviderTasklet extends ItemProviderProcessTasklet i
|
||||
itemProcessorRestartData = ((Restartable) itemProcessor).getRestartData();
|
||||
}
|
||||
|
||||
RestartableItemProviderTaskletRestartData restartData = new RestartableItemProviderTaskletRestartData(itemProviderRestartData, itemProcessorRestartData);
|
||||
RestartableItemOrientedTaskletRestartData restartData = new RestartableItemOrientedTaskletRestartData(itemProviderRestartData, itemProcessorRestartData);
|
||||
|
||||
return restartData;
|
||||
}
|
||||
@@ -67,13 +67,13 @@ public class RestartableItemProviderTasklet extends ItemProviderProcessTasklet i
|
||||
if (data == null || data.getProperties() == null)
|
||||
return;
|
||||
|
||||
RestartableItemProviderTaskletRestartData moduleRestartData;
|
||||
RestartableItemOrientedTaskletRestartData moduleRestartData;
|
||||
|
||||
if (data instanceof RestartableItemProviderTaskletRestartData) {
|
||||
moduleRestartData = (RestartableItemProviderTaskletRestartData) data;
|
||||
if (data instanceof RestartableItemOrientedTaskletRestartData) {
|
||||
moduleRestartData = (RestartableItemOrientedTaskletRestartData) data;
|
||||
}
|
||||
else {
|
||||
moduleRestartData = new RestartableItemProviderTaskletRestartData(data.getProperties());
|
||||
moduleRestartData = new RestartableItemOrientedTaskletRestartData(data.getProperties());
|
||||
}
|
||||
|
||||
if (itemProvider instanceof Restartable) {
|
||||
@@ -84,7 +84,7 @@ public class RestartableItemProviderTasklet extends ItemProviderProcessTasklet i
|
||||
}
|
||||
}
|
||||
|
||||
private class RestartableItemProviderTaskletRestartData implements RestartData {
|
||||
private class RestartableItemOrientedTaskletRestartData implements RestartData {
|
||||
|
||||
private static final String PROVIDER_KEY = "DATA_PROVIDER";
|
||||
|
||||
@@ -94,12 +94,12 @@ public class RestartableItemProviderTasklet extends ItemProviderProcessTasklet i
|
||||
|
||||
RestartData processorData;
|
||||
|
||||
public RestartableItemProviderTaskletRestartData(RestartData providerData, RestartData processorData) {
|
||||
public RestartableItemOrientedTaskletRestartData(RestartData providerData, RestartData processorData) {
|
||||
this.providerData = providerData;
|
||||
this.processorData = processorData;
|
||||
}
|
||||
|
||||
public RestartableItemProviderTaskletRestartData(Properties data) {
|
||||
public RestartableItemOrientedTaskletRestartData(Properties data) {
|
||||
providerData = new GenericRestartData(PropertiesConverter
|
||||
.stringToProperties(data.getProperty(PROVIDER_KEY)));
|
||||
processorData = new GenericRestartData(PropertiesConverter.stringToProperties(data
|
||||
@@ -39,11 +39,11 @@ import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.runtime.ScheduledJobIdentifierFactory;
|
||||
import org.springframework.batch.execution.step.SimpleStepConfiguration;
|
||||
import org.springframework.batch.execution.step.simple.SimpleStepExecutor;
|
||||
import org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet;
|
||||
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
@@ -67,7 +67,7 @@ public class SimpleJobTests extends TestCase {
|
||||
}
|
||||
};
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private DefaultJobExecutor jobExecutor = new DefaultJobExecutor();;
|
||||
|
||||
@@ -92,11 +92,11 @@ public class SimpleJobTests extends TestCase {
|
||||
return getTasklet(new String[] { arg0, arg1 });
|
||||
}
|
||||
|
||||
private ItemProviderProcessTasklet getTasklet(String[] args) throws Exception {
|
||||
ItemProviderProcessTasklet module = new ItemProviderProcessTasklet();
|
||||
private ItemOrientedTasklet getTasklet(String[] args) throws Exception {
|
||||
ItemOrientedTasklet module = new ItemOrientedTasklet();
|
||||
List items = TransactionAwareProxyFactory.createTransactionalList();
|
||||
items.addAll(Arrays.asList(args));
|
||||
provider = new ListItemProvider(items);
|
||||
provider = new ListItemReader(items);
|
||||
module.setItemRecoverer(new ItemRecoverer() {
|
||||
public boolean recover(Object item, Throwable cause) {
|
||||
recovered.add(item);
|
||||
@@ -161,7 +161,7 @@ public class SimpleJobTests extends TestCase {
|
||||
* is recovered ("skipped") on the second attempt (see retry policy
|
||||
* definition above)...
|
||||
*/
|
||||
final ItemProviderProcessTasklet module = getTasklet(new String[] { "foo", "bar", "spam" });
|
||||
final ItemOrientedTasklet module = getTasklet(new String[] { "foo", "bar", "spam" });
|
||||
StepConfiguration step = new SimpleStepConfiguration(module);
|
||||
module.setItemProcessor(new ItemProcessor() {
|
||||
public void process(Object data) throws Exception {
|
||||
@@ -177,7 +177,7 @@ public class SimpleJobTests extends TestCase {
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getJob().getStatus());
|
||||
assertEquals(0, processed.size());
|
||||
// provider should be exhausted
|
||||
assertEquals(null, provider.next());
|
||||
assertEquals(null, provider.read());
|
||||
assertEquals(3, recovered.size());
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ public class SimpleJobTests extends TestCase {
|
||||
|
||||
JobConfiguration jobConfiguration = new JobConfiguration();
|
||||
JobIdentifier runtimeInformation = new SimpleJobIdentifier("real.job");
|
||||
final ItemProviderProcessTasklet module = getTasklet(new String[] { "foo", "bar", "spam" });
|
||||
final ItemOrientedTasklet module = getTasklet(new String[] { "foo", "bar", "spam" });
|
||||
StepConfiguration step = new SimpleStepConfiguration(module);
|
||||
module.setItemProcessor(new ItemProcessor() {
|
||||
public void process(Object data) throws Exception {
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.execution.scope.StepScope;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.execution.step.SimpleStepConfiguration;
|
||||
import org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet;
|
||||
import org.springframework.batch.execution.tasklet.ItemOrientedTasklet;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.exception.handler.DefaultExceptionHandler;
|
||||
@@ -66,8 +66,8 @@ public class DefaultStepExecutorTests extends TestCase {
|
||||
|
||||
private RepeatTemplate template;
|
||||
|
||||
private ItemProvider getProvider(String[] args) {
|
||||
return new ListItemProvider(Arrays.asList(args));
|
||||
private ItemReader getProvider(String[] args) {
|
||||
return new ListItemReader(Arrays.asList(args));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class DefaultStepExecutorTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
private Tasklet getTasklet(String[] strings) throws Exception {
|
||||
ItemProviderProcessTasklet module = new ItemProviderProcessTasklet();
|
||||
ItemOrientedTasklet module = new ItemOrientedTasklet();
|
||||
module.setItemProcessor(processor);
|
||||
module.setItemProvider(getProvider(strings));
|
||||
module.afterPropertiesSet();
|
||||
|
||||
@@ -25,9 +25,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.policy.SimpleRetryPolicy;
|
||||
@@ -38,16 +38,16 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
* @author Dave Syer
|
||||
* @author Peter Zozom
|
||||
*/
|
||||
public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
public class ItemOrientedTaskletTests extends TestCase {
|
||||
|
||||
private List list = new ArrayList();
|
||||
|
||||
private List items = new ArrayList();
|
||||
|
||||
private ItemProvider itemProvider = new AbstractItemProvider() {
|
||||
private ItemReader itemProvider = new AbstractItemReader() {
|
||||
int count = 0;
|
||||
|
||||
public Object next() throws Exception {
|
||||
public Object read() throws Exception {
|
||||
if (count < items.size()) {
|
||||
Object data = items.get(count++);
|
||||
if (data instanceof Exception) {
|
||||
@@ -65,12 +65,12 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
};
|
||||
|
||||
private ItemProviderProcessTasklet module;
|
||||
private ItemOrientedTasklet module;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
|
||||
// create module
|
||||
module = new ItemProviderProcessTasklet();
|
||||
module = new ItemOrientedTasklet();
|
||||
|
||||
// set up module
|
||||
module.setItemProvider(itemProvider);
|
||||
@@ -144,15 +144,15 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testSkippableProvider() throws Exception {
|
||||
module.setItemProvider(new SkippableItemProvider());
|
||||
public void testSkippableReader() throws Exception {
|
||||
module.setItemProvider(new SkippableItemReader());
|
||||
module.setItemRecoverer(null);
|
||||
module.skip();
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
public void testSkippablProviderProcessor() throws Exception {
|
||||
module.setItemProvider(new SkippableItemProvider());
|
||||
public void testSkippablReaderProcessor() throws Exception {
|
||||
module.setItemProvider(new SkippableItemReader());
|
||||
module.setItemProcessor(new SkippableItemProcessor());
|
||||
module.setItemRecoverer(null);
|
||||
module.skip();
|
||||
@@ -160,7 +160,7 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testStatisticsProvider() throws Exception {
|
||||
module.setItemProvider(new SkippableItemProvider());
|
||||
module.setItemProvider(new SkippableItemReader());
|
||||
Properties stats = module.getStatistics();
|
||||
assertEquals(1, stats.size());
|
||||
assertEquals("bar", stats.getProperty("foo"));
|
||||
@@ -174,7 +174,7 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testStatisticsProviderProcessor() throws Exception {
|
||||
module.setItemProvider(new SkippableItemProvider());
|
||||
module.setItemProvider(new SkippableItemReader());
|
||||
module.setItemProcessor(new SkippableItemProcessor());
|
||||
Properties stats = module.getStatistics();
|
||||
assertEquals(2, stats.size());
|
||||
@@ -184,7 +184,7 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
|
||||
public void testStatisticsProviderProcessorMergeDuplicates()
|
||||
throws Exception {
|
||||
module.setItemProvider(new SkippableItemProvider());
|
||||
module.setItemProvider(new SkippableItemReader());
|
||||
module.setItemProcessor(new SkippableItemProcessor(
|
||||
"foo=bar\nspam=bucket"));
|
||||
Properties stats = module.getStatistics();
|
||||
@@ -207,8 +207,8 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
module.setItemProvider(new AbstractItemProvider() {
|
||||
public Object next() throws Exception {
|
||||
module.setItemProvider(new AbstractItemReader() {
|
||||
public Object read() throws Exception {
|
||||
return "bar";
|
||||
}
|
||||
});
|
||||
@@ -245,8 +245,8 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
module.setItemProvider(new AbstractItemProvider() {
|
||||
public Object next() throws Exception {
|
||||
module.setItemProvider(new AbstractItemReader() {
|
||||
public Object read() throws Exception {
|
||||
return "foo";
|
||||
}
|
||||
});
|
||||
@@ -295,10 +295,10 @@ public class ItemProviderProcessTaskletTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private class SkippableItemProvider implements ItemProvider,
|
||||
private class SkippableItemReader implements ItemReader,
|
||||
Skippable, StatisticsProvider {
|
||||
public Object next() throws Exception {
|
||||
return itemProvider.next();
|
||||
public Object read() throws Exception {
|
||||
return itemProvider.read();
|
||||
}
|
||||
public Object getKey(Object item) {
|
||||
return item;
|
||||
@@ -20,9 +20,9 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet;
|
||||
import org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -31,9 +31,9 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
/**
|
||||
* @author Peter Zozom
|
||||
*/
|
||||
public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
|
||||
private static class MockProvider implements ItemProvider, Restartable {
|
||||
private static class MockProvider implements ItemReader, Restartable {
|
||||
|
||||
RestartData data = new RestartData() {
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
|
||||
};
|
||||
|
||||
public Object next() {
|
||||
public Object read() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -88,11 +88,11 @@ public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private ItemProvider itemProvider;
|
||||
private ItemReader itemProvider;
|
||||
|
||||
private ItemProcessor itemProcessor;
|
||||
|
||||
private RestartableItemProviderTasklet module;
|
||||
private RestartableItemOrientedTasklet module;
|
||||
|
||||
public void testRestart() {
|
||||
|
||||
@@ -101,7 +101,7 @@ public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
itemProcessor = new MockProcessor();
|
||||
|
||||
// create and set up module
|
||||
module = new RestartableItemProviderTasklet();
|
||||
module = new RestartableItemOrientedTasklet();
|
||||
module.setItemProvider(itemProvider);
|
||||
module.setItemProcessor(itemProcessor);
|
||||
|
||||
@@ -119,7 +119,7 @@ public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
itemProcessor = new MockProcessor();
|
||||
|
||||
// create and set up module
|
||||
module = new RestartableItemProviderTasklet();
|
||||
module = new RestartableItemOrientedTasklet();
|
||||
module.setItemProvider(itemProvider);
|
||||
module.setItemProcessor(itemProcessor);
|
||||
|
||||
@@ -134,7 +134,7 @@ public class RestartableItemProviderTaskletTests extends TestCase {
|
||||
public void testRestartFromNotRestartable() {
|
||||
|
||||
// create and set up module
|
||||
module = new RestartableItemProviderTasklet();
|
||||
module = new RestartableItemOrientedTasklet();
|
||||
module.setItemProvider(null);
|
||||
module.setItemProcessor(null);
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.SimpleStepConfiguration">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.ItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ListItemProvider">
|
||||
class="org.springframework.batch.item.provider.ListItemReader">
|
||||
<constructor-arg value="foo,bar,spam"/>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.SimpleStepConfiguration">
|
||||
<constructor-arg>
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.ItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ListItemProvider">
|
||||
class="org.springframework.batch.item.provider.ListItemReader">
|
||||
<constructor-arg value="foo,bar,spam"/>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.io;
|
||||
|
||||
|
||||
/**
|
||||
* Basic interface for generic input operations. Class implementing this
|
||||
* interface will be responsible for reading records from input stream and also
|
||||
* possibly for mapping these records to objects. Generally it is responsibility
|
||||
* of implementing class to decide which technology to use for mapping and how
|
||||
* it should be configured.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface InputSource {
|
||||
|
||||
/**
|
||||
* Read record from input stream and map it to an object.
|
||||
*
|
||||
* @return the value object
|
||||
*/
|
||||
public Object read();
|
||||
}
|
||||
@@ -23,9 +23,10 @@ import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -39,7 +40,7 @@ import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link InputSource} for reading database records built on top of Hibernate.
|
||||
* {@link ItemReader} for reading database records built on top of Hibernate.
|
||||
*
|
||||
* It executes the HQL {@link #queryString} when initialized and iterates over
|
||||
* the result set as {@link #read()} method is called, returning an object
|
||||
@@ -56,15 +57,15 @@ import org.springframework.util.StringUtils;
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HibernateCursorInputSource implements InputSource, Restartable,
|
||||
public class HibernateCursorItemReader extends AbstractItemReader implements ItemReader, Restartable,
|
||||
Skippable, InitializingBean, DisposableBean, ResourceLifecycle {
|
||||
|
||||
private static final String RESTART_DATA_ROW_NUMBER_KEY = ClassUtils
|
||||
.getShortName(HibernateCursorInputSource.class)
|
||||
.getShortName(HibernateCursorItemReader.class)
|
||||
+ ".rowNumber";
|
||||
|
||||
private static final String SKIPPED_ROWS = ClassUtils
|
||||
.getShortName(HibernateCursorInputSource.class)
|
||||
.getShortName(HibernateCursorItemReader.class)
|
||||
+ ".skippedRows";;
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
@@ -90,7 +91,7 @@ public class HibernateCursorInputSource implements InputSource, Restartable,
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private TransactionSynchronization synchronization = new HibernateInputSourceTransactionSynchronization();
|
||||
private TransactionSynchronization synchronization = new HibernateItemReaderTransactionSynchronization();
|
||||
|
||||
public Object read() {
|
||||
if (!initialized) {
|
||||
@@ -238,7 +239,7 @@ public class HibernateCursorInputSource implements InputSource, Restartable,
|
||||
/**
|
||||
* Encapsulates transaction events handling.
|
||||
*/
|
||||
private class HibernateInputSourceTransactionSynchronization extends
|
||||
private class HibernateItemReaderTransactionSynchronization extends
|
||||
TransactionSynchronizationAdapter {
|
||||
|
||||
public void afterCompletion(int status) {
|
||||
@@ -29,9 +29,9 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -116,11 +116,11 @@ import org.springframework.util.StringUtils;
|
||||
* @author Lucas Ward
|
||||
* @author Peter Zozom
|
||||
*/
|
||||
public class JdbcCursorInputSource extends AbstractTransactionalIoSource
|
||||
implements InputSource, ResourceLifecycle, DisposableBean,
|
||||
public class JdbcCursorItemReader extends AbstractTransactionalIoSource
|
||||
implements ItemReader, ResourceLifecycle, DisposableBean,
|
||||
InitializingBean, Restartable, StatisticsProvider, Skippable {
|
||||
|
||||
private static Log log = LogFactory.getLog(JdbcCursorInputSource.class);
|
||||
private static Log log = LogFactory.getLog(JdbcCursorItemReader.class);
|
||||
|
||||
public static final int VALUE_NOT_SET = -1;
|
||||
|
||||
@@ -565,4 +565,13 @@ public class JdbcCursorInputSource extends AbstractTransactionalIoSource
|
||||
initialized = true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the item itself (which is already a key).
|
||||
* @see org.springframework.batch.item.ItemReader#getKey(java.lang.Object)
|
||||
*/
|
||||
public Object getKey(Object item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.io.driving;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -50,8 +50,8 @@ import org.springframework.util.Assert;
|
||||
* @author Lucas Ward
|
||||
* @since 1.0
|
||||
*/
|
||||
public class DrivingQueryInputSource extends AbstractTransactionalIoSource
|
||||
implements InputSource, ResourceLifecycle, InitializingBean,
|
||||
public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
implements ItemReader, ResourceLifecycle, InitializingBean,
|
||||
DisposableBean, Restartable {
|
||||
|
||||
private boolean initialized = false;
|
||||
@@ -66,7 +66,7 @@ public class DrivingQueryInputSource extends AbstractTransactionalIoSource
|
||||
|
||||
private KeyGenerator keyGenerator;
|
||||
|
||||
public DrivingQueryInputSource() {
|
||||
public DrivingQueryItemReader() {
|
||||
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ public class DrivingQueryInputSource extends AbstractTransactionalIoSource
|
||||
*
|
||||
* @param keys
|
||||
*/
|
||||
public DrivingQueryInputSource(List keys) {
|
||||
public DrivingQueryItemReader(List keys) {
|
||||
this.keys = keys;
|
||||
this.keysIterator = keys.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the next key in the List. If the InputSource has not been
|
||||
* initialized yet, then {@link AbstractDrivingQueryInputSource.open()} will
|
||||
* Return the next key in the List. If the ItemReader has not been
|
||||
* initialized yet, then {@link AbstractDrivingQueryItemReader.open()} will
|
||||
* be called.
|
||||
*
|
||||
* @return next key in the list if not index is not at the last element,
|
||||
@@ -103,7 +103,7 @@ public class DrivingQueryInputSource extends AbstractTransactionalIoSource
|
||||
|
||||
/**
|
||||
* Get the current key. This method will return the same object returned by
|
||||
* the last read() method. If the InputSource hasn't been initialized yet,
|
||||
* the last read() method. If the ItemReader hasn't been initialized yet,
|
||||
* then null will be returned.
|
||||
*
|
||||
* @return the current key.
|
||||
@@ -217,4 +217,12 @@ public class DrivingQueryInputSource extends AbstractTransactionalIoSource
|
||||
keysIterator = keys.listIterator(lastCommitIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the item itself (which is already a key).
|
||||
* @see org.springframework.batch.item.ItemReader#getKey(java.lang.Object)
|
||||
*/
|
||||
public Object getKey(Object item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,13 +21,13 @@ import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
/**
|
||||
* Extension of {@link DrivingQueryInputSource} that maps keys to
|
||||
* Extension of {@link DrivingQueryItemReader} that maps keys to
|
||||
* objects. An iBatis query id must be set to map and return each 'detail record'.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @see IbatisKeyGenerator
|
||||
*/
|
||||
public class IbatisDrivingQueryInputSource extends DrivingQueryInputSource {
|
||||
public class IbatisDrivingQueryItemReader extends DrivingQueryItemReader {
|
||||
|
||||
private String detailsQueryId;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class IbatisDrivingQueryInputSource extends DrivingQueryInputSource {
|
||||
/**
|
||||
* Overridden read() that uses the returned key as arguments to the details query.
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryInputSource#read()
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#read()
|
||||
*/
|
||||
public Object read() {
|
||||
Object key = super.read();
|
||||
@@ -3,7 +3,7 @@ package org.springframework.batch.io.driving.support;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.driving.DrivingQueryInputSource;
|
||||
import org.springframework.batch.io.driving.DrivingQueryItemReader;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -19,11 +19,11 @@ import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
* @author Lucas Ward
|
||||
* @see DrivingQueryInputSource
|
||||
* @see DrivingQueryItemReader
|
||||
*/
|
||||
public class IbatisKeyGenerator implements KeyGenerator {
|
||||
|
||||
public static final String RESTART_KEY = "IbatisDrivingQueryInputSource.keyIndex";
|
||||
public static final String RESTART_KEY = "IbatisDrivingQueryItemReader.keyIndex";
|
||||
|
||||
private SqlMapClientTemplate sqlMapClientTemplate;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class IbatisKeyGenerator implements KeyGenerator {
|
||||
/*
|
||||
* Retrieve the keys using the provided driving query id.
|
||||
*
|
||||
* @see org.springframework.batch.io.support.AbstractDrivingQueryInputSource#retrieveKeys()
|
||||
* @see org.springframework.batch.io.support.AbstractDrivingQueryItemReader#retrieveKeys()
|
||||
*/
|
||||
public List retrieveKeys() {
|
||||
return sqlMapClientTemplate.queryForList(drivingQuery);
|
||||
@@ -54,7 +54,7 @@ public class IbatisKeyGenerator implements KeyGenerator {
|
||||
/**
|
||||
* Restore the keys list given the provided restart data.
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryInputSource#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
*/
|
||||
public List restoreKeys(RestartData data) {
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.batch.io.driving.support;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.driving.DrivingQueryInputSource;
|
||||
import org.springframework.batch.io.driving.DrivingQueryItemReader;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -33,13 +33,13 @@ import org.springframework.util.StringUtils;
|
||||
* </p>
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @see DrivingQueryInputSource
|
||||
* @see DrivingQueryItemReader
|
||||
* @since 1.0
|
||||
*/
|
||||
public class MultipleColumnJdbcKeyGenerator implements
|
||||
KeyGenerator {
|
||||
|
||||
public static final String RESTART_KEY = "CompositeKeySqlDrivingQueryInputSource.key";
|
||||
public static final String RESTART_KEY = "CompositeKeySqlDrivingQueryItemReader.key";
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new InputSource.
|
||||
* Construct a new ItemReader.
|
||||
*
|
||||
* @param jdbcTemplate
|
||||
* @param sql - Sql statement that returns all keys to process.
|
||||
@@ -71,14 +71,14 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryInputSource#retrieveKeys()
|
||||
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryItemReader#retrieveKeys()
|
||||
*/
|
||||
public List retrieveKeys() {
|
||||
return jdbcTemplate.query(sql, keyMapper);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryInputSource#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryItemReader#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
*/
|
||||
public List restoreKeys(RestartData restartData) {
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This class is a {@link FieldSetInputSource} that supports restart,
|
||||
* This class is a {@link FieldSetItemReader} that supports restart,
|
||||
* skipping invalid lines and storing statistics.
|
||||
* </p>
|
||||
*
|
||||
@@ -41,9 +41,9 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
|
||||
* @author Tomas Slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DefaultFlatFileInputSource extends SimpleFlatFileInputSource implements Skippable, Restartable,
|
||||
public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implements Skippable, Restartable,
|
||||
StatisticsProvider {
|
||||
private static Log log = LogFactory.getLog(DefaultFlatFileInputSource.class);
|
||||
private static Log log = LogFactory.getLog(DefaultFlatFileItemReader.class);
|
||||
|
||||
public static final String READ_STATISTICS_NAME = "lines.read.count";
|
||||
|
||||
@@ -25,11 +25,12 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.exception.BatchEnvironmentException;
|
||||
import org.springframework.batch.io.file.support.separator.DefaultRecordSeparatorPolicy;
|
||||
import org.springframework.batch.io.file.support.separator.RecordSeparatorPolicy;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -57,7 +58,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
class ResourceLineReader implements ResourceLifecycle, InputSource,
|
||||
class ResourceLineReader extends AbstractItemReader implements ResourceLifecycle, ItemReader,
|
||||
DisposableBean {
|
||||
|
||||
private static final Collection DEFAULT_COMMENTS = Collections
|
||||
@@ -128,7 +129,7 @@ class ResourceLineReader implements ResourceLifecycle, InputSource,
|
||||
* if there is an IOException while accessing the input
|
||||
* resource.
|
||||
*
|
||||
* @see org.springframework.batch.item.provider.support.InputSource#read()
|
||||
* @see org.springframework.batch.item.provider.support.ItemReader#read()
|
||||
*/
|
||||
public synchronized Object read() {
|
||||
// Make a copy of the recordSeparatorPolicy reference, in case it is
|
||||
@@ -179,7 +180,7 @@ class ResourceLineReader implements ResourceLifecycle, InputSource,
|
||||
/**
|
||||
* Close the reader associated with this input source.
|
||||
*
|
||||
* @see org.springframework.batch.io.InputSource#close()
|
||||
* @see org.springframework.batch.io.ItemReader#close()
|
||||
* @throws BatchEnvironmentException
|
||||
* if there is an {@link IOException} during the close
|
||||
* operation.
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.batch.io.file.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.exception.FlatFileParsingException;
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
@@ -26,7 +25,9 @@ import org.springframework.batch.io.file.support.separator.RecordSeparatorPolicy
|
||||
import org.springframework.batch.io.file.support.transform.AbstractLineTokenizer;
|
||||
import org.springframework.batch.io.file.support.transform.DelimitedLineTokenizer;
|
||||
import org.springframework.batch.io.file.support.transform.LineTokenizer;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -39,16 +40,16 @@ import org.springframework.util.Assert;
|
||||
* structure of the file, {@link LineTokenizer} is used to parse data obtained
|
||||
* from the file. <br/>
|
||||
*
|
||||
* A {@link SimpleFlatFileInputSource} is not thread safe because it maintains
|
||||
* A {@link SimpleFlatFileItemReader} is not thread safe because it maintains
|
||||
* state in the form of a {@link ResourceLineReader}. Be careful to configure a
|
||||
* {@link SimpleFlatFileInputSource} using an appropriate factory or scope so
|
||||
* {@link SimpleFlatFileItemReader} using an appropriate factory or scope so
|
||||
* that it is not shared between threads.<br/>
|
||||
*
|
||||
* @see FieldSetInputSource
|
||||
* @see FieldSetItemReader
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SimpleFlatFileInputSource implements InputSource,
|
||||
public class SimpleFlatFileItemReader extends AbstractItemReader implements ItemReader,
|
||||
InitializingBean, DisposableBean {
|
||||
|
||||
// default encoding for input files - set to ISO-8859-1
|
||||
@@ -182,9 +183,9 @@ public class SimpleFlatFileInputSource implements InputSource,
|
||||
|
||||
/**
|
||||
* A wrapper for {@link #readFieldSet()} to make this into a real
|
||||
* {@link InputSource}.
|
||||
* {@link ItemReader}.
|
||||
*
|
||||
* @see org.springframework.batch.io.InputSource#read()
|
||||
* @see org.springframework.batch.io.ItemReader#read()
|
||||
*/
|
||||
public Object read() {
|
||||
String line = readLine();
|
||||
@@ -12,14 +12,15 @@ import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.events.StartElement;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.file.support.stax.DefaultFragmentEventReader;
|
||||
import org.springframework.batch.io.file.support.stax.DefaultTransactionalEventReader;
|
||||
import org.springframework.batch.io.file.support.stax.FragmentDeserializer;
|
||||
import org.springframework.batch.io.file.support.stax.FragmentEventReader;
|
||||
import org.springframework.batch.io.file.support.stax.TransactionalEventReader;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -35,19 +36,20 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Input source for reading XML input based on StAX.
|
||||
*
|
||||
*
|
||||
* It extracts fragments from the input XML document which correspond to records
|
||||
* for processing. The fragments are wrapped with StartDocument and EndDocument
|
||||
* events so that the fragments can be further processed like standalone XML
|
||||
* documents.
|
||||
*
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StaxEventReaderInputSource implements InputSource, ResourceLifecycle, Skippable, Restartable, StatisticsProvider, InitializingBean, DisposableBean {
|
||||
public class StaxEventReaderItemReader extends AbstractItemReader implements ItemReader, ResourceLifecycle,
|
||||
Skippable, Restartable, StatisticsProvider, InitializingBean, DisposableBean {
|
||||
|
||||
public static final String READ_COUNT_STATISTICS_NAME = "StaxEventReaderInputSource.readCount";
|
||||
public static final String READ_COUNT_STATISTICS_NAME = "StaxEventReaderItemReader.readCount";
|
||||
|
||||
private static final String RESTART_DATA_NAME = "StaxEventReaderInputSource.recordcount";
|
||||
private static final String RESTART_DATA_NAME = "StaxEventReaderItemReader.recordcount";
|
||||
|
||||
private FragmentEventReader fragmentReader;
|
||||
|
||||
@@ -63,7 +65,7 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private TransactionSynchronization synchronization = new StaxEventReaderInputSourceTransactionSychronization();
|
||||
private TransactionSynchronization synchronization = new StaxEventReaderItemReaderTransactionSychronization();
|
||||
|
||||
private long lastCommitPointRecordCount = 0;
|
||||
|
||||
@@ -73,9 +75,9 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
|
||||
/**
|
||||
* Read in the next root element from the file, and return it.
|
||||
*
|
||||
*
|
||||
* @return the next available record, if none exist, return null
|
||||
* @see org.springframework.batch.io.InputSource#read()
|
||||
* @see org.springframework.batch.io.ItemReader#read()
|
||||
*/
|
||||
public Object read() {
|
||||
if (!initialized) {
|
||||
@@ -120,8 +122,8 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
registerSynchronization();
|
||||
try {
|
||||
inputStream = resource.getInputStream();
|
||||
txReader = new DefaultTransactionalEventReader(XMLInputFactory
|
||||
.newInstance().createXMLEventReader(inputStream));
|
||||
txReader = new DefaultTransactionalEventReader(XMLInputFactory.newInstance().createXMLEventReader(
|
||||
inputStream));
|
||||
fragmentReader = new DefaultFragmentEventReader(txReader);
|
||||
}
|
||||
catch (XMLStreamException xse) {
|
||||
@@ -138,8 +140,8 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fragmentDeserializer maps xml fragments corresponding to records to
|
||||
* objects
|
||||
* @param fragmentDeserializer maps xml fragments corresponding to records
|
||||
* to objects
|
||||
*/
|
||||
public void setFragmentDeserializer(FragmentDeserializer fragmentDeserializer) {
|
||||
this.fragmentDeserializer = fragmentDeserializer;
|
||||
@@ -156,7 +158,7 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
/**
|
||||
* Mark the last read record as 'skipped', so that I will not be returned
|
||||
* from read() in the case of a rollback.
|
||||
*
|
||||
*
|
||||
* @see Skippable#skip()
|
||||
*/
|
||||
public void skip() {
|
||||
@@ -173,9 +175,9 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that all required dependencies for the InputSource to run are provided
|
||||
* after all properties have been set.
|
||||
*
|
||||
* Ensure that all required dependencies for the ItemReader to run are
|
||||
* provided after all properties have been set.
|
||||
*
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
* @throws IllegalArgumentException if the Resource, FragmentDeserializer or
|
||||
* FragmentRootElementName is null, or if the root element is empty.
|
||||
@@ -201,17 +203,17 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the input source for the given restart data by rereading and skipping
|
||||
* the number of records stored in the RestartData.
|
||||
*
|
||||
* Restores the input source for the given restart data by rereading and
|
||||
* skipping the number of records stored in the RestartData.
|
||||
*
|
||||
* @param RestartData that holds the line count from the last commit.
|
||||
* @throws IllegalStateException if the InputSource has already been initialized
|
||||
* or if the number of records to read and skip exceeds the available records.
|
||||
* @throws IllegalStateException if the ItemReader has already been
|
||||
* initialized or if the number of records to read and skip exceeds the
|
||||
* available records.
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
Assert.state(!initialized);
|
||||
if (data == null || data.getProperties() == null ||
|
||||
data.getProperties().getProperty(RESTART_DATA_NAME) == null) {
|
||||
if (data == null || data.getProperties() == null || data.getProperties().getProperty(RESTART_DATA_NAME) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -232,13 +234,15 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
}
|
||||
|
||||
/**
|
||||
* Responsible for moving the cursor before the StartElement of the fragment root.
|
||||
*
|
||||
* This implementation simply looks for the next corresponding element, it does not care
|
||||
* about element nesting. You will need to override this method to correctly handle
|
||||
* composite fragments.
|
||||
*
|
||||
* @return <code>true</code> if next fragment was found, <code>false</code> otherwise.
|
||||
* Responsible for moving the cursor before the StartElement of the fragment
|
||||
* root.
|
||||
*
|
||||
* This implementation simply looks for the next corresponding element, it
|
||||
* does not care about element nesting. You will need to override this
|
||||
* method to correctly handle composite fragments.
|
||||
*
|
||||
* @return <code>true</code> if next fragment was found,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
protected boolean moveCursorToNextFragment(XMLEventReader reader) {
|
||||
try {
|
||||
@@ -252,7 +256,8 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
QName startElementName = ((StartElement) reader.peek()).getName();
|
||||
if (startElementName.getLocalPart().equals(fragmentRootElementName)) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
reader.nextEvent();
|
||||
}
|
||||
}
|
||||
@@ -268,9 +273,9 @@ public class StaxEventReaderInputSource implements InputSource, ResourceLifecycl
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates transaction events for the StaxEventReaderInputSource.
|
||||
* Encapsulates transaction events for the StaxEventReaderItemReader.
|
||||
*/
|
||||
private class StaxEventReaderInputSourceTransactionSychronization extends TransactionSynchronizationAdapter {
|
||||
private class StaxEventReaderItemReaderTransactionSychronization extends TransactionSynchronizationAdapter {
|
||||
|
||||
/**
|
||||
* @param status
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.batch.io.support;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.ItemWriter;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -26,7 +26,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
/**
|
||||
* <p>
|
||||
* Abstract class that abstracts away transaction handling from input and
|
||||
* output. Any {@link InputSource} or {@link ItemWriter} that wants to be
|
||||
* output. Any {@link ItemReader} or {@link ItemWriter} that wants to be
|
||||
* notified of transaction events to maintain the contract that all calls to
|
||||
* read or write can extend this base class to ensure that correct ordering is
|
||||
* maintained regardless of rollbacks.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.item;
|
||||
|
||||
/**
|
||||
* Mixin interface for {@link ItemProvider} implementations if they can
|
||||
* Mixin interface for {@link ItemReader} implementations if they can
|
||||
* distinguish a new item from one that has been processed before and failed,
|
||||
* e.g. by examining a message flag.
|
||||
*
|
||||
|
||||
@@ -24,7 +24,7 @@ package org.springframework.batch.item;
|
||||
* for each batch, with each call to {@link #next} returning a different value
|
||||
* and finally returning <code>null</code> when all input data is exhausted.<br/>
|
||||
*
|
||||
* Implementations need to be thread safe and clients of a {@link ItemProvider}
|
||||
* Implementations need to be thread safe and clients of a {@link ItemReader}
|
||||
* need to be aware that this is the case. Clients can code to this interface
|
||||
* without worrying about thread safety by using the AbstractItemProvider base
|
||||
* class.<br/>
|
||||
@@ -35,7 +35,7 @@ package org.springframework.batch.item;
|
||||
* @author Rob Harrop
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public interface ItemProvider {
|
||||
public interface ItemReader {
|
||||
|
||||
/**
|
||||
* Reads a piece of input data and advance to the next one. Implementations
|
||||
@@ -46,7 +46,7 @@ public interface ItemProvider {
|
||||
*
|
||||
* @throws Exception if an underlying resource is unavailable.
|
||||
*/
|
||||
Object next() throws Exception;
|
||||
Object read() throws Exception;
|
||||
|
||||
/**
|
||||
* Get a unique identifier for the item that can be used to cache it between
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.support.AbstractDelegator;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.support.AbstractDelegator;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProcessor extends AbstractDelegator implements ItemProcessor {
|
||||
public class ItemProcessorAdapter extends AbstractMethodInvokingDelegator implements ItemProcessor {
|
||||
|
||||
public void process(Object item) throws Exception {
|
||||
invokeDelegateMethodWithArgument(item);
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.support.AbstractDelegator;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -26,11 +26,11 @@ import org.springframework.util.Assert;
|
||||
* Delegates processing to a custom method - extracts property values
|
||||
* from item object and uses them as arguments for the delegate method.
|
||||
*
|
||||
* @see DelegatingItemProcessor
|
||||
* @see ItemProcessorAdapter
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PropertyExtractingDelegatingItemProcessor extends AbstractDelegator implements ItemProcessor {
|
||||
public class PropertyExtractingDelegatingItemProcessor extends AbstractMethodInvokingDelegator implements ItemProcessor {
|
||||
|
||||
private String[] fieldsUsedAsTargetMethodArguments;
|
||||
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
package org.springframework.batch.item.provider;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* Base class for {@link ItemProvider} implementations.
|
||||
* Base class for {@link ItemReader} implementations.
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractItemProvider implements ItemProvider {
|
||||
public abstract class AbstractItemReader implements ItemReader {
|
||||
|
||||
/**
|
||||
* Simply returns the item itself. Will be adequate for many purposes, but
|
||||
* not (for example) if the item is a message - in which case the identifier
|
||||
* should be used.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProvider#getKey(java.lang.Object)
|
||||
* @see org.springframework.batch.item.ItemReader#getKey(java.lang.Object)
|
||||
*/
|
||||
public Object getKey(Object item) {
|
||||
return item;
|
||||
@@ -21,36 +21,36 @@ import java.util.Collection;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* An {@link ItemProvider} that delivers a list as its item, storing up objects
|
||||
* from the injected {@link InputSource} until they are ready to be packed out
|
||||
* as a collection. The {@link InputSource} should mark the beginning and end of
|
||||
* An {@link ItemReader} that delivers a list as its item, storing up objects
|
||||
* from the injected {@link ItemReader} until they are ready to be packed out
|
||||
* as a collection. The {@link ItemReader} should mark the beginning and end of
|
||||
* records with the constant values in {@link FieldSetMapper} ({@link FieldSetMapper#BEGIN_RECORD}
|
||||
* and {@link FieldSetMapper#END_RECORD}).<br/>
|
||||
*
|
||||
* This class is thread safe (it can be used concurrently by multiple threads)
|
||||
* as long as the {@link InputSource} is also thread safe.
|
||||
* as long as the {@link ItemReader} is also thread safe.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class AggregateItemProvider extends AbstractItemProvider {
|
||||
public class AggregateItemReader extends AbstractItemReader {
|
||||
|
||||
private static final Log log = LogFactory
|
||||
.getLog(AggregateItemProvider.class);
|
||||
.getLog(AggregateItemReader.class);
|
||||
|
||||
private InputSource inputSource;
|
||||
private ItemReader inputSource;
|
||||
|
||||
/**
|
||||
* Get the next list of records.
|
||||
* @throws Exception
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProvider#next()
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
public Object next() {
|
||||
public Object read() throws Exception {
|
||||
ResultHolder holder = new ResultHolder();
|
||||
|
||||
while (process(inputSource.read(), holder)) {
|
||||
@@ -67,7 +67,7 @@ public class AggregateItemProvider extends AbstractItemProvider {
|
||||
private boolean process(Object value, ResultHolder holder) {
|
||||
// finish processing if we hit the end of file
|
||||
if (value == null) {
|
||||
log.debug("Exhausted InputSource");
|
||||
log.debug("Exhausted ItemReader");
|
||||
holder.exhausted = true;
|
||||
return false;
|
||||
}
|
||||
@@ -91,12 +91,12 @@ public class AggregateItemProvider extends AbstractItemProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Injection setter for {@link InputSource}.
|
||||
* Injection setter for {@link ItemReader}.
|
||||
*
|
||||
* @param inputSource
|
||||
* an {@link InputSource}.
|
||||
* an {@link ItemReader}.
|
||||
*/
|
||||
public void setInputSource(InputSource inputSource) {
|
||||
public void setItemReader(ItemReader inputSource) {
|
||||
this.inputSource = inputSource;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.item.provider;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
@@ -27,24 +27,25 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple wrapper around {@link InputSource}. The input source is expected to
|
||||
* Simple wrapper around {@link ItemReader}. The input source is expected to
|
||||
* take care of open and close operations. If necessary it should be registered
|
||||
* as a step scoped bean to ensure that the lifecycle methods are called.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class InputSourceItemProvider extends AbstractItemProvider implements Restartable, StatisticsProvider, Skippable, InitializingBean{
|
||||
public class DelegatingItemReader extends AbstractItemReader implements Restartable, StatisticsProvider, Skippable, InitializingBean{
|
||||
|
||||
private InputSource inputSource;
|
||||
private ItemReader inputSource;
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(inputSource, "InputSource must not be null.");
|
||||
Assert.notNull(inputSource, "ItemReader must not be null.");
|
||||
}
|
||||
/**
|
||||
* Get the next object from the input source.
|
||||
* @see org.springframework.batch.item.ItemProvider#next()
|
||||
* @throws Exception
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
public Object next() {
|
||||
public Object read() throws Exception {
|
||||
return inputSource.read();
|
||||
}
|
||||
|
||||
@@ -89,11 +90,11 @@ public class InputSourceItemProvider extends AbstractItemProvider implements Res
|
||||
* Setter for input source.
|
||||
* @param source
|
||||
*/
|
||||
public void setInputSource(InputSource source) {
|
||||
public void setItemReader(ItemReader source) {
|
||||
this.inputSource = source;
|
||||
}
|
||||
|
||||
public InputSource getInputSource() {
|
||||
public ItemReader getItemReader() {
|
||||
return inputSource;
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@
|
||||
|
||||
package org.springframework.batch.item.provider;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.support.AbstractDelegator;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
|
||||
/**
|
||||
* Invokes a custom method which provides an item.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProvider extends AbstractDelegator implements ItemProvider {
|
||||
public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implements ItemReader {
|
||||
|
||||
/**
|
||||
* @return return value of the target method.
|
||||
*/
|
||||
public Object next() throws Exception {
|
||||
public Object read() throws Exception {
|
||||
return invokeDelegateMethod();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.jms.Message;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.FailedItemIdentifier;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.exception.UnexpectedInputException;
|
||||
import org.springframework.jms.JmsException;
|
||||
import org.springframework.jms.core.JmsOperations;
|
||||
@@ -31,15 +31,15 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* An {@link ItemProvider} for JMS using a {@link JmsTemplate}. The template
|
||||
* An {@link ItemReader} for JMS using a {@link JmsTemplate}. The template
|
||||
* should have a default destination, which will be used to provide items in
|
||||
* {@link #next()}. If a recovery step is needed, set the error destination and
|
||||
* {@link #read()}. If a recovery step is needed, set the error destination and
|
||||
* the item will be sent there if processing fails in an external retry.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class JmsItemProvider extends AbstractItemProvider implements FailedItemIdentifier {
|
||||
public class JmsItemReader extends AbstractItemReader implements FailedItemIdentifier {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
@@ -92,7 +92,7 @@ public class JmsItemProvider extends AbstractItemProvider implements FailedItemI
|
||||
this.itemType = itemType;
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
public Object read() {
|
||||
if (itemType != null && itemType.isAssignableFrom(Message.class)) {
|
||||
return jmsTemplate.receive();
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class JmsItemProvider extends AbstractItemProvider implements FailedItemI
|
||||
* Send the message back to the proovider using the specified error
|
||||
* destination property of this provider.
|
||||
*
|
||||
* @see org.springframework.batch.item.provider.AbstractItemProvider#recover(java.lang.Object,
|
||||
* @see org.springframework.batch.item.provider.AbstractItemReader#recover(java.lang.Object,
|
||||
* Throwable)
|
||||
*/
|
||||
public boolean recover(Object item, Throwable cause) {
|
||||
@@ -137,7 +137,7 @@ public class JmsItemProvider extends AbstractItemProvider implements FailedItemI
|
||||
* If the message is a {@link Message} then returns the JMS message ID.
|
||||
* Otherwise just delegate to parent class.
|
||||
*
|
||||
* @see org.springframework.batch.item.provider.AbstractItemProvider#getKey(java.lang.Object)
|
||||
* @see org.springframework.batch.item.provider.AbstractItemReader#getKey(java.lang.Object)
|
||||
*
|
||||
* @throws UnexpectedInputException if the JMS id cannot be determined from
|
||||
* a JMS Message
|
||||
@@ -20,19 +20,19 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* An {@link ItemProvider} that pulls data from a list. Useful for testing.
|
||||
* An {@link ItemReader} that pulls data from a list. Useful for testing.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ListItemProvider extends AbstractItemProvider {
|
||||
public class ListItemReader extends AbstractItemReader {
|
||||
|
||||
private List list;
|
||||
|
||||
public ListItemProvider(List list) {
|
||||
public ListItemReader(List list) {
|
||||
// If it is a proxy we assume it knows how to deal with its own state.
|
||||
// (It's probably transaction aware.)
|
||||
if (AopUtils.isAopProxy(list)) {
|
||||
@@ -43,7 +43,7 @@ public class ListItemProvider extends AbstractItemProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
public Object read() {
|
||||
if (!list.isEmpty()) {
|
||||
return list.remove(0);
|
||||
}
|
||||
@@ -19,18 +19,18 @@ import org.springframework.batch.item.validator.Validator;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple extension of InputsourceItemProvider that provides for
|
||||
* Simple extension of {@link DelegatingItemReader} that provides for
|
||||
* validation before returning input.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class ValidatingItemProvider extends InputSourceItemProvider {
|
||||
public class ValidatingItemReader extends DelegatingItemReader {
|
||||
|
||||
private Validator validator;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.provider.InputSourceItemProvider#afterPropertiesSet()
|
||||
* @see org.springframework.batch.item.provider.ItemReaderItemProvider#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.afterPropertiesSet();
|
||||
@@ -38,10 +38,10 @@ public class ValidatingItemProvider extends InputSourceItemProvider {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.provider.InputSourceItemProvider#next()
|
||||
* @see org.springframework.batch.item.provider.ItemReaderItemProvider#next()
|
||||
*/
|
||||
public Object next() {
|
||||
Object input = super.next();
|
||||
public Object read() throws Exception {
|
||||
Object input = super.read();
|
||||
if(input != null){
|
||||
validator.validate(input);
|
||||
}
|
||||
@@ -18,9 +18,8 @@ package org.springframework.batch.repeat;
|
||||
|
||||
/**
|
||||
* Callback interface for batch operations. Many simple batch processes will be
|
||||
* able to use off-the-shelf implementations of this interface, e.g.
|
||||
* {@link org.springframework.batch.repeat.callback.ItemProviderRepeatCallback},
|
||||
* enabling the batch developer to concentrate on business logic.
|
||||
* able to use off-the-shelf implementations of this interface, enabling the
|
||||
* batch developer to concentrate on business logic.
|
||||
*
|
||||
* @see RepeatOperations
|
||||
*
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.batch.repeat.callback;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
@@ -29,13 +29,13 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ItemProviderRepeatCallback implements RepeatCallback {
|
||||
public class ItemReaderRepeatCallback implements RepeatCallback {
|
||||
|
||||
ItemProvider provider;
|
||||
ItemReader provider;
|
||||
|
||||
ItemProcessor processor;
|
||||
|
||||
public ItemProviderRepeatCallback(ItemProvider provider, ItemProcessor processor) {
|
||||
public ItemReaderRepeatCallback(ItemReader provider, ItemProcessor processor) {
|
||||
super();
|
||||
this.provider = provider;
|
||||
this.processor = processor;
|
||||
@@ -47,7 +47,7 @@ public class ItemProviderRepeatCallback implements RepeatCallback {
|
||||
* provider by calling next().
|
||||
* @param provider
|
||||
*/
|
||||
public ItemProviderRepeatCallback(ItemProvider provider) {
|
||||
public ItemReaderRepeatCallback(ItemReader provider) {
|
||||
this(provider, null);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ItemProviderRepeatCallback implements RepeatCallback {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
|
||||
ExitStatus result = ExitStatus.FINISHED;
|
||||
Object item = provider.next();
|
||||
Object item = provider.read();
|
||||
|
||||
if (processor != null) {
|
||||
if (item != null) {
|
||||
@@ -19,41 +19,41 @@ package org.springframework.batch.retry.callback;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.exception.ExhaustedRetryException;
|
||||
import org.springframework.batch.retry.exception.RetryException;
|
||||
import org.springframework.batch.retry.policy.ItemProviderRetryPolicy;
|
||||
import org.springframework.batch.retry.policy.ItemReaderRetryPolicy;
|
||||
|
||||
/**
|
||||
* A {@link RetryCallback} that knows about and caches the value from an
|
||||
* {@link ItemProvider}. Used by the {@link ItemProviderRetryPolicy} to enable
|
||||
* {@link ItemReader}. Used by the {@link ItemReaderRetryPolicy} to enable
|
||||
* external retry of the item processing.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @see ItemProviderRetryPolicy
|
||||
* @see ItemReaderRetryPolicy
|
||||
* @see RetryPolicy#handleRetryExhausted(RetryContext)
|
||||
*
|
||||
*/
|
||||
public class ItemProviderRetryCallback implements RetryCallback {
|
||||
public class ItemReaderRetryCallback implements RetryCallback {
|
||||
|
||||
private final static Log logger = LogFactory
|
||||
.getLog(ItemProviderRetryCallback.class);
|
||||
.getLog(ItemReaderRetryCallback.class);
|
||||
|
||||
public static final String ITEM = ItemProviderRetryCallback.class.getName()
|
||||
public static final String ITEM = ItemReaderRetryCallback.class.getName()
|
||||
+ ".ITEM";
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private ItemProcessor processor;
|
||||
|
||||
private ItemRecoverer recoverer;
|
||||
|
||||
public ItemProviderRetryCallback(ItemProvider provider,
|
||||
public ItemReaderRetryCallback(ItemReader provider,
|
||||
ItemProcessor processor) {
|
||||
super();
|
||||
this.provider = provider;
|
||||
@@ -81,7 +81,7 @@ public class ItemProviderRetryCallback implements RetryCallback {
|
||||
Object item = context.getAttribute(ITEM);
|
||||
if (item == null) {
|
||||
try {
|
||||
item = provider.next();
|
||||
item = provider.read();
|
||||
} catch (Exception e) {
|
||||
throw new ExhaustedRetryException(
|
||||
"Unexpected end of item provider", e);
|
||||
@@ -107,7 +107,7 @@ public class ItemProviderRetryCallback implements RetryCallback {
|
||||
|
||||
/**
|
||||
* Accessor for the {@link ItemRecoverer}. If the handler is null but
|
||||
* the {@link ItemProvider} is an instanceof {@link ItemRecoverer},
|
||||
* the {@link ItemReader} is an instanceof {@link ItemRecoverer},
|
||||
* then it will be returned instead.
|
||||
*
|
||||
* @return the {@link ItemRecoverer}.
|
||||
@@ -123,11 +123,11 @@ public class ItemProviderRetryCallback implements RetryCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Public getter for the {@link ItemProvider}.
|
||||
* Public getter for the {@link ItemReader}.
|
||||
*
|
||||
* @return the {@link ItemProvider} instance.
|
||||
* @return the {@link ItemReader} instance.
|
||||
*/
|
||||
public ItemProvider getProvider() {
|
||||
public ItemReader getProvider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
@@ -19,33 +19,33 @@ package org.springframework.batch.retry.policy;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.item.FailedItemIdentifier;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.exception.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.synch.RetrySynchronizationManager;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A {@link RetryPolicy} that detects an {@link ItemProviderRetryCallback} when
|
||||
* A {@link RetryPolicy} that detects an {@link ItemReaderRetryCallback} when
|
||||
* it opens a new context, and uses it to make sure the item is in place for
|
||||
* later decisions about how to retry or backoff. The callback should be an
|
||||
* instance of {@link ItemProviderRetryCallback} otherwise an exception will be
|
||||
* instance of {@link ItemReaderRetryCallback} otherwise an exception will be
|
||||
* thrown when the context is created.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
public class ItemReaderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
public static final String EXHAUSTED = ItemProviderRetryPolicy.class
|
||||
public static final String EXHAUSTED = ItemReaderRetryPolicy.class
|
||||
.getName()
|
||||
+ ".EXHAUSTED";
|
||||
|
||||
@@ -56,7 +56,7 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
*
|
||||
* @param delegate
|
||||
*/
|
||||
public ItemProviderRetryPolicy(RetryPolicy delegate) {
|
||||
public ItemReaderRetryPolicy(RetryPolicy delegate) {
|
||||
super();
|
||||
this.delegate = delegate;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
* Default constructor. Creates a new {@link SimpleRetryPolicy} for the
|
||||
* delegate.
|
||||
*/
|
||||
public ItemProviderRetryPolicy() {
|
||||
public ItemReaderRetryPolicy() {
|
||||
this(new SimpleRetryPolicy());
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
|
||||
/**
|
||||
* Create a new context for the execution of the callback, which must be an
|
||||
* instance of {@link ItemProviderRetryCallback}.
|
||||
* instance of {@link ItemReaderRetryCallback}.
|
||||
*
|
||||
* @see org.springframework.batch.retry.RetryPolicy#open(org.springframework.batch.retry.RetryCallback)
|
||||
*
|
||||
@@ -107,10 +107,10 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
* if the callback is not of the required type.
|
||||
*/
|
||||
public RetryContext open(RetryCallback callback) {
|
||||
Assert.state(callback instanceof ItemProviderRetryCallback,
|
||||
Assert.state(callback instanceof ItemReaderRetryCallback,
|
||||
"Callback must be ItemProviderRetryCallback");
|
||||
ItemProviderRetryContext context = new ItemProviderRetryContext(
|
||||
(ItemProviderRetryCallback) callback);
|
||||
(ItemReaderRetryCallback) callback);
|
||||
context.open(callback);
|
||||
return context;
|
||||
}
|
||||
@@ -145,11 +145,11 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
// The delegate context...
|
||||
private RetryContext delegateContext;
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private ItemRecoverer recoverer;
|
||||
|
||||
public ItemProviderRetryContext(ItemProviderRetryCallback callback) {
|
||||
public ItemProviderRetryContext(ItemReaderRetryCallback callback) {
|
||||
super(RetrySynchronizationManager.getContext());
|
||||
item = callback.next(this);
|
||||
this.provider = callback.getProvider();
|
||||
@@ -243,7 +243,7 @@ public class ItemProviderRetryPolicy extends AbstractStatefulRetryPolicy {
|
||||
* @param item
|
||||
* @return
|
||||
*/
|
||||
protected boolean hasFailed(ItemProvider provider, Object item) {
|
||||
protected boolean hasFailed(ItemReader provider, Object item) {
|
||||
if (provider instanceof FailedItemIdentifier) {
|
||||
return ((FailedItemIdentifier) provider).hasFailed(item);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import org.springframework.util.MethodInvoker;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class AbstractDelegator implements InitializingBean {
|
||||
public class AbstractMethodInvokingDelegator implements InitializingBean {
|
||||
|
||||
private Object targetObject;
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorInputSource} using standard hibernate {@link Session}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorInputSourceStatefulIntegrationTests extends HibernateCursorInputSourceIntegrationTests {
|
||||
|
||||
protected boolean isUseStatelessSession() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,20 +2,20 @@ package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorInputSource} using {@link StatelessSession}.
|
||||
* Tests for {@link HibernateCursorItemReader} using {@link StatelessSession}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class HibernateCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
|
||||
factoryBean.setDataSource(super.getJdbcTemplate().getDataSource());
|
||||
factoryBean.setMappingLocations(new Resource[] { new ClassPathResource("Foo.hbm.xml", getClass()) });
|
||||
@@ -25,7 +25,7 @@ public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSour
|
||||
|
||||
String hsqlQuery = "from Foo";
|
||||
|
||||
HibernateCursorInputSource inputSource = new HibernateCursorInputSource();
|
||||
HibernateCursorItemReader inputSource = new HibernateCursorItemReader();
|
||||
inputSource.setQueryString(hsqlQuery);
|
||||
inputSource.setSessionFactory(sessionFactory);
|
||||
inputSource.setUseStatelessSession(isUseStatelessSession());
|
||||
@@ -41,11 +41,11 @@ public class HibernateCursorInputSourceIntegrationTests extends AbstractDataSour
|
||||
/**
|
||||
* Exception scenario.
|
||||
*
|
||||
* {@link HibernateCursorInputSource#setUseStatelessSession(boolean)} can be
|
||||
* {@link HibernateCursorItemReader#setUseStatelessSession(boolean)} can be
|
||||
* called only in uninitialized state.
|
||||
*/
|
||||
public void testSetUseStatelessSession() {
|
||||
HibernateCursorInputSource inputSource = ((HibernateCursorInputSource) source);
|
||||
HibernateCursorItemReader inputSource = ((HibernateCursorItemReader) source);
|
||||
|
||||
// initialize and call setter => error
|
||||
inputSource.open();
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorItemReader} using standard hibernate {@link Session}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorItemReaderStatefulIntegrationTests extends HibernateCursorItemReaderIntegrationTests {
|
||||
|
||||
protected boolean isUseStatelessSession() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
package org.springframework.batch.io.cursor;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.FooRowMapper;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* Tests for {@link JdbcCursorInputSource}
|
||||
* Tests for {@link JdbcCursorItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcCursorInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class JdbcCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
JdbcCursorInputSource result = new JdbcCursorInputSource();
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
JdbcCursorItemReader result = new JdbcCursorItemReader();
|
||||
result.setDataSource(super.getJdbcTemplate().getDataSource());
|
||||
result.setSql("select ID, NAME, VALUE from T_FOOS");
|
||||
result.setIgnoreWarnings(true);
|
||||
@@ -6,8 +6,8 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -17,9 +17,9 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class DrivingQueryInputSourceTests extends TestCase {
|
||||
public class DrivingQueryItemReaderTests extends TestCase {
|
||||
|
||||
InputSource source;
|
||||
ItemReader source;
|
||||
|
||||
static {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
@@ -28,12 +28,12 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
}
|
||||
|
||||
private InputSource createInputSource() throws Exception{
|
||||
private ItemReader createItemReader() throws Exception{
|
||||
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(new MockKeyGenerator());
|
||||
|
||||
return inputSource;
|
||||
@@ -79,7 +79,7 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -117,8 +117,9 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -129,8 +130,9 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Rollback scenario.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -159,11 +161,11 @@ public class DrivingQueryInputSourceTests extends TestCase {
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
class FooInputSource implements InputSource, Restartable, DisposableBean, InitializingBean{
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, Restartable, DisposableBean, InitializingBean{
|
||||
|
||||
DrivingQueryInputSource inputSource;
|
||||
DrivingQueryItemReader inputSource;
|
||||
FooDao fooDao = new SingleKeyFooDao();
|
||||
|
||||
public FooInputSource(DrivingQueryInputSource inputSource, JdbcTemplate jdbcTemplate) {
|
||||
public FooItemReader(DrivingQueryItemReader inputSource, JdbcTemplate jdbcTemplate) {
|
||||
this.inputSource = inputSource;
|
||||
fooDao.setJdbcTemplate(jdbcTemplate);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.IbatisKeyGenerator;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.support.AbstractDataSourceItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
/**
|
||||
* Tests for {@link IbatisDrivingQueryInputSource}
|
||||
* Tests for {@link IbatisDrivingQueryItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class IbatisInputSourceIntegrationTests extends AbstractDataSourceInputSourceIntegrationTests {
|
||||
public class IbatisItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
SqlMapClientFactoryBean factory = new SqlMapClientFactoryBean();
|
||||
factory.setConfigLocation(new ClassPathResource("ibatis-config.xml", getClass()));
|
||||
@@ -23,7 +23,7 @@ public class IbatisInputSourceIntegrationTests extends AbstractDataSourceInputSo
|
||||
factory.afterPropertiesSet();
|
||||
SqlMapClient sqlMapClient = (SqlMapClient) factory.getObject();
|
||||
|
||||
IbatisDrivingQueryInputSource inputSource = new IbatisDrivingQueryInputSource();
|
||||
IbatisDrivingQueryItemReader inputSource = new IbatisDrivingQueryItemReader();
|
||||
IbatisKeyGenerator keyGenerator = new IbatisKeyGenerator();
|
||||
keyGenerator.setDrivingQueryId("getAllFooIds");
|
||||
inputSource.setDetailsQueryId("getFooById");
|
||||
@@ -15,29 +15,29 @@
|
||||
*/
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.MultipleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcInputSourceIntegrationTests;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class MultipleColumnJdbcDrivingQueryInputSourceIntegrationTests extends
|
||||
AbstractJdbcInputSourceIntegrationTests {
|
||||
public class MultipleColumnJdbcDrivingQueryItemReaderIntegrationTests extends
|
||||
AbstractJdbcItemReaderIntegrationTests {
|
||||
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
MultipleColumnJdbcKeyGenerator keyGenerator =
|
||||
new MultipleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID, VALUE from T_FOOS order by ID, VALUE");
|
||||
|
||||
keyGenerator.setRestartQuery("SELECT ID, VALUE from T_FOOS where ID > ? and VALUE > ? order by ID");
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(keyGenerator);
|
||||
FooInputSource fooInputSource = new FooInputSource(inputSource, getJdbcTemplate());
|
||||
fooInputSource.setFooDao(new CompositeKeyFooDao(getJdbcTemplate()));
|
||||
return fooInputSource;
|
||||
FooItemReader fooItemReader = new FooItemReader(inputSource, getJdbcTemplate());
|
||||
fooItemReader.setFooDao(new CompositeKeyFooDao(getJdbcTemplate()));
|
||||
return fooItemReader;
|
||||
}
|
||||
|
||||
// private static class FooRestartDataConverter implements RestartDataRowMapper{
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.driving.support.SingleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcInputSourceIntegrationTests;
|
||||
|
||||
public class SingleColumnJdbcDrivingQueryInputSourceIntegrationTests extends AbstractJdbcInputSourceIntegrationTests {
|
||||
|
||||
protected InputSource source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected InputSource createInputSource() throws Exception {
|
||||
|
||||
SingleColumnJdbcKeyGenerator keyStrategy = new SingleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID from T_FOOS order by ID");
|
||||
keyStrategy.setRestartSql("SELECT ID from T_FOOS where ID > ? order by ID");
|
||||
DrivingQueryInputSource inputSource = new DrivingQueryInputSource();
|
||||
inputSource.setKeyGenerator(keyStrategy);
|
||||
|
||||
return new FooInputSource(inputSource, getJdbcTemplate());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.io.driving.support.SingleColumnJdbcKeyGenerator;
|
||||
import org.springframework.batch.io.sql.AbstractJdbcItemReaderIntegrationTests;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
public class SingleColumnJdbcDrivingQueryItemReaderIntegrationTests extends AbstractJdbcItemReaderIntegrationTests {
|
||||
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected ItemReader createItemReader() throws Exception {
|
||||
|
||||
SingleColumnJdbcKeyGenerator keyStrategy = new SingleColumnJdbcKeyGenerator(getJdbcTemplate(),
|
||||
"SELECT ID from T_FOOS order by ID");
|
||||
keyStrategy.setRestartSql("SELECT ID from T_FOOS where ID > ? order by ID");
|
||||
DrivingQueryItemReader inputSource = new DrivingQueryItemReader();
|
||||
inputSource.setKeyGenerator(keyStrategy);
|
||||
|
||||
return new FooItemReader(inputSource, getJdbcTemplate());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileInputSource;
|
||||
import org.springframework.batch.io.file.support.DefaultFlatFileItemReader;
|
||||
import org.springframework.batch.io.file.support.transform.LineTokenizer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -30,17 +30,17 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
|
||||
/**
|
||||
* Tests for {@link DefaultFlatFileInputSource}
|
||||
* Tests for {@link DefaultFlatFileItemReader}
|
||||
*
|
||||
* @author robert.kasanicky
|
||||
*
|
||||
* TODO only regular reading is tested currently, add exception cases, restart,
|
||||
* skip, validation...
|
||||
*/
|
||||
public class DefaultFlatFileInputSourceTests extends TestCase {
|
||||
public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private DefaultFlatFileInputSource inputSource = new DefaultFlatFileInputSource();
|
||||
private DefaultFlatFileItemReader inputSource = new DefaultFlatFileItemReader();
|
||||
|
||||
// common value used for writing to a file
|
||||
private String TEST_STRING = "FlatFileInputTemplate-TestData";
|
||||
@@ -156,7 +156,7 @@ public class DefaultFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRestartWithNullReader() throws Exception {
|
||||
inputSource = new DefaultFlatFileInputSource();
|
||||
inputSource = new DefaultFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
// do not open the template...
|
||||
@@ -34,15 +34,15 @@ import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Tests for {@link SimpleFlatFileInputSourceTests}
|
||||
* Tests for {@link SimpleFlatFileItemReaderTests}
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public class SimpleFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private SimpleFlatFileInputSource inputSource = new SimpleFlatFileInputSource();
|
||||
private SimpleFlatFileItemReader inputSource = new SimpleFlatFileItemReader();
|
||||
|
||||
// common value used for writing to a file
|
||||
private String TEST_STRING = "FlatFileInputTemplate-TestData";
|
||||
@@ -135,14 +135,14 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testReadBeforeOpen() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
|
||||
}
|
||||
|
||||
public void testCloseBeforeOpen() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
inputSource.close();
|
||||
@@ -152,7 +152,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
|
||||
public void testCloseOnDestroy() throws Exception {
|
||||
final List list = new ArrayList();
|
||||
inputSource = new SimpleFlatFileInputSource() {
|
||||
inputSource = new SimpleFlatFileItemReader() {
|
||||
public void close() {
|
||||
list.add("close");
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testInitializationWithNullResource() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
try {
|
||||
inputSource.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
@@ -178,7 +178,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetValidEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding("UTF-8");
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -186,7 +186,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetNullEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding(null);
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
try {
|
||||
@@ -199,7 +199,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testSetInvalidEncoding() throws Exception {
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setEncoding("foo");
|
||||
inputSource.setResource(getInputResource(TEST_STRING));
|
||||
try {
|
||||
@@ -229,7 +229,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testInvalidFile() throws IOException {
|
||||
DefaultFlatFileInputSource ffit = new DefaultFlatFileInputSource();
|
||||
DefaultFlatFileItemReader ffit = new DefaultFlatFileItemReader();
|
||||
|
||||
FileSystemResource resource = new FileSystemResource("FooDummy.txt");
|
||||
assertTrue(!resource.exists());
|
||||
@@ -251,7 +251,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public void testColumnNamesInHeader() throws Exception {
|
||||
final String INPUT = "name1|name2\nvalue1|value2\nvalue3|value4";
|
||||
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(INPUT));
|
||||
inputSource.setTokenizer(new DelimitedLineTokenizer('|'));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -274,7 +274,7 @@ public class SimpleFlatFileInputSourceTests extends TestCase {
|
||||
public void testLinesToSkip() throws Exception {
|
||||
final String INPUT = "foo bar spam\none two\nthree four";
|
||||
|
||||
inputSource = new SimpleFlatFileInputSource();
|
||||
inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(getInputResource(INPUT));
|
||||
inputSource.setTokenizer(new DelimitedLineTokenizer(' '));
|
||||
inputSource.setFieldSetMapper(fieldSetMapper);
|
||||
@@ -15,7 +15,7 @@ import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderInputSource;
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderItemReader;
|
||||
import org.springframework.batch.io.file.support.stax.FragmentDeserializer;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -26,14 +26,14 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
|
||||
/**
|
||||
* Tests for {@link StaxEventReaderInputSource}.
|
||||
* Tests for {@link StaxEventReaderItemReader}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private StaxEventReaderInputSource source;
|
||||
private StaxEventReaderItemReader source;
|
||||
|
||||
// test xml input
|
||||
private String xml = "<root> <fragment> <misc1/> </fragment> <misc2/> <fragment> testString </fragment> </root>";
|
||||
@@ -83,7 +83,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
* InputSource should pass XML fragments to deserializer wrapped with
|
||||
* ItemReader should pass XML fragments to deserializer wrapped with
|
||||
* StartDocument and EndDocument events.
|
||||
*/
|
||||
public void testFragmentWrapping() throws Exception {
|
||||
@@ -120,7 +120,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
source.read();
|
||||
RestartData restartData = source.getRestartData();
|
||||
assertEquals("1", restartData.getProperties().
|
||||
getProperty("StaxEventReaderInputSource.recordcount"));
|
||||
getProperty("StaxEventReaderItemReader.recordcount"));
|
||||
List expectedAfterRestart = (List) source.read();
|
||||
|
||||
source = createNewInputSouce();
|
||||
@@ -136,7 +136,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
public void testInvalidRestore() {
|
||||
Properties props = new Properties() {{
|
||||
final String MORE_RECORDS_THAN_INPUT_CONTAINS = "100000";
|
||||
setProperty("StaxEventReaderInputSource.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
setProperty("StaxEventReaderItemReader.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
}};
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(props));
|
||||
@@ -219,7 +219,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
public void testClose() throws Exception{
|
||||
|
||||
MockStaxEventReaderInputSource newSource = new MockStaxEventReaderInputSource();
|
||||
MockStaxEventReaderItemReader newSource = new MockStaxEventReaderItemReader();
|
||||
Resource resource = new ByteArrayResource(xml.getBytes());
|
||||
newSource.setResource(resource);
|
||||
|
||||
@@ -258,13 +258,13 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
private int extractRecordCountFrom(Properties statistics) {
|
||||
return Integer.valueOf(
|
||||
source.getStatistics().getProperty(StaxEventReaderInputSource.READ_COUNT_STATISTICS_NAME)).intValue();
|
||||
source.getStatistics().getProperty(StaxEventReaderItemReader.READ_COUNT_STATISTICS_NAME)).intValue();
|
||||
}
|
||||
|
||||
private StaxEventReaderInputSource createNewInputSouce() {
|
||||
private StaxEventReaderItemReader createNewInputSouce() {
|
||||
Resource resource = new ByteArrayResource(xml.getBytes());
|
||||
|
||||
StaxEventReaderInputSource newSource = new StaxEventReaderInputSource();
|
||||
StaxEventReaderItemReader newSource = new StaxEventReaderItemReader();
|
||||
newSource.setResource(resource);
|
||||
|
||||
newSource.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT);
|
||||
@@ -282,7 +282,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
/**
|
||||
* A simple mapFragment implementation checking the
|
||||
* StaxEventReaderInputSource basic read functionality.
|
||||
* StaxEventReaderItemReader basic read functionality.
|
||||
* @param eventReader
|
||||
* @return list of the events from fragment body
|
||||
*/
|
||||
@@ -349,7 +349,7 @@ public class StaxEventReaderInputSourceTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private static class MockStaxEventReaderInputSource extends StaxEventReaderInputSource {
|
||||
private static class MockStaxEventReaderItemReader extends StaxEventReaderItemReader {
|
||||
|
||||
private boolean openCalled = false;
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.springframework.batch.io.sql;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -17,20 +17,20 @@ import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Common scenarios for testing {@link InputSource} implementations which read data from database.
|
||||
* Common scenarios for testing {@link ItemReader} implementations which read data from database.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected InputSource source;
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return input source with all necessary dependencies set
|
||||
*/
|
||||
protected abstract InputSource createInputSource() throws Exception;
|
||||
protected abstract ItemReader createItemReader() throws Exception;
|
||||
|
||||
protected String[] getConfigLocations(){
|
||||
return new String[] { "org/springframework/batch/io/sql/data-source-context.xml"};
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
protected void onSetUp()throws Exception{
|
||||
super.onSetUp();
|
||||
BatchTransactionSynchronizationManager.clearSynchronizations();
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
getAsInitializingBean(source).afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -110,7 +110,7 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -126,8 +126,9 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -138,8 +139,9 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
|
||||
/**
|
||||
* Rollback scenario.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -168,15 +170,15 @@ public abstract class AbstractJdbcInputSourceIntegrationTests extends AbstractTr
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private DisposableBean getAsDisposableBean(InputSource source) {
|
||||
private DisposableBean getAsDisposableBean(ItemReader source) {
|
||||
return (DisposableBean) source;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package org.springframework.batch.io.support;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -18,20 +18,20 @@ import org.springframework.transaction.support.TransactionSynchronizationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Common scenarios for testing {@link InputSource} implementations which read data from database.
|
||||
* Common scenarios for testing {@link ItemReader} implementations which read data from database.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public abstract class AbstractDataSourceInputSourceIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
public abstract class AbstractDataSourceItemReaderIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
|
||||
protected InputSource source;
|
||||
protected ItemReader source;
|
||||
|
||||
|
||||
/**
|
||||
* @return configured input source ready for use
|
||||
*/
|
||||
protected abstract InputSource createInputSource() throws Exception;
|
||||
protected abstract ItemReader createItemReader() throws Exception;
|
||||
|
||||
protected String[] getConfigLocations(){
|
||||
return new String[] { "org/springframework/batch/io/sql/data-source-context.xml"};
|
||||
@@ -43,7 +43,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
protected void onSetUpInTransaction() throws Exception {
|
||||
super.onSetUpInTransaction();
|
||||
BatchTransactionSynchronizationManager.clearSynchronizations();
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -95,7 +95,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -133,8 +133,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Empty restart data should be handled gracefully.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() {
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
@@ -145,8 +146,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Rollback scenario - input source rollbacks to last commit point.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollback() {
|
||||
public void testRollback() throws Exception {
|
||||
Foo foo1 = (Foo) source.read();
|
||||
|
||||
commit();
|
||||
@@ -164,8 +166,9 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
|
||||
/**
|
||||
* Rollback scenario with skip - input source rollbacks to last commit point.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRollbackAndSkip() {
|
||||
public void testRollbackAndSkip() throws Exception {
|
||||
|
||||
if (!(source instanceof Skippable)) {
|
||||
return;
|
||||
@@ -217,7 +220,7 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createInputSource();
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
|
||||
@@ -238,19 +241,19 @@ public abstract class AbstractDataSourceInputSourceIntegrationTests extends Abst
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Skippable getAsSkippable(InputSource source) {
|
||||
private Skippable getAsSkippable(ItemReader source) {
|
||||
return (Skippable) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(InputSource source) {
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(InputSource source) {
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private DisposableBean getAsDisposableBean(InputSource source) {
|
||||
private DisposableBean getAsDisposableBean(ItemReader source) {
|
||||
return (DisposableBean) source;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
}
|
||||
|
||||
//AbstractInputSource should synchronize on first call to read.
|
||||
//AbstractItemReader should synchronize on first call to read.
|
||||
public void testSynchronizationRegistration(){
|
||||
|
||||
source.registerSynchronization();
|
||||
@@ -97,7 +97,7 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
assertFalse(source.rollbackCalled);
|
||||
}
|
||||
|
||||
private static class MockIoSource extends AbstractTransactionalIoSource{
|
||||
private static class MockIoSource extends AbstractTransactionalIoSource {
|
||||
|
||||
private boolean commitCalled = false;
|
||||
private boolean rollbackCalled = false;
|
||||
@@ -110,7 +110,11 @@ public class AbstractTransactionalIoSourceTests extends TestCase {
|
||||
protected void transactionRolledBack() {
|
||||
Assert.isTrue(!rollbackCalled, "Rollback aleady called");
|
||||
rollbackCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Object read() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
|
||||
@@ -18,18 +18,18 @@ package org.springframework.batch.item;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
|
||||
public class ItemProviderTests extends TestCase {
|
||||
|
||||
ItemProvider provider = new AbstractItemProvider() {
|
||||
public Object next() {
|
||||
ItemReader provider = new AbstractItemReader() {
|
||||
public Object read() {
|
||||
return "foo";
|
||||
}
|
||||
};
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingItemProcessor}.
|
||||
* Tests for {@link ItemProcessorAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProcessorIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private DelegatingItemProcessor processor;
|
||||
private ItemProcessorAdapter processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DelegatingItemProcessorIntegrationTests extends AbstractDependencyI
|
||||
}
|
||||
|
||||
//setter for auto-injection
|
||||
public void setProcessor(DelegatingItemProcessor processor) {
|
||||
public void setProcessor(ItemProcessorAdapter processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,27 +6,27 @@ import java.util.Iterator;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
public class AggregateItemProviderTests extends TestCase {
|
||||
public class AggregateItemReaderTests extends TestCase {
|
||||
|
||||
private MockControl inputControl;
|
||||
private InputSource input;
|
||||
private AggregateItemProvider provider;
|
||||
private ItemReader input;
|
||||
private AggregateItemReader provider;
|
||||
|
||||
public void setUp() {
|
||||
|
||||
//create mock for input
|
||||
inputControl = MockControl.createControl(InputSource.class);
|
||||
input = (InputSource) inputControl.getMock();
|
||||
inputControl = MockControl.createControl(ItemReader.class);
|
||||
input = (ItemReader) inputControl.getMock();
|
||||
|
||||
//create provider
|
||||
provider = new AggregateItemProvider();
|
||||
provider.setInputSource(input);
|
||||
provider = new AggregateItemReader();
|
||||
provider.setItemReader(input);
|
||||
}
|
||||
|
||||
public void testNext() {
|
||||
public void testNext() throws Exception {
|
||||
|
||||
//set-up mock input
|
||||
input.read();
|
||||
@@ -40,7 +40,7 @@ public class AggregateItemProviderTests extends TestCase {
|
||||
inputControl.replay();
|
||||
|
||||
//read object
|
||||
Object result = provider.next();
|
||||
Object result = provider.read();
|
||||
|
||||
//it should be collection of 3 strings "line"
|
||||
assertTrue(result instanceof Collection);
|
||||
@@ -52,7 +52,7 @@ public class AggregateItemProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
//read object again - it should return null
|
||||
assertNull(provider.next());
|
||||
assertNull(provider.read());
|
||||
|
||||
//verify method calls
|
||||
inputControl.verify();
|
||||
@@ -7,13 +7,13 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingItemProvider}.
|
||||
* Tests for {@link ItemReaderAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemProviderIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public class DelegatingItemReaderIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private DelegatingItemProvider provider;
|
||||
private ItemReaderAdapter provider;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class DelegatingItemProviderIntegrationTests extends AbstractDependencyIn
|
||||
public void testNext() throws Exception {
|
||||
List returnedItems = new ArrayList();
|
||||
Object item;
|
||||
while ((item = provider.next()) != null) {
|
||||
while ((item = provider.read()) != null) {
|
||||
returnedItems.add(item);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class DelegatingItemProviderIntegrationTests extends AbstractDependencyIn
|
||||
assertFalse(provider.recover(null, null));
|
||||
}
|
||||
|
||||
public void setProvider(DelegatingItemProvider provider) {
|
||||
public void setProvider(ItemReaderAdapter provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -29,21 +29,21 @@ import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* Unit test for {@link InputSourceItemProvider}
|
||||
* Unit test for {@link DelegatingItemReader}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class InputSourceItemProviderTests extends TestCase {
|
||||
public class DelegatingItemReaderTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private InputSourceItemProvider itemProvider = new InputSourceItemProvider();
|
||||
private DelegatingItemReader itemProvider = new DelegatingItemReader();
|
||||
|
||||
private InputSource source;
|
||||
private ItemReader source;
|
||||
|
||||
// create input template and inject it to data provider
|
||||
protected void setUp() throws Exception {
|
||||
source = new MockInputSource(this);
|
||||
itemProvider.setInputSource(source);
|
||||
source = new MockItemReader(this);
|
||||
itemProvider.setItemReader(source);
|
||||
}
|
||||
|
||||
public void testAfterPropertiesSet()throws Exception{
|
||||
@@ -51,9 +51,9 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
itemProvider.afterPropertiesSet();
|
||||
}
|
||||
|
||||
public void testNullInputSource(){
|
||||
public void testNullItemReader(){
|
||||
try{
|
||||
itemProvider.setInputSource(null);
|
||||
itemProvider.setItemReader(null);
|
||||
itemProvider.afterPropertiesSet();
|
||||
fail();
|
||||
}catch(Exception ex){
|
||||
@@ -63,9 +63,10 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Uses input template to provide the domain object.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testNext() {
|
||||
Object result = itemProvider.next();
|
||||
public void testNext() throws Exception {
|
||||
Object result = itemProvider.read();
|
||||
assertSame("domain object is provided by the input template", this, result);
|
||||
}
|
||||
|
||||
@@ -87,18 +88,19 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Forwared restart data to input template
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() {
|
||||
public void testRestoreFrom() throws Exception {
|
||||
itemProvider.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
assertEquals("bar", itemProvider.next());
|
||||
assertEquals("bar", itemProvider.read());
|
||||
}
|
||||
|
||||
public void testSkip() {
|
||||
public void testSkip() throws Exception {
|
||||
itemProvider.skip();
|
||||
assertEquals("after skip", itemProvider.next());
|
||||
assertEquals("after skip", itemProvider.read());
|
||||
}
|
||||
|
||||
private static class MockInputSource implements InputSource, StatisticsProvider, Restartable, Skippable {
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, Restartable, Skippable {
|
||||
|
||||
private Object value;
|
||||
|
||||
@@ -114,7 +116,7 @@ public class InputSourceItemProviderTests extends TestCase {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
public MockInputSource(Object value) {
|
||||
public MockItemReader(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.jms.core.JmsOperations;
|
||||
|
||||
public class JmsItemProviderTests extends TestCase {
|
||||
public class JmsItemReaderTests extends TestCase {
|
||||
|
||||
JmsItemProvider itemProvider = new JmsItemProvider();
|
||||
JmsItemReader itemProvider = new JmsItemReader();
|
||||
|
||||
public void testNoItemTypeSunnyDay() {
|
||||
MockControl templateControl = MockControl.createControl(JmsOperations.class);
|
||||
@@ -38,7 +38,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
templateControl.replay();
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
assertEquals("foo", itemProvider.next());
|
||||
assertEquals("foo", itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(String.class);
|
||||
assertEquals("foo", itemProvider.next());
|
||||
assertEquals("foo", itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Date.class);
|
||||
assertEquals(date, itemProvider.next());
|
||||
assertEquals(date, itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Date.class);
|
||||
try {
|
||||
itemProvider.next();
|
||||
itemProvider.read();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -97,7 +97,7 @@ public class JmsItemProviderTests extends TestCase {
|
||||
|
||||
itemProvider.setJmsTemplate(jmsTemplate);
|
||||
itemProvider.setItemType(Message.class);
|
||||
assertEquals(message, itemProvider.next());
|
||||
assertEquals(message, itemProvider.read());
|
||||
templateControl.verify();
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ListItemProviderTests extends TestCase {
|
||||
public class ListItemReaderTests extends TestCase {
|
||||
|
||||
ListItemProvider provider = new ListItemProvider(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
ListItemReader provider = new ListItemReader(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("a", provider.next());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("c", provider.next());
|
||||
assertEquals(null, provider.next());
|
||||
assertEquals("a", provider.read());
|
||||
assertEquals("b", provider.read());
|
||||
assertEquals("c", provider.read());
|
||||
assertEquals(null, provider.read());
|
||||
}
|
||||
|
||||
public void testChangeList() throws Exception {
|
||||
List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" }));
|
||||
provider = new ListItemProvider(list);
|
||||
assertEquals("a", provider.next());
|
||||
provider = new ListItemReader(list);
|
||||
assertEquals("a", provider.read());
|
||||
list.clear();
|
||||
assertEquals(0, list.size());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("b", provider.read());
|
||||
}
|
||||
}
|
||||
@@ -29,25 +29,25 @@ import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
public class TransactionAwareListItemReaderTests extends TestCase {
|
||||
|
||||
// TransactionAwareListItemProvider provider = new
|
||||
// TransactionAwareListItemProvider(Arrays.asList(new String[] { "a",
|
||||
// "b", "c" }));
|
||||
ListItemProvider provider;
|
||||
ListItemReader provider;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
TransactionAwareProxyFactory factory = new TransactionAwareProxyFactory(Arrays.asList(new String[] { "a", "b",
|
||||
"c" }));
|
||||
provider = new ListItemProvider((List) factory.createInstance());
|
||||
provider = new ListItemReader((List) factory.createInstance());
|
||||
}
|
||||
|
||||
public void testNext() throws Exception {
|
||||
assertEquals("a", provider.next());
|
||||
assertEquals("b", provider.next());
|
||||
assertEquals("c", provider.next());
|
||||
assertEquals(null, provider.next());
|
||||
assertEquals("a", provider.read());
|
||||
assertEquals("b", provider.read());
|
||||
assertEquals("c", provider.read());
|
||||
assertEquals(null, provider.read());
|
||||
}
|
||||
|
||||
public void testCommit() throws Exception {
|
||||
@@ -56,7 +56,7 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
taken.add(provider.next());
|
||||
taken.add(provider.read());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -68,10 +68,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
assertEquals(1, taken.size());
|
||||
assertEquals("a", taken.get(0));
|
||||
taken.clear();
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
// System.err.println(taken);
|
||||
assertFalse(taken.contains("a"));
|
||||
@@ -82,10 +82,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
final List taken = new ArrayList();
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(TransactionStatus status) {
|
||||
taken.add(provider.next());
|
||||
taken.add(provider.read());
|
||||
throw new RuntimeException("Rollback!");
|
||||
}
|
||||
});
|
||||
@@ -112,10 +112,10 @@ public class TransactionAwareListItemProviderTests extends TestCase {
|
||||
assertEquals(1, taken.size());
|
||||
assertEquals("a", taken.get(0));
|
||||
taken.clear();
|
||||
Object next = provider.next();
|
||||
Object next = provider.read();
|
||||
while (next != null) {
|
||||
taken.add(next);
|
||||
next = provider.next();
|
||||
next = provider.read();
|
||||
}
|
||||
System.err.println(taken);
|
||||
assertTrue(taken.contains("a"));
|
||||
@@ -18,18 +18,18 @@ package org.springframework.batch.item.provider;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.InputSource;
|
||||
import org.springframework.batch.io.exception.ValidationException;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.validator.Validator;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class ValidatingItemProviderTests extends TestCase {
|
||||
public class ValidatingItemReaderTests extends TestCase {
|
||||
|
||||
InputSource inputSource;
|
||||
ValidatingItemProvider itemProvider;
|
||||
ItemReader inputSource;
|
||||
ValidatingItemReader itemProvider;
|
||||
Validator validator;
|
||||
MockControl validatorControl = MockControl.createControl(Validator.class);
|
||||
|
||||
@@ -39,20 +39,20 @@ public class ValidatingItemProviderTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
inputSource = new MockInputSource(this);
|
||||
inputSource = new MockItemReader(this);
|
||||
validator = (Validator)validatorControl.getMock();
|
||||
itemProvider = new ValidatingItemProvider();
|
||||
itemProvider.setInputSource(inputSource);
|
||||
itemProvider = new ValidatingItemReader();
|
||||
itemProvider.setItemReader(inputSource);
|
||||
itemProvider.setValidator(validator);
|
||||
}
|
||||
|
||||
/*
|
||||
* Super class' afterPropertieSet should be called to
|
||||
* ensure InputSource is set.
|
||||
* ensure ItemReader is set.
|
||||
*/
|
||||
public void testInputSourcePropertiesSet(){
|
||||
public void testItemReaderPropertiesSet(){
|
||||
try{
|
||||
itemProvider.setInputSource(null);
|
||||
itemProvider.setItemReader(null);
|
||||
itemProvider.afterPropertiesSet();
|
||||
fail();
|
||||
}catch(Exception ex){
|
||||
@@ -70,40 +70,40 @@ public class ValidatingItemProviderTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testValidation(){
|
||||
public void testValidation() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.replay();
|
||||
assertEquals(itemProvider.next(), this);
|
||||
assertEquals(itemProvider.read(), this);
|
||||
validatorControl.verify();
|
||||
}
|
||||
|
||||
public void testValidationException(){
|
||||
public void testValidationException() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.setThrowable(new ValidationException(""));
|
||||
validatorControl.replay();
|
||||
try{
|
||||
itemProvider.next();
|
||||
itemProvider.read();
|
||||
fail();
|
||||
}catch(ValidationException ex){
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testNullInput(){
|
||||
public void testNullInput() throws Exception{
|
||||
validatorControl.replay();
|
||||
itemProvider.setInputSource(new MockInputSource(null));
|
||||
assertNull(itemProvider.next());
|
||||
itemProvider.setItemReader(new MockItemReader(null));
|
||||
assertNull(itemProvider.read());
|
||||
//assert validator wasn't called.
|
||||
validatorControl.verify();
|
||||
}
|
||||
|
||||
private static class MockInputSource implements InputSource{
|
||||
private static class MockItemReader extends AbstractItemReader {
|
||||
|
||||
Object value;
|
||||
|
||||
public MockInputSource(Object value){
|
||||
public MockItemReader(Object value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
|
||||
public class ItemProviderRepeatCallbackTests extends TestCase {
|
||||
public class ItemReaderRepeatCallbackTests extends TestCase {
|
||||
|
||||
ItemProviderRepeatCallback callback;
|
||||
ItemReaderRepeatCallback callback;
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
public void testDoWithRepeat() throws Exception {
|
||||
callback = new ItemProviderRepeatCallback(new ListItemProvider(Arrays.asList(new String[] { "foo", "bar" })),
|
||||
callback = new ItemReaderRepeatCallback(new ListItemReader(Arrays.asList(new String[] { "foo", "bar" })),
|
||||
new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
list.add(data);
|
||||
@@ -44,11 +44,11 @@ public class ItemProviderRepeatCallbackTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDoWithRepeatNullProcessor() throws Exception {
|
||||
ListItemProvider provider = new ListItemProvider(Arrays.asList(new String[] { "foo", "bar" }));
|
||||
callback = new ItemProviderRepeatCallback(provider);
|
||||
ListItemReader provider = new ListItemReader(Arrays.asList(new String[] { "foo", "bar" }));
|
||||
callback = new ItemReaderRepeatCallback(provider);
|
||||
callback.doInIteration(null);
|
||||
assertEquals(0, list.size());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FieldSet;
|
||||
import org.springframework.batch.io.file.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.support.SimpleFlatFileInputSource;
|
||||
import org.springframework.batch.io.file.support.SimpleFlatFileItemReader;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.InputSourceItemProvider;
|
||||
import org.springframework.batch.item.provider.DelegatingItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@@ -40,26 +40,26 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
|
||||
protected TradeProcessor processor = new TradeProcessor();
|
||||
|
||||
protected TradeItemProvider provider;
|
||||
protected TradeItemReader provider;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
provider = new TradeItemProvider(resource);
|
||||
provider = new TradeItemReader(resource);
|
||||
}
|
||||
|
||||
protected static class TradeItemProvider extends InputSourceItemProvider {
|
||||
protected static class TradeItemReader extends DelegatingItemReader {
|
||||
|
||||
protected TradeItemProvider(Resource resource) throws Exception {
|
||||
protected TradeItemReader(Resource resource) throws Exception {
|
||||
super();
|
||||
SimpleFlatFileInputSource inputSource = new SimpleFlatFileInputSource();
|
||||
SimpleFlatFileItemReader inputSource = new SimpleFlatFileItemReader();
|
||||
inputSource.setResource(resource);
|
||||
inputSource.setFieldSetMapper(new TradeMapper());
|
||||
inputSource.afterPropertiesSet();
|
||||
setInputSource(inputSource);
|
||||
setItemReader(inputSource);
|
||||
}
|
||||
|
||||
public synchronized Object next() {
|
||||
return super.next();
|
||||
public synchronized Object read() throws Exception {
|
||||
return super.read();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
|
||||
public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
@@ -41,7 +41,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final String threadName = Thread.currentThread().getName();
|
||||
final Set threadNames = new HashSet();
|
||||
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor) {
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
@@ -72,7 +72,7 @@ public class AsynchronousRepeatTests extends AbstractTradeBatchTests {
|
||||
final String threadName = Thread.currentThread().getName();
|
||||
final Set threadNames = new HashSet();
|
||||
|
||||
final RepeatCallback stepCallback = new ItemProviderRepeatCallback(provider, processor) {
|
||||
final RepeatCallback stepCallback = new ItemReaderRepeatCallback(provider, processor) {
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
assertNotSame(threadName, Thread.currentThread().getName());
|
||||
threadNames.add(Thread.currentThread().getName());
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.batch.repeat.support;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -46,7 +46,7 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
public void testChunkedBatchWithTerminationPolicy() throws Exception {
|
||||
|
||||
RepeatTemplate repeatTemplate = new RepeatTemplate();
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor);
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor);
|
||||
|
||||
final RepeatTemplate chunkTemplate = new RepeatTemplate();
|
||||
// The policy is resettable so we only have to resolve this dependency
|
||||
@@ -80,7 +80,7 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
public void testAsynchronousChunkedBatchWithCompletionPolicy() throws Exception {
|
||||
|
||||
RepeatTemplate repeatTemplate = new RepeatTemplate();
|
||||
final RepeatCallback callback = new ItemProviderRepeatCallback(provider, processor);
|
||||
final RepeatCallback callback = new ItemReaderRepeatCallback(provider, processor);
|
||||
|
||||
final TaskExecutorRepeatTemplate chunkTemplate = new TaskExecutorRepeatTemplate();
|
||||
// The policy is resettable so we only have to resolve this dependency
|
||||
@@ -148,17 +148,17 @@ public class ChunkedRepeatTests extends AbstractTradeBatchTests {
|
||||
|
||||
while (!chunker.ready()) {
|
||||
|
||||
ItemProvider truncated = new AbstractItemProvider() {
|
||||
ItemReader truncated = new AbstractItemReader() {
|
||||
int count = 0;
|
||||
|
||||
public Object next() throws Exception {
|
||||
public Object read() throws Exception {
|
||||
if (count++ < 2)
|
||||
return provider.next();
|
||||
return provider.read();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
chunker.reset();
|
||||
template.iterate(new ItemProviderRepeatCallback(truncated, processor) {
|
||||
template.iterate(new ItemReaderRepeatCallback(truncated, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.callback.ItemProviderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.ItemReaderRepeatCallback;
|
||||
import org.springframework.batch.repeat.callback.NestedRepeatCallback;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
@@ -44,7 +44,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}
|
||||
|
||||
public void testExecute() throws Exception {
|
||||
template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
|
||||
template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
|
||||
assertEquals(2, processor.count);
|
||||
|
||||
@@ -197,7 +197,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContext() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
@@ -225,7 +225,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
*/
|
||||
public void testEarlyCompletionWithContextTerminated() throws Exception {
|
||||
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
@@ -321,7 +321,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testResult() throws Exception {
|
||||
ExitStatus result = template.iterate(new ItemProviderRepeatCallback(provider, processor));
|
||||
ExitStatus result = template.iterate(new ItemReaderRepeatCallback(provider, processor));
|
||||
assertEquals(NUMBER_OF_ITEMS, processor.count);
|
||||
// We are complete - do not expect to be called again
|
||||
assertFalse(result.isContinuable());
|
||||
@@ -360,7 +360,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
ExitStatus result = ExitStatus.FINISHED;
|
||||
|
||||
try {
|
||||
result = template.iterate(new ItemProviderRepeatCallback(provider, processor) {
|
||||
result = template.iterate(new ItemReaderRepeatCallback(provider, processor) {
|
||||
|
||||
public ExitStatus doInIteration(RepeatContext context) throws Exception {
|
||||
ExitStatus result = super.doInIteration(context);
|
||||
|
||||
@@ -18,23 +18,23 @@ package org.springframework.batch.retry;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
|
||||
public class ListItemProviderRecoverer extends ListItemProvider implements ItemProvider, ItemRecoverer {
|
||||
public class ListItemReaderRecoverer extends ListItemReader implements ItemReader, ItemRecoverer {
|
||||
|
||||
/**
|
||||
* Delegate to super class constructor.
|
||||
* @param list
|
||||
*/
|
||||
public ListItemProviderRecoverer(List list) {
|
||||
public ListItemReaderRecoverer(List list) {
|
||||
super(list);
|
||||
}
|
||||
/**
|
||||
* Do nothing. Subclassses should override to implement recovery behaviour.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProvider#recover(java.lang.Object,
|
||||
* @see org.springframework.batch.item.ItemReader#recover(java.lang.Object,
|
||||
* Throwable)
|
||||
*
|
||||
* @return false if nothing can be done (the default), or true if the item
|
||||
@@ -23,8 +23,8 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.exception.RetryException;
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.retry.exception.TerminatedRetryException;
|
||||
import org.springframework.batch.retry.policy.NeverRetryPolicy;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
|
||||
public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public class ItemReaderRetryCallbackTests extends TestCase {
|
||||
|
||||
List calls = new ArrayList();
|
||||
|
||||
@@ -40,14 +40,14 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
|
||||
RetryTemplate template;
|
||||
|
||||
ListItemProvider provider;
|
||||
ListItemReader provider;
|
||||
|
||||
ItemProviderRetryCallback callback;
|
||||
ItemReaderRetryCallback callback;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
template = new RetryTemplate();
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
provider = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
calls.add(data);
|
||||
@@ -57,7 +57,7 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
return "key" + (count++);
|
||||
}
|
||||
};
|
||||
callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
if (data.equals("bar")) {
|
||||
@@ -73,8 +73,8 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testDataExhausted() throws Exception {
|
||||
provider.next();
|
||||
provider.next(); // line up a null data item...
|
||||
provider.read();
|
||||
provider.read(); // line up a null data item...
|
||||
|
||||
try {
|
||||
template.execute(callback);
|
||||
@@ -90,12 +90,12 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public void testContextInitializedWithItemAndCanRetry() throws Exception {
|
||||
// We can use the policy to intercept the context and do something with
|
||||
// the item...
|
||||
provider.next(); // line up an unsuccessful call...
|
||||
provider.read(); // line up an unsuccessful call...
|
||||
assertEquals(0, calls.size());
|
||||
template.setRetryPolicy(new NeverRetryPolicy() {
|
||||
public boolean canRetry(RetryContext context) {
|
||||
// ...register the failed item
|
||||
calls.add("item(" + count + ")=" + context.getAttribute(ItemProviderRetryCallback.ITEM));
|
||||
calls.add("item(" + count + ")=" + context.getAttribute(ItemReaderRetryCallback.ITEM));
|
||||
// Do not call the base class method - the attempt counts as
|
||||
// successful now
|
||||
if (count < 2) // only retry once
|
||||
@@ -121,12 +121,12 @@ public class ItemProviderRetryCallbackTests extends TestCase {
|
||||
public void testContextInitializedWithItemAndRegisterThrowable() throws Exception {
|
||||
// We can use the policy to intercept the context and do something with
|
||||
// the item...
|
||||
provider.next(); // line up an unsuccessful call...
|
||||
provider.read(); // line up an unsuccessful call...
|
||||
assertEquals(0, calls.size());
|
||||
template.setRetryPolicy(new NeverRetryPolicy() {
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) throws TerminatedRetryException {
|
||||
// ...register the failed item
|
||||
calls.add("item=" + context.getAttribute(ItemProviderRetryCallback.ITEM));
|
||||
calls.add("item=" + context.getAttribute(ItemReaderRetryCallback.ITEM));
|
||||
// Call the base class method so that the next attempt is a
|
||||
// failure.
|
||||
super.registerThrowable(context, throwable);
|
||||
@@ -25,23 +25,23 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.FailedItemIdentifier;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.ListItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.provider.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.retry.ListItemProviderRecoverer;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.context.RetryContextSupport;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
|
||||
public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
|
||||
private ItemProviderRetryPolicy policy = new ItemProviderRetryPolicy();
|
||||
private ItemReaderRetryPolicy policy = new ItemReaderRetryPolicy();
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
super.setUp();
|
||||
// The list simulates a failed delivery, redelivery of the same message,
|
||||
// then a new message...
|
||||
provider = new ListItemProviderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
provider = new ListItemReaderRecoverer(Arrays.asList(new String[] { "foo", "foo", "bar" })) {
|
||||
public boolean recover(Object data, Throwable cause) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -61,7 +61,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOpenSunnyDay() throws Exception {
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -71,8 +71,8 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// we haven't called the processor yet...
|
||||
assertEquals(0, count);
|
||||
// but the provider has been accessed:
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testOpenWithWrongCallbackType() {
|
||||
@@ -92,7 +92,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
public void testCanRetry() {
|
||||
policy.setDelegate(new AlwaysRetryPolicy());
|
||||
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testRegisterThrowable() {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -118,7 +118,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testClose() throws Exception {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -132,12 +132,12 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// (not that this would happen in practice)...
|
||||
assertFalse(policy.canRetry(context));
|
||||
// The provider has been accessed only once:
|
||||
assertEquals("foo", provider.next());
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("foo", provider.read());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testOpenTwice() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -162,13 +162,13 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
// The provider has been accessed twice, so this
|
||||
// mimics a message receive by repeating the value of the first
|
||||
// message...
|
||||
assertEquals("bar", provider.next());
|
||||
assertEquals("bar", provider.read());
|
||||
}
|
||||
|
||||
public void testRecover() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
}
|
||||
});
|
||||
@@ -196,18 +196,18 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testFailedItemIdentifier() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
MockFailedItemProvider provider = new MockFailedItemProvider(Collections.EMPTY_LIST);
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, null);
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, null);
|
||||
policy.open(callback);
|
||||
assertEquals(1, provider.hasFailedCount);
|
||||
}
|
||||
|
||||
public void testRecoverWithTemplate() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
@@ -230,7 +230,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExhaustedClearsHistoryAfterLastAttempt() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -256,9 +256,9 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRetryCount() throws Exception {
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
RetryContext context = policy.open(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
@@ -273,14 +273,14 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRetryCountPreservedBetweenRetries() throws Exception {
|
||||
ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
});
|
||||
|
||||
policy = new ItemProviderRetryPolicy();
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
RetryContext context = policy.open(callback);
|
||||
assertNotNull(context);
|
||||
@@ -299,7 +299,7 @@ public class ItemProviderRetryPolicyTests extends TestCase {
|
||||
assertTrue(policy.hasFailed(provider, "foo"));
|
||||
}
|
||||
|
||||
private static class MockFailedItemProvider extends ListItemProvider implements FailedItemIdentifier {
|
||||
private static class MockFailedItemProvider extends ListItemReader implements FailedItemIdentifier {
|
||||
|
||||
private int hasFailedCount = 0;
|
||||
|
||||
@@ -8,16 +8,16 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractDelegator}
|
||||
* Tests for {@link AbstractMethodInvokingDelegator}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class AbstractDelegatorTests extends TestCase {
|
||||
|
||||
private static class ConcreteDelegator extends AbstractDelegator {
|
||||
private static class ConcreteDelegator extends AbstractMethodInvokingDelegator {
|
||||
}
|
||||
|
||||
private AbstractDelegator delegator = new ConcreteDelegator();
|
||||
private AbstractMethodInvokingDelegator delegator = new ConcreteDelegator();
|
||||
|
||||
private Foo foo = new Foo(0, "foo", 1);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="processor" class="org.springframework.batch.item.processor.DelegatingItemProcessor">
|
||||
<bean id="processor" class="org.springframework.batch.item.processor.ItemProcessorAdapter">
|
||||
<property name="targetObject" ref="fooService" />
|
||||
<property name="targetMethod" value="processFoo" />
|
||||
</bean>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="provider" class="org.springframework.batch.item.provider.DelegatingItemProvider">
|
||||
<bean id="provider" class="org.springframework.batch.item.provider.ItemReaderAdapter">
|
||||
<property name="targetObject" ref="fooService" />
|
||||
<property name="targetMethod" value="generateFoo" />
|
||||
</bean>
|
||||
|
||||
@@ -6,16 +6,16 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderInputSource;
|
||||
import org.springframework.batch.io.file.support.StaxEventReaderItemReader;
|
||||
import org.springframework.batch.io.file.support.oxm.UnmarshallingFragmentDeserializer;
|
||||
import org.springframework.batch.io.oxm.domain.Trade;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
|
||||
public abstract class AbstractStaxEventReaderInputSourceTests extends TestCase {
|
||||
public abstract class AbstractStaxEventReaderItemReaderTests extends TestCase {
|
||||
|
||||
private StaxEventReaderInputSource source = new StaxEventReaderInputSource();
|
||||
private StaxEventReaderItemReader source = new StaxEventReaderItemReader();
|
||||
|
||||
protected Resource resource = new ClassPathResource(
|
||||
"org/springframework/batch/io/oxm/input.xml");
|
||||
@@ -4,7 +4,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.castor.CastorMarshaller;
|
||||
|
||||
public class CastorUnmarshallingTests extends AbstractStaxEventReaderInputSourceTests {
|
||||
public class CastorUnmarshallingTests extends AbstractStaxEventReaderItemReaderTests {
|
||||
|
||||
protected Unmarshaller getUnmarshaller() throws Exception {
|
||||
CastorMarshaller unmarshaller = new CastorMarshaller();
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.springframework.batch.io.oxm.domain.Trade;
|
||||
import org.springframework.oxm.Unmarshaller;
|
||||
import org.springframework.oxm.xstream.XStreamMarshaller;
|
||||
|
||||
public class XStreamUnmarshallingTests extends AbstractStaxEventReaderInputSourceTests {
|
||||
public class XStreamUnmarshallingTests extends AbstractStaxEventReaderItemReaderTests {
|
||||
|
||||
protected Unmarshaller getUnmarshaller() throws Exception {
|
||||
XStreamMarshaller unmarshaller = new XStreamMarshaller();
|
||||
|
||||
@@ -21,16 +21,16 @@ import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.AbstractItemReaderRecoverer;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemProviderRetryPolicy;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemReaderRetryPolicy;
|
||||
import org.springframework.batch.retry.policy.SimpleRetryPolicy;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -48,7 +48,7 @@ public class ExternalRetryInBatchTests extends AbstractDependencyInjectionSpring
|
||||
|
||||
private RepeatTemplate repeatTemplate;
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@@ -80,8 +80,8 @@ public class ExternalRetryInBatchTests extends AbstractDependencyInjectionSpring
|
||||
jdbcTemplate.execute("delete from T_FOOS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
jmsTemplate.convertAndSend("queue", "bar");
|
||||
provider = new AbstractItemProvider() {
|
||||
public Object next() {
|
||||
provider = new AbstractItemReaderRecoverer() {
|
||||
public Object read() {
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
return text;
|
||||
@@ -112,9 +112,9 @@ public class ExternalRetryInBatchTests extends AbstractDependencyInjectionSpring
|
||||
public void testExternalRetryRecoveryInBatch() throws Exception {
|
||||
assertInitialState();
|
||||
|
||||
retryTemplate.setRetryPolicy(new ItemProviderRetryPolicy(new SimpleRetryPolicy(1)));
|
||||
retryTemplate.setRetryPolicy(new ItemReaderRetryPolicy(new SimpleRetryPolicy(1)));
|
||||
|
||||
final ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
final ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(final Object text) {
|
||||
// No need for transaction here: the whole batch will roll
|
||||
// back. When it comes back for recovery this code is not
|
||||
|
||||
@@ -21,11 +21,11 @@ import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.item.AbstractItemReaderRecoverer;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemProvider;
|
||||
import org.springframework.batch.item.provider.AbstractItemProvider;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemProviderRetryPolicy;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.policy.ItemReaderRetryPolicy;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
@@ -41,7 +41,7 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
|
||||
|
||||
private RetryTemplate retryTemplate;
|
||||
|
||||
private ItemProvider provider;
|
||||
private ItemReader provider;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@@ -68,8 +68,8 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
|
||||
getMessages(); // drain queue
|
||||
jdbcTemplate.execute("delete from T_FOOS");
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
provider = new AbstractItemProvider() {
|
||||
public Object next() {
|
||||
provider = new AbstractItemReaderRecoverer() {
|
||||
public Object read() {
|
||||
String text = (String) jmsTemplate.receiveAndConvert("queue");
|
||||
list.add(text);
|
||||
return text;
|
||||
@@ -102,9 +102,9 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
|
||||
|
||||
assertInitialState();
|
||||
|
||||
retryTemplate.setRetryPolicy(new ItemProviderRetryPolicy());
|
||||
retryTemplate.setRetryPolicy(new ItemReaderRetryPolicy());
|
||||
|
||||
final ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
final ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(final Object text) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
|
||||
Integer.valueOf(list.size()), text });
|
||||
@@ -167,9 +167,9 @@ public class ExternalRetryTests extends AbstractDependencyInjectionSpringContext
|
||||
|
||||
assertInitialState();
|
||||
|
||||
retryTemplate.setRetryPolicy(new ItemProviderRetryPolicy());
|
||||
retryTemplate.setRetryPolicy(new ItemReaderRetryPolicy());
|
||||
|
||||
final ItemProviderRetryCallback callback = new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
final ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(final Object text) {
|
||||
jdbcTemplate.update("INSERT into T_FOOS (id,name,foo_date) values (?,?,null)", new Object[] {
|
||||
Integer.valueOf(list.size()), text });
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.JmsItemProvider;
|
||||
import org.springframework.batch.item.provider.JmsItemReader;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -142,12 +142,12 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
|
||||
|
||||
assertInitialState();
|
||||
|
||||
JmsItemProvider provider = new JmsItemProvider();
|
||||
JmsItemReader provider = new JmsItemReader();
|
||||
// provider.setItemType(Message.class);
|
||||
provider.setJmsTemplate(jmsTemplate);
|
||||
jmsTemplate.setDefaultDestinationName("queue");
|
||||
|
||||
retryTemplate.execute(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
retryTemplate.execute(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(final Object text) {
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
|
||||
@@ -20,10 +20,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.provider.JmsItemProvider;
|
||||
import org.springframework.batch.item.provider.JmsItemReader;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.callback.ItemProviderRetryCallback;
|
||||
import org.springframework.batch.retry.callback.ItemReaderRetryCallback;
|
||||
import org.springframework.batch.retry.support.RetryTemplate;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -138,12 +138,12 @@ public class SynchronousTests extends AbstractTransactionalDataSourceSpringConte
|
||||
|
||||
assertInitialState();
|
||||
|
||||
JmsItemProvider provider = new JmsItemProvider();
|
||||
JmsItemReader provider = new JmsItemReader();
|
||||
// provider.setItemType(Message.class);
|
||||
provider.setJmsTemplate(jmsTemplate);
|
||||
jmsTemplate.setDefaultDestinationName("queue");
|
||||
|
||||
retryTemplate.execute(new ItemProviderRetryCallback(provider, new ItemProcessor() {
|
||||
retryTemplate.execute(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(final Object text) {
|
||||
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader" ref="fileInputTemplate" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -35,11 +35,11 @@
|
||||
<bean id="step2" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate2" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader" ref="fileInputTemplate2" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -55,7 +55,7 @@
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step" >
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileLocator" />
|
||||
@@ -63,7 +63,7 @@
|
||||
<property name="fieldSetMapper" ref="fieldSetMapper" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputTemplate2" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileInputTemplate2" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileLocator2" />
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader" ref="fileInputTemplate" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -46,7 +46,7 @@
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileLocator" />
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.ItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.item.provider.DelegatingItemProvider">
|
||||
<bean class="org.springframework.batch.item.provider.ItemReaderAdapter">
|
||||
<property name="targetObject" ref="delegatingObject" />
|
||||
<property name="targetMethod" value="getData" />
|
||||
</bean>
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader" ref="fileInputTemplate" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -37,7 +37,7 @@
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<!-- This input source is injected into the test case to verify the output - not used by the job at all -->
|
||||
<bean id="testInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<bean id="testInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="fixedFileDescriptor" />
|
||||
<property name="fieldSetMapper" ref="fieldSetMapper" />
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
<property name="allowStartIfComplete" value="false" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="playerFileInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="playerFileItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -56,12 +56,12 @@
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="gameFileInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="gameFileItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -86,11 +86,11 @@
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="playerSummarizationSource" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -113,8 +113,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="playerFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource" scope="step">
|
||||
<bean id="playerFileItemReader"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader" scope="step">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="resource" value="classpath:data/footballjob/input/player.csv" />
|
||||
<property name="tokenizer">
|
||||
@@ -130,8 +130,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="gameFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource" scope="step">
|
||||
<bean id="gameFileItemReader"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader" scope="step">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="resource" value="classpath:data/footballjob/input/games.csv"/>
|
||||
<property name="tokenizer">
|
||||
@@ -148,7 +148,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="playerSummarizationSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorInputSource" scope="step">
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorItemReader" scope="step">
|
||||
<aop:scoped-proxy/>
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
<property name="mapper">
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
class="org.springframework.batch.execution.step.RepeatOperationsStepConfiguration">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="hibernateInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="hibernateItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -76,8 +76,8 @@
|
||||
<property name="sessionFactory" ref="sessionFactory" />
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateInputSource"
|
||||
class="org.springframework.batch.io.cursor.HibernateCursorInputSource"
|
||||
<bean id="hibernateItemReader"
|
||||
class="org.springframework.batch.io.cursor.HibernateCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="queryString" value="from CustomerCredit" />
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource" ref="ibatisInputSource" />
|
||||
<bean class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader" ref="ibatisItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -43,7 +43,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="ibatisInputSource" class="org.springframework.batch.io.driving.IbatisDrivingQueryInputSource"
|
||||
<bean id="ibatisItemReader" class="org.springframework.batch.io.driving.IbatisDrivingQueryItemReader"
|
||||
scope="step" >
|
||||
<aop:scoped-proxy />
|
||||
<property name="detailsQueryId" value="getCustomerCreditById" />
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.AggregateItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="fileInputSource" />
|
||||
class="org.springframework.batch.item.provider.AggregateItemReader">
|
||||
<property name="itemReader"
|
||||
ref="fileItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -43,8 +43,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileItemReader"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
http://www.springframework.org/schema/aop
|
||||
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
|
||||
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileInputLocator" />
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean class="org.springframework.batch.sample.item.provider.OrderItemProvider">
|
||||
<property name="inputSource" ref="fileInputTemplate" />
|
||||
<bean class="org.springframework.batch.sample.item.provider.OrderItemReader">
|
||||
<property name="itemReader" ref="fileInputTemplate" />
|
||||
<property name="headerMapper" ref="headerFieldSetMapper" />
|
||||
<property name="customerMapper" ref="customerFieldSetMapper" />
|
||||
<property name="addressMapper" ref="addressFieldSetMapper" />
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
<bean id="staging" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="playerFileInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="playerFileItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -56,10 +56,10 @@
|
||||
class="org.springframework.batch.execution.step.RepeatOperationsStepConfiguration">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.ItemProviderProcessTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.ItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.provider.StagingItemProvider"
|
||||
class="org.springframework.batch.sample.item.provider.StagingItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource"
|
||||
@@ -109,12 +109,12 @@
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="gameFileInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="gameFileItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -139,11 +139,11 @@
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="playerSummarizationSource" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -166,8 +166,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="playerFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="playerFileItemReader"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource"
|
||||
@@ -185,8 +185,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="gameFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="gameFileItemReader"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource"
|
||||
@@ -205,7 +205,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="playerSummarizationSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorInputSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
<bean class="org.springframework.batch.sample.tasklet.ExceptionRestartableTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource" ref="fileInputSource" />
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader" ref="fileItemReader" />
|
||||
<property name="validator" ref="fixedValidator" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
<!-- INFRASTRUCTURE SETUP -->
|
||||
|
||||
<bean id="fileInputSource" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
<bean id="fileItemReader" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
scope="step" >
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileLocator" />
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
</property>
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource"
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="fileInputTemplate" />
|
||||
<property name="validator"
|
||||
ref="tradeValidator" />
|
||||
@@ -64,11 +64,11 @@
|
||||
<bean id="step2" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider"
|
||||
p:input-source-ref="tradeSqlInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader"
|
||||
p:item-reader-ref="tradeSqlItemReader" />
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
<bean
|
||||
@@ -81,8 +81,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeSqlInputSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorInputSource"
|
||||
<bean id="tradeSqlItemReader"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
@@ -94,8 +94,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="customerSqlInputSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorInputSource"
|
||||
<bean id="customerSqlItemReader"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
<property name="tasklet">
|
||||
<bean id="tradeTasklet"
|
||||
class="org.springframework.batch.sample.tasklet.SimpleTradeTasklet">
|
||||
<property name="inputSource"
|
||||
ref="fileInputSource" />
|
||||
<property name="itemReader"
|
||||
ref="fileItemReader" />
|
||||
<property name="tradeDao" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -39,13 +39,13 @@
|
||||
</bean>
|
||||
|
||||
<!-- This input source is injected into the test case to verify the output - not used by the job at all -->
|
||||
<bean id="testInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource">
|
||||
<bean id="testInputTemplate" class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader">
|
||||
<property name="resource" ref="fileLocator" />
|
||||
<property name="tokenizer" ref="tradeTokenizer" />
|
||||
<property name="fieldSetMapper" ref="tradeMapper" />
|
||||
</bean>
|
||||
|
||||
<bean id="fileInputSource" parent="testInputTemplate"
|
||||
<bean id="fileItemReader" parent="testInputTemplate"
|
||||
autowire-candidate="false" scope="step">
|
||||
<aop:scoped-proxy />
|
||||
</bean>
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.ValidatingItemProvider">
|
||||
<property name="inputSource"
|
||||
class="org.springframework.batch.item.provider.ValidatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="fileInputTemplate" />
|
||||
<property name="validator"
|
||||
ref="tradeValidator" />
|
||||
@@ -40,12 +40,12 @@
|
||||
<bean id="step2" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource"
|
||||
ref="tradeSqlInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader"
|
||||
ref="tradeSqlItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -59,11 +59,11 @@
|
||||
<bean id="step3" parent="simpleStep">
|
||||
<property name="tasklet">
|
||||
<bean
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemProviderTasklet">
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemProvider">
|
||||
<bean
|
||||
class="org.springframework.batch.item.provider.InputSourceItemProvider">
|
||||
<property name="inputSource" ref="customerSqlInputSource" />
|
||||
class="org.springframework.batch.item.provider.DelegatingItemReader">
|
||||
<property name="itemReader" ref="customerSqlItemReader" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemProcessor">
|
||||
@@ -78,8 +78,8 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="tradeSqlInputSource"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorInputSource"
|
||||
<bean id="tradeSqlItemReader"
|
||||
class="org.springframework.batch.io.cursor.JdbcCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
@@ -92,7 +92,7 @@
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="customerSqlInputSource" class="org.springframework.batch.io.cursor.JdbcCursorInputSource"
|
||||
<bean id="customerSqlItemReader" class="org.springframework.batch.io.cursor.JdbcCursorItemReader"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource" ref="dataSource" />
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
</bean>
|
||||
|
||||
<bean
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileInputSource"
|
||||
class="org.springframework.batch.io.file.support.DefaultFlatFileItemReader"
|
||||
id="fileInputTemplate" scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="resource" ref="fileLocator" />
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user