Java Reference
In-Depth Information
JdbcBatchItemWriter
ClassifierComposite
ItemWriter
FlatFileItemReader
ItemProcessor
JdbcBatchItemWriter
Figure 10-5. Structure of the importCustomerAndTransaction step
Figure 10-5 shows that you have the FlatFileItemReader and your implementation of the
ItemProcessor ( CustomerLookupItemProcessor ). It also shows that you define three ItemWriters for this
step: customerImportWriter as a JdbcBatchItemWriter; followed by the transactionImportWriter , which
is also a JdbcBatchItemWriter; and the ClassifierCompositeItemWriter defined by the bean
customerTransactionItemWriter , which wraps those two ItemWriters. This maps Customer items to one
writer and Transaction items to the other.
The nice part about this step's writers is that they require zero code. The JdbcBatchItemWriters both
look the same except for the SQL being used. For customerImportWriter , you use an update statement
because this step only updates existing customers' information and doesn't add new customers.
However, for transactionImportWriter , you insert each one new, so it uses an insert statement as
expected. Listing 10-18 shows the configuration for all three of this step's ItemWriters.
Listing 10-18. ItemWriters for the Customer and Transaction Import as Configured in statementJob.xml
<beans:bean id="customerImportWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="update customer set firstName = :firstName, lastName = :lastName, address1 =
:address.address1, city = :address.city, state = :address.state, zip = :address.zip where ssn
= :taxId"/>
<beans:property name="itemSqlParameterSourceProvider">
<beans:bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider"/>
</beans:property>
</beans:bean>
<beans:bean id="transactionImportWriter"
class="org.springframework.batch.item.database.JdbcBatchItemWriter">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql"
value="insert into transaction (transactionType, executedTime, dollarAmount, qty,
tickerId, account_id) values (:type.intValue, :tradeTimestamp, :dollarAmount, :quantity,
:tickerId, :accountId)"/>
<beans:property name="itemSqlParameterSourceProvider">
<beans:bean
class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider"/>
</beans:property>
 
Search WWH ::




Custom Search