LockMode.cs :  » Persistence-Frameworks » NHibernate » NHibernate » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » NHibernate 
NHibernate » NHibernate » LockMode.cs
using System;

namespace NHibernate{
  /// <summary>
  /// Instances represent a lock mode for a row of a relational database table.
  /// </summary>
  /// <remarks>
  /// It is not intended that users spend much time worrying about locking since Hibernate
  /// usually obtains exactly the right lock level automatically. Some "advanced" users may
  /// wish to explicitly specify lock levels.
  /// </remarks>
  [Serializable]
  public sealed class LockMode
  {
    private readonly int level;
    private readonly string name;
    private readonly int hashcode;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="level"></param>
    /// <param name="name"></param>
    private LockMode(int level, string name)
    {
      this.level = level;
      this.name = name;
      unchecked
      {
        hashcode = (level * 37) ^ (name != null ? name.GetHashCode() : 0);
      }
    }

    /// <summary></summary>
    public override string ToString()
    {
      return name;
    }

    /// <summary>
    /// Is this lock mode more restrictive than the given lock mode?
    /// </summary>
    /// <param name="mode"></param>
    public bool GreaterThan(LockMode mode)
    {
      return level > mode.level;
    }

    /// <summary>
    /// Is this lock mode less restrictive than the given lock mode?
    /// </summary>
    /// <param name="mode"></param>
    public bool LessThan(LockMode mode)
    {
      return level < mode.level;
    }

    /// <summary>
    /// No lock required. 
    /// </summary>
    /// <remarks>
    /// If an object is requested with this lock mode, a <c>Read</c> lock
    /// might be obtained if necessary.
    /// </remarks>
    public static LockMode None = new LockMode(0, "None");

    /// <summary>
    /// A shared lock. 
    /// </summary>
    /// <remarks>
    /// Objects are loaded in <c>Read</c> mode by default
    /// </remarks>
    public static LockMode Read = new LockMode(5, "Read");

    /// <summary>
    /// An upgrade lock. 
    /// </summary>
    /// <remarks>
    /// Objects loaded in this lock mode are materialized using an
    /// SQL <c>SELECT ... FOR UPDATE</c>
    /// </remarks>
    public static LockMode Upgrade = new LockMode(10, "Upgrade");

    /// <summary>
    /// Attempt to obtain an upgrade lock, using an Oracle-style
    /// <c>SELECT ... FOR UPGRADE NOWAIT</c>. 
    /// </summary>
    /// <remarks>
    /// The semantics of this lock mode, once obtained, are the same as <c>Upgrade</c>
    /// </remarks>
    public static LockMode UpgradeNoWait = new LockMode(10, "UpgradeNoWait");

    /// <summary>
    /// A <c>Write</c> lock is obtained when an object is updated or inserted.
    /// </summary>
    /// <remarks>
    /// This is not a valid mode for <c>Load()</c> or <c>Lock()</c>.
    /// </remarks>
    public static LockMode Write = new LockMode(10, "Write");

    // TODO H3.2: Implement Force where required
    /// <summary> 
    /// Similar to <see cref="Upgrade"/> except that, for versioned entities,
    /// it results in a forced version increment.
    /// </summary>
    public static readonly LockMode Force = new LockMode(15, "Force");

    public override bool Equals(object obj)
    {
      return Equals(obj as LockMode);
    }

    public bool Equals(LockMode other)
    {
      if (other == null)
      {
        return false;
      }
      if (ReferenceEquals(this, other))
      {
        return true;
      }
      return other.level == level && Equals(other.name, name);
    }

    public override int GetHashCode()
    {
      return hashcode;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.