Skip to content

Commit aa40acd

Browse files
committed
Introduce new IsExtendedAttribute property to AttributeValue
The object model doesn't care whether or not an `AttributeValue` was loaded from an `IsExtendedAttribute` repository store or not. Nevertheless, keeping track of this is useful for if the attribute is `Save()`d, as it allows us to detect potential mismatches between where the attribute _was_ saved, and where it is _supposed_ to be saved. As such, tracking this will enable us—in a future commit!—to detect cases where an attribute value hasn't changed (i.e., `!IsDirty`) _but_ the attribute should be saved _anyway_ since its _configured storage location_ (from `AttributeDescriptor.IsExtendedAttribute`) has changed since the attribute value was last saved.
1 parent a5b9e08 commit aa40acd

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

OnTopic/Attributes/AttributeValue.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public AttributeValue(string key, string? value, bool isDirty = true) {
9898
/// populating the topic graph from a persistent data store as a means of indicating the current version for each
9999
/// attribute. This is used when e.g. importing values to determine if the existing value is newer than the source value.
100100
/// </param>
101+
/// <param name="isExtendedAttribute">Determines if the attribute originated from an extended attributes data store.</param>
101102
/// <requires
102103
/// description="The key must be specified for the key/value pair." exception="T:System.ArgumentNullException">
103104
/// !String.IsNullOrWhiteSpace(key)
@@ -107,14 +108,16 @@ internal AttributeValue(
107108
string? value,
108109
bool isDirty,
109110
bool enforceBusinessLogic,
110-
DateTime? lastModified = null
111+
DateTime? lastModified = null,
112+
bool? isExtendedAttribute = null
111113
): this(
112114
key,
113115
value,
114116
isDirty
115117
) {
116118
EnforceBusinessLogic = enforceBusinessLogic;
117119
LastModified = lastModified?? DateTime.Now;
120+
IsExtendedAttribute = isExtendedAttribute;
118121
}
119122

120123
/*==========================================================================================================================
@@ -191,5 +194,36 @@ internal AttributeValue(
191194
/// </summary>
192195
public DateTime LastModified { get; internal set; } = DateTime.Now;
193196

197+
/*==========================================================================================================================
198+
| PROPERTY: IS EXTENDED ATTRIBUTE
199+
\-------------------------------------------------------------------------------------------------------------------------*/
200+
/// <summary>
201+
/// Determines if this attribute originated from a data store as an extended attribute.
202+
/// </summary>
203+
/// <remarks>
204+
/// <para>
205+
/// How an attribute is stored in the underlying repository doesn't impact how the attribute is treated as part of the
206+
/// object model. By tracking this, however, OnTopic is able to evaluate configuration mismatches during <see
207+
/// cref="ITopicRepository.Save"/>. This allows the <see cref="ITopicRepository"/> to effective handle scenarios where
208+
/// the configuration for an <see cref="AttributeDescriptor"/> has changed prior to the last time a <see cref="Topic"/>
209+
/// was saved, and thus change the location where it is stored.
210+
/// </para>
211+
/// <para>
212+
/// This is important because, otherwise, <see cref="ITopicRepository"/> implementations rely primarily on <see
213+
/// cref="IsDirty"/> to determine if a value should be saved. If an attribute's value hasn't changed, but the location
214+
/// it should be stored has, that could potentially result in the attribute being deleted, as the attribute won't show
215+
/// up for when <see cref="TopicRepositoryBase.GetAttributes"/> is called with <c>isDirty</c> set to <c>true</c> and
216+
/// <c>isExtendedAttribute</c> is set to either <c>true</c> or <c>false</c>. By introducing <see
217+
/// cref="IsExtendedAttribute"/>, the <see cref="TopicRepositoryBase"/> is able to detect conflicts between the
218+
/// configuration and the underlying data store, and ensure data is stored appropriately.
219+
/// </para>
220+
/// <para>
221+
/// The <see cref="IsExtendedAttribute"/> property maps to the <see cref="AttributeDescriptor.IsExtendedAttribute"/>
222+
/// property. The former describes where the data was <i>actually</i> stored, whereas the latter describes where the
223+
/// data <i>should</i> be stored.
224+
/// </para>
225+
/// </remarks>
226+
public bool? IsExtendedAttribute { get; internal set; }
227+
194228
} //Class
195229
} //Namespace

0 commit comments

Comments
 (0)