Skip to content

Commit 79c6067

Browse files
committed
Update DeleteDataHint with internal enum state
1 parent c89bd21 commit 79c6067

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

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

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,46 @@ namespace Xtensive.Modelling.Comparison.Hints
1717
[Serializable]
1818
public class DeleteDataHint : DataHint
1919
{
20+
[Flags]
21+
internal enum DeleteDataHintInfo : byte
22+
{
23+
None = 0,
24+
PostCopy = 1,
25+
TableMovement = 2,
26+
All = PostCopy | TableMovement
27+
}
28+
29+
private readonly DeleteDataHintInfo info = DeleteDataHintInfo.None;
30+
2031
/// <summary>
21-
/// Gets or sets a value indicating whether deletion must be performed after completion of copy data hint processing.
32+
/// Gets a value indicating whether deletion must be performed after completion of copy data hint processing.
2233
/// Normally this flag is used to remove records related to types moved to other hierarchies -
2334
/// these records are still necessary during upgrade to be copied, but must be removed on its
2435
/// completion.
2536
/// </summary>
26-
public bool PostCopy { get; private set; }
37+
public bool PostCopy => info.HasFlag(DeleteDataHintInfo.PostCopy);
38+
39+
/// <summary>
40+
/// Gets a value indicating whether cause of data deletion is due to table have changed its owner type.
41+
/// </summary>
42+
public bool DueToTableOwnerChange => info.HasFlag(DeleteDataHintInfo.TableMovement);
43+
44+
/// <summary>
45+
/// Gets a value indication whether deletion is unsafe. Deletion is considered insafe
46+
/// if PostCopy or DueToTableOwnerChange equals <see langword="true"/>.
47+
/// </summary>
48+
public bool IsUnsafe => info != DeleteDataHintInfo.None;
49+
2750

2851
/// <summary>
29-
/// Gets value indicating whether cause of data deletion was moving table to another hierarchy.
30-
/// This flag is used to ideitify and prevent unsafe data clean-up even if database structure
31-
/// remain identical but logically table serves completely different entity.
52+
/// Internal infomations about this hint.
53+
/// <para>
54+
/// It is used in some cases to create new hint
55+
/// based on this one. It can be done by open
56+
/// constructors but enum is better.
57+
/// </para>
3258
/// </summary>
33-
public bool TableChangedOwner { get; private set; }
59+
internal DeleteDataHintInfo Info => info;
3460

3561
/// <inheritdoc/>
3662
public override string ToString()
@@ -41,10 +67,9 @@ public override string ToString()
4167
string.Join(" and ",
4268
Identities.Select(pair => pair.ToString()).ToArray()),
4369
PostCopy ? " (after data copying)" : string.Empty,
44-
TableChangedOwner ? " due to table owner changed" : string.Empty);
70+
DueToTableOwnerChange ? " due to table changed owner type" : string.Empty);
4571
}
4672

47-
4873
// Constructors
4974

5075
/// <summary>
@@ -64,7 +89,9 @@ public DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities)
6489
public DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities, bool postCopy)
6590
: base(sourceTablePath, identities)
6691
{
67-
PostCopy = postCopy;
92+
if (postCopy) {
93+
info |= DeleteDataHintInfo.PostCopy;
94+
}
6895
}
6996

7097
/// <summary>
@@ -73,12 +100,29 @@ public DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities, b
73100
/// <param name="sourceTablePath">Source table path.</param>
74101
/// <param name="identities">Identities for data operation.</param>
75102
/// <param name="postCopy"><see cref="PostCopy"/> property value.</param>
76-
/// <param name="tableChangedOwner"><see cref="TableChangedOwner"/> property value.</param>
77-
public DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities, bool postCopy, bool tableChangedOwner)
103+
/// <param name="dueToOnwerChange"><see langword="true"/> if reason of deletion is the table <paramref name="sourceTablePath"/>
104+
/// has changed assigned type.</param>
105+
public DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities, bool postCopy, bool dueToOnwerChange)
106+
: this(sourceTablePath, identities)
107+
{
108+
if (postCopy) {
109+
info |= DeleteDataHintInfo.PostCopy;
110+
}
111+
if (dueToOnwerChange) {
112+
info |= DeleteDataHintInfo.TableMovement;
113+
}
114+
}
115+
116+
/// <summary>
117+
/// Initializes new instance of this type.
118+
/// </summary>
119+
/// <param name="sourceTablePath"></param>
120+
/// <param name="identities"></param>
121+
/// <param name="deleteDataInfo"></param>
122+
internal DeleteDataHint(string sourceTablePath, IList<IdentityPair> identities, DeleteDataHintInfo deleteDataInfo)
78123
: base(sourceTablePath, identities)
79124
{
80-
PostCopy = postCopy;
81-
TableChangedOwner = tableChangedOwner;
125+
info = deleteDataInfo;
82126
}
83127
}
84128
}

0 commit comments

Comments
 (0)