Java Reference
In-Depth Information
Figure 8-2. CompositeItemProcessor processing
As Figure 8-2 shows, the CompositeItemProcessor serves as a wrapper for multiple ItemProcessors,
calling them in order. As one completes, the next one is called with the item returned from the previous
one. Let's take a look at how this looks in practice.
In this example, you are going to take a Customer item that was read in from an input file, look it up
in the database to get its database ID in the first ItemProcessor, and then pass it onto a second
ItemProcessor to lookup its AccountExecutive. You will update the Customer object with its
AccountExecutive reference and pass that to the writer to be written to a file.
The data model for this example will be the same as the one you used in the ItemProcessorAdapter
example, consisting of two tables: a customer table containing all of the basic customer information
(name and address) as well as a reference to an account executive. For this example, the account
executive will consist only of its name.
As mentioned, this step will first look up the customer and set the ID on the customer, then look up
the customer's account executive and update the item with that as well. In both cases, the
ItemProcessor really does nothing more than do a database lookup and update the item appropriately.
Let's look at the first ItemProcessor, the CustomerItemProcessor. Listing 8-17 shows the code involved.
Listing 8-17. CustomerItemProcessor
package com.apress.springbatch.chapter8;
import org.springframework.batch.item.ItemProcessor;
public class CustomerItemProcessor implements ItemProcessor<Customer, Customer> {
private CustomerDao customerDao;
public Customer process(Customer customer) {
Customer currentCustomer =
return customer;
public void setCustomerDao(CustomerDao customerDao) {
Search WWH ::

Custom Search