different sql statements in a writer
Hi all, i have the following:
1)Read from a DB
2)Proccess those rows
3)Write in a DB
And the files that i have are:
1)LeerBBDDJob.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schem...spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDrive r"/>
<property name="url" value="jdbc:sqlserver://10.90.33.7;DatabaseName=INT001"/>
<property name="username" value="INTGENE"/>
<property name="password" value="INTGENE"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager" lazy-init="true">
<property name="dataSource" ref="dataSource" />
</bean>
<batch:job-repository id="jobRepository" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<batch:job id="leerBBDDJob"> <!-- incrementer="dynamicJobParameters">-->
<!-- Da error en ejecución
<listeners>
<listener class="com.ListenerOne"/>
</listeners>-->
<batch:step id="imprimirPorConsola">
<batch:tasklet>
<batch:chunk reader="gestionesItemReader"
processor="tratarFila"
writer="gestionesItemWriter"
commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="gestionesItemReader" class="org.springframework.batch.item.database.Jdb cCursorItemReader">
<property name="dataSource" ref="dataSource" />
<property name="sql" value="select * from GESTIONES where estado=0 and tipogestion!='DUP'"/>
<property name="rowMapper">
<bean id="gestionesMapper" class="org.springframework.jdbc.core.BeanPropertyR owMapper">
<property name="mappedClass">
<value type="java.lang.Class">com.Gestiones</value>
</property>
</bean>
</property>
</bean>
<bean id="gestionesItemWriter" class="org.springframework.batch.item.database.Jdb cBatchItemWriter">
<property name="assertUpdates" value="true" />
<property name="itemSqlParameterSourceProvider">
<bean name="sqlParameterSourceProvider" id="sqlParameterSourceProvider" class="org.springframework.batch.item.database.Bea nPropertyItemSqlParameterSourceProvider" />
</property>
<property name="sql" value="UPDATE GESTIONES set estado = :estado where inscripcion = :inscripcion and estado = 0 and tipogestion = :tipogestion "/>
<property name="dataSource" ref="dataSource" />
</bean>
<!-- <bean id="dynamicJobParameters" class="com.DynamicJobParameters" />-->
<bean id="tratarFila" class="com.GestionesProcessor"/>
<!-- <bean id="jobExplorer" class="org.springframework.batch.core.explore.supp ort.JobExplorerFactoryBean"
p:dataSource-ref="dataSource"
p:tablePrefix="batch_" />-->
</beans>
2)GestionesProcessor.java
public class GestionesProcessor implements ItemProcessor<Gestiones, Gestiones>{
protected final Log _logger = LogFactory.getLog(GestionesProcessor.class);
public Gestiones process(Gestiones gestiones) throws Exception {
// TODO Apéndice de método generado automáticamente
if (gestiones==null) return null;
gestiones.setEstado(new Byte((byte) 10));
_logger.info("[" + this.getClass().getName() + "]" + "process() Tratado registro con inscripcion="+gestiones.getInscripcion()+" y tipoGestion="+gestiones.getTipogestion());
return gestiones;
}
}
Until here, if everything is ok, but i need to do another update sentence if something was wrong. How i could implement this??
Thanks in advance.