Java Reference
In-Depth Information
DelimitedLineTokenizer">
<beans:property name="names"
value="prefix,accountNumber,transactionDate,amount"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
<beans:bean id="customerFieldSetMapper"
class="org.springframework.batch.item.file.mapping.
BeanWrapperFieldSetMapper">
<beans:property name="prototypeBeanName" value="customer"/>
</beans:bean>
<beans:bean id="transactionFieldSetMapper"
class="com.apress.springbatch.chapter7.TransactionFieldSetMapper"/>
<beans:bean id="customer" class="com.apress.springbatch.chapter7.Customer"
scope="prototype"/>
The configuration in Listing 7-27 should look familiar. It's essentially the exact same as the
configuration you used for multiple record formats (see Listing 7-19). The only addition, as highlighted
in bold, is the configuration of your new CustomerFileReader with its reference to the old ItemReader
and renaming the old ItemReader.
With the updated object model, the previous method for writing to your output file won't work for
this example. Because of this, I chose to use Spring Batch's PassThroughLineAggregator to write the
output for this example. It calls the item's toString() method and writes the output to the output file.
Listing 7-28 shows the updated ItemWriter configuration.
Listing 7-28. Updated outputWriter Configuration
<beans:bean id="outputFile"
class="org.springframework.core.io.FileSystemResyource" scope="step">
<beans:constructor-arg value="#{jobParameters[outputFile]}"/>
</beans:bean>
<beans:bean id="outputWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter">
<beans:property name="resource" ref="outputFile" />
<beans:property name="lineAggregator">
<beans:bean class="org.springframework.batch.item.file.transform.
PassThroughLineAggregator"/>
</beans:property>
</beans:bean>
For each Customer object, it will print how many transactions the user has. This will provide enough
detail for you to verify that your reading worked correctly. With the PassThroughLineAggregator
configured as it is, you only need to override the Customer's toString() method to format the output.
Listing 7-29 shows the updated method.
Listing 7-29. Customer's toString() Method
 
Search WWH ::




Custom Search