Java Reference
In-Depth Information
<beans:entry key="customer"
value="com.apress.springbatch.chapter7.Customer" />
<beans:entry key="transaction"
value="com.apress.springbatch.chapter7.Transaction" />
<beans:entry key="account" value="java.lang.String"/>
<beans:entry key="zip" value="java.lang.String"/>
</beans:map>
</beans:property>
<beans:property name="implicitCollection">
<beans:map>
<beans:entry key="transactions"
value="com.apress.springbatch.chapter7.Customer"/>
</beans:map>
</beans:property>
<beans:property name="converters">
<beans:list>
<beans:ref local="dateConverter"/>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="dateConverter"
class="com.thoughtworks.xstream.converters.basic.DateConverter">
<beans:constructor-arg value="yyyy-MM-dd HH:mm:ss"/>
<beans:constructor-arg value="yyyy-MM-dd HH:mm:ss"/>
</beans:bean>
As you can see in Listing 7-36, you configure the aliases to tell your parser what each tag maps to.
Note that you don't need to map every tag since the parser can figure out most of the Strings. However,
in the case of the zip code and account number, you need to let XStream know that those are not any
type of number field. You also let your parser know what each of the two root tags map to: transaction
maps to the Transaction class and customer maps to the Customer class. The implicitCollection
dependency identifies that the field transactions on the Customer object is a collection. Finally, you
provide a list of converters for XStream to use when it finds types that it can't parse by default. In your
case, you provide the com.thoughtworks.xstream.converters.basic.DateConverter with the correct
format for the dates found in your file.
That's all you need to parse XML into items in Spring Batch! By running this job, you will get the
same output as you did from the multiline record job.
Over the course of this section, you have covered a wide array of input formats. Fixed length files,
delimited files, and various record configurations as well as XML are all available to be handled via
Spring Batch with no or very limited coding, as you have seen. However, not all input will come from a
file. Relational databases will provide a large amount of the input for your batch processes. The next
section will cover the facilities that Spring Batch provides for database input.
Database Input
Databases serve as a great source of input for batch processes for a number of reasons. They provide
transactionality built in, they are typically more performant, and they scale better than flat files. They
also provide better recovery features out of the box than most other input formats. When you consider
all of the above and the fact that most enterprise data is stored in relational databases to begin with, your
 
Search WWH ::




Custom Search