本文整理汇总了C#中LockMode.LessThan方法的典型用法代码示例。如果您正苦于以下问题:C# LockMode.LessThan方法的具体用法?C# LockMode.LessThan怎么用?C# LockMode.LessThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LockMode
的用法示例。
在下文中一共展示了LockMode.LessThan方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateLockingStrategy
/// <summary>
/// Construct a locking strategy based on SQL UPDATE statements.
/// </summary>
/// <param name="lockable">The metadata for the entity to be locked. </param>
/// <param name="lockMode">Indictates the type of lock to be acquired. </param>
/// <remarks>
/// read-locks are not valid for this strategy.
/// </remarks>
public UpdateLockingStrategy(ILockable lockable, LockMode lockMode)
{
this.lockable = lockable;
this.lockMode = lockMode;
if (lockMode.LessThan(LockMode.Upgrade))
{
throw new HibernateException("[" + lockMode + "] not valid for update statement");
}
if (!lockable.IsVersioned)
{
log.Warn("write locks via update not supported for non-versioned entities [" + lockable.EntityName + "]");
sql = null;
}
else
{
sql = GenerateLockString();
}
}
示例2: DoLoad
/// <summary>
/// Actually do all the hard work of loading up an object
/// </summary>
/// <param name="theClass"></param>
/// <param name="id"></param>
/// <param name="optionalObject"></param>
/// <param name="lockMode"></param>
/// <param name="checkDeleted"></param>
/// <returns></returns>
/// <remarks>
/// 1. see if it is already loaded
/// 2. see if it is cached
/// 3. actually go to the database
/// </remarks>
private object DoLoad( System.Type theClass, object id, object optionalObject, LockMode lockMode, bool checkDeleted )
{
//DONT need to flush before a load by id, because ids are constant
if( log.IsDebugEnabled )
{
log.Debug( "attempting to resolve " + MessageHelper.InfoString( theClass, id ) );
}
IClassPersister persister = GetClassPersister( theClass );
Key key = new Key( id, persister );
if( optionalObject != null )
{
persister.SetIdentifier( optionalObject, id );
}
// LOOK FOR LOADED OBJECT
// Look for Status.Loaded object
object old = GetEntity( key );
if( old != null )
{
//if this object was already loaded
EntityEntry oldEntry = GetEntry( old );
Status status = oldEntry.Status;
if( checkDeleted && ( status == Status.Deleted || status == Status.Gone ) )
{
throw new ObjectDeletedException( "The object with that id was deleted", id, theClass );
}
UpgradeLock( old, oldEntry, lockMode );
if( log.IsDebugEnabled )
{
log.Debug( "resolved object in session cache " + MessageHelper.InfoString( persister, id ) );
}
return old;
}
else
{
// check to see if we know already that it does not exist:
if( nonExists.Contains( key ) )
{
log.Debug( "entity does not exist" );
return null;
}
// LOOK IN CACHE
CacheEntry entry = persister.HasCache && lockMode.LessThan( LockMode.Read ) ?
( CacheEntry ) persister.Cache.Get( id, Timestamp ) :
null;
if( entry != null )
{
return AssembleCacheEntry( entry, id, persister, optionalObject );
}
else
{
//GO TO DATABASE
if( log.IsDebugEnabled )
{
log.Debug( "object not resolved in any cache " + MessageHelper.InfoString( persister, id ) );
}
object result = persister.Load( id, optionalObject, lockMode, this );
if( result == null )
{
// remember it doesn't exist, in case of next time
AddNonExist( key );
}
return result;
}
}
}