RESOLVED - issue BATCH-640: FieldSetMapper.mapLine() should contain the line number

Added rownum parameter to field set mapper (with default value -1 defined as constant in FieldSetMapper)
This commit is contained in:
dsyer
2008-06-05 15:03:10 +00:00
parent b89bbbadb6
commit 85e168e2db
24 changed files with 76 additions and 63 deletions

View File

@@ -91,7 +91,7 @@ public class OrderItemReader extends DelegatingItemReader {
// start a new Order
if (Order.LINE_ID_HEADER.equals(lineId)) {
log.debug("STARTING NEW RECORD");
order = (Order) headerMapper.mapLine(fieldSet);
order = (Order) headerMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN);
return;
}
@@ -116,7 +116,7 @@ public class OrderItemReader extends DelegatingItemReader {
log.debug("MAPPING CUSTOMER");
if (order.getCustomer() == null) {
order.setCustomer((Customer) customerMapper.mapLine(fieldSet));
order.setCustomer((Customer) customerMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
order.getCustomer().setBusinessCustomer(true);
}
@@ -127,7 +127,7 @@ public class OrderItemReader extends DelegatingItemReader {
log.debug("MAPPING CUSTOMER");
if (order.getCustomer() == null) {
order.setCustomer((Customer) customerMapper.mapLine(fieldSet));
order.setCustomer((Customer) customerMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
order.getCustomer().setBusinessCustomer(false);
}
@@ -136,25 +136,25 @@ public class OrderItemReader extends DelegatingItemReader {
if (Address.LINE_ID_BILLING_ADDR.equals(lineId)) {
log.debug("MAPPING BILLING ADDRESS");
order.setBillingAddress((Address) addressMapper.mapLine(fieldSet));
order.setBillingAddress((Address) addressMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
return;
}
if (Address.LINE_ID_SHIPPING_ADDR.equals(lineId)) {
log.debug("MAPPING SHIPPING ADDRESS");
order.setShippingAddress((Address) addressMapper.mapLine(fieldSet));
order.setShippingAddress((Address) addressMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
return;
}
if (BillingInfo.LINE_ID_BILLING_INFO.equals(lineId)) {
log.debug("MAPPING BILLING INFO");
order.setBilling((BillingInfo) billingMapper.mapLine(fieldSet));
order.setBilling((BillingInfo) billingMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
return;
}
if (ShippingInfo.LINE_ID_SHIPPING_INFO.equals(lineId)) {
log.debug("MAPPING SHIPPING INFO");
order.setShipping((ShippingInfo) shippingMapper.mapLine(fieldSet));
order.setShipping((ShippingInfo) shippingMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
return;
}
@@ -165,7 +165,7 @@ public class OrderItemReader extends DelegatingItemReader {
order.setLineItems(new ArrayList());
}
order.getLineItems().add(itemMapper.mapLine(fieldSet));
order.getLineItems().add(itemMapper.mapLine(fieldSet, FieldSetMapper.ROW_NUMBER_UNKNOWN));
return;
}

View File

@@ -33,7 +33,7 @@ public class AddressFieldSetMapper implements FieldSetMapper {
public static final String COUNTRY_COLUMN = "COUNTRY";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
Address address = new Address();
address.setAddressee(fieldSet.readString(ADDRESSEE_COLUMN));

View File

@@ -27,7 +27,7 @@ public class BillingFieldSetMapper implements FieldSetMapper {
public static final String PAYMENT_TYPE_ID_COLUMN = "PAYMENT_TYPE_ID";
public static final String PAYMENT_DESC_COLUMN = "PAYMENT_DESC";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
BillingInfo info = new BillingInfo();
info.setPaymentId(fieldSet.readString(PAYMENT_TYPE_ID_COLUMN));

View File

@@ -34,7 +34,7 @@ public class CustomerFieldSetMapper implements FieldSetMapper {
public static final String REG_ID_COLUMN = "REG_ID";
public static final String VIP_COLUMN = "VIP";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
Customer customer = new Customer();
if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {

View File

@@ -6,7 +6,7 @@ import org.springframework.batch.sample.domain.Game;
public class GameFieldSetMapper implements FieldSetMapper {
public Object mapLine(FieldSet fs) {
public Object mapLine(FieldSet fs, int rownum) {
if(fs == null){
return null;

View File

@@ -27,7 +27,7 @@ public class HeaderFieldSetMapper implements FieldSetMapper {
public static final String ORDER_ID_COLUMN = "ORDER_ID";
public static final String ORDER_DATE_COLUMN = "ORDER_DATE";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
Order order = new Order();
order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN));
order.setOrderDate(fieldSet.readDate(ORDER_DATE_COLUMN));

View File

@@ -33,7 +33,7 @@ public class OrderItemFieldSetMapper implements FieldSetMapper {
public static final String ITEM_ID_COLUMN = "ITEM_ID";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
LineItem item = new LineItem();
item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN));

View File

@@ -6,7 +6,7 @@ import org.springframework.batch.sample.domain.Player;
public class PlayerFieldSetMapper implements FieldSetMapper {
public Object mapLine(FieldSet fs) {
public Object mapLine(FieldSet fs, int rownum) {
if(fs == null){
return null;

View File

@@ -28,7 +28,7 @@ public class ShippingFieldSetMapper implements FieldSetMapper {
public static final String SHIPPING_TYPE_ID_COLUMN = "SHIPPING_TYPE_ID";
public static final String SHIPPER_ID_COLUMN = "SHIPPER_ID";
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
ShippingInfo info = new ShippingInfo();
info.setShipperId(fieldSet.readString(SHIPPER_ID_COLUMN));

View File

@@ -30,7 +30,7 @@ public class TradeFieldSetMapper implements FieldSetMapper {
public static final int PRICE_COLUMN = 2;
public static final int CUSTOMER_COLUMN = 3;
public Object mapLine(FieldSet fieldSet) {
public Object mapLine(FieldSet fieldSet, int rownum) {
if ("BEGIN".equals(fieldSet.readString(0))) {
return AggregateItemReader.BEGIN_RECORD;

View File

@@ -90,19 +90,19 @@ public class OrderItemReaderTests extends TestCase {
mapperControl = MockControl.createControl(FieldSetMapper.class);
mapper = (FieldSetMapper)mapperControl.getMock();
//set how mapper should respond - set return values for mapper
mapper.mapLine(headerFS);
mapper.mapLine(headerFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(order);
mapper.mapLine(customerFS);
mapper.mapLine(customerFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(customer);
mapper.mapLine(billingFS);
mapper.mapLine(billingFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(billing);
mapper.mapLine(shippingFS);
mapper.mapLine(shippingFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(shipping);
mapper.mapLine(billingInfoFS);
mapper.mapLine(billingInfoFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(billingInfo);
mapper.mapLine(shippingInfoFS);
mapper.mapLine(shippingInfoFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(shippingInfo);
mapper.mapLine(itemFS);
mapper.mapLine(itemFS, FieldSetMapper.ROW_NUMBER_UNKNOWN);
mapperControl.setReturnValue(item,3);
mapperControl.replay();

View File

@@ -1,10 +1,10 @@
package org.springframework.batch.sample.mapping;
import junit.framework.TestCase;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import junit.framework.TestCase;
/**
* Encapsulates basic logic for testing custom {@link FieldSetMapper} implementations.
*
@@ -35,7 +35,7 @@ public abstract class AbstractFieldSetMapperTests extends TestCase {
* Assumes the domain object implements sensible <code>equals(Object other)</code>
*/
public void testRegularUse() {
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet()));
assertEquals(expectedDomainObject(), fieldSetMapper().mapLine(fieldSet(), FieldSetMapper.ROW_NUMBER_UNKNOWN));
}
}

View File

@@ -40,11 +40,11 @@ public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests{
}
public void testBeginRecord() throws Exception {
assertEquals(AggregateItemReader.BEGIN_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"BEGIN"})));
assertEquals(AggregateItemReader.BEGIN_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"BEGIN"}), FieldSetMapper.ROW_NUMBER_UNKNOWN));
}
public void testEndRecord() throws Exception {
assertEquals(AggregateItemReader.END_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"END"})));
assertEquals(AggregateItemReader.END_RECORD, fieldSetMapper().mapLine(new DefaultFieldSet(new String[] {"END"}), FieldSetMapper.ROW_NUMBER_UNKNOWN));
}
}