Skip to content

Commit cd35f73

Browse files
committed
Refactored SqlServer's SucceedFunction SqlGenerator-method
1 parent d95cd6c commit cd35f73

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ public string CreateFunction(
166166
}
167167

168168
private string? _succeedFunctionSql;
169-
public string SucceedFunction(
170-
StoredId storedId, byte[]? result, long timestamp, int expectedEpoch,
171-
SqlCommand command, string paramPrefix)
169+
public StoreCommand SucceedFunction(StoredId storedId, byte[]? result, long timestamp, int expectedEpoch, string paramPrefix)
172170
{
173171
_succeedFunctionSql ??= @$"
174172
UPDATE {tablePrefix}
@@ -178,14 +176,15 @@ public string SucceedFunction(
178176
var sql = paramPrefix == ""
179177
? _succeedFunctionSql
180178
: _succeedFunctionSql.Replace("@", $"@{paramPrefix}");
181-
182-
command.Parameters.AddWithValue($"@{paramPrefix}ResultJson", result ?? SqlBinary.Null);
183-
command.Parameters.AddWithValue($"@{paramPrefix}Timestamp", timestamp);
184-
command.Parameters.AddWithValue($"@{paramPrefix}FlowInstance", storedId.Instance.Value);
185-
command.Parameters.AddWithValue($"@{paramPrefix}FlowType", storedId.Type.Value);
186-
command.Parameters.AddWithValue($"@{paramPrefix}ExpectedEpoch", expectedEpoch);
187179

188-
return sql;
180+
var command = new StoreCommand(sql);
181+
command.AddParameter($"@{paramPrefix}ResultJson", result ?? SqlBinary.Null);
182+
command.AddParameter($"@{paramPrefix}Timestamp", timestamp);
183+
command.AddParameter($"@{paramPrefix}FlowInstance", storedId.Instance.Value);
184+
command.AddParameter($"@{paramPrefix}FlowType", storedId.Type.Value);
185+
command.AddParameter($"@{paramPrefix}ExpectedEpoch", expectedEpoch);
186+
187+
return command;
189188
}
190189

191190
private string? _postponedFunctionSql;

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,14 @@ public async Task<bool> SucceedFunction(
393393
ComplimentaryState complimentaryState)
394394
{
395395
await using var conn = await _connFunc();
396-
await using var command = new SqlCommand();
397-
command.Connection = conn;
398-
399-
var sql = _sqlGenerator.SucceedFunction(
400-
storedId,
401-
result,
402-
timestamp,
403-
expectedEpoch,
404-
command,
405-
paramPrefix: ""
406-
);
407-
command.CommandText = sql;
396+
await using var command = _sqlGenerator
397+
.SucceedFunction(
398+
storedId,
399+
result,
400+
timestamp,
401+
expectedEpoch,
402+
paramPrefix: ""
403+
).ToSqlCommand(conn);
408404

409405
var affectedRows = await command.ExecuteNonQueryAsync();
410406
return affectedRows > 0;

0 commit comments

Comments
 (0)