Java Reference
In-Depth Information
curCustomer.setId(storedCustomer.getId());
curCustomer.setAccount(account);
}
public void setCustomerDao(CustomerDao customerDao) {
this.customerDao = customerDao;
}
public void setTickerDao(TickerDao tickerDao) {
this.tickerDao = tickerDao;
}
public void setAccountDao(AccountDao accountDao) {
this.accountDao = accountDao;
}
}
Listing 10-13 looks like it has quite a bit going on, but it's really not that bad. Like any
ItemProcessor, the logic begins in the
process
method. Here you determine what type of item you're
processing and pass it to the appropriate method to update that type.
For a
Customer
object, you look up the customer's database id and update the
Customer
object with
it. You do the same for the customer's
Account
object before you return it to be written. For a
Transaction
object, you update the
ticker
object's id if the ticker is already in the database. If it isn't,
you save it to the database for future objects to reference. You also update the account id on the
Transaction
object as well as identify the type of transaction before you return it to be written.
CustomerLookupItemProcessor
requires a few data access objects (DAOs) to look up the ids you
populate. First is
CustomerDaoJdbc
, which looks up the customer's id (see Listing 10-14).
Listing 10-14.
CustomerDaoJdbc
package com.apress.springbatch.statement.dao.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import com.apress.springbatch.statement.dao.CustomerDao;
import com.apress.springbatch.statement.domain.Address;
import com.apress.springbatch.statement.domain.Customer;
public class CustomerDaoJdbc extends JdbcTemplate implements CustomerDao {
private static final String FIND_BY_TAX_ID = "select * from customer c where ssn = ?";
@SuppressWarnings("unchecked")
public Customer findCustomerByTaxId(String taxId) {
List<Customer> customers = query(FIND_BY_TAX_ID,
new Object[] { taxId }, new RowMapper() {