protected virtual IndexInsertAction[] CreateGroupedIndexInsertActions(IStructureSchema structureSchema, IStructure[] structures)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var insertActions     = new Dictionary <DataTypeCode, IndexInsertAction>(indexesTableNames.All.Length);

            foreach (var group in structures.SelectMany(s => s.Indexes).GroupBy(i => i.DataTypeCode))
            {
                var insertAction = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, group.Key, group.ToArray());
                if (insertAction.HasData)
                {
                    insertActions.Add(group.Key, insertAction);
                }
            }

            var mergeStringsAndEnums = insertActions.ContainsKey(DataTypeCode.String) && insertActions.ContainsKey(DataTypeCode.Enum);

            if (mergeStringsAndEnums)
            {
                var strings = insertActions[DataTypeCode.String];
                var enums   = insertActions[DataTypeCode.Enum];
                insertActions.Remove(DataTypeCode.Enum);

                insertActions[DataTypeCode.String] = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, DataTypeCode.String, strings.Data.MergeWith(enums.Data).ToArray());
            }

            return(insertActions.Values.ToArray());
        }
Beispiel #2
0
        public static void should_have_been_deleted_from_indexes_tables(this ITestDbUtils db, IStructureSchema structureSchema, object structureId)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();

            foreach (var indexesTableName in indexesTableNames.All)
            {
                db.RowCount(indexesTableName, "{0} = '{1}'".Inject(IndexStorageSchema.Fields.StructureId.Name, structureId)).ShouldEqual(0);
            }
        }
Beispiel #3
0
        public static void should_not_have_been_deleted_from_indexes_tables(this ITestDbUtils db, IStructureSchema structureSchema, object structureId)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var countSum          = 0;

            foreach (var indexesTableName in indexesTableNames.All)
            {
                countSum += db.RowCount(indexesTableName, "{0} = '{1}'".Inject(IndexStorageSchema.Fields.StructureId.Name, structureId));
            }

            countSum.ShouldBeGreaterThan(0);
        }
