Purge ItemProcessor
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user