コード例 #1
0
        private void CheckColumns(ObjectClass objClass, ICollection <Property> properties, string prefix)
        {
            Log.Debug("  Columns: ");
            foreach (ValueTypeProperty prop in properties.OfType <ValueTypeProperty>()
                     .Where(p => !p.IsList)
                     .OrderBy(p => p.Module.Namespace).ThenBy(p => p.Name))
            {
                var tblName = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
                var colName = Construct.NestedColumnName(prop, prefix);
                Log.DebugFormat("    {0}", colName);
                CheckColumn(tblName, colName, prop.GetDbType(), prop.GetSize(), prop.GetScale(), prop.IsNullable(), SchemaManager.GetDefaultConstraint(prop));
            }

            foreach (CompoundObjectProperty sprop in properties.OfType <CompoundObjectProperty>().Where(p => !p.IsList))
            {
                CheckColumns(objClass, sprop.CompoundObjectDefinition.Properties, Construct.NestedColumnName(sprop, prefix));
            }
        }
コード例 #2
0
        private void CheckCompoundObjectCollections(ObjectClass objClass)
        {
            Log.Debug("CompoundObject Collections: ");

            foreach (CompoundObjectProperty prop in objClass.Properties.OfType <CompoundObjectProperty>()
                     .Where(p => p.IsList)
                     .OrderBy(p => p.Module.Namespace).ThenBy(p => p.Name))
            {
                var  tblName            = db.GetTableName(prop.Module.SchemaName, prop.GetCollectionEntryTable());
                var  fkName             = "fk_" + prop.ObjectClass.Name;
                var  basePropName       = prop.Name;
                var  valPropIndexName   = prop.Name + "Index";
                var  assocName          = prop.GetAssociationName();
                var  refTblName         = db.GetTableName(objClass.Module.SchemaName, objClass.TableName);
                bool hasPersistentOrder = prop.HasPersistentOrder;
                if (db.CheckTableExists(tblName))
                {
                    Log.DebugFormat("{0}", prop.Name);

                    CheckColumn(tblName, fkName, System.Data.DbType.Int32, 0, 0, false, null);
                    // TODO: Support neested CompoundObject
                    foreach (ValueTypeProperty p in prop.CompoundObjectDefinition.Properties)
                    {
                        CheckColumn(tblName, Construct.NestedColumnName(p.Name, basePropName), p.GetDbType(), p.GetSize(), p.GetScale(), true, SchemaManager.GetDefaultConstraint(p));
                    }
                    if (hasPersistentOrder)
                    {
                        CheckColumn(tblName, valPropIndexName, System.Data.DbType.Int32, 0, 0, true, null);
                    }
                    if (!hasPersistentOrder && db.CheckColumnExists(tblName, valPropIndexName))
                    {
                        Log.WarnFormat("Index Column '{0}' exists but property is not indexed", valPropIndexName);
                    }
                    if (!db.CheckFKConstraintExists(tblName, assocName))
                    {
                        Log.WarnFormat("FK Constraint is missing", prop.Name);
                        if (repair)
                        {
                            db.CreateFKConstraint(tblName, refTblName, fkName, assocName, true);
                        }
                    }
                }
                else
                {
                    Log.WarnFormat("Table '{0}' for Property '{1}' is missing", tblName, prop.Name);
                    if (repair)
                    {
                        Case.DoNewCompoundObjectPropertyList(objClass, prop);
                    }
                }
            }
        }