Java Reference
In-Depth Information
</job>
The configuration for the ItemWriters is about what you would expect. You begin the configuration
with the configuration of the output file ( outputFile ). From there, the XML writer you're using
( xmlOutputWriter ) is configured as in the example earlier on in the chapter. The JDBC ItemWriter is next,
with the prepared statement configured and an ItemPreparedStatementSetter configured to set the
values onto the PreparedStatement . Finally you get to the CompositeItemWriter definition
( customerCompositeWriter ). For customerCompositeWriter , you configure a list of ItemWriters for the
wrapper to call. It's important to note that the ItemWriters is called in the order they're configured with
all of the items in a chunk. So if there are 10 items in a chunk, the first ItemWriter is called with all 10
items followed by the next ItemWriter and so on. It's important to note that although the execution of
the writing is serial (one writer at a time), all of the writes across all of the ItemWriters occur in the same
transaction. Because of that, if an item fails to be written at any point in the chunk, the entire chunk is
rolled back.
When you run this job as configured via the command java -jar itemWriters-0.0.1-SNAPSHOT.jar
jobs/formatJob.xml formatJob customerFile=/input/customerWithEmail.csv
outputFile=/output/xmlCustomer.xml , you can see that the output consists of all the records being
written to both the database and an XML file. You would think that if the file had 100 customers in it,
Spring Batch would consider this to be 200 writes. But if you look at what Spring Batch recorded in the
JobRepository, it says that 100 writes were executed, as shown in Figure 9-12.
Details for Step Execution
Figure 9-12. Spring Batch Admin recording of writing 100 customers
 
Search WWH ::




Custom Search