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
Data
Calculate
Transaction
Fees
Retrieve Stock
Prices
Import Stock
Prices
Generate
Statements
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
HD,31.09,200,08:38:05
WMT,53.38,500,09:25:55
ADI,35.96,-300,10:56:10
REGN,29.53,-500,10:56:22
938472047,Robert,Johnson,1060 Addison St,Chicago,IL,60657
CABN,0.890,10000,14:52:15
NUAN,17.11,15000,15:02:45
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
SHLD,71.98
 
 
Search WWH ::




Custom Search