예제 #1
0
        private static void GetUniqueAndMandatory(Role role, out bool hasUniqueness, out bool hasMandatory, out bool mandatoryIsImplied)
        {
            hasUniqueness      = false;
            hasMandatory       = false;
            mandatoryIsImplied = false;
            LinkedElementCollection <ConstraintRoleSequence> constraintRoleSequences = role.ConstraintRoleSequenceCollection;
            int roleSequenceCount = constraintRoleSequences.Count;

            for (int i = 0; i < roleSequenceCount; ++i)
            {
                ConstraintRoleSequence roleSequence = constraintRoleSequences[i];
                IConstraint            constraint   = roleSequence.Constraint;
                if (constraint != null && constraint.Modality == ConstraintModality.Alethic)
                {
                    switch (constraint.ConstraintType)
                    {
                    case ConstraintType.SimpleMandatory:
                        hasMandatory = true;
                        if (hasUniqueness)
                        {
                            return;
                        }
                        break;

                    case ConstraintType.InternalUniqueness:
                        // Ignore spanning internal constraints, these are treated as external
                        // uniquenesses in the binarized form
                        if (roleSequence.RoleCollection.Count == 1)
                        {
                            hasUniqueness = true;
                            if (hasMandatory)
                            {
                                return;
                            }
                        }
                        break;

                    case ConstraintType.ImpliedMandatory:
                        if (roleSequence.RoleCollection.Count == 1)
                        {
                            hasMandatory       = true;
                            mandatoryIsImplied = true;
                            if (hasUniqueness)
                            {
                                return;
                            }
                        }
                        break;
                    }
                }
            }
        }
예제 #2
0
            /// <summary>
            /// Checks the <see cref="IConstraint"/>s on the binarized unary <see cref="FactType"/> as specified by
            /// the <see cref="FactType"/>'s <paramref name="unaryRole"/> and the <paramref name="implicitBooleanRole"/>.
            /// </summary>
            private static bool ValidateConstraints(Role unaryRole, Role implicitBooleanRole)
            {
                ConstraintRoleSequence unaryRoleUniquenessConstraint = unaryRole.SingleRoleAlethicUniquenessConstraint;

                if (unaryRoleUniquenessConstraint == null)
                {
                    // The alethic single role uniqueness constraint is missing from the unary role.
                    return(false);
                }

                // Validate the constraints on the unary role
                foreach (ConstraintRoleSequence constraintRoleSequence in unaryRole.ConstraintRoleSequenceCollection)
                {
                    IConstraint constraint = constraintRoleSequence.Constraint;
                    switch (constraint.ConstraintType)
                    {
                    case ConstraintType.InternalUniqueness:
                    case ConstraintType.ExternalUniqueness:
                    case ConstraintType.ValueComparison:
                    case ConstraintType.Frequency:
                        if (constraintRoleSequence != unaryRoleUniquenessConstraint)
                        {
                            // The unary role has a constraint attached to it that it shouldn't
                            return(false);
                        }
                        break;
                    }
                }

                // Validate the constraints on the implicit boolean role
                foreach (ConstraintRoleSequence constraintRoleSequence in implicitBooleanRole.ConstraintRoleSequenceCollection)
                {
                    IConstraint constraint = constraintRoleSequence.Constraint;
                    switch (constraint.ConstraintType)
                    {
                    case ConstraintType.DisjunctiveMandatory:
                    case ConstraintType.Equality:
                    case ConstraintType.Exclusion:
                    case ConstraintType.Ring:
                    case ConstraintType.SimpleMandatory:
                    case ConstraintType.Subset:
                    case ConstraintType.InternalUniqueness:
                    case ConstraintType.ValueComparison:
                        // The implicit boolean role has a constraint attached to it that it shouldn't
                        return(false);
                    }
                }

                return(true);
            }
예제 #3
0
            /// <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));
                }
            }
예제 #4
0
        /// <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;
                }
            }
        }
		private void Reset()
		{
			myConstraintRoleSequence = null;
			myInitialSelectedRoles = null;
			mySelectedRoles = null;
			mySourceShape = null;
			myActiveConstraint = null;
			myPendingOnClickedAction = OnClickedAction.Normal;
			mySubtypeConnection = false;
			myAllowSubtypeConnection = false;
			FactTypeShape.ActiveExternalConstraintConnectAction = null;
		}