Beispiel #4
0
        public static void should_not_have_stored_member_in_indexes_table <T>(this ITestDbUtils db, IStructureSchema structureSchema, object structureId, Expression <Func <T, object> > memberExpression, Type memberType)
        {
            var memberPath = GetMemberPath(memberExpression);

            structureSchema.IndexAccessors.Count(iac => iac.Path == memberPath).ShouldEqual(0);

            var tablename = structureSchema.GetIndexesTableNames().GetNameByType(DataTypeConverter.Convert(memberType, memberPath));

            db.RowCount(tablename, "{0} = '{1}' and {2} = '{3}'".Inject(
                            IndexStorageSchema.Fields.StructureId.Name, structureId,
                            IndexStorageSchema.Fields.MemberPath.Name, memberPath)).ShouldEqual(0);
        }
        public virtual bool AnyIndexesTableHasMember <T>(IStructureSchema structureSchema, object id, Expression <Func <T, object> > member) where T : class
        {
            var memberPath        = GetMemberPath(member);
            var indexesTableNames = structureSchema.GetIndexesTableNames();

            foreach (var indexesTableName in indexesTableNames.All)
            {
                var sql = "[{0}] = @pStructureId and [{1}] = @pPath".Inject(IndexStorageSchema.Fields.StructureId.Name, IndexStorageSchema.Fields.MemberPath.Name);
                if (RowCount(indexesTableName, sql, new DacParameter("pStructureId", id), new DacParameter("pPath", memberPath)) > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #6
0
        public override void ClearQueryIndexes(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sqlFormat     = SqlStatements.GetSql("EmptyTable");
            var indexesTables = structureSchema.GetIndexesTableNames();

            using (var cmd = CreateCommand(null))
            {
                foreach (var tableName in indexesTables.All)
                {
                    cmd.CommandText = sqlFormat.Inject(tableName);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Beispiel #7
0
        public virtual void DeleteIndexesAndUniquesById(IStructureId structureId, IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var uniquesTableName  = structureSchema.GetUniquesTableName();

            var sql = StringExtensions.Inject(SqlStatements.GetSql("DeleteIndexesAndUniquesById"), uniquesTableName,
                                              indexesTableNames.BooleansTableName,
                                              indexesTableNames.DatesTableName,
                                              indexesTableNames.FractalsTableName,
                                              indexesTableNames.GuidsTableName,
                                              indexesTableNames.IntegersTableName,
                                              indexesTableNames.StringsTableName,
                                              indexesTableNames.TextsTableName);

            ExecuteNonQuery(sql, new DacParameter("id", structureId.Value));
        }
        public virtual void DeleteQueryIndexesFor(IStructureSchema structureSchema, IEnumerable <Guid> structureIds)
        {
            var guidIds           = string.Join(",", structureIds.Select(id => string.Format("'{0}'", id)));
            var sqlFormat         = "delete from [{0}] where StructureId in({1});".Inject("{0}", guidIds);
            var indexesTableNames = structureSchema.GetIndexesTableNames();

            using (var cn = CreateConnection())
            {
                cn.Open();
                using (var cmd = Driver.CreateCommand(cn, null))
                {
                    foreach (var tableName in indexesTableNames.All)
                    {
                        cmd.CommandText = sqlFormat.Inject(tableName);
                        cmd.ExecuteNonQuery();
                    }
                    cn.Close();
                }
            }
        }
        public override void Drop(IStructureSchema structureSchema)
        {
			Ensure.That(structureSchema, "structureSchema").IsNotNull();

        	var indexesTableNames = structureSchema.GetIndexesTableNames();

            var sql = SqlStatements.GetSql("DropStructureTables").Inject(
                indexesTableNames.IntegersTableName,
				indexesTableNames.FractalsTableName,
				indexesTableNames.BooleansTableName,
				indexesTableNames.DatesTableName,
				indexesTableNames.GuidsTableName,
				indexesTableNames.StringsTableName,
				indexesTableNames.TextsTableName,
                structureSchema.GetUniquesTableName(),
                structureSchema.GetStructureTableName());

            using (var cmd = CreateCommand(sql, new DacParameter("entityName", structureSchema.Name)))
            {
                cmd.ExecuteNonQuery();
            }
        }
        public override void ClearQueryIndexes(IStructureSchema structureSchema)
        {
            Ensure.That(structureSchema, "structureSchema").IsNotNull();

            var sqlFormat = SqlStatements.GetSql("EmptyTable");
            var indexesTables = structureSchema.GetIndexesTableNames();

            using(var cmd = CreateCommand(null))
            {
                foreach (var tableName in indexesTables.All)
                {
                    cmd.CommandText = sqlFormat.Inject(tableName);
                    cmd.ExecuteNonQuery();
                }   
            }
        }
        protected virtual IndexInsertAction[] CreateGroupedIndexInsertActions(IStructureSchema structureSchema, IStructure[] structures)
        {
            var indexesTableNames = structureSchema.GetIndexesTableNames();
            var insertActions = new Dictionary<DataTypeCode, IndexInsertAction>(indexesTableNames.All.Length);
            foreach (var group in structures.SelectMany(s => s.Indexes).GroupBy(i => i.DataTypeCode))
            {
                var insertAction = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, group.Key, group.ToArray());
                if (insertAction.HasData)
                    insertActions.Add(group.Key, insertAction);
            }

            var mergeStringsAndEnums = insertActions.ContainsKey(DataTypeCode.String) && insertActions.ContainsKey(DataTypeCode.Enum);
            if (mergeStringsAndEnums)
            {
                var strings = insertActions[DataTypeCode.String];
                var enums = insertActions[DataTypeCode.Enum];
                insertActions.Remove(DataTypeCode.Enum);

                insertActions[DataTypeCode.String] = CreateIndexInsertActionGroup(structureSchema, indexesTableNames, DataTypeCode.String, strings.Data.MergeWith(enums.Data).ToArray());
            }

            return insertActions.Values.ToArray();
        }