Skip to content

Commit f97ab5c

Browse files
committed
Refactored SqlServer's CreateFunction SqlGenerator-method
1 parent cd35f73 commit f97ab5c

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,14 @@ DELETE FROM {tablePrefix}_effects
115115
}
116116

117117
private string? _createFunctionSql;
118-
public string CreateFunction(
118+
public StoreCommand CreateFunction(
119119
StoredId storedId,
120120
FlowInstance humanInstanceId,
121121
byte[]? param,
122122
long leaseExpiration,
123123
long? postponeUntil,
124124
long timestamp,
125125
StoredId? parent,
126-
SqlCommand command,
127126
string? paramPrefix)
128127
{
129128
_createFunctionSql ??= @$"
@@ -153,16 +152,17 @@ public string CreateFunction(
153152
if (paramPrefix != null)
154153
sql = sql.Replace("@", $"@{paramPrefix}");
155154

156-
command.Parameters.AddWithValue($"@{paramPrefix}FlowType", storedId.Type.Value);
157-
command.Parameters.AddWithValue($"@{paramPrefix}FlowInstance", storedId.Instance.Value);
158-
command.Parameters.AddWithValue($"@{paramPrefix}Status", (int)(postponeUntil == null ? Status.Executing : Status.Postponed));
159-
command.Parameters.AddWithValue($"@{paramPrefix}ParamJson", param == null ? SqlBinary.Null : param);
160-
command.Parameters.AddWithValue($"@{paramPrefix}Expires", postponeUntil ?? leaseExpiration);
161-
command.Parameters.AddWithValue($"@{paramPrefix}HumanInstanceId", humanInstanceId.Value);
162-
command.Parameters.AddWithValue($"@{paramPrefix}Timestamp", timestamp);
163-
command.Parameters.AddWithValue($"@{paramPrefix}Parent", parent?.Serialize() ?? (object)DBNull.Value);
155+
var command = new StoreCommand(sql);
156+
command.AddParameter($"@{paramPrefix}FlowType", storedId.Type.Value);
157+
command.AddParameter($"@{paramPrefix}FlowInstance", storedId.Instance.Value);
158+
command.AddParameter($"@{paramPrefix}Status", (int)(postponeUntil == null ? Status.Executing : Status.Postponed));
159+
command.AddParameter($"@{paramPrefix}ParamJson", param == null ? SqlBinary.Null : param);
160+
command.AddParameter($"@{paramPrefix}Expires", postponeUntil ?? leaseExpiration);
161+
command.AddParameter($"@{paramPrefix}HumanInstanceId", humanInstanceId.Value);
162+
command.AddParameter($"@{paramPrefix}Timestamp", timestamp);
163+
command.AddParameter($"@{paramPrefix}Parent", parent?.Serialize() ?? (object)DBNull.Value);
164164

165-
return sql;
165+
return command;
166166
}
167167

168168
private string? _succeedFunctionSql;

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,18 @@ public async Task<bool> CreateFunction(
145145
await using var conn = await _connFunc();
146146

147147
try
148-
{
149-
await using var command = new SqlCommand();
150-
command.Connection = conn;
151-
command.CommandText = _sqlGenerator.CreateFunction(
152-
storedId,
153-
humanInstanceId,
154-
param,
155-
leaseExpiration,
156-
postponeUntil,
157-
timestamp,
158-
parent,
159-
command,
160-
paramPrefix: null
161-
);
148+
{
149+
await using var command = _sqlGenerator
150+
.CreateFunction(
151+
storedId,
152+
humanInstanceId,
153+
param,
154+
leaseExpiration,
155+
postponeUntil,
156+
timestamp,
157+
parent,
158+
paramPrefix: null
159+
).ToSqlCommand(conn);
162160

163161
await command.ExecuteNonQueryAsync();
164162
}

0 commit comments

Comments
 (0)