Table of Contents

Class SqlServerOperationExecutor

Namespace
Excalibur.EventSourcing.SqlServer
Assembly
Excalibur.EventSourcing.SqlServer.dll

Deduplicates a single SQL event append using a receipt committed in its append transaction.

public sealed class SqlServerOperationExecutor : ISqlServerOperationExecutor
Inheritance
SqlServerOperationExecutor
Implements
Inherited Members

Remarks

Apply Scripts/006_CreateOperationReceipts.sql first (adapt names for a custom events table). The callback may perform one nonempty append through SqlServerEventStore to this exact destination and tenant. It must not perform independently committed business writes or external effects. No-event callbacks are not recorded. Receipts are retained indefinitely. Concurrent callbacks may run; the unique receipt in the append transaction permits only one committed append.

Constructors

SqlServerOperationExecutor(Func<SqlConnection>, ITenantContext)

Initializes an executor using the event store's canonical schema and table names.

public SqlServerOperationExecutor(Func<SqlConnection> connectionFactory, ITenantContext tenantContext)

Parameters

connectionFactory Func<SqlConnection>

Creates fresh owned primary SQL connections.

tenantContext ITenantContext

The event store's tenant context.

SqlServerOperationExecutor(Func<SqlConnection>, ITenantContext, string, string)

Initializes an executor for the same primary database and names as the event store.

public SqlServerOperationExecutor(Func<SqlConnection> connectionFactory, ITenantContext tenantContext, string schema, string eventsTable)

Parameters

connectionFactory Func<SqlConnection>

Creates fresh owned primary SQL connections.

tenantContext ITenantContext

The event store's tenant context.

schema string

The event store schema.

eventsTable string

The event table; receipts use this name followed by Operations.

Methods

BindSourceAsync(string, ReadOnlyMemory<byte>, CancellationToken)

Binds a configured source to its database/capture generation, refusing silent history replacement.

[SuppressMessage("Security", "CA2100", Justification = "Only constructor-validated SQL identifiers are interpolated; source and identity are typed parameters.")]
public Task BindSourceAsync(string source, ReadOnlyMemory<byte> sourceIdentity, CancellationToken cancellationToken)

Parameters

source string

Stable configured source name; do not include its changing generation.

sourceIdentity ReadOnlyMemory<byte>

SHA-256 of database identity, recovery fork and capture creation identity.

cancellationToken CancellationToken

Cancels the check.

Returns

Task

Remarks

Store this binding outside databases refreshed from source backups. Check before each delivery and on startup. A mismatch requires operator-coordinated reconciliation or rebuild before explicit rebind. This check is not a fence against an administrator forcing a restore during an in-flight handler; maintenance must stop and drain all consumers before replacing the source.

ExecuteAsync(string, string, ReadOnlyMemory<byte>, Func<CancellationToken, Task>, CancellationToken)

Runs a single-append operation or returns its original durable receipt without running it.

public Task<SqlServerOperationResult> ExecuteAsync(string scope, string operationKey, ReadOnlyMemory<byte> fingerprint, Func<CancellationToken, Task> action, CancellationToken cancellationToken)

Parameters

scope string

A stable authenticated caller and operation namespace, or CDC source incarnation.

operationKey string

The caller's stable retry key. Compared ordinally.

fingerprint ReadOnlyMemory<byte>

SHA-256 of immutable input, including target and original preconditions.

action Func<CancellationToken, Task>

The handler. At most one nonempty event append is supported.

cancellationToken CancellationToken

Cancels this attempt; cancellation does not prove rollback.

Returns

Task<SqlServerOperationResult>

The original receipt on replay, or the outcome of this attempt.