Java Reference
In-Depth Information
public class Statement {
private Customer customer;
private BigDecimal securityTotal;
private List<Transaction> stocks;
// Accessors go here
The Statement object consists of the customer's information to display on the statement. It also
includes the total value of all the stocks the customer currently holds (the total is easier to get in the
database than it is to calculate as you process the statements). Finally, it contains a list the stock
holdings the customer currently has. It's important to note that the list of Transaction objects isn't a list
of all the customer's actual transactions—you're just reusing an existing domain object because the
format is similar.
Because you now know what you need to populate, you can begin to look at how to populate it.
When you're designing a complex ItemReader structure like this, begin by thinking about what the item
is. In this case, the item or single unit to be processed is the statement. Because of that, your ItemReader
returns a Statement object.
By looking at the Statement class in Listing 10-41, you can tell that given the complexity of the data,
using a single ItemReader is not going to be practical. Instead, to read the statement data, you layer
ItemReaders as you've done in the past. You use a regular JDBC ItemReader to read the customer data.
Although you could use a DAO, because each statement is based on a Customer anyway, using an
ItemReader makes more sense. From there, you can use DAOs to populate the related data.
However, notice that the Statement has no data. Everything is associated with the Statement , but
nothing is Statement specific. Because of that, you use a custom ItemReader to aggregate all the
datasources. To start, let's look at the code for the custom ItemReader, CustomerStatementReader (see
Listing 10-42).
Listing 10-42. CustomerStatementReader
package com.apress.springbatch.statement.reader;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import com.apress.springbatch.statement.dao.TickerDao;
import com.apress.springbatch.statement.domain.Customer;
import com.apress.springbatch.statement.domain.Statement;
public class CustomerStatementReader implements ItemReader<Statement> {
private ItemReader<Customer> customerReader;
private TickerDao tickerDao;
public Statement read() throws Exception, UnexpectedInputException,
ParseException {
Customer customer =;
Search WWH ::

Custom Search