Optimistic Concurrency Control

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:

ConcurrencyWin

In ASP.NET Web applications:

ConcurrencyWeb

In Mobile applications:

ConcurrencyMobile

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.

ConcurrencyDeleted

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 XpoDefault.TrackPropertiesModifications static property to true.

  • In the Program.cs(vb) file of a WinForms application project:

    static void Main() {
        DevExpress.Xpo.XpoDefault.TrackPropertiesModifications = true;
        // ...
    }
    
  • In the Global.asax.cs(vb) file of an ASP.NET application project:

    protected void Session_Start(object sender, EventArgs e) {
        DevExpress.Xpo.XpoDefault.TrackPropertiesModifications = true;
        // ...
    }
    

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:

    ConcurrencyMerge

  • In ASP.NET Web applications:

    ConcurrencyMerge

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:

    ConcurrencyRefresh

  • In ASP.NET Web applications:

    ConcurrencyRefresh

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 18.1\Components\eXpressApp Framework\FeatureCenter.

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.

ConcurrencyLock