Java Reference
In-Depth Information
</beans:bean>
<beans:bean id="customerTransactionItemWriter"
class="org.springframework.batch.item.support.ClassifierCompositeItemWriter">
<beans:property name="classifier">
<beans:bean class="org.springframework.batch.classify.SubclassClassifier">
<beans:property name="typeMap">
<beans:map>
<beans:entry key="com.apress.springbatch.statement.domain.Customer"
value-ref="customerImportWriter"/>
<beans:entry key="com.apress.springbatch.statement.domain.Transaction"
value-ref="transactionImportWriter"/>
</beans:map>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
Each of the JdbcBatchItemWriters as shown in Listing 10-18 provides the same three dependencies.
First, they provide a datasource to be able to connect to the database. Second, they provide the SQL to
be executed for each item. In both cases, you provide a statement using named parameters. This allows
you to use BeanPropertyItemSqlParameterSourceProvider as your third dependency to set the values for
PreparedStatement .
Note The BeanPropertyItemSqlParameterSourceProvider supports dot notation when referring to the
properties to be set in your SQL, such as address.city and address.state .
The last element of this step's configuration is the driver for the ItemWriters,
customerTransactionItemWriter . This ItemWriter sends all items of type Customer to
customerImportWriter and all items of type Transaction to the writer transactionImportWriter . Although
it isn't used in this example, SubclassClassifier does what it says in that it identifies not only by type but
by subtype as well. If you had items that extended Customer ( VIPCustomer , for example), those would be
routed to customerImportWriter as well.
Believe it or not, that is all you need to be able to import the customer transaction file. If you build
the project right now using the mvn clean install command from the root of the project, and then
execute it, you see that your customer records are updated, the transactions are imported, and all the
stocks that have been traded have a single record in the Ticker table.
The next section looks at the next step, which consists of downloading the current prices for each of
the stocks you just imported.
Downloading Current Stock Prices
After you've imported the transactions, you can get the current prices of all the stocks your customers
currently hold. This allows you to generate a statement that accurately displays what your customers'
current investments are worth. This section looks at how to download the current prices for the stocks
your customers hold.
 
Search WWH ::




Custom Search