Search code examples
sql-servertalend

How to set Rollback in case of Error in Talend?


I have a Talend Project, that Synchronize two tables by :

  1. DELETE TABLE 1
  2. SELECT * TABLE 2
  3. INSERT TABLE 1

look at photo down below.

Imagine, two first steps go fine, but at final step (insertion) it throws an error. Can I restore deleted rows, that were executed on the very first step?

And how tMSSqlRollback works anyway? I tried in vain to set it up. (There're no components in "List of components" drop down list, in 'Simple parameter' tab.

Talend project photo


Solution

  • First of all, as garpitmzn said, you should open a connection with the corresponding element for your database type, say tMySQLConnection. This could be done with a tPreJob. Now, also add a tMySQLCommit in a tPostJob.

    You want to add some error handling. There are two ways

    • Extended inserts is activated for tMySQLOutput: You would have to add a tLogRowCatcher somewhere outside your job. Add a tRollback for your database type directly after it (like with the tPre/tPostJob, link it with OnComponentOk).

    • Extended inserts is deactivated: Additionally to Main, you also can connect per right click Recjected. Those rows are rejected for some reason. You can collect these records and store them in a table or some kind of error reporting where you handle those rejected rows. NOTE: This way, although more detailed, can be very very bad on performance. Also, if the database connection crashes or something else is wrong, you still would need a tLogRowCatcher

    The rollback component doesn't need to be part of the main job.