Purge ItemProcessor
This commit is contained in:
@@ -18,7 +18,6 @@ package org.springframework.batch.execution.tasklet;
|
||||
|
||||
import org.springframework.batch.core.tasklet.Tasklet;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemRecoverer;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
@@ -34,16 +33,16 @@ import org.springframework.util.Assert;
|
||||
* A concrete implementation of the {@link Tasklet} interface that provides
|
||||
* 'split processing'. This type of processing is characterized by separating
|
||||
* the reading and processing of batch data into two separate classes:
|
||||
* {@link ItemReader} and {@link ItemProcessor}. The {@link ItemReader} class
|
||||
* {@link ItemReader} and {@link ItemWriter}. The {@link ItemReader} class
|
||||
* provides a solid means for re-usability and enforces good architecture
|
||||
* practices. Because an object <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 calculations and output.<br/>
|
||||
* {@link ItemWriter} will then use this object for calculations and output.<br/>
|
||||
*
|
||||
* If a {@link RetryPolicy} is provided it will be used to construct a stateful
|
||||
* retry around the {@link ItemProcessor}, delegating identity concerns to the
|
||||
* retry around the {@link ItemWriter}, delegating identity concerns to the
|
||||
* {@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,
|
||||
@@ -60,7 +59,7 @@ import org.springframework.util.Assert;
|
||||
* transactional recover method.
|
||||
*
|
||||
* @see ItemReader
|
||||
* @see ItemProcessor
|
||||
* @see ItemWriter
|
||||
* @see RetryPolicy
|
||||
* @see Recoverable
|
||||
*
|
||||
@@ -120,7 +119,7 @@ public class ItemOrientedTasklet implements Tasklet, Skippable, InitializingBean
|
||||
|
||||
/**
|
||||
* Read from the {@link ItemReader} and process (if not null) with the
|
||||
* {@link ItemProcessor}. The call to {@link ItemProcessor} is wrapped in a
|
||||
* {@link ItemWriter}. The call to {@link ItemWriter} 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
|
||||
* to apply alternate processing to the item. If the stateful retry is in
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.execution.tasklet;
|
||||
|
||||
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;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
* {@link Restartable} to the provider and processor.
|
||||
*
|
||||
* @see ItemReader
|
||||
* @see ItemProcessor
|
||||
* @see ItemWriter
|
||||
* @see Restartable
|
||||
*
|
||||
* @author Lucas Ward
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
</configSuffixes>
|
||||
<configs>
|
||||
<config>src/test/resources/org/springframework/batch/io/sql/data-source-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/item/processor/delegating-item-processor.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/item/processor/pe-delegating-item-processor.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/retry/aop/retry-transaction-test.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
|
||||
@@ -30,10 +30,10 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.io.exception.BatchEnvironmentException;
|
||||
import org.springframework.batch.io.file.transform.Converter;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -64,16 +64,6 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
ItemWriter, ResourceLifecycle, Restartable, StatisticsProvider, InitializingBean,
|
||||
DisposableBean {
|
||||
|
||||
/**
|
||||
* @author dsyer
|
||||
*
|
||||
*/
|
||||
public static class BooleanHolder {
|
||||
|
||||
public boolean value;
|
||||
|
||||
}
|
||||
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
public static final String WRITTEN_STATISTICS_NAME = "written";
|
||||
@@ -90,12 +80,20 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
private OutputState state = new OutputState();
|
||||
|
||||
private Converter converter = new Converter() {
|
||||
public Object convert(Object input) {
|
||||
private ItemTransformer transformer = new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "" + input;
|
||||
}
|
||||
};
|
||||
|
||||
private static class BooleanHolder {
|
||||
public boolean value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that mandatory properties (resource) are set.
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(resource);
|
||||
File file = resource.getFile();
|
||||
@@ -106,10 +104,10 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
* Public setter for the converter. If not-null this will be used to convert
|
||||
* the input data before it is output.
|
||||
*
|
||||
* @param converter the converter to set
|
||||
* @param transformer the converter to set
|
||||
*/
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
public void setTransformer(ItemTransformer transformer) {
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,17 +150,19 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
*
|
||||
* @param data Object (a String or Object that can be converted) to be
|
||||
* written to output stream
|
||||
* @throws Exception if the transformer or file output fail
|
||||
*/
|
||||
public void write(Object data) {
|
||||
convertAndWrite(data, new BooleanHolder());
|
||||
public void write(Object data) throws Exception {
|
||||
transformAndWrite(data, new BooleanHolder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the date to a format that can be output and then write it out.
|
||||
* @param data
|
||||
* @param converted
|
||||
* @throws Exception
|
||||
*/
|
||||
private void convertAndWrite(Object data, BooleanHolder converted) {
|
||||
private void transformAndWrite(Object data, BooleanHolder converted) throws Exception {
|
||||
|
||||
if (data instanceof Collection) {
|
||||
converted.value = false;
|
||||
@@ -190,7 +190,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
else if (!converted.value) {
|
||||
// (recursive)
|
||||
converted.value = true;
|
||||
convertAndWrite(converter.convert(data), converted);
|
||||
transformAndWrite(transformer.transform(data), converted);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.batch.io.file.transform;
|
||||
* Generic converter interface for transforming an object into another form for
|
||||
* output or after input.
|
||||
*
|
||||
* TODO: replace with ItemTransformer
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,36 +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.item;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public interface ItemProcessor {
|
||||
|
||||
/**
|
||||
* Process the supplied data element. Will be called multiple times during a
|
||||
* larger batch operation. Will not be called with null data in normal
|
||||
* operation.
|
||||
*
|
||||
* @throws Exception if there are errors. If the processor is used inside a
|
||||
* retry or a batch the framework will catch the exception and convert or
|
||||
* rethrow it as appropriate.
|
||||
*/
|
||||
void process(Object data) throws Exception;
|
||||
|
||||
}
|
||||
@@ -18,20 +18,22 @@ package org.springframework.batch.item;
|
||||
|
||||
/**
|
||||
* Basic interface for generic output operations. Class implementing this
|
||||
* interface will be responsible for serializing objects. Generally, it is
|
||||
* responsibility of implementing class to decide which technology to use for
|
||||
* mapping and how it should be configured.
|
||||
* interface will be responsible for serializing objects ias necessary.
|
||||
* 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 ItemWriter {
|
||||
|
||||
/**
|
||||
* Writes provided object to an output stream or similar.
|
||||
* Process the supplied data element. Will be called multiple times during a
|
||||
* larger batch operation. Will not be called with null data in normal
|
||||
* operation.
|
||||
*
|
||||
* @param item
|
||||
* the object to write.
|
||||
* @throws Exception if something goes wrong
|
||||
* @throws Exception if there are errors. If the processor is used inside a
|
||||
* retry or a batch the framework will catch the exception and convert or
|
||||
* rethrow it as appropriate.
|
||||
*/
|
||||
public void write(Object item) throws Exception;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -6,7 +6,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
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;
|
||||
@@ -100,14 +99,13 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
/**
|
||||
* @param extractor used to extract Properties from {@link ItemReader}s
|
||||
* @return compound Properties containing all the Properties from injected
|
||||
* {@link ItemProcessor}s with property keys prefixed by list index.
|
||||
* {@link ItemWriter}s with property keys prefixed by list index.
|
||||
*/
|
||||
private Properties createCompoundProperties(PropertiesExtractor extractor) {
|
||||
Properties stats = new Properties();
|
||||
int index = 0;
|
||||
for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) {
|
||||
ItemProcessor processor = (ItemProcessor) iterator.next();
|
||||
Properties processorStats = extractor.extractProperties(processor);
|
||||
Properties processorStats = extractor.extractProperties(iterator.next());
|
||||
if (processorStats != null) {
|
||||
for (Iterator iterator2 = processorStats.entrySet().iterator(); iterator2.hasNext();) {
|
||||
Map.Entry entry = (Map.Entry) iterator2.next();
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable,
|
||||
* delegate {@link ItemWriter}.
|
||||
* @throws Exception
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object)
|
||||
* @see ItemWriter#process(java.lang.Object)
|
||||
*/
|
||||
final public void write(Object item) throws Exception {
|
||||
Object result = doProcess(item);
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
/**
|
||||
* Interface for item transformations during processing phase.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemProcessorAdapter extends AbstractMethodInvokingDelegator implements ItemProcessor {
|
||||
public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter {
|
||||
|
||||
public void process(Object item) throws Exception {
|
||||
public void write(Object item) throws Exception {
|
||||
invokeDelegateMethodWithArgument(item);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
|
||||
@@ -26,7 +26,7 @@ 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 ItemProcessorAdapter
|
||||
* @see ItemWriterAdapter
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@@ -25,8 +25,7 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FlatFileItemWriter;
|
||||
import org.springframework.batch.io.file.transform.Converter;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -103,8 +102,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteString() throws IOException {
|
||||
public void testWriteString() throws Exception {
|
||||
inputSource.write(TEST_STRING);
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -114,8 +114,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteCollection() throws IOException {
|
||||
public void testWriteCollection() throws Exception {
|
||||
inputSource.write(Collections.singleton(TEST_STRING));
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -124,10 +125,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverter() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverter() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -141,10 +143,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoop() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndInfiniteLoop() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -158,10 +161,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoopInCollection() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndInfiniteLoopInCollection() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -176,12 +180,13 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoopInConvertedCollection() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public void testWriteWithConverterAndInfiniteLoopInConvertedCollection() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
boolean converted = false;
|
||||
|
||||
public Object convert(Object input) {
|
||||
public Object transform(Object input) {
|
||||
if (converted) {
|
||||
return input;
|
||||
}
|
||||
@@ -205,10 +210,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndString() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndString() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -221,10 +227,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndCollectionOfString() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndCollectionOfString() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -237,8 +244,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteArray() throws IOException {
|
||||
public void testWriteArray() throws Exception {
|
||||
inputSource.write(new String[] { TEST_STRING, TEST_STRING });
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -249,8 +257,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String[], LineDescriptor)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteRecord() throws IOException {
|
||||
public void testWriteRecord() throws Exception {
|
||||
String args = "1";
|
||||
|
||||
// AggregatorStub ignores the LineDescriptor, so we pass null
|
||||
@@ -287,7 +296,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
assertEquals("testLine1", lineFromFile);
|
||||
}
|
||||
|
||||
public void testRestart() throws IOException {
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
// write some lines
|
||||
inputSource.write("testLine1");
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.writer.CompositeItemTransformer;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeItemTransformer}.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -8,9 +8,8 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.processor.CompositeItemWriter;
|
||||
import org.springframework.batch.item.writer.CompositeItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -21,7 +20,7 @@ import org.springframework.batch.statistics.StatisticsProvider;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CompositeItemProcessorTests extends TestCase {
|
||||
public class CompositeItemWriterTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private CompositeItemWriter itemProcessor = new CompositeItemWriter();
|
||||
@@ -64,11 +63,11 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() {
|
||||
//this mock with undefined behavior makes sure not-Restartable processor is ignored
|
||||
MockControl p1c = MockControl.createStrictControl(ItemProcessor.class);
|
||||
final ItemProcessor p1 = (ItemProcessor) p1c.getMock();
|
||||
MockControl p1c = MockControl.createStrictControl(ItemWriter.class);
|
||||
final ItemWriter p1 = (ItemWriter) p1c.getMock();
|
||||
|
||||
final ItemProcessor p2 = new ItemProcessorStub();
|
||||
final ItemProcessor p3 = new ItemProcessorStub();
|
||||
final ItemWriter p2 = new ItemWriterStub();
|
||||
final ItemWriter p3 = new ItemWriterStub();
|
||||
List itemProcessors = new ArrayList(){{
|
||||
add(p1);
|
||||
add(p2);
|
||||
@@ -80,10 +79,10 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
itemProcessor.restoreFrom(rd);
|
||||
|
||||
for (Iterator iterator = itemProcessors.iterator(); iterator.hasNext();) {
|
||||
ItemProcessor processor = (ItemProcessor) iterator.next();
|
||||
if (processor instanceof ItemProcessorStub) {
|
||||
ItemWriter processor = (ItemWriter) iterator.next();
|
||||
if (processor instanceof ItemWriterStub) {
|
||||
assertTrue("Injected processors are restarted",
|
||||
((ItemProcessorStub)processor).restarted);
|
||||
((ItemWriterStub)processor).restarted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
* Stub for testing restart. Checks the restart data received is the same that was returned by
|
||||
* <code>getRestartData()</code>
|
||||
*/
|
||||
private static class ItemProcessorStub implements ItemProcessor, Restartable, StatisticsProvider {
|
||||
private static class ItemWriterStub implements ItemWriter, Restartable, StatisticsProvider {
|
||||
|
||||
private static final String RESTART_KEY = "restartData";
|
||||
private static final String STATS_KEY = "stats";
|
||||
@@ -117,7 +116,7 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
restarted = true;
|
||||
}
|
||||
|
||||
public void process(Object data) throws Exception {
|
||||
public void write(Object data) throws Exception {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.batch.item.writer.ItemWriterAdapter;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link ItemProcessorAdapter}.
|
||||
* Tests for {@link ItemWriterAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public class ItemWriterAdapterIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private ItemProcessorAdapter processor;
|
||||
private ItemWriterAdapter processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -29,7 +30,7 @@ public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInje
|
||||
public void testProcess() throws Exception {
|
||||
Foo foo;
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
processor.process(foo);
|
||||
processor.write(foo);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
@@ -44,7 +45,7 @@ public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInje
|
||||
}
|
||||
|
||||
//setter for auto-injection
|
||||
public void setProcessor(ItemProcessorAdapter processor) {
|
||||
public void setProcessor(ItemWriterAdapter processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.batch.item.writer.PropertyExtractingDelegatingItemWriter;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.item.writer.ItemTransformerItemWriterr;
|
||||
|
||||
/**
|
||||
* Tests for {@link ItemTransformerItemWriterr}.
|
||||
@@ -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.ItemProcessorAdapter">
|
||||
<bean id="processor" class="org.springframework.batch.item.writer.ItemWriterAdapter">
|
||||
<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="processor" class="org.springframework.batch.item.processor.PropertyExtractingDelegatingItemWriter">
|
||||
<bean id="processor" class="org.springframework.batch.item.writer.PropertyExtractingDelegatingItemWriter">
|
||||
<property name="targetObject" ref="fooService" />
|
||||
<property name="targetMethod" value="processNameValuePair" />
|
||||
<property name="fieldsUsedAsTargetMethodArguments" value="name,value" />
|
||||
@@ -31,7 +31,6 @@
|
||||
<config>src/main/resources/jobs/delegatingJob.xml</config>
|
||||
<config>src/main/resources/jobs/parallelJob.xml</config>
|
||||
<config>src/main/resources/jobs/rollbackJob.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/item/processor/staging-test-context.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
@@ -223,7 +222,6 @@
|
||||
<incomplete>false</incomplete>
|
||||
<configs>
|
||||
<config>src/main/resources/data-source-context.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/sample/item/processor/staging-test-context.xml</config>
|
||||
</configs>
|
||||
</configSet>
|
||||
<configSet>
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.batch.sample.dao;
|
||||
|
||||
import org.springframework.batch.io.file.transform.Converter;
|
||||
import org.springframework.batch.item.processor.DelegatingItemWriter;
|
||||
import org.springframework.batch.sample.item.processor.OrderWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.sample.item.writer.OrderWriter;
|
||||
|
||||
|
||||
/**
|
||||
@@ -33,22 +33,22 @@ public class FlatFileOrderWriter extends DelegatingItemWriter {
|
||||
/**
|
||||
* Converter for order
|
||||
*/
|
||||
private Converter converter = new OrderConverter();
|
||||
private ItemTransformer transformer = new OrderTransformer();
|
||||
|
||||
/**
|
||||
* Public setter for the converter.
|
||||
*
|
||||
* @param converter the converter to set
|
||||
* @param transformer the converter to set
|
||||
*/
|
||||
public void setConverter(Converter converter) {
|
||||
this.converter = converter;
|
||||
public void setTransformer(ItemTransformer transformer) {
|
||||
this.transformer = transformer;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.processor.DelegatingItemWriter#doProcess(java.lang.Object)
|
||||
*/
|
||||
protected Object doProcess(Object item) throws Exception {
|
||||
return converter.convert(item);
|
||||
return transformer.transform(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.batch.io.file.transform.Converter;
|
||||
import org.springframework.batch.io.file.transform.LineAggregator;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.sample.domain.Address;
|
||||
import org.springframework.batch.sample.domain.BillingInfo;
|
||||
import org.springframework.batch.sample.domain.Customer;
|
||||
@@ -34,7 +34,7 @@ import org.springframework.batch.sample.domain.Order;
|
||||
* Converts <code>Order</code> object to a String.
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class OrderConverter implements Converter {
|
||||
public class OrderTransformer implements ItemTransformer {
|
||||
|
||||
/**
|
||||
* Aggregators for all types of lines in the output file
|
||||
@@ -44,7 +44,7 @@ public class OrderConverter implements Converter {
|
||||
/**
|
||||
* Converts information from an Order object to a collection of Strings for output.
|
||||
*/
|
||||
public Object convert(Object data) {
|
||||
public Object transform(Object data) {
|
||||
Order order = (Order) data;
|
||||
|
||||
List result = new ArrayList();
|
||||
@@ -19,48 +19,48 @@ package org.springframework.batch.sample.domain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* Custom class that contains logic that would normally be
|
||||
* be contained in {@link ItemReader} (<code>getData()</code>) and
|
||||
* {@link ItemProcessor} (<code>processData(..)</code>).
|
||||
* Custom class that contains logic that would normally be be contained in
|
||||
* {@link ItemReader} and {@link ItemWriter}.
|
||||
*
|
||||
* @author tomas.slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class PersonService {
|
||||
|
||||
|
||||
private static final int GENERATION_LIMIT = 10;
|
||||
|
||||
|
||||
private int generatedCounter = 0;
|
||||
|
||||
private int processedCounter = 0;
|
||||
|
||||
|
||||
public Person getData() {
|
||||
if (generatedCounter >= GENERATION_LIMIT) return null;
|
||||
|
||||
if (generatedCounter >= GENERATION_LIMIT)
|
||||
return null;
|
||||
|
||||
Person person = new Person();
|
||||
Address address = new Address();
|
||||
Child child = new Child();
|
||||
List children = new ArrayList(1);
|
||||
|
||||
|
||||
children.add(child);
|
||||
|
||||
|
||||
person.setFirstName("John" + generatedCounter);
|
||||
person.setAge(20 + generatedCounter);
|
||||
address.setCity("Johnsville" + generatedCounter);
|
||||
child.setName("Little Johny" + generatedCounter);
|
||||
|
||||
|
||||
person.setAddress(address);
|
||||
person.setChildren(children);
|
||||
|
||||
|
||||
generatedCounter++;
|
||||
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Badly designed method signature which accepts multiple implicitly related
|
||||
* arguments instead of a single Person argument.
|
||||
@@ -68,11 +68,11 @@ public class PersonService {
|
||||
public void processPerson(String name, String city) {
|
||||
processedCounter++;
|
||||
}
|
||||
|
||||
|
||||
public int getReturnedCount() {
|
||||
return generatedCounter;
|
||||
}
|
||||
|
||||
|
||||
public int getReceivedCount() {
|
||||
return processedCounter;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.springframework.batch.execution.scope.StepContextAware;
|
||||
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.StagingItemWriter;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.processor.DelegatingItemWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.dao.PlayerDao;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.Types;
|
||||
@@ -60,7 +60,7 @@ public class StagingItemWriter extends JdbcDaoSupport implements
|
||||
/**
|
||||
* Serialize the item to the staging table, and add a NEW processed flag.
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object)
|
||||
* @see ItemWriter#write(java.lang.Object)
|
||||
*/
|
||||
public void write(Object data) {
|
||||
Long id = new Long(incrementer.nextLongValue());
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
package org.springframework.batch.sample.item.writer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -25,7 +25,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.TradeWriter">
|
||||
<property name="dao" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
@@ -38,7 +38,7 @@
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemReader" ref="fileInputTemplate2" />
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.PersonWriter" />
|
||||
<bean class="org.springframework.batch.sample.item.writer.PersonWriter" />
|
||||
</property>
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -24,14 +24,14 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.item.processor.CompositeItemWriter" >
|
||||
<bean class="org.springframework.batch.item.writer.CompositeItemWriter" >
|
||||
<property name="itemWriters" >
|
||||
<list>
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.TradeWriter">
|
||||
<property name="dao" ref="tradeDao" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.batch.item.processor.DelegatingItemWriter">
|
||||
<bean class="org.springframework.batch.item.writer.DelegatingItemWriter">
|
||||
<property name="delegate" ref="flatFileOutputSource" />
|
||||
</bean>
|
||||
</list>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.item.processor.PropertyExtractingDelegatingItemWriter">
|
||||
<bean class="org.springframework.batch.item.writer.PropertyExtractingDelegatingItemWriter">
|
||||
<property name="targetObject" ref="delegatingObject" />
|
||||
<property name="targetMethod" value="processPerson" />
|
||||
<property name="fieldsUsedAsTargetMethodArguments">
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.TradeWriter">
|
||||
<property name="dao" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
ref="playerFileItemReader" />
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.PlayerItemWriter">
|
||||
class="org.springframework.batch.sample.item.writer.PlayerItemWriter">
|
||||
<property name="playerDao">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.dao.JdbcPlayerDao">
|
||||
@@ -151,7 +151,7 @@
|
||||
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">
|
||||
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
|
||||
pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
|
||||
method="doStronglyTypedLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="hibernateCreditWriter"
|
||||
class="org.springframework.batch.sample.item.processor.CustomerCreditIncreaseWriter">
|
||||
class="org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter">
|
||||
<property name="customerCreditDao" ref="customerCreditDao"/>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
|
||||
<property name="itemReader" ref="ibatisItemReader" />
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.CustomerCreditIncreaseWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter">
|
||||
<property name="customerCreditDao">
|
||||
<bean class="org.springframework.batch.sample.dao.IbatisCustomerCreditWriter"
|
||||
scope="step">
|
||||
|
||||
@@ -32,12 +32,12 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.OrderWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.OrderWriter">
|
||||
<property name="delegate">
|
||||
<bean class="org.springframework.batch.sample.dao.FlatFileOrderWriter">
|
||||
<property name="delegate" ref="flatFileOutputSource" />
|
||||
<property name="converter">
|
||||
<bean class="org.springframework.batch.sample.dao.OrderConverter">
|
||||
<property name="transformer">
|
||||
<bean class="org.springframework.batch.sample.dao.OrderTransformer">
|
||||
<property name="aggregators" ref="outputDescriptors" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.StagingItemWriter"
|
||||
class="org.springframework.batch.sample.item.writer.StagingItemWriter"
|
||||
scope="step">
|
||||
<aop:scoped-proxy />
|
||||
<property name="dataSource"
|
||||
@@ -67,7 +67,7 @@
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.TradeWriter">
|
||||
class="org.springframework.batch.sample.item.writer.TradeWriter">
|
||||
<property name="dao"
|
||||
ref="tradeDao" />
|
||||
</bean>
|
||||
@@ -163,7 +163,7 @@
|
||||
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">
|
||||
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
|
||||
pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
|
||||
method="doStronglyTypedLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean class="org.springframework.batch.sample.item.processor.TradeWriter">
|
||||
<bean class="org.springframework.batch.sample.item.writer.TradeWriter">
|
||||
<property name="dao" ref="tradeDao" />
|
||||
</bean>
|
||||
</property>
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.TradeWriter"
|
||||
class="org.springframework.batch.sample.item.writer.TradeWriter"
|
||||
p:dao-ref="tradeDao" p:failure="3"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</property>
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.TradeWriter"
|
||||
class="org.springframework.batch.sample.item.writer.TradeWriter"
|
||||
p:dao-ref="tradeDao" />
|
||||
</property>
|
||||
</bean>
|
||||
@@ -44,7 +44,7 @@
|
||||
<property name="itemReader" ref="tradeSqlItemReader" />
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.CustomerUpdateWriter"
|
||||
class="org.springframework.batch.sample.item.writer.CustomerUpdateWriter"
|
||||
p:dao-ref="customerDao" />
|
||||
</property>
|
||||
</bean>
|
||||
@@ -57,7 +57,7 @@
|
||||
<property name="itemReader" ref="customerSqlItemReader" />
|
||||
<property name="itemWriter">
|
||||
<bean
|
||||
class="org.springframework.batch.sample.item.processor.CustomerCreditUpdateWriter"
|
||||
class="org.springframework.batch.sample.item.writer.CustomerCreditUpdateWriter"
|
||||
p:writer-ref="customerReportOutputSource" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
@@ -29,6 +29,6 @@ log4j.logger.org.springframework.batch.sample=debug
|
||||
#log4j.logger.org.springframework.orm=debug
|
||||
|
||||
### debug your specific package or classes with the following example
|
||||
log4j.logger.org.springframework.batch.io=debug
|
||||
log4j.logger.org.springframework.batch=debug
|
||||
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
|
||||
log4j.logger.org.springframework.batch.container.common.module.process.support.DefaultXmlDataProvider=debug
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
<aop:aspect id="moduleLogging" ref="itemProcessorLogAdvice">
|
||||
|
||||
<aop:after
|
||||
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
|
||||
pointcut="execution( * org.springframework.batch.item.ItemWriter+.write(Object)) and args(item)"
|
||||
method="doStronglyTypedLogging" />
|
||||
|
||||
</aop:aspect>
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.sample.item.processor.CustomerCreditIncreaseWriter;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.batch.sample;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.batch.sample.item.processor.StagingItemWriter;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class FlatFileOrderWriterTests extends TestCase {
|
||||
//create map of aggregators and set it to writer
|
||||
Map aggregators = new HashMap();
|
||||
|
||||
OrderConverter converter = new OrderConverter();
|
||||
OrderTransformer converter = new OrderTransformer();
|
||||
aggregators.put("header", aggregator);
|
||||
aggregators.put("customer", aggregator);
|
||||
aggregators.put("address", aggregator);
|
||||
@@ -68,7 +68,7 @@ public class FlatFileOrderWriterTests extends TestCase {
|
||||
aggregators.put("item", aggregator);
|
||||
aggregators.put("footer", aggregator);
|
||||
converter.setAggregators(aggregators);
|
||||
writer.setConverter(converter);
|
||||
writer.setTransformer(converter);
|
||||
|
||||
//call tested method
|
||||
writer.write(order);
|
||||
|
||||
@@ -33,9 +33,9 @@ import org.springframework.batch.sample.domain.Order;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class OrderConverterTests extends TestCase {
|
||||
public class OrderTransformerTests extends TestCase {
|
||||
|
||||
private OrderConverter converter = new OrderConverter();
|
||||
private OrderTransformer converter = new OrderTransformer();
|
||||
|
||||
public void testConvert() throws Exception {
|
||||
converter.setAggregators(new HashMap() {
|
||||
@@ -55,7 +55,7 @@ public class OrderConverterTests extends TestCase {
|
||||
order.setBilling(new BillingInfo());
|
||||
order.setLineItems(Collections.EMPTY_LIST);
|
||||
order.setTotalPrice(BigDecimal.TEN);
|
||||
Object result = converter.convert(order);
|
||||
Object result = converter.transform(order);
|
||||
assertTrue(result instanceof Collection);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditIncreaseWriter;
|
||||
|
||||
/**
|
||||
* Tests for {@link CustomerCreditIncreaseWriter}.
|
||||
|
||||
@@ -7,7 +7,7 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.CustomerCreditDao;
|
||||
import org.springframework.batch.sample.domain.CustomerCredit;
|
||||
import org.springframework.batch.sample.item.processor.CustomerCreditUpdateWriter;
|
||||
import org.springframework.batch.sample.item.writer.CustomerCreditUpdateWriter;
|
||||
|
||||
public class CustomerCreditUpdateProcessorTests extends TestCase {
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.sample.dao.JdbcCustomerDebitWriter;
|
||||
import org.springframework.batch.sample.domain.CustomerDebit;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.processor.CustomerUpdateWriter;
|
||||
import org.springframework.batch.sample.item.writer.CustomerUpdateWriter;
|
||||
|
||||
public class CustomerUpdateProcessorTests extends TestCase {
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.easymock.MockControl;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.sample.domain.Order;
|
||||
import org.springframework.batch.sample.item.writer.OrderWriter;
|
||||
|
||||
public class OrderWriterTests extends TestCase {
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.execution.scope.SimpleStepContext;
|
||||
import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.sample.dao.TradeDao;
|
||||
import org.springframework.batch.sample.domain.Trade;
|
||||
import org.springframework.batch.sample.item.writer.TradeWriter;
|
||||
|
||||
public class TradeProcessorTests extends TestCase {
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.springframework.batch.execution.scope.StepSynchronizationManager;
|
||||
import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
|
||||
import org.springframework.batch.sample.item.processor.StagingItemWriter;
|
||||
import org.springframework.batch.sample.item.writer.StagingItemWriter;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
class="org.springframework.batch.execution.scope.StepScope" />
|
||||
|
||||
<bean id="processor"
|
||||
class="org.springframework.batch.sample.item.processor.StagingItemWriter"
|
||||
class="org.springframework.batch.sample.item.writer.StagingItemWriter"
|
||||
scope="step">
|
||||
<property name="incrementer">
|
||||
<bean id="jobIncrementer" parent="incrementerParent">
|
||||
Reference in New Issue
Block a user