One Star

Commit and rollback management

Hello everyone,
i have tow subjob: subjob1 ---OnSubjOK--->subjob2 and everyone affects my postgresql database by inserting or updating datas.
i want to commit if every subjob end without any problem but if subjob1 or subjob2 generate a problem i want to do a rollback to the initial state of database.
example: if subjob1 succeed to run and subjob2 generate a problem,modifications caused by subjob1 should disappear
can anyone help me plz?
thx a lot.
3 REPLIES
Four Stars

Re: Commit and rollback management

Hi Helronald,
There is no straight forward way to control job and subjob for rollback.
I can think of a work around for this.
Set a flag in subjob using context variable or routine (getter-setter). Use this flag as a checkpoint in main job to control the rollback.
eg... if your subjob failed, so you can rollback in that job. This is what you can do easily. --> Set flag to false
Once subjob execution is completed, read the flag value in tPostJob in main job. If the value is false, do rollback in main job.
I think you got an idea...
Thanks
Vaibhav
One Star

Re: Commit and rollback management

Hi sanvaibhav,
Thanks a lot for your reply,i understand your idea and i think it's what i really want.
I'm new in using talend so can u plz simplify me how to do this and thank you very much.
Four Stars

Re: Commit and rollback management

Hi Helronald,
First create your two jobs... Call second job in first job
create context variable as boolean
in second job... OnSubjob error - set the value of variable to false and then do rollback.
in main job - intPostJob read the the context variable value. If value is false --- execute roll back.
Same logic you can implement for multiple tables.
You can please put the screenshot of completed jobs, I will let you know in case if you need any further help or changes.
Thanks
Vaibhav