Makes the object available for state optimistic locking using PersistentOptimisticLockServer. This locking strategy uses the object state to detect changes to the object.
type: A class specifying a non-abstract persistent type.
view-name: Name of the view to be used for detecting state changes. By default the full view is used, which contains all mapped database fields of the persistent type (value type properties and foreign-key values of object references).
· Types marked with the <StateOptimisticLock/> are available for optimistic locking with PersistentOptimisticLockServer. When changes are committed, the state of the locked object (as it was loaded from the database) is compared with the current database state.
· Unlike <OptimisticLock/>, which requires a version field, this locking strategy can be implemented without modifying the database schema.
· Compared to <OptimisticLock/>, the disadvantages of this locking strategy are higher resource consumption (because the old state has to be stored in memory) and poorer database performance (because all state fields have to be compared when committing).
· To exclude large fields, e.g. images mapped to binary, specify a custom view to be used.
To use state optimistic locking, you need to:
· specify <StateOptimisticLock/> strategy in the mapping
· set up a PersistentOptimisticLockServer in the DataDomain.
· configure optimistic locking semantics for the Context
The following code enables state optimistic locking on Customer and specifies MyLockView to be used:
The following code sets up the infrastructure for maintaining persistent optimistic locks in the DataDomain. Please note that the lock server can only be set up when you instantiate the DataDomain. You cannot add a lock server to an existing DataDomain instance:
The lock server is set for a given type (in this case System.Object) and automatically applies to all derived types as well.
Please refer to the User’s Guide to learn more about how to initialise and use the DataDomain in your project.
Finally, before using locking, you need to configure optimistic locking semantics for the context:
Editions:Professional, Evaluation, Express
Database Platforms:Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2, IBM DB2
Optimistic object-level locking in the User’s Guide, <OptimisticLock/> element, <View/> element