Skip to content

Commit a21d308

Browse files
committed
Added Version field to SetValue()
In order to allow the `AttributeValue` to be annotated with `LastModified` metadata, we're adding `Version` to the `SetValue()` calls, based on data retrieved from the `GetTopics` stored procedure. Because the published schema for 4.0.0 doesn't return a `Version` field when calling `GetTopics`, this code checks for the number of returned columns to maintain backward compatibility; this allows this to be published as an minor version without breaking semantic versioning rules. Preferably, we'd actually check for the existence of the `value` property, but that's quite a bit more involved with `SqlDataReader`, and the column count gives us confidence in that, at least for this version. (We'll ideally want to remove this in the 5.0.0 release.)
1 parent aab51f6 commit a21d308

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

OnTopic.Data.Sql/SqlTopicRepository.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
121121
var id = Int32.Parse(reader["TopicID"]?.ToString(), CultureInfo.InvariantCulture);
122122
var name = reader["AttributeKey"]?.ToString();
123123
var value = reader["AttributeValue"]?.ToString();
124+
var version = DateTime.Now;
125+
126+
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
127+
//### TODO JJC20200221: This condition can be removed and accepted as a breaking change in v5.0.
128+
if (reader.FieldCount > 3) {
129+
version = DateTime.Parse(reader["Version"]?.ToString(), CultureInfo.InvariantCulture);
130+
}
124131

125132
/*------------------------------------------------------------------------------------------------------------------------
126133
| Validate conditions
@@ -141,7 +148,7 @@ private static void SetIndexedAttributes(SqlDataReader reader, Dictionary<int, T
141148
/*------------------------------------------------------------------------------------------------------------------------
142149
| Set attribute value
143150
\-----------------------------------------------------------------------------------------------------------------------*/
144-
current.Attributes.SetValue(name, value, false);
151+
current.Attributes.SetValue(name, value, false, version);
145152

146153
}
147154

@@ -169,6 +176,13 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
169176
| Identify attributes
170177
\-----------------------------------------------------------------------------------------------------------------------*/
171178
var id = Int32.Parse(reader["TopicID"]?.ToString(), CultureInfo.InvariantCulture);
179+
var version = DateTime.Now;
180+
181+
//Check field count to avoid breaking changes with the 4.0.0 release, which didn't include a "Version" column
182+
//### TODO JJC20200221: This condition can be removed and accepted as a breaking change in v5.0.
183+
if (reader.FieldCount > 2) {
184+
version = DateTime.Parse(reader["Version"]?.ToString(), CultureInfo.InvariantCulture);
185+
}
172186

173187
/*------------------------------------------------------------------------------------------------------------------------
174188
| Validate conditions
@@ -214,7 +228,7 @@ private static void SetExtendedAttributes(SqlDataReader reader, Dictionary<int,
214228
| Set attribute value
215229
\---------------------------------------------------------------------------------------------------------------------*/
216230
if (String.IsNullOrEmpty(value)) continue;
217-
current.Attributes.SetValue(name, value, false);
231+
current.Attributes.SetValue(name, value, false, version);
218232

219233
} while (xmlReader.Name == "attribute");
220234

0 commit comments

Comments
 (0)