Java Reference
In-Depth Information
used to configure the
ItemReader,
ItemProcessor, and
ItemWriter to be
executed within a single
transaction.
completeItemProcessor, and
outputWriter.
The configuration for even a simple CompositeItemProcessor job is not short. However, the
amount of code you need to develop—and even more importantly the amount of code you need to write
that depends on Spring Batch—is minimal to none 3 .
By executing this job, Spring Batch will read in each of your customer records into Customer objects,
apply the logic of both ItemProcessors, and write out the Customer object to your output file for each
record. An example of the output generated by this batch job can be found in Listing 8-22.
Listing 8-22. Sample Output of the CompositeItemProcessor Example
Richard N Darrow lives at 5570 Isabella Ave St. Louis, IL 58540 and has Manuel Castro as
their account exec
Warren L Darrow lives at 4686 Mt. Lee Drive St. Louis, NY 94935 and has Manuel Castro as
their account exec
Ann Z Benes lives at 2447 S. Greenwood Ave Las Vegas, NY 55366 and has Manuel Castro as
their account exec
Laura S Johnson lives at 8177 4th Street Dallas, FL 04119 and has Manuel Castro as their
account exec
Erica Z Gates lives at 3141 Farnam Street Omaha, CA 57640 and has Manuel Castro as their
account exec
Harry T Darrow lives at 3273 Isabella Ave Houston, FL 97261 and has Anita Jordan as their
account exec
The CompositeItemProcessor allows you to apply multiple flows of logic to each item within a
transaction. This approach gives you the opportunity to keep your logical concerns separate for
maintainability and reuse.
In the next section, you will look at writing your own ItemProcessor to filter items from the
ItemWriter. Although you have written your own ItemProcessors in this section, you have passed all of
the records you received to the writer up to this point. In the next section, you will look at how to change
that.
Writing Your Own ItemProcessor
The ItemProcessor is really the easiest piece of the Spring Batch framework to implement yourself. This
is by design. Input and output is standard across environments and business cases. Reading a file is the
same regardless of if it contains financial data or scientific data. Writing to a database works the same
3 You could have implemented the CustomerItemProcessor and the AccountExecutiveItemProcessors as
services and used the ItemProcessorAdapter to reference them. This approach would isolate your code
completely from the Spring Batch framework.
 
Search WWH ::




Custom Search