Java Reference
In-Depth Information
Listing 9-3. Formatted Customer Output
Richard N Darrow lives at 5570 Isabella Ave in St. Louis, IL.
Warren L Darrow lives at 4686 Mt. Lee Drive in St. Louis, NY.
Barack G Donnelly lives at 7844 S. Greenwood Ave in Houston, CA.
Ann Z Benes lives at 2447 S. Greenwood Ave in Las Vegas, NY.
Laura 9S Minella lives at 8177 4th Street in Dallas, FL.
Erica Z Gates lives at 3141 Farnam Street in Omaha, CA.
Warren M Williams lives at 6670 S. Greenwood Ave in Hollywood, FL.
Harry T Darrow lives at 3273 Isabella Ave in Houston, FL.
Steve O Darrow lives at 8407 Infinite Loop Drive in Las Vegas, WA.
Erica Z Minella lives at 513 S. Greenwood Ave in Miami, IL.
How do you do this? For this example, you'll use a single step job that reads in the input file and
writes it to the output file; you don't need an ItemProcessor. Because the only code you need to write is
that for the Customer class, you can start there; see Listing 9-4.
Listing 9-4. Customer.java
package com.apress.springbatch.chapter9;
import java.io.Serializable;
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String firstName;
private String middleInitial;
private String lastName;
private String address;
private String city;
private String state;
private String zip;
// Accessors go here
...
}
As you can see in Listing 9-4, the fields of the Customer object map to the fields in the customer.csv
file. 1 With the item coded, you can begin configuring the job. 2 The input side should be familiar from
Chapter 7. Listing 9-5 shows the configuration of the input file as a resource (the value is passed in via a
job parameter), the FlatFileItemReader configuration, and the required reference to the Customer
object.
1 The Customer object has an id attribute that you use later; it has no data in the file.
2 As with all the previous examples in this topic, batch.properties for the project is the same as it was
using MySQL in Chapter 2. Also, unless otherwise specified, launch-context.xml is the same as well.
 
Search WWH ::




Custom Search