Java Reference
In-Depth Information
Importing Stock Prices into Database
This step reads the file and imports the data into the database. This step showcases the strengths of the
declarative I/O provided by Spring Batch. Both the input and output of this job require no code on your
part. Spring Batch provides the ability to read the CSV file you downloaded in the previous step via stock
components of the framework as well as to update the database.
You may wonder why you don't import the data directly. The reason is error handling. You're
importing data that was provided to you by a third-party source. Because you can't be sure of the quality
of the data, you need to be able to handle any errors that may occur during the import. By writing the
data to a file for a future step to process, you can restart the step without having to re-download the
stock prices.
Calculating Transaction Fee Tiers
Up to this point, you haven't had to do any real processing of the data you're reading and writing. All
you've done is pipe data from a file to a database (with some validation for good measure). When you're
finished importing the required data, you begin doing the required calculations. Your brokerage
company charges fees based on how much a customer trades. The more the customer trades, the less
they're charged per trade. The amounts customers are charged are assigned via tiers; each tier is defined
by the number of trades performed over the previous month and has a dollar amount associated with it.
In this step, you introduce an item processor between the reader and writer to determine the tier to
which the customer belongs. You declare the reader via XML to load the customer's trade information
and the writer to update the customer's account in the same manner.
Calculating Transaction Fees
When you've determined the tier for each customer, you can calculate the fee for each trade. In the
previous step, you processed records at the customer level, with each customer being assigned a tier. In
this step, you process records at the individual transaction level. As you can imagine, you process many
more records in this step than in any previous step; you examine this step in further detail later, when
the topic talks about scalability options. However, to start, this step looks almost exactly like the previous
one, but with different SQL for the reader, different logic in the item processor, and yet another
JdbcItemWriter for the writer.
Generating Customer Monthly Statements
The last step seems to be the most complex—but as you know, looks can be deceiving. This step involves
the generation of the statements themselves. It demonstrates some of the beauty of applying decoupled
solutions to batch problems. By providing a custom-coded formatter, you can do virtually all the work
with a single simple class. This step also uses the callbacks for the headers.
All of this sounds great in theory but leaves a lot of questions to be answered. That's good. You'll
spend the rest of the topic working through how these features are implemented in the processes as well
as examining things like exception handling and restart/retry logic. One final item you should be familiar
Search WWH ::

Custom Search