Skip to content

Commit 44c4a25

Browse files
committed
New hint for comparer
1 parent cafc8ed commit 44c4a25

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

Orm/Xtensive.Orm/Modelling/Comparison/Comparer.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ protected virtual MovementInfo BuildMovementInfo(Node source, Node target)
228228
return movementInfo;
229229
}
230230

231+
var recreateHint = Hints.GetHint<RecreateTableHint>(source);
232+
if (recreateHint != null) {
233+
movementInfo |= MovementInfo.Removed | MovementInfo.Created;// recreated;
234+
}
231235
var sc = StringComparer.OrdinalIgnoreCase;
232236

233237
// both source!=null && target!=null
@@ -611,9 +615,9 @@ protected bool HasDataChangeHint(Node source)
611615
return false;
612616

613617
return
614-
Hints.GetHints<CopyDataHint>(source).Any()
615-
|| Hints.GetHints<DeleteDataHint>(source).Any()
616-
|| Hints.GetHints<UpdateDataHint>(source).Any();
618+
Hints.HasHints<CopyDataHint>(source)
619+
|| Hints.HasHints<DeleteDataHint>(source)
620+
|| Hints.HasHints<UpdateDataHint>(source);
617621
}
618622

619623
/// <summary>

Orm/Xtensive.Orm/Modelling/Comparison/Hints/HintSet.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ public bool HasHints(Node node)
188188
return nodeHintMap.Values.Count > 0;
189189
}
190190

191+
public bool HasHints<THint>(Node node)
192+
where THint : Hint
193+
{
194+
ArgumentValidator.EnsureArgumentNotNull(node, "node");
195+
196+
if (!hintMap.ContainsKey(node))
197+
hintMap.Add(node, new Dictionary<Type, object>());
198+
var nodeHintMap = hintMap.GetValueOrDefault(node);
199+
if (nodeHintMap == null)
200+
return false;
201+
return nodeHintMap.ContainsKey(typeof(THint));
202+
}
203+
191204
#region IEnumerable<...> methods
192205

193206
/// <inheritdoc/>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (C) 2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Xtensive.Modelling.Comparison.Hints
10+
{
11+
/// <summary>
12+
/// Hints comparer that the table is recreated.
13+
/// How to treat it is up to comparer.
14+
/// </summary>
15+
[Serializable]
16+
public sealed class RecreateTableHint : Hint
17+
{
18+
/// <summary>
19+
/// Path to the table.
20+
/// </summary>
21+
public string Path { get; private set; }
22+
23+
/// <inheritdoc/>
24+
public override IEnumerable<HintTarget> GetTargets()
25+
{
26+
yield return new HintTarget(ModelType.Source, Path);
27+
yield return new HintTarget(ModelType.Target, Path);
28+
}
29+
30+
public override string ToString() => $"Recreate '{Path}'";
31+
32+
public RecreateTableHint(string path)
33+
{
34+
Path = path;
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)