Java Reference
In-Depth Information
generator.nextInt(middleInitial.length() - 1))));
customer.setLastName(
lastNames[generator.nextInt(lastNames.length - 1)]);
customer.setAddress(generator.nextInt(9999) + " " +
streets[generator.nextInt(streets.length - 1)]);
customer.setCity(cities[generator.nextInt(cities.length - 1)]);
customer.setState(states[generator.nextInt(states.length - 1)]);
customer.setZip(String.valueOf(generator.nextInt(99999)));
return customer;
}
public Customer getCustomer() {
Customer cust = null;
if(curIndex < customers.size()) {
cust = customers.get(curIndex);
curIndex++;
}
return cust;
}
}
Finally, to use the service you have developed in Listing 7-54, using the ItemReaderAdapter, you
configure your customerItemReader to call the getCustomer method for each item. Listing 7-55 shows
the configuration for this.
Listing 7-55. Configuring the ItemReaderAdapter to Call the CustomerService
<beans:bean id="customerItemReader"
class="org.springframework.batch.item.adapter.ItemReaderAdapter">
<beans:property name="targetObject" ref="customerService"/>
<beans:property name="targetMethod" value="getCustomer"/>
</beans:bean>
<beans:bean id="customerService"
class="com.apress.springbatch.chapter7.CustomerService"/>
That's all that is required to use one of your existing services as the source of data for your batch job.
Using existing services can allow you to reuse code that is tested and proven instead of running the risk
of introducing new bugs by rewriting existing processes.
Spring Batch provides a wide array of ItemReader implementations, many of which you have
covered up to now. However, there is now way the developers of the framework can plan for every
possible scenario. Because of this, they provide the facilities for you to create your own ItemReader
implementations. The next section will look at how to implement your own custom ItemReader.
 
Search WWH ::




Custom Search