Concurrency resolving
Concurrency can be resolved by pessimistic or optimistic locking on transaction management level. XData is supported an automatic (or manual) transaction management with both locking types support (when locking is supported on RDBMS level).
Pessimistic locking is RDBMS ability to define lock over one record for one thread of application until transaction is committed. In case of concurrent raise first thread acquired and lock data and other threads will get an exception. XData pessimistic locking is acquired by repository Lock method call, or an extension method Lock of IDataObject interface. In case of reject of locking the exception is handled, but method returns false. To acquire the pessimistic lock the transaction is required. When no transaction is defined then runtime XDataRuntimeException is raised.
Optimistic locking require a special field inside data table - the concurrency token. Concurrency token is always updated on insert or update of the table using some algorithm. When data changes submitted (update or delete) the value is checked for not changed until request data. If value is changes the XDataConcurrencyException is raised. To mark property as concurrency token then define mapping use property flag - ConcurrencyToken and set one of default value type to choose one of concurrency value generation algorithm. Concurrency token value checking is provided automatically. There is possible to set IgnoreConcurrency flag to ignore concurrency when submitting changes using repository Submit method, or an extension method Submit of IDataObject interface. When concurrency is ignored no checks are provided and concurrency is resolved with "last change is applied" rule.
Tip
Concurrency token field can be hidden, but required to be selected from data source table (see Hidden property).
Important
Concurrency token property mapping required to define default value behavior with extension feature DefaultFeature.UseOnUpdate.
Ways to define concurrency token property mapping is various to static and dynamic notation and described in corresponding topics.