Java Reference
In-Depth Information
it. To be able to map your input file to an object model that represents this data model effectively, you
need to use a layered approach to building your reader. Figure 10-4 shows how these layers stack up.
Figure 10-4. How the CustomerFileReader is structured
There are two essential layers for this reader. The first major layer, the FlatFileItemReader, works
with the strings that make up the file you read in. This layer is responsible for parsing each record into
objects that you can use in your batch process. The other layer, represented by the CustomerFileReader,
is responsible for associating the objects in the correct way. You've looked at these different types of
readers previously when you examined delimited files and files with multiple record formats in Chapter
7. Let's start by parsing the basics ( Customer and Transaction ). From there, you can add the abstraction
of the Account and Address objects and associate them together.
The first layer of this reader, which handles parsing records, is very similar to the example for
multiple record formats in Chapter 7. Before you begin parsing the records, Listing 10-7 shows the
Customer and Transaction domain objects into which you parse the records.
Listing 10-7. Customer and Transaction
package com.apress.springbatch.statement.domain;
public class Customer {
private long id = -1l;
private String firstName;
private String lastName;
private Address address;
private Account account;
private String taxId;
// Accessors removed
public String toString() {
String output = "Customer number " + id + ", " + firstName + " " + lastName;
if(address != null) {
output = output + " who lives in "
+ address.getCity() + "," + address.getState();
if(account != null && account.getTransactions() != null) {
output = output + " has "
Search WWH ::

Custom Search