Example #1
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];
				}
Example #2
0
					/// <summary>
					/// Test for equality without checking the state of the flags or the resolved supertype
					/// </summary>
					public bool CoreEquals(ColumnPathStep otherStep)
					{
						return myObjectType == otherStep.myObjectType && myFromRole == otherStep.myFromRole;
					}