IN PROGRESS - BATCH-712: Upgrade ItemReaders and ItemWriters to use Parameterized types
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.batch.item.support.DelegatingItemReader;
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class ExceptionThrowingItemReaderProxy extends DelegatingItemReader {
|
||||
public class ExceptionThrowingItemReaderProxy extends DelegatingItemReader<Object> {
|
||||
|
||||
private int counter = 0;
|
||||
private int throwExceptionOnRecordNumber = 4;
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.springframework.batch.sample.domain.Trade;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class GeneratingItemReader implements ItemReader, ItemRecoverer {
|
||||
public class GeneratingItemReader implements ItemReader<Trade>, ItemRecoverer {
|
||||
|
||||
private int limit = 1;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class GeneratingItemReader implements ItemReader, ItemRecoverer {
|
||||
|
||||
private int marked;
|
||||
|
||||
public Object read() throws Exception {
|
||||
public Trade read() throws Exception {
|
||||
if (counter < limit) {
|
||||
counter++;
|
||||
return new Trade(
|
||||
|
||||
@@ -35,30 +35,30 @@ import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
* @author peter.zozom
|
||||
*
|
||||
*/
|
||||
public class OrderItemReader extends DelegatingItemReader {
|
||||
public class OrderItemReader extends DelegatingItemReader<Order> {
|
||||
private static Log log = LogFactory.getLog(OrderItemReader.class);
|
||||
|
||||
private Order order;
|
||||
|
||||
private boolean recordFinished;
|
||||
|
||||
private FieldSetMapper headerMapper;
|
||||
private FieldSetMapper<Order> headerMapper;
|
||||
|
||||
private FieldSetMapper customerMapper;
|
||||
private FieldSetMapper<Customer> customerMapper;
|
||||
|
||||
private FieldSetMapper addressMapper;
|
||||
private FieldSetMapper<Address> addressMapper;
|
||||
|
||||
private FieldSetMapper billingMapper;
|
||||
private FieldSetMapper<BillingInfo> billingMapper;
|
||||
|
||||
private FieldSetMapper itemMapper;
|
||||
private FieldSetMapper<LineItem> itemMapper;
|
||||
|
||||
private FieldSetMapper shippingMapper;
|
||||
private FieldSetMapper<ShippingInfo> shippingMapper;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
public Object read() throws Exception {
|
||||
public Order read() throws Exception {
|
||||
recordFinished = false;
|
||||
|
||||
while (!recordFinished) {
|
||||
@@ -67,7 +67,7 @@ public class OrderItemReader extends DelegatingItemReader {
|
||||
|
||||
log.info("Mapped: " + order);
|
||||
|
||||
Object result = order;
|
||||
Order result = order;
|
||||
order = null;
|
||||
|
||||
return result;
|
||||
@@ -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, -1);
|
||||
order = headerMapper.mapLine(fieldSet, -1);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class OrderItemReader extends DelegatingItemReader {
|
||||
log.debug("MAPPING CUSTOMER");
|
||||
|
||||
if (order.getCustomer() == null) {
|
||||
order.setCustomer((Customer) customerMapper.mapLine(fieldSet, -1));
|
||||
order.setCustomer(customerMapper.mapLine(fieldSet, -1));
|
||||
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, -1));
|
||||
order.setCustomer(customerMapper.mapLine(fieldSet, -1));
|
||||
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, -1));
|
||||
order.setBillingAddress(addressMapper.mapLine(fieldSet, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Address.LINE_ID_SHIPPING_ADDR.equals(lineId)) {
|
||||
log.debug("MAPPING SHIPPING ADDRESS");
|
||||
order.setShippingAddress((Address) addressMapper.mapLine(fieldSet, -1));
|
||||
order.setShippingAddress(addressMapper.mapLine(fieldSet, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (BillingInfo.LINE_ID_BILLING_INFO.equals(lineId)) {
|
||||
log.debug("MAPPING BILLING INFO");
|
||||
order.setBilling((BillingInfo) billingMapper.mapLine(fieldSet, -1));
|
||||
order.setBilling(billingMapper.mapLine(fieldSet, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (ShippingInfo.LINE_ID_SHIPPING_INFO.equals(lineId)) {
|
||||
log.debug("MAPPING SHIPPING INFO");
|
||||
order.setShipping((ShippingInfo) shippingMapper.mapLine(fieldSet, -1));
|
||||
order.setShipping(shippingMapper.mapLine(fieldSet, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public class OrderItemReader extends DelegatingItemReader {
|
||||
if (order.getLineItems() == null) {
|
||||
order.setLineItems(new ArrayList<LineItem>());
|
||||
}
|
||||
order.getLineItems().add((LineItem) itemMapper.mapLine(fieldSet, -1));
|
||||
order.getLineItems().add(itemMapper.mapLine(fieldSet, -1));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -173,27 +173,27 @@ public class OrderItemReader extends DelegatingItemReader {
|
||||
|
||||
}
|
||||
|
||||
public void setAddressMapper(FieldSetMapper addressMapper) {
|
||||
public void setAddressMapper(FieldSetMapper<Address> addressMapper) {
|
||||
this.addressMapper = addressMapper;
|
||||
}
|
||||
|
||||
public void setBillingMapper(FieldSetMapper billingMapper) {
|
||||
public void setBillingMapper(FieldSetMapper<BillingInfo> billingMapper) {
|
||||
this.billingMapper = billingMapper;
|
||||
}
|
||||
|
||||
public void setCustomerMapper(FieldSetMapper customerMapper) {
|
||||
public void setCustomerMapper(FieldSetMapper<Customer> customerMapper) {
|
||||
this.customerMapper = customerMapper;
|
||||
}
|
||||
|
||||
public void setHeaderMapper(FieldSetMapper headerMapper) {
|
||||
public void setHeaderMapper(FieldSetMapper<Order> headerMapper) {
|
||||
this.headerMapper = headerMapper;
|
||||
}
|
||||
|
||||
public void setItemMapper(FieldSetMapper itemMapper) {
|
||||
public void setItemMapper(FieldSetMapper<LineItem> itemMapper) {
|
||||
this.itemMapper = itemMapper;
|
||||
}
|
||||
|
||||
public void setShippingMapper(FieldSetMapper shippingMapper) {
|
||||
public void setShippingMapper(FieldSetMapper<ShippingInfo> shippingMapper) {
|
||||
this.shippingMapper = shippingMapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
||||
* Thread-safe database {@link ItemReader} implementing the process indicator
|
||||
* pattern.
|
||||
*/
|
||||
public class StagingItemReader extends JdbcDaoSupport implements ItemStream, ItemReader, StepExecutionListener {
|
||||
public class StagingItemReader<T> extends JdbcDaoSupport implements ItemStream, ItemReader<T>, StepExecutionListener {
|
||||
|
||||
// Key for buffer in transaction synchronization manager
|
||||
private static final String BUFFER_KEY = StagingItemReader.class.getName() + ".BUFFER";
|
||||
@@ -106,13 +106,14 @@ public class StagingItemReader extends JdbcDaoSupport implements ItemStream, Ite
|
||||
|
||||
}
|
||||
|
||||
public Object read() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
public T read() throws Exception {
|
||||
Long id = doRead();
|
||||
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
Object result = getJdbcTemplate().queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
|
||||
T result = (T) getJdbcTemplate().queryForObject("SELECT VALUE FROM BATCH_STAGING WHERE ID=?",
|
||||
new Object[] { id }, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
byte[] blob = lobHandler.getBlobAsBytes(rs, 1);
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.batch.sample.domain.Address;
|
||||
|
||||
|
||||
|
||||
public class AddressFieldSetMapper implements FieldSetMapper {
|
||||
public class AddressFieldSetMapper implements FieldSetMapper<Address> {
|
||||
|
||||
public static final String ADDRESSEE_COLUMN = "ADDRESSEE";
|
||||
public static final String ADDRESS_LINE1_COLUMN = "ADDR_LINE1";
|
||||
@@ -33,7 +33,7 @@ public class AddressFieldSetMapper implements FieldSetMapper {
|
||||
public static final String COUNTRY_COLUMN = "COUNTRY";
|
||||
|
||||
|
||||
public Object mapLine(FieldSet fieldSet, int lineNum) {
|
||||
public Address mapLine(FieldSet fieldSet, int lineNum) {
|
||||
Address address = new Address();
|
||||
|
||||
address.setAddressee(fieldSet.readString(ADDRESSEE_COLUMN));
|
||||
|
||||
@@ -22,12 +22,12 @@ import org.springframework.batch.sample.domain.BillingInfo;
|
||||
|
||||
|
||||
|
||||
public class BillingFieldSetMapper implements FieldSetMapper {
|
||||
public class BillingFieldSetMapper implements FieldSetMapper<BillingInfo> {
|
||||
|
||||
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, int lineNum) {
|
||||
public BillingInfo mapLine(FieldSet fieldSet, int lineNum) {
|
||||
BillingInfo info = new BillingInfo();
|
||||
|
||||
info.setPaymentId(fieldSet.readString(PAYMENT_TYPE_ID_COLUMN));
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.batch.sample.domain.Customer;
|
||||
|
||||
|
||||
|
||||
public class CustomerFieldSetMapper implements FieldSetMapper {
|
||||
public class CustomerFieldSetMapper implements FieldSetMapper<Customer> {
|
||||
|
||||
public static final String LINE_ID_COLUMN = "LINE_ID";
|
||||
public static final String COMPANY_NAME_COLUMN = "COMPANY_NAME";
|
||||
@@ -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, int lineNum) {
|
||||
public Customer mapLine(FieldSet fieldSet, int lineNum) {
|
||||
Customer customer = new Customer();
|
||||
|
||||
if (Customer.LINE_ID_BUSINESS_CUST.equals(fieldSet.readString(LINE_ID_COLUMN))) {
|
||||
|
||||
@@ -4,9 +4,9 @@ import org.springframework.batch.item.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Game;
|
||||
|
||||
public class GameFieldSetMapper implements FieldSetMapper {
|
||||
public class GameFieldSetMapper implements FieldSetMapper<Game> {
|
||||
|
||||
public Object mapLine(FieldSet fs, int lineNum) {
|
||||
public Game mapLine(FieldSet fs, int lineNum) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
|
||||
@@ -22,12 +22,12 @@ import org.springframework.batch.sample.domain.Order;
|
||||
|
||||
|
||||
|
||||
public class HeaderFieldSetMapper implements FieldSetMapper {
|
||||
public class HeaderFieldSetMapper implements FieldSetMapper<Order> {
|
||||
|
||||
public static final String ORDER_ID_COLUMN = "ORDER_ID";
|
||||
public static final String ORDER_DATE_COLUMN = "ORDER_DATE";
|
||||
|
||||
public Object mapLine(FieldSet fieldSet, int lineNum) {
|
||||
public Order mapLine(FieldSet fieldSet, int lineNum) {
|
||||
Order order = new Order();
|
||||
order.setOrderId(fieldSet.readLong(ORDER_ID_COLUMN));
|
||||
order.setOrderDate(fieldSet.readDate(ORDER_DATE_COLUMN));
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.LineItem;
|
||||
|
||||
|
||||
public class OrderItemFieldSetMapper implements FieldSetMapper {
|
||||
public class OrderItemFieldSetMapper implements FieldSetMapper<LineItem> {
|
||||
|
||||
public static final String TOTAL_PRICE_COLUMN = "TOTAL_PRICE";
|
||||
public static final String QUANTITY_COLUMN = "QUANTITY";
|
||||
@@ -33,7 +33,7 @@ public class OrderItemFieldSetMapper implements FieldSetMapper {
|
||||
public static final String ITEM_ID_COLUMN = "ITEM_ID";
|
||||
|
||||
|
||||
public Object mapLine(FieldSet fieldSet, int lineNum) {
|
||||
public LineItem mapLine(FieldSet fieldSet, int lineNum) {
|
||||
LineItem item = new LineItem();
|
||||
|
||||
item.setItemId(fieldSet.readLong(ITEM_ID_COLUMN));
|
||||
|
||||
@@ -4,9 +4,9 @@ import org.springframework.batch.item.file.mapping.FieldSet;
|
||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.sample.domain.Player;
|
||||
|
||||
public class PlayerFieldSetMapper implements FieldSetMapper {
|
||||
public class PlayerFieldSetMapper implements FieldSetMapper<Player> {
|
||||
|
||||
public Object mapLine(FieldSet fs, int lineNum) {
|
||||
public Player mapLine(FieldSet fs, int lineNum) {
|
||||
|
||||
if(fs == null){
|
||||
return null;
|
||||
|
||||
@@ -22,13 +22,13 @@ import org.springframework.batch.sample.domain.ShippingInfo;
|
||||
|
||||
|
||||
|
||||
public class ShippingFieldSetMapper implements FieldSetMapper {
|
||||
public class ShippingFieldSetMapper implements FieldSetMapper<ShippingInfo> {
|
||||
|
||||
public static final String ADDITIONAL_SHIPPING_INFO_COLUMN = "ADDITIONAL_SHIPPING_INFO";
|
||||
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, int lineNum) {
|
||||
public ShippingInfo mapLine(FieldSet fieldSet, int lineNum) {
|
||||
ShippingInfo info = new ShippingInfo();
|
||||
|
||||
info.setShipperId(fieldSet.readString(SHIPPER_ID_COLUMN));
|
||||
|
||||
Reference in New Issue
Block a user