forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDelayedPostInsertIdentifier.cs
54 lines (47 loc) · 1.37 KB
/
DelayedPostInsertIdentifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Threading;
namespace NHibernate.Action
{
/// <summary>
/// Acts as a stand-in for an entity identifier which is supposed to be
/// generated on insert (like an IDENTITY column), when an entity is <c>Persist</c>ed.
/// <c>Save</c> still performs the insert.
/// </summary>
/// <remarks>
/// The stand-in is only used within the <see cref="NHibernate.Engine.IPersistenceContext"/>
/// in order to distinguish one instance from another; it is never injected into
/// the entity instance or returned to the client.
/// </remarks>
[Serializable]
public class DelayedPostInsertIdentifier
{
private static long GlobalSequence = 0;
private readonly long sequence;
public DelayedPostInsertIdentifier()
{
sequence = Interlocked.Increment(ref GlobalSequence);
}
public override bool Equals(object obj)
{
if(ReferenceEquals(this,obj))
return true;
return Equals(obj as DelayedPostInsertIdentifier);
}
public bool Equals(DelayedPostInsertIdentifier that)
{
return that == null ? false : sequence == that.sequence;
}
public override int GetHashCode()
{
return sequence.GetHashCode();
}
public override string ToString()
{
return string.Format("<delayed:{0}>", sequence);
}
/// <summary>
/// The actual identifier value that has been generated.
/// </summary>
public object ActualId { get; set; }
}
}