Reputation: 271
I am developing a batch using spring batch, i have two steps, a step1 that updated table1 and another step2 updated table2.
I want if the second step2 fails then all the treatment is canceled (rollback). What should I do??
I have the sample xml config below:
<b:step id="Step1" parent="Tache">
<b:tasklet>
<b:chunk reader="baseReader" processor="baseProcessor"
chunk-completion-policy="completionPolicy" />
</b:tasklet>
</b:step>
<b:step id="Step2" parent="Tache">
<b:tasklet>
<b:chunk reader="baseReaderEcriture"
writer="ecritureWriter" chunk-completion-policy="completionPolicy" />
</b:tasklet>
</b:step>
<b:job id="batch" parent="Batch">
<b:step id="step1" parent="Step1" next="step2"/>
<b:step id="step2" parent="Step2" />
</b:job>
Thanks!
Upvotes: 3
Views: 12190
Reputation: 1
Hi I hope that it can help someone else. Just need to create a step for each inspection task if these steps succeed, then launch the final step which'll save your data to database.
Upvotes: 0
Reputation: 18423
You can't rollback already committed data (after every chunk - based on you completition policy - your data as long as spring-batch metadata are commited), so you can't automatically rollback all data stored in step1.
Maybe you can use this syntax:
<b:job id="batch" parent="Batch">
<b:step id="step1" parent="Step1" next="step2"/>
<b:step id="step2" parent="Step2">
<next on="ROLLBACK_ALL" to="deleteDataSavedByStep1Step" />
<end on="*" />
</b:step>
</b:job>
to move next to a step used to delete data saved by step 1, but you have to know which data you have to delete in deleteDataSavedByStep1Step
step.
Upvotes: 4
Reputation: 4030
See this. This might give an idea. Spring batch and XA and local transactions
https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-1-the-basics/
Upvotes: 0