Optimistic locking is usually used in the following scenarios:
- Replication of data between external data source and ERP.net.
- Implementing external UI for data apps.
External app allows its users to modify an entity, stored in an ERP.net instance.
- The external app reads the entity, including the Object version.
- The external app presents a UI to the end user and allows them to edit the entity.
- When the user saves the data, the app call the update API, providing the data + the previously read Object version.
- The system checks whether the Object version in the ERP.net instance is still the same and proceeds with the update ONLY if it is the same; otherwise, it returns error.
For replication scenarios, the steps are the same, with the exception of step 2, which might not be a UI, but a time frame between two synchronizations.
By implementing the above scenario, the app guarantees that it would not overwrite other apps changes if such have occurred in ERP.net between step 1 and step 3.
It is the decision of the app to provide Object version when updating the entity. If Object version is not provided, the system would not perform the optimistic locking check.