Java Reference
In-Depth Information
Datasource : There are many ways to obtain a datasource in Spring. In this case,
defining one using Spring's BasicDataSource suffices. The values for the JDBC
connection are stored in the file, which you update next.
TransactionManager : When you begin reading data from and writing data to the
database, this becomes a more important piece of the Spring Batch puzzle.
Because you run this locally and with a single datasource, Spring JDBC's
DataSourceTransactionManager does nicely.
PlaceholderProperties : This bean handles the loading and population of any
properties you choose to extract into your file. For now, the only
things you configure are the JDBC connection values.
With that, the setup of the statement job's project is complete. You now have an empty Spring Batch
project: the database is configured to point to your database, and all the example code that is included
has been removed.
Because Spring Batch jobs are designed to consist of steps that are independent of each other, you
can develop them in their entirety independently. Over the course of the remainder of this chapter, you
will develop the statement job using the project structure you just configured, the requirements
discussed earlier this chapter and in Chapter 3, and the knowledge you've gained over the course of this
book. The first step in the job is importing the customer and transaction data which is covered next.
Importing Customer and Transaction Data
As the job begins, it receives a file from another department that contains information about your
customers and their transactions. Both types of data are included in the same CSV file. This section looks
at how to configure the step to import the customer and transaction data into your database.
Before you get into the code, however, let's review the data model used for this job. The data model
for this job consists of four tables. The Customer table contains all customer-related data including
name, address, and Social Security number. Each customer is associated with an account in the Account
table. The Account table contains information about how much cash a customer has in their account as
well as the pricing tier they have been calculated to be part of for the month. As you would expect, the
account has a one-to-many relationship to the Transaction table. Each of the customer's trades has a
record in the Transaction table. The Transaction table contains information about the trade itself: the
stock that was traded, how many shares were traded, how much the fee was, and so on. The final table is
the Ticker table. This table is used to abstract the current values of each stock. Figure 10-3 shows the
data model for the statement job.
Figure 10-3. Data model for the statement job
Search WWH ::

Custom Search