Java Reference
In-Depth Information
directory in a file called
statementJob
. This file for now contains the configuration for a single job
(
statementJob
) with the first step configured. Listing 10-6 shows the configuration to start with.
Listing 10-6.
statementJob.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="
http://www.springframework.org/schema/batch"
xmlns:beans="
http://www.springframework.org/schema/beans"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="
http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
<beans:import resource="../launch-context.xml"/>
<step id="importCustomerAndTransactionData">
<tasklet>
<chunk reader="customerTransactionReader" processor="customerLookupItemProcessor"
writer="customerTransactionItemWriter" commit-interval="100"/>
</tasklet>
</step>
<job id="statementJob">
<step id="step1" parent="importCustomerAndTransactionData"/>
</job>
</beans:beans>
There are a couple of things to notice right away. The first is that the file in Listing 10-6 won't work
by itself. As you can see, you configure the step
importCustomerAndTransactionData
to use an ItemReader
(
customerTransactionReader
), ItemProcessor (
customerLookupItemProcessor
), and ItemWriter
(
customerTransactionWriter
). Without these beans configured, the job won't run. The other thing to
notice is that you define a few more XSDs than are currently in use. Rest assured that by the end of the
chapter, they will all be used.
The configuration for the job as of right now consists of the inclusion of the
launch-context.xml
file,
which you looked at in Listing 10-4, and the definition of the first step
(
importCustomerAndTransactionData
) with its reader, processor and writer. Finally, it has the definition of
the job itself, the
statementJob
. To get development started, let's begin by creating the ItemReader,
customerTransactionReader
.
Creating the Customer Transaction Reader
When you consider the input file for this step as shown in Listing 10-5 and the data model you need to
translate that data into, it quickly becomes apparent that
customerTransactionReader
isn't a simple
FlatFileItemReader
. Instead, this ItemReader is built by assembling a number of different components.
This section looks at how to read in the input for the
importCustomerAndTransactionData
step.
The best way to think about
customerTransactionReader
is to visualize layers similar to your object
model. The customer object has an account object, and the account object has many transactions under