Ejemplo n.º 1
0
        public SQLiteStateEntitySaver(
            ChannelBatchOperator <StateEntity> .Factory batchOperatorFactory,
            IClaptrapIdentity identity,
            ISQLiteDbFactory sqLiteDbFactory,
            ISQLiteStateStoreOptions options,
            ISqlTemplateCache sqlTemplateCache,
            IBatchOperatorContainer batchOperatorContainer)
        {
            _sqlTemplateCache = sqlTemplateCache;
            var locator        = options.RelationalStateStoreLocator;
            var stateTableName = locator.GetStateTableName(identity);

            _stateTableName = stateTableName;
            _connectionName = locator.GetConnectionName(identity);

            var operatorKey = new BatchOperatorKey()
                              .With(nameof(SQLiteStateEntitySaver))
                              .With(_connectionName)
                              .With(stateTableName);

            _batchOperator = (IBatchOperator <StateEntity>)batchOperatorContainer.GetOrAdd(
                operatorKey, () => batchOperatorFactory.Invoke(
                    new BatchOperatorOptions <StateEntity>(options)
            {
                DoManyFunc = (entities, cacheData) =>
                             SaveManyCoreMany(sqLiteDbFactory, entities, (string[])cacheData ![UpsertSqlKey]),
        public SQLiteStateStoreMigration(
            ILogger <SQLiteStateStoreMigration> logger,
            DbUpMigration.Factory factory,
            ISQLiteDbFactory sqLiteDbFactory,
            IClaptrapIdentity identity,
            IStorageMigrationContainer storageMigrationContainer,
            ISQLiteStateStoreOptions options)
        {
            var locator        = options.RelationalStateStoreLocator;
            var stateTableName = locator.GetStateTableName(identity);
            var connectionName = locator.GetConnectionName(identity);

            var migrationOptions = new DbUpMigrationOptions(
                new[] { Assembly.GetExecutingAssembly() },
                fileName => fileName.EndsWith("-state.sql"),
                new Dictionary <string, string>
            {
                { "StateTableName", stateTableName }
            },
                () =>
            {
                var dbConnection = sqLiteDbFactory.GetConnection(connectionName);
                var builder      = DeployChanges.To.SQLiteDatabase(new SharedConnection(dbConnection));
                return(builder, dbConnection);
            });

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

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

            _migrationTask = storageMigrationContainer.CreateTask(migrationKey, migration);
        }
        public SQLiteStateEntityLoader(
            IClaptrapIdentity claptrapIdentity,
            ISQLiteDbFactory sqLiteDbFactory,
            ISQLiteStateStoreOptions options)
        {
            _claptrapIdentity = claptrapIdentity;
            _sqLiteDbFactory  = sqLiteDbFactory;
            var locator        = options.RelationalStateStoreLocator;
            var stateTableName = locator.GetStateTableName(claptrapIdentity);

            _connectionName = locator.GetConnectionName(claptrapIdentity);
            _selectSql      =
                $"SELECT * FROM {stateTableName} WHERE claptrap_type_code=@ClaptrapTypeCode AND claptrap_id=@ClaptrapId LIMIT 1";
        }