Java Reference
In-Depth Information
a FieldSetMapper can't be found, a ParseException is thrown indicating that the record couldn't be
parsed.
The last part of the parsing puzzle is to configure all the pieces. You need to configure the two
FieldSetMappers, two LineTokenizers, a LineMapper and ItemReader all so your step can use them.
Listing 10-12 contains the configuration of the pieces you've defined up to now.
Listing 10-12. Configuring the Parsing of the customerTransaction File
...
<beans:bean id="customerTransactionFile"
class="org.springframework.core.io.FileSystemResource">
<beans:constructor-arg value="/input/customerTransaction.csv"/>
</beans:bean>
<beans:bean id="customerLineTokenizer"
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<beans:property name="names"
value="taxId,firstName,lastName,address,city,state,zip,accountNumber"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
<beans:bean id="transactionLineTokenizer"
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<beans:property name="names" value="accountNumber,stockTicker,price,quantity,timestamp"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
<beans:bean id="customerFieldSetMapper"
class="com.apress.springbatch.statement.reader.CustomerFieldSetMapper"/>
<beans:bean id="transactionFieldSetMapper"
class="com.apress.springbatch.statement.reader.TransactionFieldSetMapper"/>
<beans:bean id="customerTransactionLineMapper"
class="com.apress.springbatch.statement.reader.RegularExpressionLineMapper">
<beans:property name="lineTokenizers">
<beans:map>
<beans:entry key="^\d+,[A-Z][a-zA-Z]+,[A-Z][a-zA-Z]+,.*"
value-ref="customerLineTokenizer"/>
<beans:entry key="^\d+,[A-Z\.\ ]+,\d+.*"
value-ref="transactionLineTokenizer"/>
</beans:map>
</beans:property>
<beans:property name="fieldSetMappers">
<beans:map>
<beans:entry key="^\d+,[A-Z][a-zA-Z]+,[A-Z][a-zA-Z]+,.*"
value-ref="customerFieldSetMapper"/>
<beans:entry key="^\d+,[A-Z\.\ ]+,\d+.*"
value-ref="transactionFieldSetMapper"/>
</beans:map>
</beans:property>
 
Search WWH ::




Custom Search