Architecture
Introduction
The Unit Of Work is used by the Persistence Manager to manage the transactional logic. It is based on the Unit Of Work pattern.
As the Persistence Manager is used along all the Wattyo Application, the Unit of Work it’s also implicitly used by most features.
DML optimization
The target of the Unit of Work is to reduce the number of DML operations performed in a transaction by grouping everything that is possible into a single DML operation.
The Wattyo Implementations goes a step further by allowing to handle Hierarchys that use the same Object Type in different levels. For example, a hierarchy that has a Parent Account and a Child Account. This is not possible with the standard Unit of Work pattern.
This is achieved by using the level parameter when adding a record to the Unit of Work. This parameter is used to identify the level of the record in the hierarchy. The Unit of Work will use this parameter to identify the records that are in the same level and group them into a single DML operation. As if a Parent and a Child are inserted in the same transaction it wouldn’t be possible to relate them.