public TimeoutPersister( Func<DbConnection> connectionBuilder, string tablePrefix, SqlVarient sqlVarient) { this.connectionBuilder = connectionBuilder; timeoutCommands = TimeoutCommandBuilder.Build(sqlVarient, tablePrefix); }
public SubscriptionPersister(Func<DbConnection> connectionBuilder,string tablePrefix, SqlVarient sqlVarient) { this.connectionBuilder = connectionBuilder; this.tablePrefix = tablePrefix; this.sqlVarient = sqlVarient; subscriptionCommands = SubscriptionCommandBuilder.Build(sqlVarient, tablePrefix); }
public OutboxPersister( SqlVarient sqlVarient, Func<DbConnection> connectionBuilder, string tablePrefix) { this.connectionBuilder = connectionBuilder; outboxCommands = OutboxCommandBuilder.Build(sqlVarient, tablePrefix); }
public static TimeoutCommands Build(SqlVarient sqlVarient, string tablePrefix) { var tableName = $@"{tablePrefix}TimeoutData"; switch (sqlVarient) { case SqlVarient.MsSqlServer: return BuildSqlServerCommands(tableName); case SqlVarient.MySql: return BuildMySqlCommands(tableName); default: throw new Exception($"Unknown SqlVarient: {sqlVarient}."); } }
public static OutboxCommands Build(SqlVarient sqlVarient, string tablePrefix) { var tableName = $@"{tablePrefix}OutboxData"; string storeCommandText = $@" insert into {tableName} ( MessageId, Operations, PersistenceVersion ) values ( @MessageId, @Operations, @PersistenceVersion )"; string cleanupCommandText = $@" delete from {tableName} where Dispatched = true And DispatchedAt < @Date"; string getCommandText = $@" select Dispatched, Operations from {tableName} where MessageId = @MessageId"; string setAsDispatchedCommandText = $@" update {tableName} set Dispatched = 1, DispatchedAt = @DispatchedAt where MessageId = @MessageId"; return new OutboxCommands( store: storeCommandText, get: getCommandText, setAsDispatched: setAsDispatchedCommandText, cleanup: cleanupCommandText); }
public static void SqlVarient(this PersistenceExtensions<SqlPersistence> configuration, SqlVarient sqlVarient) { var settings = configuration.GetSettings(); settings.Set("SqlPersistence.SqlVarient", sqlVarient); }
public static string FindScriptDirectory(SqlVarient sqlVarient) { var codeBase = Assembly.GetExecutingAssembly().CodeBase; var currentDirectory = Directory.GetParent(new Uri(codeBase).LocalPath).FullName; return Path.Combine(currentDirectory, "NServiceBus.Persistence.Sql", sqlVarient.ToString()); }
static void Write(string testDirectory, SqlVarient varient, string suffix, string script) { Write(testDirectory, suffix, script, varient.ToString()); }
public static SubscriptionCommands Build(SqlVarient sqlVarient, string tablePrefix) { var tableName = $@"{tablePrefix}SubscriptionData"; string subscribeCommandText; switch (sqlVarient) { case SqlVarient.MsSqlServer: subscribeCommandText = $@" declare @dummy int; merge {tableName} with (holdlock) as target using(select @Endpoint as Endpoint, @Subscriber as Subscriber, @MessageType as MessageType) as source on target.Endpoint = source.Endpoint and target.Subscriber = source.Subscriber and target.MessageType = source.MessageType when matched then update set @dummy = 0 when not matched then insert ( Subscriber, MessageType, Endpoint, PersistenceVersion ) values ( @Subscriber, @MessageType, @Endpoint, @PersistenceVersion );"; break; case SqlVarient.MySql: subscribeCommandText = $@" insert into {tableName} ( Subscriber, MessageType, Endpoint, PersistenceVersion ) values ( @Subscriber, @MessageType, @Endpoint, @PersistenceVersion ) on duplicate key update Endpoint = @Endpoint, PersistenceVersion = @PersistenceVersion "; break; default: throw new Exception($"Unknown SqlVarient: {sqlVarient}."); } string unsubscribeCommandText = $@" delete from {tableName} where Subscriber = @Subscriber and MessageType = @MessageType"; var getSubscribersPrefix = $@" select distinct Subscriber, Endpoint from {tablePrefix}SubscriptionData where MessageType in ("; return new SubscriptionCommands( subscribe: subscribeCommandText, unsubscribe: unsubscribeCommandText, getSubscribers: messageTypes => { var builder = new StringBuilder(getSubscribersPrefix); for (var i = 0; i < messageTypes.Count; i++) { var paramName = $"@type{i}"; builder.Append(paramName); if (i < messageTypes.Count - 1) { builder.Append(", "); } } builder.Append(")"); return builder.ToString(); }); }
public SagaCommandBuilder(SqlVarient sqlVarient, string tablePrefix) { this.tablePrefix = tablePrefix; }