Esempio n. 1
0
        public PostgreSQLStateEntitySaver(
            BatchOperator <StateEntity> .Factory batchOperatorFactory,
            IBatchOperatorContainer batchOperatorContainer,
            IDbFactory dbFactory,
            IClaptrapIdentity identity,
            IPostgreSQLStateStoreOptions options)
        {
            var locator = options.RelationalStateStoreLocator;

            var(connectionName, schemaName, stateTableName) = locator.GetNames(identity);
            _connectionName = connectionName;
            _schemaName     = schemaName;
            _stateTableName = stateTableName;

            var operatorKey = new BatchOperatorKey()
                              .With(nameof(PostgreSQLStateEntitySaver))
                              .With(_connectionName)
                              .With(_schemaName)
                              .With(_stateTableName);

            _batchOperator = (IBatchOperator <StateEntity>)batchOperatorContainer.GetOrAdd(
                operatorKey, () => batchOperatorFactory.Invoke(
                    new BatchOperatorOptions <StateEntity>(options)
            {
                DoManyFunc = (entities, cacheData) =>
                             SaveManyCoreMany(dbFactory, entities, (string)cacheData ![UpsertSqlKey]),
        public PostgreSQLStateStoreMigration(
            ILogger <PostgreSQLStateStoreMigration> logger,
            DbUpMigration.Factory factory,
            IClaptrapIdentity identity,
            IDbFactory dbFactory,
            IStorageMigrationContainer storageMigrationContainer,
            IPostgreSQLStateStoreOptions options)
        {
            var locator = options.RelationalStateStoreLocator;

            var(connectionName, schemaName, stateTableName) = locator.GetNames(identity);

            var migrationOptions = new DbUpMigrationOptions(
                new[] { Assembly.GetExecutingAssembly() },
                fileName => fileName.EndsWith("-state.sql"),
                new Dictionary <string, string>
            {
                { "SchemaName", schemaName },
                { "StateTableName", stateTableName },
            },
                () =>
                (DeployChanges
                 .To.PostgresqlDatabase(dbFactory.GetConnectionString(connectionName)), null));

            var migration = factory.Invoke(logger, migrationOptions);

            var migrationKey =
                $"{nameof(PostgreSQLStateStoreMigration)}_{connectionName}_{schemaName}_{stateTableName}";

            _migrationTask = storageMigrationContainer.CreateTask(migrationKey, migration);
        }