Exemplo n.º 1
0
        /// <summary>
        /// DeletingRule: typeof(UniquenessConstraintIncludesColumn)
        /// If a uniqueness constraint column is being removed, then remove the corresponding column
        /// in any reference constraints that target the columns in the uniqueness constraint.
        /// </summary>
        private static void UniquenessConstraintColumnDeleting(ElementDeletingEventArgs e)
        {
            UniquenessConstraintIncludesColumn link   = (UniquenessConstraintIncludesColumn)e.ModelElement;
            UniquenessConstraint uniquenessConstraint = link.UniquenessConstraint;

            if (!uniquenessConstraint.IsDeleting)
            {
                bool haveIndex = false;
                int  index     = -1;
                foreach (ReferenceConstraint referenceConstraint in uniquenessConstraint.ReferenceConstraintCollection)
                {
                    if (!haveIndex)
                    {
                        haveIndex = true;
                        index     = UniquenessConstraintIncludesColumn.GetLinksToColumnCollection(uniquenessConstraint).IndexOf(link);
                    }
                    LinkedElementCollection <ColumnReference> columnRefs = referenceConstraint.ColumnReferenceCollection;
                    if (index < columnRefs.Count && columnRefs[index].TargetColumn == link.Column)                     // Sanity check
                    {
                        columnRefs.RemoveAt(index);
                    }
                    else
                    {
                        // Something is off, delay validate this later
                        ReferenceConstraintTargetsTable tableLink = ReferenceConstraintTargetsTable.GetLinkToTargetTable(referenceConstraint);
                        if (tableLink != null)
                        {
                            FrameworkDomainModel.DelayValidateElement(tableLink, DelayValidateTargetUniquenessConstraint);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void ValidateTargetUniquenessConstraint(ReferenceConstraintTargetsTable tableReference, INotifyElementAdded notifyAdded)
        {
            if (tableReference.IsDeleted)
            {
                return;
            }
            Table targetTable = tableReference.TargetTable;
            ReferenceConstraint referenceConstraint = tableReference.ReferenceConstraint;
            LinkedElementCollection <ColumnReference> columnRefs = referenceConstraint.ColumnReferenceCollection;
            int columnRefCount = columnRefs.Count;
            ReferenceConstraintTargetsUniquenessConstraint targetUniquenessLink = ReferenceConstraintTargetsUniquenessConstraint.GetLinkToTargetUniquenessConstraint(referenceConstraint);

            if (targetUniquenessLink != null)
            {
                // Verify the target uniqueness
                UniquenessConstraint targetUniqueness = targetUniquenessLink.TargetUniquenessConstraint;
                bool existingIsValid = targetUniqueness.Table == targetTable;
                if (existingIsValid)
                {
                    LinkedElementCollection <Column> uniquenessColumns = targetUniqueness.ColumnCollection;
                    existingIsValid = uniquenessColumns.Count == columnRefCount;
                    if (existingIsValid)
                    {
                        for (int i = 0; i < columnRefCount; ++i)
                        {
                            if (uniquenessColumns[i] != columnRefs[i].TargetColumn)
                            {
                                existingIsValid = false;
                                break;
                            }
                        }
                    }
                }
                if (!existingIsValid)
                {
                    // Delete the link without deleting the reference constraint we're processing
                    targetUniquenessLink.Delete(ReferenceConstraintTargetsUniquenessConstraint.ReferenceConstraintDomainRoleId);
                    targetUniquenessLink = null;
                }
            }
            if (targetUniquenessLink == null)
            {
                foreach (UniquenessConstraint testUniqueness in targetTable.UniquenessConstraintCollection)
                {
                    LinkedElementCollection <Column> uniquenessColumns = testUniqueness.ColumnCollection;
                    if (uniquenessColumns.Count == columnRefCount)
                    {
                        int i = 0;
                        for (; i < columnRefCount; ++i)
                        {
                            if (uniquenessColumns[i] != columnRefs[i].TargetColumn)
                            {
                                break;
                            }
                        }
                        if (i == columnRefCount)
                        {
                            // We have a match
                            targetUniquenessLink = new ReferenceConstraintTargetsUniquenessConstraint(referenceConstraint, testUniqueness);
                            if (notifyAdded != null)
                            {
                                notifyAdded.ElementAdded(targetUniquenessLink, false);
                            }
                            break;
                        }
                    }
                }
                if (targetUniquenessLink == null)
                {
                    referenceConstraint.Delete();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// RolePlayerPositionChangeRule: typeof(UniquenessConstraintIncludesColumn)
        /// If a uniqueness constraint column is being repositioned, then reposition the corresponding column
        /// in any reference constraints that target the columns in the uniqueness constraint.
        /// </summary>
        private static void UniquenessConstraintColumnPositionChanged(RolePlayerOrderChangedEventArgs e)
        {
            if (e.CounterpartDomainRole.Id == UniquenessConstraintIncludesColumn.ColumnDomainRoleId)
            {
                UniquenessConstraint uniquenessConstraint = (UniquenessConstraint)e.SourceElement;
                int oldIndex = e.OldOrdinal;
                int newIndex = e.NewOrdinal;
                foreach (ReferenceConstraint referenceConstraint in uniquenessConstraint.ReferenceConstraintCollection)
                {
                    LinkedElementCollection <ColumnReference> columnRefs = referenceConstraint.ColumnReferenceCollection;
                    int columnRefCount = columnRefs.Count;
                    if (newIndex < columnRefCount && oldIndex < columnRefCount && columnRefs[oldIndex].TargetColumn == e.CounterpartRolePlayer)                     // Sanity check
                    {
                        Column sourceColumn = columnRefs[oldIndex].SourceColumn;
                        columnRefs.Move(oldIndex, newIndex);

                        // Any uniqueness constraint that includes all columns in the
                        // reference constraint will generate in a different order and
                        // should be updated
                        Table sourceTable;
                        if (null != (sourceTable = referenceConstraint.SourceTable))
                        {
                            foreach (UniquenessConstraint sourceUniquenessConstraint in sourceTable.UniquenessConstraintCollection)
                            {
                                LinkedElementCollection <Column> uniquenessColumns = sourceUniquenessConstraint.ColumnCollection;
                                int uniquenessColumnCount = uniquenessColumns.Count;
                                if (uniquenessColumnCount >= columnRefCount)
                                {
                                    int firstMatchColumn = int.MaxValue;
                                    for (int i = 0; i < columnRefCount; ++i)
                                    {
                                        Column matchColumn = columnRefs[i].SourceColumn;
                                        int    j           = 0;
                                        for (; j < uniquenessColumnCount; ++j)
                                        {
                                            if (uniquenessColumns[j] == matchColumn)
                                            {
                                                firstMatchColumn = Math.Min(firstMatchColumn, j);
                                                break;
                                            }
                                        }
                                        if (j == uniquenessColumnCount)
                                        {
                                            // Not included
                                            firstMatchColumn = int.MaxValue;
                                            break;
                                        }
                                    }
                                    if (firstMatchColumn != int.MaxValue)
                                    {
                                        uniquenessColumnCount -= firstMatchColumn;
                                        if (newIndex < uniquenessColumnCount &&
                                            oldIndex < uniquenessColumnCount &&
                                            uniquenessColumns[firstMatchColumn + oldIndex] == sourceColumn)                                             // Sanity check
                                        {
                                            uniquenessColumns.Move(firstMatchColumn + oldIndex, firstMatchColumn + newIndex);
                                        }
                                        // If this does not line up then something is clearly off, but
                                        // this is a non-critical error in that the model is still correctly
                                        // aligned and generates correct DDL.
                                        // However, the constraint will now have a different column order
                                        // than with a full regeneration.
                                        // UNDONE: Delay validation routine for this situation
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // Something is off, delay validate this later
                        ReferenceConstraintTargetsTable tableLink = ReferenceConstraintTargetsTable.GetLinkToTargetTable(referenceConstraint);
                        if (tableLink != null)
                        {
                            FrameworkDomainModel.DelayValidateElement(tableLink, DelayValidateTargetUniquenessConstraint);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
		public static void SetTargetUniquenessConstraint(ReferenceConstraint element, UniquenessConstraint newTargetUniquenessConstraint)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ReferenceConstraintDomainRoleId, newTargetUniquenessConstraint);
		}
Exemplo n.º 5
0
		/// <summary>
		/// Constructor
		/// Creates a ReferenceConstraintTargetsUniquenessConstraint link in the same Partition as the given ReferenceConstraint
		/// </summary>
		/// <param name="source">ReferenceConstraint to use as the source of the relationship.</param>
		/// <param name="target">UniquenessConstraint to use as the target of the relationship.</param>
		public ReferenceConstraintTargetsUniquenessConstraint(ReferenceConstraint source, UniquenessConstraint target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ReferenceConstraintTargetsUniquenessConstraint.ReferenceConstraintDomainRoleId, source), new DslModeling::RoleAssignment(ReferenceConstraintTargetsUniquenessConstraint.TargetUniquenessConstraintDomainRoleId, target)}, null)
		{
		}
Exemplo n.º 6
0
		public static DslModeling::LinkedElementCollection<ReferenceConstraint> GetReferenceConstraintCollection(UniquenessConstraint element)
		{
			return new DslModeling::LinkedElementCollection<ReferenceConstraint>(element, TargetUniquenessConstraintDomainRoleId);
		}
Exemplo n.º 7
0
		public static DslModeling::LinkedElementCollection<Column> GetColumnCollection(UniquenessConstraint element)
		{
			return new DslModeling::LinkedElementCollection<Column>(element, UniquenessConstraintDomainRoleId);
		}
Exemplo n.º 8
0
		/// <summary>
		/// Constructor
		/// Creates a UniquenessConstraintIncludesColumn link in the same Partition as the given UniquenessConstraint
		/// </summary>
		/// <param name="source">UniquenessConstraint to use as the source of the relationship.</param>
		/// <param name="target">Column to use as the target of the relationship.</param>
		public UniquenessConstraintIncludesColumn(UniquenessConstraint source, Column target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(UniquenessConstraintIncludesColumn.UniquenessConstraintDomainRoleId, source), new DslModeling::RoleAssignment(UniquenessConstraintIncludesColumn.ColumnDomainRoleId, target)}, null)
		{
		}
Exemplo n.º 9
0
		public static void SetTable(UniquenessConstraint element, Table newTable)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, UniquenessConstraintDomainRoleId, newTable);
		}
Exemplo n.º 10
0
		public static Table GetTable(UniquenessConstraint element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, UniquenessConstraintDomainRoleId) as Table;
		}
Exemplo n.º 11
0
		/// <summary>
		/// Constructor
		/// Creates a TableContainsUniquenessConstraint link in the same Partition as the given Table
		/// </summary>
		/// <param name="source">Table to use as the source of the relationship.</param>
		/// <param name="target">UniquenessConstraint to use as the target of the relationship.</param>
		public TableContainsUniquenessConstraint(Table source, UniquenessConstraint target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(TableContainsUniquenessConstraint.TableDomainRoleId, source), new DslModeling::RoleAssignment(TableContainsUniquenessConstraint.UniquenessConstraintDomainRoleId, target)}, null)
		{
		}