Esempio n. 1
0
		/// <summary>
		/// Cache the location of any table shape associated with the provided <see cref="ObjectType"/> and <see cref="Table"/>
		/// </summary>
		private static void RememberTableShapeLocations(ObjectType objectType, Table table)
		{
			foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(table))
			{
				TableShape shape = pel as TableShape;
				if (pel != null)
				{
					Dictionary<object, object> context = objectType.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;
					object tablePositionsObject;
					Dictionary<Guid, PointD> tablePositions;
					if (!context.TryGetValue(TablePositionDictionaryKey, out tablePositionsObject) ||
						(tablePositions = tablePositionsObject as Dictionary<Guid, PointD>) == null)
					{
						context[TablePositionDictionaryKey] = tablePositions = new Dictionary<Guid, PointD>();
					}
					tablePositions[objectType.Id] = shape.Location;
				}
			}
		}
Esempio n. 2
0
		/// <summary>
		/// Constructor
		/// Creates a SchemaContainsTable link in the same Partition as the given Schema
		/// </summary>
		/// <param name="source">Schema to use as the source of the relationship.</param>
		/// <param name="target">Table to use as the target of the relationship.</param>
		public SchemaContainsTable(Schema source, Table target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(SchemaContainsTable.SchemaDomainRoleId, source), new DslModeling::RoleAssignment(SchemaContainsTable.TableDomainRoleId, target)}, null)
		{
		}
Esempio n. 3
0
		public static void SetTargetTable(ReferenceConstraint element, Table newTargetTable)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ReferenceConstraintDomainRoleId, newTargetTable);
		}
Esempio n. 4
0
		public static DslModeling::LinkedElementCollection<ReferenceConstraint> GetReferenceConstraints(Table element)
		{
			return new DslModeling::LinkedElementCollection<ReferenceConstraint>(element, TargetTableDomainRoleId);
		}
Esempio n. 5
0
		/// <summary>
		/// Constructor
		/// Creates a ReferenceConstraintTargetsTable 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">Table to use as the target of the relationship.</param>
		public ReferenceConstraintTargetsTable(ReferenceConstraint source, Table target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ReferenceConstraintTargetsTable.ReferenceConstraintDomainRoleId, source), new DslModeling::RoleAssignment(ReferenceConstraintTargetsTable.TargetTableDomainRoleId, target)}, null)
		{
		}
Esempio n. 6
0
		public static DslModeling::LinkedElementCollection<CheckConstraint> GetCheckConstraintCollection(Table element)
		{
			return new DslModeling::LinkedElementCollection<CheckConstraint>(element, TableDomainRoleId);
		}
Esempio n. 7
0
				string IDatabaseNameGenerator.GenerateTableName(Table table, int phase)
				{
					return GenerateTableName(table, phase);
				}
Esempio n. 8
0
		public static void SetTable(Column element, Table newTable)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ColumnDomainRoleId, newTable);
		}
Esempio n. 9
0
		public static DslModeling::LinkedElementCollection<Column> GetColumnCollection(Table element)
		{
			return new DslModeling::LinkedElementCollection<Column>(element, TableDomainRoleId);
		}
Esempio n. 10
0
			private static void ValidateTableNameChanged(Table table)
			{
				if (null != table)
				{
					FrameworkDomainModel.DelayValidateElement(table, DelayValidateTableNameChanged);
				}
			}
Esempio n. 11
0
		/// <summary>
		/// Constructor
		/// Creates a TableContainsColumn 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">Column to use as the target of the relationship.</param>
		public TableContainsColumn(Table source, Column target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(TableContainsColumn.TableDomainRoleId, source), new DslModeling::RoleAssignment(TableContainsColumn.ColumnDomainRoleId, target)}, null)
		{
		}
Esempio n. 12
0
		public static DslModeling::LinkedElementCollection<UniquenessConstraint> GetUniquenessConstraintCollection(Table element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<UniquenessConstraint>, UniquenessConstraint>(element, TableDomainRoleId);
		}
Esempio n. 13
0
		public static DslModeling::ReadOnlyLinkedElementCollection<Constraint> GetConstraintCollection(Table element)
		{
			return GetRoleCollection<DslModeling::ReadOnlyLinkedElementCollection<Constraint>, Constraint>(element, TableDomainRoleId);
		}
