@Override public LineItem mapFieldSet(FieldSet fieldSet) { LineItem item = new LineItem(); item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN)); item.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN)); item.setDiscountPerc(fieldSet.readBigDecimal(DISCOUNT_PERC_COLUMN)); item.setDiscountAmount(fieldSet.readBigDecimal(DISCOUNT_AMOUNT_COLUMN)); item.setShippingPrice(fieldSet.readBigDecimal(SHIPPING_PRICE_COLUMN)); item.setHandlingPrice(fieldSet.readBigDecimal(HANDLING_PRICE_COLUMN)); item.setQuantity(fieldSet.readInt(QUANTITY_COLUMN)); item.setTotalPrice(fieldSet.readBigDecimal(TOTAL_PRICE_COLUMN)); return item; } }
@Override public CustomerUpdate mapFieldSet(FieldSet fs) { if (fs == null) { return null; } CustomerOperation operation = CustomerOperation.fromCode(fs.readChar(0)); String name = fs.readString(1); BigDecimal credit = fs.readBigDecimal(2); return new CustomerUpdate(operation, name, credit); }
Trade(FieldSet fieldSet) { this.isin = fieldSet.readString(0); this.quantity = fieldSet.readLong(1); this.price = fieldSet.readBigDecimal(2); }
@Override public CustomerCredit mapFieldSet(FieldSet fieldSet) { CustomerCredit trade = new CustomerCredit(); trade.setId(fieldSet.readInt(ID_COLUMN)); trade.setName(fieldSet.readString(NAME_COLUMN)); trade.setCredit(fieldSet.readBigDecimal(CREDIT_COLUMN)); return trade; } }
order.setTotalPrice(fieldSet.readBigDecimal("TOTAL_PRICE")); order.setTotalLines(fieldSet.readInt("TOTAL_LINE_ITEMS")); order.setTotalItems(fieldSet.readInt("TOTAL_ITEMS"));
@Override public Trade mapFieldSet(FieldSet fieldSet) { Trade trade = new Trade(); trade.setIsin(fieldSet.readString(ISIN_COLUMN)); trade.setQuantity(fieldSet.readLong(QUANTITY_COLUMN)); trade.setPrice(fieldSet.readBigDecimal(PRICE_COLUMN)); trade.setCustomer(fieldSet.readString(CUSTOMER_COLUMN)); return trade; } }
/** * @see org.springframework.batch.item.ItemReader#read() */ @Override public Trade read() throws Exception { Trade t = null; for (FieldSet line; (line = this.delegate.read()) != null;) { String prefix = line.readString(0); if (prefix.equals("BEGIN")) { t = new Trade(); // Record must start with 'BEGIN' } else if (prefix.equals("INFO")) { Assert.notNull(t, "No 'BEGIN' was found."); t.setIsin(line.readString(1)); t.setCustomer(line.readString(2)); } else if (prefix.equals("AMNT")) { Assert.notNull(t, "No 'BEGIN' was found."); t.setQuantity(line.readInt(1)); t.setPrice(line.readBigDecimal(2)); } else if (prefix.equals("END")) { return t; // Record must end with 'END' } } Assert.isNull(t, "No 'END' was found."); return null; }
import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.validation.BindException; public class ProductFieldSetMapper implements org.springframework.batch.item.file.mapping.FieldSetMapper<Product> { public Product mapFieldSet(FieldSet fieldSet) throws BindException { Product product = new Product(); product.setId(fieldSet.readString("PRODUCT_ID")); product.setName(fieldSet.readString("NAME")); product.setDescription(fieldSet.readString("DESCRIPTION")); product.setPrice(fieldSet.readBigDecimal("PRICE")); return product; } }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { final Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { final Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }
public Product mapFieldSet(FieldSet fieldSet) throws BindException { Product product = new Product(); product.setId(fieldSet.readString("PRODUCT_ID")); product.setName(fieldSet.readString("NAME")); product.setDescription(fieldSet.readString("DESCRIPTION")); product.setPrice(fieldSet.readBigDecimal("PRICE")); return product; }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { final Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }
public Product mapFieldSet(FieldSet fieldSet) { Product product = new Product(); product.setId(fieldSet.readString("id")); product.setName(fieldSet.readString("name")); product.setDescription(fieldSet.readString("description")); product.setPrice(fieldSet.readBigDecimal("price")); return product; } }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { final Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }
@Override public Payment mapFieldSet(FieldSet fieldSet) throws BindException { final Payment payment = new Payment(); payment.setSourceAccountNo(fieldSet.readString("source")); payment.setDestinationAccountNo(fieldSet.readString("destination")); payment.setAmount(fieldSet.readBigDecimal("amount")); payment.setDate(fieldSet.readDate("date")); return payment; } }