Use database transactions
Use the DB Transaction Start and DB Transaction End nodes to group multiple database operations into a single unit of work. Either all operations in the transaction succeed (commit), or none of them take effect (rollback).
Before you begin
- Establish a database connection. See Connect to a database using a dedicated connector node.
Set up a transaction
Chain the transaction nodes around the database operations you want to group into a single unit of work.
- Connect the DB Connection output port to a DB Transaction Start node and execute it. This opens a transaction on the connection. The input connection cannot be used outside the transaction while it is open.
- Connect the DB Data or DB Connection output of DB Transaction Start to the first node in your transaction chain (for example, a DB Writer).
- Chain the database operation nodes in sequence.
- Connect the final node's output port to the first input port of a DB Transaction End node.
- Connect the DB Connection output of DB Transaction Start directly to the second input port of DB Transaction End.
- Execute the DB Transaction End node:
- If all nodes in the chain executed successfully, the node commits the transaction and makes all changes visible.
- If any node in the chain failed, the node rolls back the transaction and restores the database to its state at the start of the transaction.
TIP
The first input port of DB Transaction End should be connected from the end of the transaction chain. The second input port should be connected directly from DB Transaction Start. On commit, the first port's connection is forwarded to the output; on rollback, the second port's connection is forwarded.