Esempio n. 14
0
				private string GenerateTableName(Table table, int phase)
				{
					if (phase != 0)
					{
						return null;
					}
					NamePart singleName = default(NamePart);
					List<NamePart> nameCollection = null;
					NameGenerator nameGenerator = TableNameGenerator;

					ReferenceModeNaming.SeparateObjectTypeParts(
						ConceptTypeIsForObjectType.GetObjectType(TableIsPrimarilyForConceptType.GetConceptType(table)),
						nameGenerator,
						delegate(NamePart newPart, int? insertIndex)
						{
							AddToNameCollection(ref singleName, ref nameCollection, newPart, insertIndex.HasValue ? insertIndex.Value : -1, true);
						});

					string finalName = GetFinalName(singleName, nameCollection, nameGenerator);
					return string.IsNullOrEmpty(finalName) ? "TABLE" : finalName;
				}
Esempio n. 15
0
		public static Schema GetSchema(Table element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, TableDomainRoleId) as Schema;
		}
Esempio n. 16
0
		/// <summary>
		/// Constructor
		/// Creates a TableContainsCheckConstraint 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">CheckConstraint to use as the target of the relationship.</param>
		public TableContainsCheckConstraint(Table source, CheckConstraint target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(TableContainsCheckConstraint.TableDomainRoleId, source), new DslModeling::RoleAssignment(TableContainsCheckConstraint.CheckConstraintDomainRoleId, target)}, null)
		{
		}
Esempio n. 17
0
		public static void SetSchema(Table element, Schema newSchema)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, TableDomainRoleId, newSchema);
		}
Esempio n. 18
0
		public static void SetTable(CheckConstraint element, Table newTable)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, CheckConstraintDomainRoleId, newTable);
		}
Esempio n. 19
0
		private static void UpdateTablePresentationSize(Table table)
		{
			if (table != null)
			{
				foreach (PresentationElement pel in PresentationViewsSubject.GetPresentation(table))
				{
					TableShape shape;
					ColumnElementListCompartment compartment;
					if (null != (shape = pel as TableShape) &&
						null != (compartment = shape.FindCompartment("ColumnsCompartment") as ColumnElementListCompartment))
					{
						compartment.InvalidateOrUpdateSize();
					}
				}
			}
		}
