Announcement Announcement Module
Collapse
No announcement yet.
Reading from Database and writing into XML file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading from Database and writing into XML file

    Hi All,

    hi All,

    I have some requirement, where i have to read n number of records based on some criteria, then generate a XML file and FTP to some server then update the table.

    Please let me know if i am doing the right approach.

    1. Reading data using JdbcCursorItemReader and set the values using mapper and used CompositeItemWriter to generate XML file and upate into the table.
    Code:
    <bean id="inventoryReceivedReadStep"
    		class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    		<property name="transactionManager" ref="transactionManager" />
    		<property name="jobRepository" ref="jobRepository" />
    		        <property name="commitInterval" value="1000" />
    		<property name="streams">
    			<list>
    				<ref bean="jdbcCursorReader" />
    				<ref bean="xmlItemWriter" />
    				 <ref bean="jdbcItemWriter" />  
    			</list>
    		</property>
    		<property name="itemReader" ref="jdbcCursorReader" />
    		<property name="itemWriter" ref="compositeWriter" />
    		<property name="allowStartIfComplete" value="true"></property>
    	</bean>
    	<bean id="compositeWriter"
    		class="org.springframework.batch.item.support.CompositeItemWriter">
    		<property name="delegates">
    			<list>
    				<ref bean="xmlItemWriter" />
    			 	<ref bean="jdbcItemWriter" />  
    			</list>
    		</property>
    	</bean>
    <bean id="jdbcCursorReader"
    		class="org.springframework.batch.item.database.JdbcCursorItemReader">
    		<property name="dataSource" ref="dataSourceDB2" />
    <property name="sql"
                   value="some sql" />
    <property name="mapper">
       <bean class="MapperClass">
    </bean>
    </property>
    <bean class="org.springframework.batch.item.xml.StaxEventItemWriter"
    		id="xmlItemWriter">
    		<property name="resource"
    			value="${packageXML}" />
    		<property name="serializer" ref="tradeMarshallingSerializer" />
    		<property name="rootTagName" value="PlatePackageShipment" />
    		<property name="overwriteOutput" value="true" />
    	</bean>
    
    	<bean
    		class="org.springframework.batch.item.xml.oxm.MarshallingEventWriterSerializer"
    		id="tradeMarshallingSerializer">
    		<constructor-arg>
    			<bean
    				class="org.springframework.oxm.xstream.XStreamMarshaller">
    				<property name="aliases" ref="aliases" />
    			</bean>
    		</constructor-arg>
    	</bean>
    
    	<util:map id="aliases">
    		<entry key="package"
    			value="packageClass" ></entry>
    			<entry key="file1" value="java.lang.String" />
    			<entry key="field2" value="java.lang.String" />
    			</util:map>
    	
    	
    	<bean id="jdbcItemWriter" class="us.tn.state.trust.batch.inventory.writer.InventoryWiriter">
    		<property name="iDao">
    			<bean class="DAOIMPLCLASS">
    								
    			</bean>
    		</property>
    	</bean>
    but i am getting an error as
    Code:
    2009-08-21 12:06:41,234 [ main] ERROR support.CommandLineJobRunner - Job Terminated in error:
    java.lang.ClassCastException: org.springframework.batch.core.step.item.ItemOrientedStep
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:199)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:252)
    Please let me know where i am doing wrong..
    Thanks in advance.
    Last edited by adish1234; Aug 21st, 2009, 01:01 PM.
Working...
X