private void ExpandDomainsIfNeeded(Dictionary <MemberPath, CellConstantSet> domainMapForMembers)
 {
     // For the S-side, we always says that NOT(...) is
     // present. For example, if we are told "C", "P", we assume
     // that NOT(C, P) is possibly present in that column
     foreach (var path in domainMapForMembers.Keys)
     {
         var possibleValues = domainMapForMembers[path];
         if (path.IsScalarType()
             &&
             possibleValues.Any(c => c is NegatedConstant) == false)
         {
             if (MetadataHelper.HasDiscreteDomain(path.EdmType))
             {
                 // for a discrete domain, add all values that are not currently represented
                 // in the domain
                 var completeDomain = Domain.DeriveDomainFromMemberPath(path, m_edmItemCollection, true /* leaveDomainUnbounded */);
                 possibleValues.Unite(completeDomain);
             }
             else
             {
                 // for a non-discrete domain, add NOT("C", "P")
                 var negatedConstant = new NegatedConstant(possibleValues);
                 possibleValues.Add(negatedConstant);
             }
         }
     }
 }
Пример #2
0
        internal static Dictionary <MemberPath, Set <Constant> > ComputeConstantDomainSetsForSlotsInQueryViews(
            IEnumerable <Cell> cells,
            EdmItemCollection edmItemCollection,
            bool isValidationEnabled)
        {
            Dictionary <MemberPath, Set <Constant> > dictionary = new Dictionary <MemberPath, Set <Constant> >(MemberPath.EqualityComparer);

            foreach (Cell cell in cells)
            {
                foreach (MemberRestriction memberRestriction in cell.CQuery.GetConjunctsFromWhereClause())
                {
                    MemberProjectedSlot restrictedMemberSlot = memberRestriction.RestrictedMemberSlot;
                    Set <Constant>      set1 = Domain.DeriveDomainFromMemberPath(restrictedMemberSlot.MemberPath, edmItemCollection, isValidationEnabled);
                    set1.AddRange(memberRestriction.Domain.Values.Where <Constant>((Func <Constant, bool>)(c =>
                    {
                        if (!c.Equals((object)Constant.Null))
                        {
                            return(!c.Equals((object)Constant.NotNull));
                        }
                        return(false);
                    })));
                    Set <Constant> set2;
                    if (!dictionary.TryGetValue(restrictedMemberSlot.MemberPath, out set2))
                    {
                        dictionary[restrictedMemberSlot.MemberPath] = set1;
                    }
                    else
                    {
                        set2.AddRange((IEnumerable <Constant>)set1);
                    }
                }
            }
            return(dictionary);
        }
        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));
                    }
                }
            }
        }
 private void ExpandDomainsIfNeeded(
     Dictionary <MemberPath, Set <Constant> > domainMapForMembers)
 {
     foreach (MemberPath key in domainMapForMembers.Keys)
     {
         Set <Constant> domainMapForMember = domainMapForMembers[key];
         if (key.IsScalarType() && !domainMapForMember.Any <Constant>((Func <Constant, bool>)(c => c is NegatedConstant)))
         {
             if (MetadataHelper.HasDiscreteDomain(key.EdmType))
             {
                 Set <Constant> set = Domain.DeriveDomainFromMemberPath(key, this.m_edmItemCollection, true);
                 domainMapForMember.Unite((IEnumerable <Constant>)set);
             }
             else
             {
                 NegatedConstant negatedConstant = new NegatedConstant((IEnumerable <Constant>)domainMapForMember);
                 domainMapForMember.Add((Constant)negatedConstant);
             }
         }
     }
 }
 private static void ReduceEnumerableDomainToEnumeratedValues(
     Dictionary <MemberPath, Set <Constant> > domainMap,
     ConfigViewGenerator config,
     EdmItemCollection edmItemCollection)
 {
     foreach (MemberPath key in domainMap.Keys)
     {
         if (MetadataHelper.HasDiscreteDomain(key.EdmType))
         {
             Set <Constant> set1 = Domain.DeriveDomainFromMemberPath(key, edmItemCollection, true);
             Set <Constant> set2 = domainMap[key].Difference((IEnumerable <Constant>)set1);
             set2.Remove(Constant.Undefined);
             if (set2.Count > 0)
             {
                 if (config.IsNormalTracing)
                 {
                     Helpers.FormatTraceLine("Changed domain of {0} from {1} - subtract {2}", (object)key, (object)domainMap[key], (object)set2);
                 }
                 domainMap[key].Subtract((IEnumerable <Constant>)set2);
             }
         }
     }
 }
 // effects: Fixes the domains of variables in this as specified in FixEnumerableDomains
 private static void ReduceEnumerableDomainToEnumeratedValues(
     Dictionary <MemberPath, CellConstantSet> domainMap, ConfigViewGenerator config,
     EdmItemCollection edmItemCollection)
 {
     foreach (var member in domainMap.Keys)
     {
         if (MetadataHelper.HasDiscreteDomain(member.EdmType) == false)
         {
             continue;
         }
         var domain = Domain.DeriveDomainFromMemberPath(member, edmItemCollection, true /* leaveDomainUnbounded */);
         var extra  = domainMap[member].Difference(domain);
         extra.Remove(Constant.Undefined);
         if (extra.Count > 0)
         {
             // domainMap has extra members -- we should get rid of them
             if (config.IsNormalTracing)
             {
                 Helpers.FormatTraceLine("Changed domain of {0} from {1} - subtract {2}", member, domainMap[member], extra);
             }
             domainMap[member].Subtract(extra);
         }
     }
 }
        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));
                    }
                }
            }
        }
Пример #8
0
 private static bool GetRestrictedOrUnrestrictedDomain(
     MemberProjectedSlot slot,
     CellQuery cellQuery,
     EdmItemCollection edmItemCollection,
     out Set <Constant> domain)
 {
     return(Domain.TryGetDomainRestrictedByWhereClause((IEnumerable <Constant>)Domain.DeriveDomainFromMemberPath(slot.MemberPath, edmItemCollection, true), slot, cellQuery, out domain));
 }