Java Reference
In-Depth Information
Date readDate(String name, String pattern, Date defaultValue);
int getFieldCount();
Properties getProperties();
}
Note Unlike the JDBC ResultSet, which begins indexing columns at 1, the index used by Spring Batch's FieldSet
is zero-based.
To put the CustomerFieldSetMapper to use, you need to update the configuration to use it. Replace
the BeanWrapperFieldSetMapper reference with your own bean reference, as shown in Listing 7-15.
Listing 7-15. customerFileReader Configured with the CustomerFieldSetMapper
<beans:bean id="customerFile"
class="org.springframework.core.io.FileSystemResource" scope="step">
<beans:constructor-arg value="#{jobParameters[customerFile]}"/>
</beans:bean>
<beans:bean id="customerFileReader"
class="org.springframework.batch.item.file.FlatFileItemReader">
<beans:property name="resource" ref="customerFile" />
<beans:property name="lineMapper">
<beans:bean
class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<beans:property name="lineTokenizer">
<beans:bean class="org.springframework.batch.item.file.transform.
DelimitedLineTokenizer">
<beans:property name="names"
value="firstName,middleInitial,lastName,addressNumber,street,
city,state,zip"/>
<beans:property name="delimiter" value=","/>
</beans:bean>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean
class="com.apress.springbatch.chapter7.CustomerFieldSetMapper"/>
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
Note that with your new CustomerFieldSetMapper, you don't need to configure the reference to the
Customer bean. Since you handle the instantiation yourselves, this is no longer needed.
Parsing files with the standard Spring Batch parsers, as you have shown, requires nothing more than
a few lines of XML. However, not all files consist of Unicode characters laid out in a format that is easy
for Java to understand. When dealing with legacy systems, it's common to come across data storage
Search WWH ::




Custom Search