internal MemberDomainMap( ViewTarget viewTarget, bool isValidationEnabled, IEnumerable <Cell> extentCells, EdmItemCollection edmItemCollection, ConfigViewGenerator config, Dictionary <EntityType, Set <EntityType> > inheritanceGraph) { m_conditionDomainMap = new Dictionary <MemberPath, CellConstantSet>(MemberPath.EqualityComparer); m_edmItemCollection = edmItemCollection; Dictionary <MemberPath, CellConstantSet> domainMap = null; if (viewTarget == ViewTarget.UpdateView) { domainMap = Domain.ComputeConstantDomainSetsForSlotsInUpdateViews(extentCells, m_edmItemCollection); } else { domainMap = Domain.ComputeConstantDomainSetsForSlotsInQueryViews(extentCells, m_edmItemCollection, isValidationEnabled); } foreach (var cell in extentCells) { var cellQuery = cell.GetLeftQuery(viewTarget); // Get the atoms from cellQuery and only keep the ones that // are condition members foreach (var condition in cellQuery.GetConjunctsFromWhereClause()) { // Note: TypeConditions are created using OneOfTypeConst and // scalars are created using OneOfScalarConst var memberPath = condition.RestrictedMemberSlot.MemberPath; Debug.Assert( condition is ScalarRestriction || condition is TypeRestriction, "Unexpected restriction"); // Take the narrowed domain from domainMap, if any CellConstantSet domainValues; if (!domainMap.TryGetValue(memberPath, out domainValues)) { domainValues = Domain.DeriveDomainFromMemberPath(memberPath, edmItemCollection, isValidationEnabled); } //Don't count conditions that are satisfied through IsNull=false if (!domainValues.Contains(Constant.Null)) { //multiple values of condition represent disjunction in conditions (not currently supported) // if there is any condition constant that is NotNull if (condition.Domain.Values.All(conditionConstant => (conditionConstant.Equals(Constant.NotNull)))) { continue; } //else there is atleast one condition value that is allowed, continue view generation } //------------------------------------------ //| Nullable | IsNull | Test case | //| T | T | T | //| T | F | T | //| F | T | F | //| F | F | T | //------------------------------------------ //IsNull condition on a member that is non nullable is an invalid condition if (domainValues.Count <= 0 || (!domainValues.Contains(Constant.Null) && condition.Domain.Values.Contains(Constant.Null))) { var message = Strings.ViewGen_InvalidCondition(memberPath.PathToString(false)); var record = new ErrorLog.Record(ViewGenErrorCode.InvalidCondition, message, cell, String.Empty); ExceptionHelpers.ThrowMappingException(record, config); } if (memberPath.IsAlwaysDefined(inheritanceGraph) == false) { domainValues.Add(Constant.Undefined); } AddToDomainMap(memberPath, domainValues); } } // Fill up the domains for the remaining slots as well m_nonConditionDomainMap = new Dictionary <MemberPath, CellConstantSet>(MemberPath.EqualityComparer); foreach (var cell in extentCells) { var cellQuery = cell.GetLeftQuery(viewTarget); // Get the atoms from cellQuery and only keep the ones that // are condition members foreach (var slot in cellQuery.GetAllQuerySlots()) { var member = slot.MemberPath; if (m_conditionDomainMap.ContainsKey(member) == false && m_nonConditionDomainMap.ContainsKey(member) == false) { var memberSet = Domain.DeriveDomainFromMemberPath( member, m_edmItemCollection, true /* Regardless of validation, leave the domain unbounded because this is not a condition member */); if (member.IsAlwaysDefined(inheritanceGraph) == false) { // nonConditionMember may belong to subclass memberSet.Add(Constant.Undefined); } memberSet = Domain.ExpandNegationsInDomain(memberSet, memberSet); m_nonConditionDomainMap.Add(member, new CellConstantSetInfo(memberSet)); } } } }
internal MemberDomainMap( ViewTarget viewTarget, bool isValidationEnabled, IEnumerable <Cell> extentCells, EdmItemCollection edmItemCollection, ConfigViewGenerator config, Dictionary <EntityType, Set <EntityType> > inheritanceGraph) { this.m_conditionDomainMap = new Dictionary <MemberPath, Set <Constant> >(MemberPath.EqualityComparer); this.m_edmItemCollection = edmItemCollection; Dictionary <MemberPath, Set <Constant> > dictionary = viewTarget != ViewTarget.UpdateView ? Domain.ComputeConstantDomainSetsForSlotsInQueryViews(extentCells, this.m_edmItemCollection, isValidationEnabled) : Domain.ComputeConstantDomainSetsForSlotsInUpdateViews(extentCells, this.m_edmItemCollection); foreach (Cell extentCell in extentCells) { foreach (MemberRestriction memberRestriction in extentCell.GetLeftQuery(viewTarget).GetConjunctsFromWhereClause()) { MemberPath memberPath = memberRestriction.RestrictedMemberSlot.MemberPath; Set <Constant> set; if (!dictionary.TryGetValue(memberPath, out set)) { set = Domain.DeriveDomainFromMemberPath(memberPath, edmItemCollection, isValidationEnabled); } if (set.Contains(Constant.Null) || !memberRestriction.Domain.Values.All <Constant>((Func <Constant, bool>)(conditionConstant => conditionConstant.Equals((object)Constant.NotNull)))) { if (set.Count <= 0 || !set.Contains(Constant.Null) && memberRestriction.Domain.Values.Contains <Constant>(Constant.Null)) { ExceptionHelpers.ThrowMappingException(new ErrorLog.Record(ViewGenErrorCode.InvalidCondition, Strings.ViewGen_InvalidCondition((object)memberPath.PathToString(new bool?(false))), extentCell, string.Empty), config); } if (!memberPath.IsAlwaysDefined(inheritanceGraph)) { set.Add(Constant.Undefined); } this.AddToDomainMap(memberPath, (IEnumerable <Constant>)set); } } } this.m_nonConditionDomainMap = new Dictionary <MemberPath, Set <Constant> >(MemberPath.EqualityComparer); foreach (Cell extentCell in extentCells) { foreach (MemberProjectedSlot allQuerySlot in extentCell.GetLeftQuery(viewTarget).GetAllQuerySlots()) { MemberPath memberPath = allQuerySlot.MemberPath; if (!this.m_conditionDomainMap.ContainsKey(memberPath) && !this.m_nonConditionDomainMap.ContainsKey(memberPath)) { Set <Constant> set = Domain.DeriveDomainFromMemberPath(memberPath, this.m_edmItemCollection, true); if (!memberPath.IsAlwaysDefined(inheritanceGraph)) { set.Add(Constant.Undefined); } Set <Constant> iconstants = Domain.ExpandNegationsInDomain((IEnumerable <Constant>)set, (IEnumerable <Constant>)set); this.m_nonConditionDomainMap.Add(memberPath, (Set <Constant>) new MemberDomainMap.CellConstantSetInfo(iconstants)); } } } }