Java Reference
In-Depth Information
<beans:property name="delimiter" value=","/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<beans:property name="prototypeBeanName" value="stock"/>
</beans:bean>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
<beans:bean id="stock" class="com.apress.springbatch.statement.domain.Ticker"
scope="prototype"/>
<step id="importStockPrices">
<tasklet>
<chunk reader="stockFileReader" writer="tickerUpdateWriter" commit-interval="100"/>
</tasklet>
</step>
<job id="statementJob" incrementer="idIncrementer">
<step id="step1" parent="importCustomerAndTransactionData" next="step2"/>
<step id="step2" parent="retrieveStockPrices" next="step3"/>
<step id="step3" parent="importStockPrices"/>
</job>
With this reader configured, you can now obtain the closing prices for all the stocks your customers
currently hold as well as read in the output you receive from the web service so that you can import it
into your database. In the next section, you look at how to update the database with the stock prices you
received in step 2.
Writing Stock Prices to the Database
With the ability to read stock prices in from your file configured, you can move to updating the database
with the values you read. This section looks at the configuration for the ItemWriter required to import
the stock prices you download in step 2.
In the previous section, you used a FlatFileItemReader to read in the CSV generated in step 2. To
update the tickers stored as part of the process of updating the Transaction in step 1, you again use a
simple JdbcBatchItemWriter to update the currentPrice column of the Ticker table. Listing 10-27 shows
the configuration of the ItemWriter required for this step.
Listing 10-27. tickerUpdateItemWriter Configuration
...
<beans:bean id="tickerUpdateWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
 
Search WWH ::




Custom Search