Exemplo n.º 1
0
        private void Check_1_1_RelationColumns(Relation rel, RelationEnd relEnd, RelationEndRole role)
        {
            if (rel.HasStorage(role))
            {
                var         tblName    = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
                RelationEnd otherEnd   = rel.GetOtherEnd(relEnd);
                var         refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
                string      colName    = Construct.ForeignKeyColumnName(otherEnd);
                string      assocName  = rel.GetRelationAssociationName(role);
                string      idxName    = Construct.IndexName(tblName.Name, colName);

                CheckColumn(tblName, Construct.ForeignKeyColumnName(otherEnd), System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
                if (!db.CheckFKConstraintExists(tblName, assocName))
                {
                    Log.WarnFormat("FK Constraint '{0}' is missing", assocName);
                    if (repair)
                    {
                        db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
                    }
                }
                if (!db.CheckIndexExists(tblName, idxName))
                {
                    Log.WarnFormat("Index '{0}' is missing", idxName);
                    if (repair)
                    {
                        db.CreateIndex(tblName, idxName, true, false, colName);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void CheckIndexConstraints(ObjectClass objClass)
 {
     foreach (var uc in objClass.Constraints.OfType <IndexConstraint>())
     {
         var tblName = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
         var columns = Cases.GetUCColNames(uc);
         var idxName = Construct.IndexName(tblName.Name, columns);
         if (!db.CheckIndexExists(tblName, idxName))
         {
             Log.WarnFormat("Index Constraint '{0}' is missing", idxName);
             if (repair)
             {
                 Case.DoNewIndexConstraint(uc);
             }
         }
     }
 }
Exemplo n.º 3
0
        private void Check_N_M_RelationColumns(Relation rel)
        {
            string assocName = rel.GetAssociationName();

            var    tblName    = db.GetTableName(rel.Module.SchemaName, rel.GetRelationTableName());
            string fkAName    = rel.GetRelationFkColumnName(RelationEndRole.A);
            string fkBName    = rel.GetRelationFkColumnName(RelationEndRole.B);
            string assocAName = rel.GetRelationAssociationName(RelationEndRole.A);
            string assocBName = rel.GetRelationAssociationName(RelationEndRole.B);
            string fkAIndex   = fkAName + Zetbox.API.Helper.PositionSuffix;
            string fkBIndex   = fkBName + Zetbox.API.Helper.PositionSuffix;

            Log.DebugFormat("Checking [{0}]", assocName);

            if (!db.CheckTableExists(tblName))
            {
                Log.WarnFormat("Relation table '{0}' is missing for [{1}]", tblName, assocName);
                if (repair)
                {
                    Case.DoNew_N_M_Relation(rel);
                }
                return;
            }
            CheckColumn(tblName, fkAName, System.Data.DbType.Int32, 0, 0, false, null);
            CheckColumn(tblName, fkBName, System.Data.DbType.Int32, 0, 0, false, null);

            if (!db.CheckFKConstraintExists(tblName, assocAName))
            {
                Log.WarnFormat("FK Constraint '{0}' for A is missing for [{1}]", assocAName, assocName);
                if (repair)
                {
                    db.CreateFKConstraint(tblName, db.GetTableName(rel.A.Type.Module.SchemaName, rel.A.Type.TableName), fkAName, assocAName, true);
                }
            }
            if (!db.CheckFKConstraintExists(tblName, assocBName))
            {
                Log.WarnFormat("FK Constraint '{0}' for B is missing for [{1}]", assocBName, assocName);
                if (repair)
                {
                    db.CreateFKConstraint(tblName, db.GetTableName(rel.B.Type.Module.SchemaName, rel.B.Type.TableName), fkBName, assocBName, true);
                }
            }

            if (!db.CheckIndexExists(tblName, Construct.IndexName(tblName.Name, fkAName)))
            {
                Log.WarnFormat("Index '{0}' is missing", Construct.IndexName(tblName.Name, fkAName));
                if (repair)
                {
                    db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkAName), false, false, fkAName);
                }
            }
            if (!db.CheckIndexExists(tblName, Construct.IndexName(tblName.Name, fkBName)))
            {
                Log.WarnFormat("Index '{0}' is missing", Construct.IndexName(tblName.Name, fkBName));
                if (repair)
                {
                    db.CreateIndex(tblName, Construct.IndexName(tblName.Name, fkBName), false, false, fkBName);
                }
            }


            if (rel.NeedsPositionStorage(RelationEndRole.A))
            {
                CheckColumn(tblName, fkAIndex, System.Data.DbType.Int32, 0, 0, true, null);
                if (repair)
                {
                    // TODO: Call case
                }
            }
            if (!rel.NeedsPositionStorage(RelationEndRole.A) && db.CheckColumnExists(tblName, fkAIndex))
            {
                Log.WarnFormat("Navigator A '{0}' Index Column exists but property is not indexed for [{1}]", fkAName, assocName);
                if (repair)
                {
                    // TODO: Call case
                }
            }

            if (rel.NeedsPositionStorage(RelationEndRole.B))
            {
                CheckColumn(tblName, fkBIndex, System.Data.DbType.Int32, 0, 0, true, null);
                if (repair)
                {
                    // TODO: Call case
                }
            }
            if (!rel.NeedsPositionStorage(RelationEndRole.B) && db.CheckColumnExists(tblName, fkBIndex))
            {
                Log.WarnFormat("Navigator B '{0}' Index Column exists but property is not indexed for [{1}]", fkBName, assocName);
                if (repair)
                {
                    // TODO: Call case
                }
            }

            if (rel.A.Type.ImplementsIExportable() && rel.B.Type.ImplementsIExportable())
            {
                CheckColumn(tblName, "ExportGuid", System.Data.DbType.Guid, 0, 0, false, new NewGuidDefaultConstraint());
            }
        }
Exemplo n.º 4
0
        private void Check_1_N_RelationColumns(Relation rel)
        {
            string assocName = rel.GetAssociationName();

            RelationEnd relEnd, otherEnd;

            switch (rel.Storage)
            {
            case StorageType.MergeIntoA:
                relEnd   = rel.A;
                otherEnd = rel.B;
                break;

            case StorageType.MergeIntoB:
                otherEnd = rel.A;
                relEnd   = rel.B;
                break;

            default:
                Log.ErrorFormat("Relation '{0}' has unsupported Storage set: {1}, skipped", assocName, rel.Storage);
                return;
            }

            var  tblName    = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var  refTblName = db.GetTableName(otherEnd.Type.Module.SchemaName, otherEnd.Type.TableName);
            bool isIndexed  = rel.NeedsPositionStorage(relEnd.GetRole());

            string colName   = Construct.ForeignKeyColumnName(otherEnd);
            string indexName = Construct.ListPositionColumnName(otherEnd);

            CheckColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);

            if (!db.CheckFKConstraintExists(tblName, assocName))
            {
                Log.WarnFormat("FK Constraint '{0}' is missing", assocName);
                if (repair)
                {
                    db.CreateFKConstraint(tblName, refTblName, colName, assocName, false);
                }
            }

            if (!db.CheckIndexExists(tblName, Construct.IndexName(tblName.Name, colName)))
            {
                Log.WarnFormat("Index '{0}' is missing", Construct.IndexName(tblName.Name, colName));
                if (repair)
                {
                    db.CreateIndex(tblName, Construct.IndexName(tblName.Name, colName), false, false, colName);
                }
            }

            if (isIndexed)
            {
                CheckOrderColumn(tblName, indexName);
            }
            if (!isIndexed && db.CheckColumnExists(tblName, indexName))
            {
                Log.WarnFormat("Index Column exists but property is not indexed");
                if (repair)
                {
                    Case.Do_1_N_RelationChange_FromIndexed_To_NotIndexed(rel);
                }
            }
        }