Esempio n. 20
0
				private LinkedNode<ColumnPathStep> GetColumnPath(Column column)
				{
					Table table = column.Table;
					if (myColumnStepTable == table)
					{
						return myColumnSteps[column];
					}
					Dictionary<Column, LinkedNode<ColumnPathStep>> columnSteps = myColumnSteps;
					if (myColumnStepTable == null)
					{
						myColumnSteps = columnSteps = new Dictionary<Column, LinkedNode<ColumnPathStep>>();
					}
					else
					{
						columnSteps.Clear();
					}
					myColumnStepTable = table;
#if DEBUGCOLUMNPATH
					Debug.WriteLine("Table: " + table.Name);
					Debug.Indent();
					Debug.Indent();
#endif // DEBUGCOLUMNPATH

					// Seed the cross-cutting dictionary and seed it with the main represented
					// ObjectTypes to force decorations on columns that loop back into this table.
					Dictionary<ObjectType, LinkedNode<LinkedNode<ColumnPathStep>>> objectTypeToSteps = new Dictionary<ObjectType, LinkedNode<LinkedNode<ColumnPathStep>>>();
					ConceptType primaryConceptType = TableIsPrimarilyForConceptType.GetConceptType(table);
					if (primaryConceptType != null)
					{
						ObjectType targetObjectType = ConceptTypeIsForObjectType.GetObjectType(primaryConceptType);
						objectTypeToSteps[targetObjectType] = new LinkedNode<LinkedNode<ColumnPathStep>>(new LinkedNode<ColumnPathStep>(new ColumnPathStep(null, targetObjectType, null, ColumnPathStepFlags.None)));
					}
					foreach (ConceptType secondaryConceptType in TableIsAlsoForConceptType.GetConceptType(table))
					{
						ObjectType targetObjectType = ConceptTypeIsForObjectType.GetObjectType(secondaryConceptType);
						objectTypeToSteps[targetObjectType] = new LinkedNode<LinkedNode<ColumnPathStep>>(new LinkedNode<ColumnPathStep>(new ColumnPathStep(null, targetObjectType, null, ColumnPathStepFlags.None)));
					}
					LinkedElementCollection<Column> columns = table.ColumnCollection;
					int columnCount = columns.Count;
					for (int iColumn = 0; iColumn < columnCount; ++iColumn)
					{
						Column currentColumn = columns[iColumn];
#if DEBUGCOLUMNPATH
						Debug.Unindent();
						Debug.WriteLine("Column: " + currentColumn.Name);
						Debug.Indent();
#endif // DEBUGCOLUMNPATH
						LinkedElementCollection<ConceptTypeChild> childPath = ColumnHasConceptTypeChild.GetConceptTypeChildPath(currentColumn);
						int childPathCount = childPath.Count;
						LinkedNode<ColumnPathStep> headNode = null;
						LinkedNode<ColumnPathStep> tailNode = null;
						bool passedIdentifier = false;
						bool processTailDelayed = false;
						ConceptType nextComingFromConceptType = primaryConceptType;
						Objectification assimilationObjectification = null;
						for (int iChild = 0; iChild < childPathCount; ++iChild)
						{
							ConceptType comingFromConceptType = nextComingFromConceptType;
							ConceptTypeChild child = childPath[iChild];
							ConceptTypeAssimilatesConceptType assimilation = child as ConceptTypeAssimilatesConceptType;
							bool reverseAssimilation = false;
							bool forwardToReverseTransition = false;
							bool towardsSubtype = false;
							if (assimilation != null)
							{
								if (comingFromConceptType == assimilation.Parent)
								{
									nextComingFromConceptType = assimilation.ReferencedConceptType;
								}
								else
								{
									towardsSubtype = true;
									nextComingFromConceptType = assimilation.Parent;
								}
#if DEBUGCOLUMNPATH
								Debug.WriteLine("From: " + comingFromConceptType.Name + " To: " + nextComingFromConceptType.Name + "(" + (assimilation.RefersToSubtype && assimilation.IsPreferredForTarget).ToString() + ")");
#endif // DEBUGCOLUMNPATH
								if (tailNode != null)
								{
									// If we're already moving down an assimilation path in a specific direction then keep
									// going that direction
									ColumnPathStep pathStep = tailNode.Value;
									ColumnPathStepFlags stepFlags = pathStep.Flags;
									if (0 != (stepFlags & ColumnPathStepFlags.ForwardAssimilation))
									{
										// Keep going forward
										if (0 != (stepFlags & ColumnPathStepFlags.AssimilationIsSubtype) &&
											AssimilationMapping.GetAbsorptionChoiceFromAssimilation(assimilation) != AssimilationAbsorptionChoice.Absorb &&
											comingFromConceptType == (0 == (stepFlags & ColumnPathStepFlags.AssimilationTowardsSubtype) ? assimilation.AssimilatedConceptType : assimilation.AssimilatorConceptType))
										{
											forwardToReverseTransition = true;
										}
									}
									else if (0 != (stepFlags & ColumnPathStepFlags.ReverseAssimilation))
									{
										// Keep going backward
										reverseAssimilation = true;
									}
									else
									{
										// Figure it out from this step
										reverseAssimilation = AssimilationMapping.GetAbsorptionChoiceFromAssimilation(assimilation) != AssimilationAbsorptionChoice.Absorb;
									}
								}
								else
								{
									reverseAssimilation = AssimilationMapping.GetAbsorptionChoiceFromAssimilation(assimilation) != AssimilationAbsorptionChoice.Absorb;
								}
							}
							else
							{
								nextComingFromConceptType = child.Target as ConceptType;
#if DEBUGCOLUMNPATH
								Debug.WriteLine("From: " + comingFromConceptType.Name + " To: " + ((nextComingFromConceptType != null) ? nextComingFromConceptType.Name : ((InformationTypeFormat)child.Target).Name));
#endif // DEBUGCOLUMNPATH
							}
							LinkedElementCollection<FactType> factTypes = ConceptTypeChildHasPathFactType.GetPathFactTypeCollection(child);
							int factTypeCount = factTypes.Count;
							for (int iFactType = 0; iFactType < factTypeCount; ++iFactType)
							{
								FactType factType = factTypes[iFactType];
								Role targetRole = FactTypeMapsTowardsRole.GetTowardsRole(factType).Role;
								ColumnPathStepFlags flags = passedIdentifier ? ColumnPathStepFlags.PassedIdentifier : 0;
								ColumnPathStep pathStep = default(ColumnPathStep);
								bool processPreviousTail = false;
								Objectification previousAssimilationObjectification = assimilationObjectification;
								assimilationObjectification = null;
								bool processAsFactType = true;
								if (assimilation != null)
								{
									Role nonAssimilationTargetRole = targetRole;
									if (!towardsSubtype)
									{
										targetRole = targetRole.OppositeRoleAlwaysResolveProxy.Role;
									}
									processAsFactType = false;
									Objectification objectification;
									bool assimilationIsSubtype = assimilation.RefersToSubtype;
									bool secondarySubtype = assimilationIsSubtype && !assimilation.IsPreferredForTarget;
									if (!assimilationIsSubtype &&
										null != (objectification = factType.ImpliedByObjectification) &&
										objectification.NestingType == targetRole.RolePlayer)
									{
										assimilationObjectification = objectification;
									}
									if (tailNode != null)
									{
										pathStep = tailNode.Value;
										ColumnPathStepFlags tailFlags = pathStep.Flags;
										if (0 != (tailFlags & (ColumnPathStepFlags.ForwardAssimilation | ColumnPathStepFlags.ReverseAssimilation)))
										{
											bool tailIsSubtype = 0 != (tailFlags & ColumnPathStepFlags.AssimilationIsSubtype);
											if (tailIsSubtype && assimilationIsSubtype)
											{
												if (forwardToReverseTransition)
												{
													flags |= ColumnPathStepFlags.DeclinedAssimilation;
													targetRole = towardsSubtype ? targetRole.OppositeRoleAlwaysResolveProxy.Role : nonAssimilationTargetRole;
													processAsFactType = true;
												}
												else
												{
													if (secondarySubtype && 0 == (tailFlags & ColumnPathStepFlags.NonPreferredSubtype))
													{
														tailNode.Value = new ColumnPathStep(pathStep.FromRole, pathStep.ObjectType, pathStep.AlternateObjectType, tailFlags | ColumnPathStepFlags.NonPreferredSubtype);
													}
													// If this is a subtype chain, then keep going, using the first
													// subtype in the chain as a node used in the final name.
													continue;
												}
											}
											else if (assimilationObjectification != null)
											{
												// The type of assimilation has changed, but we have an objectifying object type,
												// so we treat it like a separate link in the chain, or the previous element was
												// also not a subtype.
												tailNode.Value = new ColumnPathStep(pathStep.FromRole, pathStep.ObjectType, nonAssimilationTargetRole.RolePlayer, pathStep.Flags);
												processPreviousTail = processTailDelayed;
											}
											else
											{
												flags |= ColumnPathStepFlags.DeclinedAssimilation;
												targetRole = towardsSubtype ? targetRole.OppositeRoleAlwaysResolveProxy.Role : nonAssimilationTargetRole;
												processAsFactType = true;
											}
										}
									}
									else if (!assimilationIsSubtype && assimilationObjectification == null)
									{
										flags |= ColumnPathStepFlags.DeclinedAssimilation;
										targetRole = towardsSubtype ? targetRole.OppositeRoleAlwaysResolveProxy.Role : nonAssimilationTargetRole;
										processAsFactType = true;
									}
									if (!processAsFactType)
									{
										if (reverseAssimilation)
										{
											flags |= ColumnPathStepFlags.ReverseAssimilation;
										}
										else
										{
											flags |= ColumnPathStepFlags.ForwardAssimilation;
										}
										if (assimilationIsSubtype)
										{
											flags |= ColumnPathStepFlags.AssimilationIsSubtype;
											if (secondarySubtype)
											{
												flags |= ColumnPathStepFlags.NonPreferredSubtype;
											}
											if (towardsSubtype)
											{
												flags |= ColumnPathStepFlags.AssimilationTowardsSubtype;
											}
										}
										pathStep = new ColumnPathStep(
											null,
											towardsSubtype ? ConceptTypeIsForObjectType.GetObjectType(comingFromConceptType) : targetRole.RolePlayer,
											towardsSubtype ? targetRole.RolePlayer : null,
											flags);
										processTailDelayed = true;
									}
								}
								if (processAsFactType)
								{
									bool haveStep = false;
									if (tailNode != null)
									{
										pathStep = tailNode.Value;
										ColumnPathStepFlags tailFlags = pathStep.Flags;
										if (0 != (tailFlags & (ColumnPathStepFlags.ForwardAssimilation | ColumnPathStepFlags.ReverseAssimilation)))
										{
											RoleProxy oppositeProxy;
											Role objectifiedResolvedProxyRole;
											Role objectifiedOppositeRole;
											if (previousAssimilationObjectification != null &&
												factType.ImpliedByObjectification == previousAssimilationObjectification &&
												null != (oppositeProxy = targetRole.OppositeRole as RoleProxy) &&
												null != (objectifiedOppositeRole = (objectifiedResolvedProxyRole = oppositeProxy.Role).OppositeRole as Role))
											{
												flags |= ColumnPathStepFlags.ObjectifiedFactType;
												// Replace both factTypes with the original unobjectified FactType
												ObjectType fromObjectType = objectifiedOppositeRole.RolePlayer;
												if (pathStep.ObjectType == previousAssimilationObjectification.NestingType)
												{
													// Trivial path leading in, remove the subtype completely
													processTailDelayed = false;
													tailNode.Value = new ColumnPathStep(objectifiedOppositeRole, objectifiedResolvedProxyRole.RolePlayer, null, flags);
													ProcessTailNode(tailNode, objectTypeToSteps);
													continue;
												}
												tailNode.Value = new ColumnPathStep(pathStep.FromRole, pathStep.ObjectType, fromObjectType, pathStep.Flags);
												pathStep = new ColumnPathStep(objectifiedOppositeRole, objectifiedResolvedProxyRole.RolePlayer, null, flags);
												haveStep = true;
											}
											else
											{
												// Add a resolved supertype to the forward subtype to
												// allow later steps to be compared to this one.
												tailNode.Value = new ColumnPathStep(pathStep.FromRole, pathStep.ObjectType, targetRole.RolePlayer, pathStep.Flags);
											}
										}
										else if (!processTailDelayed && 0 != (tailFlags & ColumnPathStepFlags.DeclinedAssimilation))
										{
											// Add a resolved supertype to the previous step
											tailNode.Value = new ColumnPathStep(pathStep.FromRole, pathStep.ObjectType, targetRole.RolePlayer, pathStep.Flags);
										}
									}
									if (!haveStep)
									{
										Role oppositeRole = targetRole.OppositeRoleAlwaysResolveProxy.Role;
										ORMUniquenessConstraint pid = targetRole.RolePlayer.PreferredIdentifier;
										if (pid != null && pid.RoleCollection.Contains(oppositeRole))
										{
											flags |= ColumnPathStepFlags.IsIdentifier;
											passedIdentifier = true;
										}
										pathStep = new ColumnPathStep(targetRole, oppositeRole.RolePlayer, null, flags);
									}
									processPreviousTail = processTailDelayed;
									processTailDelayed = false;
								}
								if (processPreviousTail && tailNode != null)
								{
									ProcessTailNode(tailNode, objectTypeToSteps);
								}
								LinkedNode<ColumnPathStep> newNode = new LinkedNode<ColumnPathStep>(pathStep);
								if (tailNode == null)
								{
									headNode = tailNode = newNode;
								}
								else
								{
									tailNode.SetNext(newNode, ref headNode);
									tailNode = newNode;
								}
								if (!processTailDelayed)
								{
									ProcessTailNode(tailNode, objectTypeToSteps);
								}
							}
						}
						if (processTailDelayed)
						{
							ProcessTailNode(tailNode, objectTypeToSteps);
						}
						columnSteps.Add(currentColumn, headNode);
					}
					Debug.Unindent();
					Debug.Unindent();
					return columnSteps[column];
				}