Makes the object available for optimistic locking using PersistentOptimisticLockServer.
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.
BusinessContact.cs
public abstract class BusinessContact : Persistent {
...
}
public abstract class Supplier : BusinessContact {
...
}
public abstract class Customer : BusinessContact {
...
}
NorthwindSchema.xml
<Mapping xmlns="urn:TechTalk:TT.OODAL.XmlMapping">
...
<Type name="BusinessContact">
<RootInheritance />
<OptimisticLock fieldName="Version" /><!-- fieldName is optional here -->
...
</Type>
<Type name="Supplier">
<SharedInheritance />
<OptimisticLock /> <!-- fieldName cannot be specified here because of shared inheritance -->
...
</Type>
<Type name="Customer">
<JoinedInheritance />
<OptimisticLock /> <!-- fieldName is optional here -->
...
</Type>
</Mapping>
...
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);
using(Context.Push(LocalContext.Create(semanticsBindings))
{
BusinessContact contact = (BusinessContact)dataDomain.Extent(typeof(BusinessContact))["Id == 2"].ToObject();
Context.Current.Lock(contact);
...
Context.Commit();
}
...
Type: TechTalk.Genome.Mapping.OptimisticLockXmlData
Assembly: TechTalk.Genome.dll
Version: 4.2.4
Editions: Professional, Evaluation, Express
Database Platforms: Microsoft SQL Server 2000, Microsoft SQL Server 2005, Oracle 9i Release 2, Oracle 10g Release 2
Context.Lock Overload List | Context.TryLock Overload List | PersistentOptimisticLockServer | DataDomainConfiguration.LockServers