/// <summary> /// DeletingRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ConstraintRoleSequenceHasRole) /// Propagate role deletion in a uniqueness constraint to an absorbed uniqueness /// </summary> private static void UniquenessConstraintRoleDeleting(ElementDeletingEventArgs e) { UniquenessConstraint constraint; Uniqueness uniqueness; ConstraintRoleSequenceHasRole link = (ConstraintRoleSequenceHasRole)e.ModelElement; ConstraintRoleSequence sequence = link.ConstraintRoleSequence; if (!sequence.IsDeleting && null != (constraint = sequence as UniquenessConstraint) && !link.Role.IsDeleting && null != (uniqueness = UniquenessIsForUniquenessConstraint.GetUniqueness(constraint))) { uniqueness.ConceptTypeChildCollection.RemoveAt(ConstraintRoleSequenceHasRole.GetLinksToRoleCollection(sequence).IndexOf(link)); } }
/// <summary> /// DeleteRule: typeof(ConstraintRoleSequenceHasRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Block roles from being removed from a subtype fact /// after it is included in a model. /// </summary> private static void LimitSubtypeConstraintRolesDeleteRule(ElementDeletedEventArgs e) { ConstraintRoleSequenceHasRole link = e.ModelElement as ConstraintRoleSequenceHasRole; SetConstraint ic = link.ConstraintRoleSequence as SetConstraint; LinkedElementCollection <FactType> facts; if (ic != null && !ic.IsDeleted && ic.Constraint.ConstraintIsInternal && 1 == (facts = ic.FactTypeCollection).Count) { SubtypeFact subtypeFact = facts[0] as SubtypeFact; if (null != (subtypeFact = facts[0] as SubtypeFact) && !subtypeFact.IsDeleted && subtypeFact.ResolvedModel != null) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(subtypeFact.Store); } } }
/// <summary> /// DeleteRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ConstraintRoleSequenceHasRole) /// </summary> private static void ConstraintRoleDeletedRule(ElementDeletedEventArgs e) { ConstraintRoleSequenceHasRole link = (ConstraintRoleSequenceHasRole)e.ModelElement; IConstraint constraint = link.ConstraintRoleSequence.Constraint; if (constraint != null && !(constraint is IHasAlternateOwner)) { if (IsRelevantConstraint(constraint)) { FactTypeConstraintPatternChanged(link.Role.BinarizedFactType); } switch (constraint.ConstraintType) { // UNDONE: Incremental uniqueness changes case ConstraintType.InternalUniqueness: case ConstraintType.ExternalUniqueness: SignificantObjectTypeChange(constraint.PreferredIdentifierFor); break; } } }
/// <summary> /// AddRule: typeof(ConstraintRoleSequenceHasRole) /// Block internal constraints from being modified on a subtype, block /// external constraints from being added to the subtype role, and /// limit external constraints being added to the supertype role /// </summary> private static void LimitSubtypeConstraintRolesAddRule(ElementAddedEventArgs e) { ConstraintRoleSequenceHasRole link = e.ModelElement as ConstraintRoleSequenceHasRole; Role untypedRole = link.Role; SupertypeMetaRole supertypeRole = untypedRole as SupertypeMetaRole; SubtypeMetaRole subtypeRole = (supertypeRole == null) ? untypedRole as SubtypeMetaRole : null; ConstraintRoleSequence sequence = link.ConstraintRoleSequence; IConstraint constraint; if (supertypeRole != null || subtypeRole != null) { SetConstraint ic; SetComparisonConstraintRoleSequence externalSequence; bool invalidConstraintOnSubtypeRole = false; bool invalidConstraintOnSupertypeRole = false; if (null != (ic = sequence as SetConstraint)) { constraint = ic.Constraint; if (constraint.ConstraintIsInternal) { SubtypeFact subtypeFact; Store store; if (null != (subtypeFact = untypedRole.FactType as SubtypeFact) && subtypeFact.ResolvedModel != null && CopyMergeUtility.GetIntegrationPhase(store = subtypeFact.Store) == CopyClosureIntegrationPhase.None) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(store); } } else if (constraint.ConstraintType == ConstraintType.ImpliedMandatory) { // Nothing to do } else if (subtypeRole != null) { invalidConstraintOnSubtypeRole = true; } else if (constraint.ConstraintType != ConstraintType.DisjunctiveMandatory) { invalidConstraintOnSupertypeRole = true; } } else if (subtypeRole != null) { invalidConstraintOnSubtypeRole = true; } else if (null != (externalSequence = sequence as SetComparisonConstraintRoleSequence)) { constraint = externalSequence.Constraint; if (constraint != null) { switch (constraint.ConstraintType) { case ConstraintType.Exclusion: FrameworkDomainModel.DelayValidateElement((ModelElement)constraint, DelayValidateSupertypeExclusionSingleColumnOnly); break; case ConstraintType.Subset: FrameworkDomainModel.DelayValidateElement((ModelElement)constraint, DelayValidateSupertypeSubsetPattern); break; default: invalidConstraintOnSupertypeRole = true; break; } } } if (invalidConstraintOnSupertypeRole) { ThrowInvalidSupertypeMetaRoleConstraint(); } else if (invalidConstraintOnSubtypeRole) { ThrowInvalidSubtypeMetaRoleConstraint(); } } else if (null != (constraint = sequence.Constraint)) { switch (constraint.ConstraintType) { case ConstraintType.Exclusion: FrameworkDomainModel.DelayValidateElement((ModelElement)constraint, DelayValidateSupertypeExclusionSingleColumnOnly); break; case ConstraintType.Subset: FrameworkDomainModel.DelayValidateElement((ModelElement)constraint, DelayValidateSupertypeSubsetPattern); break; } } }