Java Reference
In-Depth Information
goal, the example includes elements that may seem a bit complex right now, such as headers, multiple
file format imports, and complex output including subheadings. The reason is that Spring Batch
provides facilities exactly for these features. Let's dig into how you structure this batch process by
outlining the job and describing its steps.
Job Description
In order to implement the statement-generation process, you build a single job with six steps. Figure 3-3
shows the flow of the batch job for this process, and the following sections describe the steps.
Import Customer
and Transaction
Retrieve Stock
Import Stock
Calculate Tiers
Figure 3-3. Stock statement jobflow
Importing Customer Transaction Data
To start the job, you begin by importing the customer and transaction data. Contained in a flat file, this
data has a complex format consisting of two record types. The first record type is that of the customer,
consisting of the customer's name, address, and account information. The second record type consists
of detailed information about each transaction, including the stock ticker, the price paid, the quantity
purchased or sold, and the timestamp when the transaction occurred. Using Spring Batch's ability to
read multiline records allows you to process this file with minimal coding. You write a data access object
(DAO) for the JDBC persistence of the imported data, as shown in Listing 3-1.
Listing 3-1. Customer/Transaction Input File
392041928,William,Robinson,9764 Jeopardy Lane,Chicago,IL,60606
938472047,Robert,Johnson,1060 Addison St,Chicago,IL,60657
Retrieving Stock Closing Prices
After you've imported the customer's information and transactions, you move on to obtaining the stock
price information. This is a simple step that retrieves all the closing values for the stocks that have been
traded over the previous month. To do this, you create a tasklet (as you did last chapter for the Hello,
World batch process) to call the Yahoo web service specified in the requirements, and you download a
CSV with the required stock data. This step writes the output to a file similar to that in Listing 3-2, for the
next step to process.
Listing 3-2. Stock Closing Price Input File
Search WWH ::

Custom Search