OPEN - issue BATCH-320: Refactor ItemWriter as primary collaborator (with wrapper for processor)
http://jira.springframework.org/browse/BATCH-320 Half way there - tests OK, but some naming and tidying up to do.
This commit is contained in:
@@ -114,10 +114,11 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatInterceptor,
|
||||
/**
|
||||
* Use the delegate to actually do the writing, but flush aggressively if
|
||||
* the item was previously part of a failed chunk.
|
||||
* @throws Exception
|
||||
*
|
||||
* @see org.springframework.batch.io.OutputSource#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object output) {
|
||||
public void write(Object output) throws Exception {
|
||||
getProcessed().add(output);
|
||||
delegate.write(output);
|
||||
flushIfNecessary(output);
|
||||
|
||||
@@ -31,6 +31,7 @@ public interface ItemWriter {
|
||||
*
|
||||
* @param item
|
||||
* the object to write.
|
||||
* @throws Exception if something goes wrong
|
||||
*/
|
||||
public void write(Object item);
|
||||
public void write(Object item) throws Exception;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -17,18 +18,18 @@ import org.springframework.batch.restart.Restartable;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CompositeItemProcessor implements ItemProcessor, Restartable {
|
||||
public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
|
||||
private static final String SEPARATOR = "#";
|
||||
|
||||
private List itemProcessors;
|
||||
private List delegates;
|
||||
|
||||
/**
|
||||
* Calls injected ItemProcessors in order.
|
||||
*/
|
||||
public void process(Object data) throws Exception {
|
||||
for (Iterator iterator = itemProcessors.listIterator(); iterator.hasNext();) {
|
||||
((ItemProcessor) iterator.next()).process(data);
|
||||
public void write(Object data) throws Exception {
|
||||
for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) {
|
||||
((ItemWriter) iterator.next()).write(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,24 +64,24 @@ public class CompositeItemProcessor implements ItemProcessor, Restartable {
|
||||
List restartDataList = parseProperties(data.getProperties());
|
||||
|
||||
// iterators would make the loop below less readable
|
||||
for (int i = 0; i < itemProcessors.size(); i++) {
|
||||
if (itemProcessors.get(i) instanceof Restartable) {
|
||||
((Restartable) itemProcessors.get(i)).restoreFrom((RestartData) restartDataList.get(i));
|
||||
for (int i = 0; i < delegates.size(); i++) {
|
||||
if (delegates.get(i) instanceof Restartable) {
|
||||
((Restartable) delegates.get(i)).restoreFrom((RestartData) restartDataList.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setItemProcessors(List itemProcessors) {
|
||||
this.itemProcessors = itemProcessors;
|
||||
public void setItemWriters(List itemProcessors) {
|
||||
this.delegates = itemProcessors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses compound properties into a list of RestartData.
|
||||
*/
|
||||
private List parseProperties(Properties props) {
|
||||
List restartDataList = new ArrayList(itemProcessors.size());
|
||||
for (int i = 0; i < itemProcessors.size(); i++) {
|
||||
List restartDataList = new ArrayList(delegates.size());
|
||||
for (int i = 0; i < delegates.size(); i++) {
|
||||
restartDataList.add(new GenericRestartData(new Properties()));
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ public class CompositeItemProcessor implements ItemProcessor, Restartable {
|
||||
private Properties createCompoundProperties(PropertiesExtractor extractor) {
|
||||
Properties stats = new Properties();
|
||||
int index = 0;
|
||||
for (Iterator iterator = itemProcessors.listIterator(); iterator.hasNext();) {
|
||||
for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) {
|
||||
ItemProcessor processor = (ItemProcessor) iterator.next();
|
||||
Properties processorStats = extractor.extractProperties(processor);
|
||||
if (processorStats != null) {
|
||||
@@ -3,7 +3,6 @@ package org.springframework.batch.item.processor;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
@@ -18,17 +17,18 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemWriterItemProcessor implements ItemProcessor, Restartable, Skippable, InitializingBean {
|
||||
public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable, InitializingBean {
|
||||
|
||||
private ItemWriter writer;
|
||||
|
||||
/**
|
||||
* Calls {@link #doProcess(Object)} and then writes the result to the
|
||||
* {@link ItemWriter}.
|
||||
* delegate {@link ItemWriter}.
|
||||
* @throws Exception
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object)
|
||||
*/
|
||||
final public void process(Object item) throws Exception {
|
||||
final public void write(Object item) throws Exception {
|
||||
Object result = doProcess(item);
|
||||
writer.write(result);
|
||||
}
|
||||
@@ -36,6 +36,7 @@ public class ItemWriterItemProcessor implements ItemProcessor, Restartable, Skip
|
||||
/**
|
||||
* By default returns the argument. This method is an extension point meant
|
||||
* to be overridden by subclasses that implement processing logic.
|
||||
* @throws Exception
|
||||
*/
|
||||
protected Object doProcess(Object item) throws Exception {
|
||||
return item;
|
||||
@@ -44,7 +45,7 @@ public class ItemWriterItemProcessor implements ItemProcessor, Restartable, Skip
|
||||
/**
|
||||
* Setter for {@link ItemWriter}.
|
||||
*/
|
||||
public void setItemWriter(ItemWriter writer) {
|
||||
public void setDelegate(ItemWriter writer) {
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
* Delegates item processing to a custom method -
|
||||
* passes the item as an argument for the delegate method.
|
||||
*
|
||||
* @see PropertyExtractingDelegatingItemProcessor
|
||||
* @see PropertyExtractingDelegatingItemWriter
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class TransformerWriterItemProcessor extends ItemWriterItemProcessor {
|
||||
public class ItemTransformerItemWriterr extends DelegatingItemWriter {
|
||||
|
||||
private ItemTransformer itemTransformer;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.batch.item.processor;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PropertyExtractingDelegatingItemProcessor extends AbstractMethodInvokingDelegator implements ItemProcessor {
|
||||
public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator implements ItemWriter {
|
||||
|
||||
private String[] fieldsUsedAsTargetMethodArguments;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class PropertyExtractingDelegatingItemProcessor extends AbstractMethodInv
|
||||
* Extracts values from item's fields named in fieldsUsedAsTargetMethodArguments
|
||||
* and passes them as arguments to the delegate method.
|
||||
*/
|
||||
public void process(Object item) throws Exception {
|
||||
public void write(Object item) throws Exception {
|
||||
// helper for extracting property values from a bean
|
||||
BeanWrapper beanWrapper = new BeanWrapperImpl();
|
||||
beanWrapper.setWrappedInstance(item);
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package org.springframework.batch.repeat.callback;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.repeat.RepeatCallback;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
* Simple wrapper for two business interfaces: get the next item from a
|
||||
* ItemProvider and apply the given processor to the result (if not null).
|
||||
* reader and apply the given writer to the result (if not null).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -33,12 +33,12 @@ public class ItemReaderRepeatCallback implements RepeatCallback {
|
||||
|
||||
ItemReader provider;
|
||||
|
||||
ItemProcessor processor;
|
||||
ItemWriter writer;
|
||||
|
||||
public ItemReaderRepeatCallback(ItemReader provider, ItemProcessor processor) {
|
||||
public ItemReaderRepeatCallback(ItemReader provider, ItemWriter writer) {
|
||||
super();
|
||||
this.provider = provider;
|
||||
this.processor = processor;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ public class ItemReaderRepeatCallback implements RepeatCallback {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the processor to process the next item if there is one. Return the
|
||||
* Use the writer to process the next item if there is one. Return the
|
||||
* item processed, or null if nothing was available.
|
||||
* @see org.springframework.batch.repeat.RepeatCallback#doInIteration(org.springframework.batch.item.BatchContextAdapter)
|
||||
* @param context the current context.
|
||||
@@ -63,9 +63,9 @@ public class ItemReaderRepeatCallback implements RepeatCallback {
|
||||
ExitStatus result = ExitStatus.FINISHED;
|
||||
Object item = provider.read();
|
||||
|
||||
if (processor != null) {
|
||||
if (writer != null) {
|
||||
if (item != null) {
|
||||
processor.process(item);
|
||||
writer.write(item);
|
||||
result = ExitStatus.CONTINUABLE;
|
||||
}
|
||||
item = null;
|
||||
|
||||
@@ -18,9 +18,9 @@ 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.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.retry.RetryCallback;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
import org.springframework.batch.retry.RetryPolicy;
|
||||
@@ -49,15 +49,15 @@ public class ItemReaderRetryCallback implements RetryCallback {
|
||||
|
||||
private ItemReader provider;
|
||||
|
||||
private ItemProcessor processor;
|
||||
private ItemWriter writer;
|
||||
|
||||
private ItemRecoverer recoverer;
|
||||
|
||||
public ItemReaderRetryCallback(ItemReader provider,
|
||||
ItemProcessor processor) {
|
||||
ItemWriter writer) {
|
||||
super();
|
||||
this.provider = provider;
|
||||
this.processor = processor;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ public class ItemReaderRetryCallback implements RetryCallback {
|
||||
private Object process(RetryContext context) throws Exception {
|
||||
Object item = next(context);
|
||||
if (item != null) {
|
||||
processor.process(item);
|
||||
writer.write(item);
|
||||
}
|
||||
context.removeAttribute(ITEM); // if successful
|
||||
return item;
|
||||
|
||||
@@ -133,8 +133,9 @@ public class HibernateAwareItemWriterTests extends TestCase {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.io.support.HibernateAwareItemWriter#write(java.lang.Object)}.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWrite() {
|
||||
public void testWrite() throws Exception {
|
||||
writer.write("foo");
|
||||
assertEquals(1, list.size());
|
||||
assertTrue(list.contains("foo"));
|
||||
@@ -165,8 +166,9 @@ public class HibernateAwareItemWriterTests extends TestCase {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.io.support.HibernateAwareItemWriter#write(java.lang.Object)}.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteAndCloseWithFailure() {
|
||||
public void testWriteAndCloseWithFailure() throws Exception {
|
||||
final RuntimeException ex = new RuntimeException("bar");
|
||||
writer.setHibernateTemplate(new HibernateTemplateWrapper() {
|
||||
public void flush() throws DataAccessException {
|
||||
|
||||
@@ -9,21 +9,22 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.processor.CompositeItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.processor.CompositeItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeItemProcessor}
|
||||
* Tests for {@link CompositeItemWriter}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CompositeItemProcessorTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private CompositeItemProcessor itemProcessor = new CompositeItemProcessor();
|
||||
private CompositeItemWriter itemProcessor = new CompositeItemWriter();
|
||||
|
||||
/**
|
||||
* Regular usage scenario.
|
||||
@@ -38,10 +39,10 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
List processors = new ArrayList(NUMBER_OF_PROCESSORS);
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_PROCESSORS; i++) {
|
||||
MockControl control = MockControl.createStrictControl(ItemProcessor.class);
|
||||
ItemProcessor processor = (ItemProcessor) control.getMock();
|
||||
MockControl control = MockControl.createStrictControl(ItemWriter.class);
|
||||
ItemWriter processor = (ItemWriter) control.getMock();
|
||||
|
||||
processor.process(data);
|
||||
processor.write(data);
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
|
||||
@@ -49,8 +50,8 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
controls.add(control);
|
||||
}
|
||||
|
||||
itemProcessor.setItemProcessors(processors);
|
||||
itemProcessor.process(data);
|
||||
itemProcessor.setItemWriters(processors);
|
||||
itemProcessor.write(data);
|
||||
|
||||
for (Iterator iterator = controls.iterator(); iterator.hasNext();) {
|
||||
MockControl control = (MockControl) iterator.next();
|
||||
@@ -73,7 +74,7 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
add(p2);
|
||||
add(p3);
|
||||
}};
|
||||
itemProcessor.setItemProcessors(itemProcessors);
|
||||
itemProcessor.setItemWriters(itemProcessors);
|
||||
|
||||
RestartData rd = itemProcessor.getRestartData();
|
||||
itemProcessor.restoreFrom(rd);
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
*/
|
||||
public class ItemWriterItemProcessorTests extends TestCase {
|
||||
|
||||
private ItemWriterItemProcessor processor = new ItemWriterItemProcessor();
|
||||
private DelegatingItemWriter processor = new DelegatingItemWriter();
|
||||
|
||||
private ItemWriter writer;
|
||||
|
||||
@@ -45,12 +45,12 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
writer = new MockOutputSource("test");
|
||||
processor.setItemWriter(writer);
|
||||
processor.setDelegate(writer);
|
||||
processor.afterPropertiesSet();
|
||||
}
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
processor.process("foo");
|
||||
processor.write("foo");
|
||||
assertEquals(1, list.size());
|
||||
assertEquals("test:foo", list.get(0));
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.process("foo");
|
||||
processor.write("foo");
|
||||
assertEquals("bar:foo", list.get(0));
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testGetRestartDataWithoutRestartable() throws Exception {
|
||||
processor.setItemWriter(null);
|
||||
processor.setDelegate(null);
|
||||
try {
|
||||
processor.getRestartData();
|
||||
fail("Expected IllegalStateException");
|
||||
@@ -93,7 +93,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromWithoutRestartable() throws Exception {
|
||||
processor.setItemWriter(null);
|
||||
processor.setDelegate(null);
|
||||
try {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
fail("Expected IllegalStateException");
|
||||
@@ -113,7 +113,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* ItemWriter property must be set.
|
||||
*/
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
processor.setItemWriter(null);
|
||||
processor.setDelegate(null);
|
||||
try {
|
||||
processor.afterPropertiesSet();
|
||||
fail();
|
||||
|
||||
@@ -7,14 +7,14 @@ import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link PropertyExtractingDelegatingItemProcessor}
|
||||
* Tests for {@link PropertyExtractingDelegatingItemWriter}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PropertyExtractingDelegatingItemProccessorIntegrationTests
|
||||
extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private PropertyExtractingDelegatingItemProcessor processor;
|
||||
private PropertyExtractingDelegatingItemWriter processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class PropertyExtractingDelegatingItemProccessorIntegrationTests
|
||||
public void testProcess() throws Exception {
|
||||
Foo foo;
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
processor.process(foo);
|
||||
processor.write(foo);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
@@ -47,7 +47,7 @@ public class PropertyExtractingDelegatingItemProccessorIntegrationTests
|
||||
|
||||
}
|
||||
|
||||
public void setProcessor(PropertyExtractingDelegatingItemProcessor processor) {
|
||||
public void setProcessor(PropertyExtractingDelegatingItemWriter processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* Tests for {@link TransformerWriterItemProcessor}.
|
||||
* Tests for {@link ItemTransformerItemWriterr}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class TransformerWriterItemProcessorTests extends TestCase {
|
||||
|
||||
private TransformerWriterItemProcessor processor = new TransformerWriterItemProcessor();
|
||||
private ItemTransformerItemWriterr processor = new ItemTransformerItemWriterr();
|
||||
|
||||
private ItemTransformer transformer;
|
||||
private ItemWriter itemWriter;
|
||||
@@ -25,7 +25,7 @@ public class TransformerWriterItemProcessorTests extends TestCase {
|
||||
itemWriter = (ItemWriter) outControl.getMock();
|
||||
|
||||
processor.setItemTransformer(transformer);
|
||||
processor.setItemWriter(itemWriter);
|
||||
processor.setDelegate(itemWriter);
|
||||
processor.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TransformerWriterItemProcessorTests extends TestCase {
|
||||
tControl.replay();
|
||||
outControl.replay();
|
||||
|
||||
processor.process(item);
|
||||
processor.write(item);
|
||||
|
||||
tControl.verify();
|
||||
outControl.verify();
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.ListItemReader;
|
||||
|
||||
public class ItemReaderRepeatCallbackTests extends TestCase {
|
||||
@@ -33,8 +33,8 @@ public class ItemReaderRepeatCallbackTests extends TestCase {
|
||||
|
||||
public void testDoWithRepeat() throws Exception {
|
||||
callback = new ItemReaderRepeatCallback(new ListItemReader(Arrays.asList(new String[] { "foo", "bar" })),
|
||||
new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
list.add(data);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.batch.repeat.support;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.SimpleFlatFileItemReader;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.DelegatingItemReader;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -38,7 +38,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
|
||||
Resource resource = new ClassPathResource("trades.csv", getClass());
|
||||
|
||||
protected TradeProcessor processor = new TradeProcessor();
|
||||
protected TradeWriter processor = new TradeWriter();
|
||||
|
||||
protected TradeItemReader provider;
|
||||
|
||||
@@ -69,12 +69,12 @@ public abstract class AbstractTradeBatchTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class TradeProcessor implements ItemProcessor {
|
||||
protected static class TradeWriter implements ItemWriter {
|
||||
int count = 0;
|
||||
|
||||
// This has to be synchronized because we are going to test the state
|
||||
// (count) at the end of a concurrent batch run.
|
||||
public synchronized void process(Object data) {
|
||||
public synchronized void write(Object data) {
|
||||
count++;
|
||||
System.out.println("Executing trade '" + data + "'");
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.ListItemReader;
|
||||
import org.springframework.batch.retry.ListItemReaderRecoverer;
|
||||
import org.springframework.batch.retry.RetryContext;
|
||||
@@ -57,8 +57,8 @@ public class ItemReaderRetryCallbackTests extends TestCase {
|
||||
return "key" + (count++);
|
||||
}
|
||||
};
|
||||
callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
if (data.equals("bar")) {
|
||||
throw new IllegalStateException("Bar detected");
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.FailedItemIdentifier;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.reader.ListItemReader;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
@@ -61,8 +61,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOpenSunnyDay() throws Exception {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -92,8 +92,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
public void testCanRetry() {
|
||||
policy.setDelegate(new AlwaysRetryPolicy());
|
||||
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
}
|
||||
}));
|
||||
@@ -105,8 +105,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testRegisterThrowable() {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -118,8 +118,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
|
||||
public void testClose() throws Exception {
|
||||
policy.setDelegate(new NeverRetryPolicy());
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -137,8 +137,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOpenTwice() throws Exception {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -168,8 +168,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
public void testRecover() throws Exception {
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
}
|
||||
});
|
||||
RetryContext context = policy.open(callback);
|
||||
@@ -207,8 +207,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
public void testRecoverWithTemplate() throws Exception {
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
throw new RuntimeException("Barf!");
|
||||
}
|
||||
});
|
||||
@@ -230,8 +230,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testExhaustedClearsHistoryAfterLastAttempt() throws Exception {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -258,8 +258,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
public void testRetryCount() throws Exception {
|
||||
policy = new ItemReaderRetryPolicy();
|
||||
policy.setDelegate(new SimpleRetryPolicy(1));
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
RetryContext context = policy.open(new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
@@ -273,8 +273,8 @@ public class ItemReaderRetryPolicyTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testRetryCountPreservedBetweenRetries() throws Exception {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemProcessor() {
|
||||
public void process(Object data) {
|
||||
ItemReaderRetryCallback callback = new ItemReaderRetryCallback(provider, new ItemWriter() {
|
||||
public void write(Object data) {
|
||||
count++;
|
||||
list.add(data);
|
||||
}
|
||||
|
||||
@@ -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.PropertyExtractingDelegatingItemProcessor">
|
||||
<bean id="processor" class="org.springframework.batch.item.processor.PropertyExtractingDelegatingItemWriter">
|
||||
<property name="targetObject" ref="fooService" />
|
||||
<property name="targetMethod" value="processNameValuePair" />
|
||||
<property name="fieldsUsedAsTargetMethodArguments" value="name,value" />
|
||||
|
||||
Reference in New Issue
Block a user