本文整理汇总了C#中LockMode.GreaterThan方法的典型用法代码示例。如果您正苦于以下问题:C# LockMode.GreaterThan方法的具体用法?C# LockMode.GreaterThan怎么用?C# LockMode.GreaterThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LockMode
的用法示例。
在下文中一共展示了LockMode.GreaterThan方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpgradeLock
/// <summary>
/// Performs a pessimistic lock upgrade on a given entity, if needed.
/// </summary>
/// <param name="entity">The entity for which to upgrade the lock.</param>
/// <param name="entry">The entity's EntityEntry instance.</param>
/// <param name="requestedLockMode">The lock mode being requested for locking. </param>
/// <param name="source">The session which is the source of the event being processed.</param>
protected virtual void UpgradeLock(object entity, EntityEntry entry, LockMode requestedLockMode, ISessionImplementor source)
{
if (requestedLockMode.GreaterThan(entry.LockMode))
{
// The user requested a "greater" (i.e. more restrictive) form of
// pessimistic lock
if (entry.Status != Status.Loaded)
{
throw new ObjectDeletedException("attempted to lock a deleted instance", entry.Id, entry.EntityName);
}
IEntityPersister persister = entry.Persister;
if (log.IsDebugEnabled)
{
log.Debug(string.Format("locking {0} in mode: {1}", MessageHelper.InfoString(persister, entry.Id, source.Factory), requestedLockMode));
}
ISoftLock slock;
CacheKey ck;
if (persister.HasCache)
{
ck = new CacheKey(entry.Id, persister.IdentifierType, persister.RootEntityName, source.EntityMode, source.Factory);
slock = persister.Cache.Lock(ck, entry.Version);
}
else
{
ck = null;
slock = null;
}
try
{
if (persister.IsVersioned && requestedLockMode == LockMode.Force)
{
// todo : should we check the current isolation mode explicitly?
object nextVersion = persister.ForceVersionIncrement(entry.Id, entry.Version, source);
entry.ForceLocked(entity, nextVersion);
}
else
{
persister.Lock(entry.Id, entry.Version, entity, requestedLockMode, source);
}
entry.LockMode = requestedLockMode;
}
finally
{
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if (persister.HasCache)
{
persister.Cache.Release(ck, slock);
}
}
}
}
示例2: NeedsLockHint
private bool NeedsLockHint(LockMode lockMode)
{
return lockMode.GreaterThan(LockMode.Read);
}
示例3: AppendLockHint
public override string AppendLockHint(LockMode lockMode, string tableName)
{
if (lockMode.GreaterThan(LockMode.Read))
return tableName + " holdlock";
return tableName;
}
示例4: NeedsLockHint
protected bool NeedsLockHint(LockMode lockMode)
{
return lockMode.GreaterThan(LockMode.Read);
}
示例5: GetLockingStrategy
public override ILockingStrategy GetLockingStrategy(ILockable lockable, LockMode lockMode)
{
if (lockMode.GreaterThan(LockMode.Read))
{
return new UpdateLockingStrategy(lockable, lockMode);
}
else
{
return new SelectLockingStrategy(lockable, lockMode);
}
}
示例6: UpgradeLock
private void UpgradeLock( object obj, EntityEntry entry, LockMode lockMode )
{
if( lockMode.GreaterThan( entry.LockMode ) )
{
if( entry.Status != Status.Loaded )
{
throw new ObjectDeletedException( "attempted to lock a deleted instance", entry.Id, obj.GetType() );
}
IClassPersister persister = entry.Persister;
if( log.IsDebugEnabled )
{
log.Debug( "locking " + MessageHelper.InfoString( persister, entry.Id ) + " in mode: " + lockMode );
}
ISoftLock myLock = null;
if( persister.HasCache )
{
myLock = persister.Cache.Lock( entry.Id, entry.Version );
}
try
{
persister.Lock( entry.Id, entry.Version, obj, lockMode, this );
entry.LockMode = lockMode;
}
finally
{
// the database now holds a lock + the object is flushed from the cache,
// so release the soft lock
if( persister.HasCache )
{
persister.Cache.Release( entry.Id, myLock );
}
}
}
}