コード例 #1
0
        public string GenerateSql(IStructureSchema structureSchema)
        {
            var columnDefinitions = structureSchema.IndexAccessors
                .Select(GenerateColumnDefinition);
            var columnsString = string.Join(",", columnDefinitions);
            var sql = structureSchema.IdAccessor.IdType == IdTypes.Guid
                          ? _sqlStrings.GetSql("CreateIndexesGuid")
                          : _sqlStrings.GetSql("CreateIndexesIdentity");

            return sql.Inject(
                structureSchema.GetStructureTableName(),
                structureSchema.GetIndexesTableName(),
                columnsString);
        }
コード例 #2
0
        public void Upsert(IStructureSchema structureSchema)
        {
            var structuresTableName = structureSchema.GetStructureTableName();
            var indexesTableName = structureSchema.GetIndexesTableName();
            var uniquesTableName = structureSchema.GetUniquesTableName();

            var structuresTableExists = _dbClient.TableExists(structuresTableName);
            var indexesTableExists = _dbClient.TableExists(indexesTableName);
            var uniquesTableExists = _dbClient.TableExists(uniquesTableName);

            if (structuresTableExists && indexesTableExists && uniquesTableExists)
            {
                _indexesDbSchemaSynchronizer.Synchronize(structureSchema);
                _uniquesDbSchemaSynchronizer.Synchronize(structureSchema);
                return;
            }

            var structuresSql = structuresTableExists ? "" : _structuresDbSchemaBuilder.GenerateSql(structureSchema);
            var indexesSql = indexesTableExists ? "" : _indexesDbSchemaBuilder.GenerateSql(structureSchema);
            var uniquesSql = uniquesTableExists ? "" : _uniquesDbSchemaBuilder.GenerateSql(structureSchema);

            using (var cmd = _dbClient.CreateCommand(CommandType.Text, null,
                new QueryParameter("entityHash", structureSchema.Hash),
                new QueryParameter("entityName", structureSchema.Name)))
            {
                if (!structuresTableExists)
                {
                    cmd.CommandText = structuresSql;
                    cmd.ExecuteNonQuery();
                }

                if (!indexesTableExists)
                {
                    cmd.CommandText = indexesSql;
                    cmd.ExecuteNonQuery();
                }
                else
                    _indexesDbSchemaSynchronizer.Synchronize(structureSchema);

                if (!uniquesTableExists)
                {
                    cmd.CommandText = uniquesSql;
                    cmd.ExecuteNonQuery();
                }
                else
                    _uniquesDbSchemaSynchronizer.Synchronize(structureSchema);
            }
        }
コード例 #3
0
        public void DropStructureSet(IStructureSchema structureSchema)
        {
            lock (_upsertedSchemas)
            {
                _upsertedSchemas.Remove(structureSchema.Name);

                var sql = _sqlStrings.GetSql("DropStructureTables").Inject(
                    structureSchema.GetIndexesTableName(),
                    structureSchema.GetStructureTableName());

                using (var client = new SqlDbClient(_connectionInfo, false))
                {
                    client.ExecuteNonQuery(CommandType.Text, sql, new QueryParameter("entityHash", structureSchema.Hash));
                }
            }
        }
コード例 #4
0
        public void Synchronize(IStructureSchema structureSchema)
        {
            var tableName = structureSchema.GetIndexesTableName();

            var schemaChanges = GetSchemaChanges(structureSchema);
            if (schemaChanges.Count() < 1)
                return;

            var columnsToDrop = schemaChanges
                .Where(sc => sc.Change == SchemaChanges.IsObsoleteColumn)
                .ToList();
            DropColumns(tableName, columnsToDrop);

            var columnsToAdd = schemaChanges
                .Where(sc => sc.Change == SchemaChanges.IsMissingColumn)
                .ToList();
            AddColumns(tableName, columnsToAdd);
        }
コード例 #5
0
 internal IndexStorageSchema(IStructureSchema structureSchema)
     : base(structureSchema, structureSchema.GetIndexesTableName())
 {
 }
コード例 #6
0
        private IList<SqlDbColumn> GetIndexesColumns(IStructureSchema structureSchema)
        {
            var dbColumns = _dbClient.GetColumns(structureSchema.GetIndexesTableName(), IndexStorageSchema.Fields.StructureId.Name);

            return dbColumns ?? new List<SqlDbColumn>();
        }