예제 #1
0
        public virtual void Drop(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var names = new ModelTableNames(structureSchema);

            EnsureValidNames(names);

            var sql = SqlStatements.GetSql("DropStructureTables").Inject(
                names.IndexesTableNames.IntegersTableName,
                names.IndexesTableNames.FractalsTableName,
                names.IndexesTableNames.BooleansTableName,
                names.IndexesTableNames.DatesTableName,
                names.IndexesTableNames.GuidsTableName,
                names.IndexesTableNames.StringsTableName,
                names.IndexesTableNames.TextsTableName,
                names.SpatialTableName,
                names.UniquesTableName,
                names.StructureTableName);

            using (var cmd = CreateCommand(sql, new DacParameter(DbSchemaInfo.Parameters.EntityNameParamPrefix, structureSchema.Name)))
            {
                cmd.ExecuteNonQuery();
            }
        }
예제 #2
0
 protected virtual void EnsureValidNames(ModelTableNames names)
 {
     foreach (var tableName in names.AllTableNames)
     {
         EnsureValidDbObjectName(tableName);
     }
 }
예제 #3
0
        public async Task <IList <IDataEntity> > GetAllItemsAsync(string queryId, ModelTableNames tableName)
        {
            switch (tableName)
            {
            case ModelTableNames.User:
                return(await GetAllItemsAsyncHelper(_userTable, queryId));

            case ModelTableNames.Category:
                return(await GetAllItemsAsyncHelper(_categoriesTable, queryId));

            case ModelTableNames.Favorites:
                return(await GetAllItemsAsyncHelper(_favoritesTable, queryId));

            case ModelTableNames.Ingredient:
                return(await GetAllItemsAsyncHelper(_ingredientsTable, queryId));

            case ModelTableNames.QuantityType:
                return(await GetAllItemsAsyncHelper(_quantityTypeTable, queryId));

            case ModelTableNames.Recipe:
                return(await GetAllItemsAsyncHelper(_recipiesTable, queryId));

            default:
                throw new ArgumentOutOfRangeException(nameof(tableName));
            }
        }
예제 #4
0
        public virtual ModelTablesInfo GetModelTablesInfo(IStructureSchema structureSchema)
        {
            var names = new ModelTableNames(structureSchema);

            EnsureValidNames(names);

            return(new ModelTablesInfo(names, GetModelTableStatuses(names)));
        }
        public void AllTableNames_WhenRegistreredManualStructureNameGenerator_AllTableNamesShouldHaveGainedThePrefix()
        {
            DbSchemaNamingPolicy.StructureNamePrefix = "Gooofy_";

            var names = new ModelTableNames("MyStructure");

            foreach (var tableName in names.AllTableNames)
            {
                Assert.IsTrue(tableName.StartsWith("Gooofy_"));
            }
        }
        public void AllTableNames_Should_ContainAllTableNamesInCorrectOrder()
        {
            var names = new ModelTableNames("MyStructure");

            Assert.AreEqual(10, names.AllTableNames.Length);
            Assert.AreEqual(names.StructureTableName, names.AllTableNames[0]);
            Assert.AreEqual(names.SpatialTableName, names.AllTableNames[1]);
            Assert.AreEqual(names.UniquesTableName, names.AllTableNames[2]);
            Assert.AreEqual(names.IndexesTableNames.IntegersTableName, names.AllTableNames[3]);
            Assert.AreEqual(names.IndexesTableNames.FractalsTableName, names.AllTableNames[4]);
            Assert.AreEqual(names.IndexesTableNames.BooleansTableName, names.AllTableNames[5]);
            Assert.AreEqual(names.IndexesTableNames.DatesTableName, names.AllTableNames[6]);
            Assert.AreEqual(names.IndexesTableNames.GuidsTableName, names.AllTableNames[7]);
            Assert.AreEqual(names.IndexesTableNames.StringsTableName, names.AllTableNames[8]);
            Assert.AreEqual(names.IndexesTableNames.TextsTableName, names.AllTableNames[9]);
        }
예제 #7
0
        public virtual void ClearQueryIndexes(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var names = new ModelTableNames(structureSchema);

            EnsureValidNames(names);

            var sql = StringExtensions.Inject(SqlStatements.GetSql("ClearIndexesTables"), names.IndexesTableNames.IntegersTableName,
                                              names.IndexesTableNames.FractalsTableName,
                                              names.IndexesTableNames.BooleansTableName,
                                              names.IndexesTableNames.DatesTableName,
                                              names.IndexesTableNames.GuidsTableName,
                                              names.IndexesTableNames.StringsTableName,
                                              names.IndexesTableNames.TextsTableName);

            using (var cmd = CreateCommand(sql))
            {
                cmd.ExecuteNonQuery();
            }
        }
예제 #8
0
        public async Task SaveItemsAsync(IDataEntity item, ModelTableNames tableName)
        {
            switch (tableName)
            {
            case ModelTableNames.Category:
                await CheckAndSaveItem((Category)item, _categoriesTable);

                break;

            case ModelTableNames.User:
                await CheckAndSaveItem((User)item, _userTable);

                break;

            case ModelTableNames.Favorites:
                await CheckAndSaveItem((Favorites)item, _favoritesTable);

                break;

            case ModelTableNames.Ingredient:
                await CheckAndSaveItem((Ingredient)item, _ingredientsTable);

                break;

            case ModelTableNames.QuantityType:
                await CheckAndSaveItem((QuantityType)item, _quantityTypeTable);

                break;

            case ModelTableNames.Recipe:
                await CheckAndSaveItem((Recipe)item, _recipiesTable);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(tableName));
            }
        }
예제 #9
0
        public virtual ModelTableStatuses GetModelTableStatuses(ModelTableNames names)
        {
            var sql           = SqlStatements.GetSql("GetModelTableStatuses");
            var parameters    = names.AllTableNames.Select((n, i) => new DacParameter(DbSchemaInfo.Parameters.TableNameParamPrefix + i, n)).ToArray();
            var matchingNames = new HashSet <string>();

            SingleResultSequentialReader(
                sql,
                dr => matchingNames.Add(dr.GetString(0)),
                parameters);

            return(new ModelTableStatuses(
                       matchingNames.Contains(names.StructureTableName),
                       matchingNames.Contains(names.SpatialTableName),
                       matchingNames.Contains(names.UniquesTableName),
                       new IndexesTableStatuses(
                           matchingNames.Contains(names.IndexesTableNames.IntegersTableName),
                           matchingNames.Contains(names.IndexesTableNames.FractalsTableName),
                           matchingNames.Contains(names.IndexesTableNames.DatesTableName),
                           matchingNames.Contains(names.IndexesTableNames.BooleansTableName),
                           matchingNames.Contains(names.IndexesTableNames.GuidsTableName),
                           matchingNames.Contains(names.IndexesTableNames.StringsTableName),
                           matchingNames.Contains(names.IndexesTableNames.TextsTableName))));
        }