Exemple #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]),
Exemple #2
0
        public SQLiteEventStoreMigration(
            ILogger <SQLiteEventStoreMigration> logger,
            DbUpMigration.Factory factory,
            ISQLiteDbFactory sqLiteDbFactory,
            IStorageMigrationContainer storageMigrationContainer,
            IMasterOrSelfIdentity masterOrSelfIdentity,
            ISQLiteEventStoreOptions options)
        {
            var identity         = masterOrSelfIdentity.Identity;
            var storeLocator     = options.RelationalEventStoreLocator;
            var connectionName   = storeLocator.GetConnectionName(identity);
            var eventTableName   = storeLocator.GetEventTableName(identity);
            var migrationOptions = new DbUpMigrationOptions(
                new[] { Assembly.GetExecutingAssembly() },
                fileName => fileName.EndsWith("-event.sql"),
                new Dictionary <string, string>
            {
                { "EventTableName", eventTableName }
            },
                () =>
            {
                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(SQLiteEventStoreMigration)}_{connectionName}_{eventTableName}";

            _migrationTask = storageMigrationContainer.CreateTask(migrationKey, migration);
        }
Exemple #3
0
        public SQLiteEventEntitySaver(
            ChannelBatchOperator <EventEntity> .Factory batchOperatorFactory,
            IClaptrapIdentity identity,
            ISQLiteDbFactory sqLiteDbFactory,
            ISQLiteEventStoreOptions options,
            IBatchOperatorContainer batchOperatorContainer,
            ISqlTemplateCache sqlTemplateCache)
        {
            _sqLiteDbFactory  = sqLiteDbFactory;
            _sqlTemplateCache = sqlTemplateCache;
            var storeLocator = options.RelationalEventStoreLocator;

            _connectionName = storeLocator.GetConnectionName(identity);
            _eventTableName = storeLocator.GetEventTableName(identity);

            var operatorKey = new BatchOperatorKey()
                              .With(nameof(SQLiteEventEntitySaver))
                              .With(_connectionName)
                              .With(_eventTableName);

            _batchOperator = (IBatchOperator <EventEntity>)batchOperatorContainer.GetOrAdd(
                operatorKey, () => batchOperatorFactory.Invoke(
                    new BatchOperatorOptions <EventEntity>(options)
            {
                DoManyFunc = (entities, cacheData) =>
                             SaveManyAsync(entities),
                DoManyFuncName = $"event batch saver for {operatorKey.AsStringKey()}"
            }));
        }
        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";
        }
Exemple #5
0
        public SQLiteEventEntityLoader(
            ISQLiteDbFactory sqLiteDbFactory,
            ISQLiteEventStoreOptions options,
            IMasterOrSelfIdentity masterOrSelfIdentity)
        {
            _sqLiteDbFactory      = sqLiteDbFactory;
            _masterOrSelfIdentity = masterOrSelfIdentity.Identity;
            var storeLocator = options.RelationalEventStoreLocator;

            _connectionName = storeLocator.GetConnectionName(_masterOrSelfIdentity);
            var eventTableName = storeLocator.GetEventTableName(_masterOrSelfIdentity);

            _selectSql =
                $"SELECT * FROM {eventTableName} WHERE version >= @startVersion AND version < @endVersion AND claptrap_type_code=@ClaptrapTypeCode AND claptrap_id=@ClaptrapId ORDER BY version";
        }