TechTalk Genome v4.2

<OptimisticLock> Element

Makes the object available for optimistic locking using PersistentOptimisticLockServer.

<Type name=" type ">
<OptimisticLock fieldName=" database-field-name " />
A class specifying a non-abstract persistent type.
Name of the rowversion field used to track changes. Cannot be specified for types with the <SharedInheritance> type extent provider. Optional for types with the <RootInheritance> or <JoinedInheritance> type extent providers. If not specified, the default value __optLockVersion is used.


Types marked with the <OptimisticLock> element are available for optimistic locking with PersistentOptimisticLockServer. The locking uses a rowversion (timestamp) field in the database table assigned to the type to track changes of the objects.

Depending on the underlying database platform, the row-version field is mapped to the field type which is either automatically updated by the database (Microsoft SQL Server) or else Genome explicitly updates the field with a new version when updating rows (Oracle, IBM DB2 and Microsoft SQL CE).

If a type is marked with the <OptimisticLock> element , all of its non-abstract base types must also be marked with this element.


public abstract class BusinessContact : Persistent {

public abstract class Supplier : BusinessContact {

public abstract class Customer : BusinessContact {

<Mapping xmlns="urn:TechTalk:TT.OODAL.XmlMapping">

    <Type name="BusinessContact">
        <RootInheritance />
        <OptimisticLock fieldName="Version" /><!-- fieldName is optional here -->
    <Type name="Supplier">
        <SharedInheritance />
        <OptimisticLock /> <!-- fieldName cannot be specified here because of shared inheritance -->        
    <Type name="Customer">
        <JoinedInheritance />
        <OptimisticLock /> <!-- fieldName is optional here -->

DataDomainConfiguration ddConfig = new DataDomainConfiguration(connectionString, schema);
ddConfig.LockServers.Add(typeof(BusinessContact), PersistentOptimisticLockServer.Value);
DataDomain dataDomain = new DataDomain(ddConfig);               


LockingSemanticsBindings semanticsBindings = new LockingSemanticsBindings();
semanticsBindings.Add(dataDomain, typeof(BusinessContact), OptimisticLockingSemantics.Value);
    BusinessContact contact = (BusinessContact)dataDomain.Extent(typeof(BusinessContact))["Id == 2"].ToObject();




Type: TechTalk.Genome.Mapping.OptimisticLockXmlData

Assembly: TechTalk.Genome.dll

Version: 4.2.11

Editions: Professional, Evaluation, Express

Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2

See Also

Context.Lock Overload List | Context.TryLock Overload List | PersistentOptimisticLockServer | DataDomainConfiguration.LockServers