forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplicationMode.cs
108 lines (87 loc) · 3.16 KB
/
ReplicationMode.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using NHibernate.Type;
namespace NHibernate
{
/// <summary>
/// Represents a replication strategy.
/// </summary>
/// <seealso cref="ISession.Replicate(object, ReplicationMode)"/>
public abstract class ReplicationMode
{
public static readonly ReplicationMode Exception = new ExceptionReplicationMode("EXCEPTION");
public static readonly ReplicationMode Ignore = new IgnoreReplicationMode("IGNORE");
public static readonly ReplicationMode LatestVersion = new LatestVersionReplicationMode("LATEST_VERSION");
public static readonly ReplicationMode Overwrite = new OverwriteReplicationMode("OVERWRITE");
private readonly string name;
protected ReplicationMode(string name)
{
this.name = name;
}
public override string ToString()
{
return name;
}
public abstract bool ShouldOverwriteCurrentVersion(object entity, object currentVersion, object newVersion,
IVersionType versionType);
#region Nested type: ExceptionReplicationMode
private sealed class ExceptionReplicationMode : ReplicationMode
{
public ExceptionReplicationMode(string name) : base(name) {}
/// <summary>
/// Throw an exception when a row already exists
/// </summary>
public override bool ShouldOverwriteCurrentVersion(object entity, object currentVersion, object newVersion,
IVersionType versionType)
{
throw new AssertionFailure("should not be called");
}
}
#endregion
#region Nested type: IgnoreReplicationMode
private sealed class IgnoreReplicationMode : ReplicationMode
{
public IgnoreReplicationMode(string name) : base(name) {}
/// <summary>
/// Ignore replicated entities when a row already exists
/// </summary>
public override bool ShouldOverwriteCurrentVersion(object entity, object currentVersion, object newVersion,
IVersionType versionType)
{
return false;
}
}
#endregion
#region Nested type: LatestVersionReplicationMode
private sealed class LatestVersionReplicationMode : ReplicationMode
{
public LatestVersionReplicationMode(string name) : base(name) {}
/// <summary>
/// When a row already exists, choose the latest version
/// </summary>
public override bool ShouldOverwriteCurrentVersion(object entity, object currentVersion, object newVersion,
IVersionType versionType)
{
if (versionType == null)
{
// always overwrite nonversioned data
return true;
}
return versionType.Comparator.Compare(currentVersion, newVersion) <= 0;
}
}
#endregion
#region Nested type: OverwriteReplicationMode
private sealed class OverwriteReplicationMode : ReplicationMode
{
public OverwriteReplicationMode(string name) : base(name) {}
/// <summary>
/// Overwrite existing rows when a row already exists
/// </summary>
public override bool ShouldOverwriteCurrentVersion(object entity, object currentVersion, object newVersion,
IVersionType versionType)
{
return true;
}
}
#endregion
}
}