Optimistic Concurrency Control
- 3 minutes to read
The optimistic concurrency control (OCC) mechanism is used in XAF applications if you inherit from any of the base persistent classes (with the exception of the XPLiteObject). This topic describes how data collisions are handled in an XAF application.
Object-Level Locking
Consider the following scenario. Two users access the same object, and edit it from different workstations. The first user makes modifications to the object’s properties and persists them in a database. The second user also makes modifications, but tries to persist them after the first user has already done so. In this case, the second user will receive the following message.
In WinForms applications:
In ASP.NET Web Forms applications:
After refreshing the object (if required), the second user will be able to make modifications against the renewed object and persist them. If the first user deleted the object, the second user will not be able to make any modifications, and will instead receive the following message.
Field-Level Locking
In multi-user data-aware applications, there are times when one user edits a record while another user is editing the same record. As long as the changes being made do not affect the same field (e.g., one user modifies the task description while another user attaches a file), XAF applications can resolve the situation, and merge simultaneous changes made by different users. To enable field-level locking, set the static XpoDefault.TrackPropertiesModifications property to true.
In the Program.cs(vb) file of a WinForms application project:
In the Global.asax.cs(vb) file of an ASP.NET Web Forms application project:
When this property is set to true and a user modifies an object that was already changed by another user, a dialog window that suggests merging changes is displayed.
In WinForms applications:
In ASP.NET Web Forms applications:
Merging is possible when users modify the values of different fields. If both users change the same field value, merging is not possible, and the user can either refresh data or cancel saving.
In WinForms applications:
In ASP.NET Web Forms applications:
The dialogs illustrated above are provided by the ProcessDataLockingInfoController Controller from the SystemModule module.
Note
To see field-level locking in action, refer to the Concurrent Modifications section of Feature Center demo installed with XAF. By default, the Feature Center demo is installed in %PUBLIC%\Documents\DevExpress Demos 24.2\Components\XAF\FeatureCenter.NETFramework.XPO.
View-Level Locking
Besides concurrency control at the data level, the LockController from the SystemWindowsForms module tracks changes at the View level (in WinForms applications). It displays the following message when an object is being modified in two or more different Views.