public void ValidateClassNames(ValidationContext context, IClass cls) { // Property and Role names must be unique within a class hierarchy. List<string> foundNames = new List<string>(); List<IProperty> allPropertiesInHierarchy = new List<IProperty>(); List<IProperty> superRoles = new List<IProperty>(); FindAllAssocsInSuperClasses(superRoles, cls.SuperClasses); foreach (IProperty p in cls.GetOutgoingAssociationEnds()) { superRoles.Add(p); } foreach (IProperty p in superRoles) { allPropertiesInHierarchy.Add(p); } foreach (IProperty p in cls.Members) { allPropertiesInHierarchy.Add(p); } foreach (IProperty attribute in allPropertiesInHierarchy) { string name = attribute.Name; if (!string.IsNullOrEmpty(name) && foundNames.Contains(name)) { context.LogError( string.Format("Duplicate property or role name '{0}' in class '{1}'", name, cls.Name), "001", cls); } foundNames.Add(name); } }
private void AssociationTableProcessing(IStereotypeInstance table, IClass cls) { foreach (IProperty p in cls.Members) { IEnumerable<IStereotypeInstance> columns = p.AppliedStereotypes.Where(s => s.Name == "Column"); foreach (IStereotypeInstance column in columns) { _py.AddProperty(p); _sql.AddProperty(p); } } List<string> unique = new List<string>(); foreach (IProperty ae in cls.GetOutgoingAssociationEnds()) { IAssociation association = ae.Association; IEnumerable<IProperty> comps = association.MemberEnds.Where(s => s.IsComposite && s.Name == ae.Name); foreach (IProperty pComp in comps) { _py.AddCompositeProperty(pComp); _sql.AddCompositeProperty(pComp); unique.Add(pComp.Name); } IEnumerable<IStereotypeInstance> fks = association.AppliedStereotypes.Where(s => s.Name == "ForeignKey"); foreach (IStereotypeInstance fk in fks) { if (IsNavigableAssoc(ae) && fk != null) { unique.Add(ae.Name + "Id"); _py.AddFKProperty(ae); _sql.AddFKProperty(ae); _sql.AddFKConstraint(association.Name, cls.Name, ae.Name, ae.Type.Name, TableKeys[ae.Type.Name], UmlHelper.GetDeleteAction(fk)); } } IEnumerable<IStereotypeInstance> ars = association.AppliedStereotypes.Where(s => s.Name == "AbstractReference"); foreach (IStereotypeInstance ar in ars) { if (IsNavigableAssoc(ae)) { _sql.AddAbstractReferenceProperty(ae); _sql.AddIndexConstraint(ae.Name + "AbstractRefIndex", ae.Name + "Id, " + ae.Name + "Table", ""); _py.AddAbstractReferenceProperty(ae); unique.Add(ae.Name + "Id, " + ae.Name + "Table"); } } IEnumerable<IStereotypeInstance> refs = association.AppliedStereotypes.Where(s => s.Name == "Reference"); foreach (IStereotypeInstance r in refs) { DealWithReflexiveReferences(ae, association); unique.Add(ae.Name + "Id"); } } _sql.AddUniqueConstraint(unique); }
public void ValidateTableHierarchAssociations(ValidationContext context, IClass cls) { // All Classes that are TableHierarchies must have exactly one Parent and Child Association IEnumerable<IStereotypeInstance> classKinds = cls.AppliedStereotypes.Where(s => s.Name == "TableHierarchy"); foreach (IStereotypeInstance classKind in classKinds) { int parentCount = 0; int childCount = 0; foreach (IProperty prop in cls.GetOutgoingAssociationEnds()) { IAssociation assoc = prop.Association; IEnumerable<IStereotypeInstance> kindsParent = assoc.AppliedStereotypes.Where(s => s.Name == "Parent"); IEnumerable<IStereotypeInstance> kindsChild = assoc.AppliedStereotypes.Where(s => s.Name == "Child"); parentCount += kindsParent.Count(); childCount += kindsChild.Count(); } if (!(parentCount == 1 && childCount == 1)) { context.LogError( string.Format("Class '{0}' is a TableHierarchy so must not have exactly one Parent and Child association type", cls.Name), "0012", cls); } } }
private void HierarchyTableProcessing(IStereotypeInstance table, IClass cls) { String childName = String.Empty; String parentName = String.Empty; String kindName = String.Empty; foreach (IProperty p in cls.Members) { IEnumerable<IStereotypeInstance> columns = p.AppliedStereotypes.Where(s => s.Name == "Column"); foreach (IStereotypeInstance column in columns) { _py.AddProperty(p); _sql.AddProperty(p); } } foreach (IProperty p in cls.GetOutgoingAssociationEnds()) { IAssociation association = p.Association; IEnumerable<IStereotypeInstance> parent = association.AppliedStereotypes.Where(s => s.Name == "Parent"); foreach (IStereotypeInstance fk in parent) { //kindName is the Table kind for which this table is a hierarchy kindName = association.EndTypes.Where(s => s.Name != cls.Name).First().Name; if (IsNavigableAssoc(p) && fk != null) { parentName = p.Name + "Id"; _py.AddFKProperty(p); _sql.AddFKProperty(p); _sql.AddFKConstraint(association.Name, cls.Name, p.Name, p.Type.Name, TableKeys[p.Type.Name], "Delete"); } } IEnumerable<IStereotypeInstance> child = association.AppliedStereotypes.Where(s => s.Name == "Child"); foreach (IStereotypeInstance fk in child) { if (IsNavigableAssoc(p) && fk != null) { childName = p.Name + "Id"; _py.AddFKProperty(p); _sql.AddFKProperty(p); _sql.AddFKConstraint(association.Name, cls.Name, p.Name, p.Type.Name, TableKeys[p.Type.Name], "Delete"); } } } _sql.AddIndexConstraint(cls.Name + "Index", parentName + ", " + childName, ""); _sql.AddSubtreeProcedure(cls.Name, kindName, parentName, childName); }