private static bool IsMemberPartOfNotNullCondition(
     IEnumerable <LeftCellWrapper> wrappers,
     MemberPath leftMember,
     ViewTarget viewTarget)
 {
     foreach (LeftCellWrapper wrapper in wrappers)
     {
         CellQuery leftQuery = wrapper.OnlyInputCell.GetLeftQuery(viewTarget);
         if (ErrorPatternMatcher.HasNotNullCondition(leftQuery, leftMember))
         {
             return(true);
         }
         CellQuery rightQuery = wrapper.OnlyInputCell.GetRightQuery(viewTarget);
         int       slotNum    = leftQuery.GetProjectedMembers().TakeWhile <MemberPath>((Func <MemberPath, bool>)(path => !path.Equals(leftMember))).Count <MemberPath>();
         if (slotNum < leftQuery.GetProjectedMembers().Count <MemberPath>())
         {
             MemberPath memberPath = ((MemberProjectedSlot)rightQuery.ProjectedSlotAt(slotNum)).MemberPath;
             if (ErrorPatternMatcher.HasNotNullCondition(rightQuery, memberPath))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
        public static bool FindMappingErrors(ViewgenContext context, MemberDomainMap domainMap, ErrorLog errorLog)
        {
            //Can't get here if Update Views have validation disabled
            Debug.Assert(context.ViewTarget == ViewTarget.QueryView || context.Config.IsValidationEnabled);

            if (context.ViewTarget == ViewTarget.QueryView &&
                !context.Config.IsValidationEnabled)
            {
                return(false); // Rules for QV under no validation are different
            }

            var matcher = new ErrorPatternMatcher(context, domainMap, errorLog);

            matcher.MatchMissingMappingErrors();
            matcher.MatchConditionErrors();
            matcher.MatchSplitErrors();

            if (matcher.m_errorLog.Count
                == matcher.m_originalErrorCount)
            {
                //this will generate redundant errors if one of the above routine finds an error
                // so execute it only when we dont have any other errors
                matcher.MatchPartitionErrors();
            }

            if (matcher.m_errorLog.Count
                > matcher.m_originalErrorCount)
            {
                ExceptionHelpers.ThrowMappingException(matcher.m_errorLog, matcher.m_viewgenContext.Config);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private void ReportConstraintViolation(
            string message,
            BoolExpression extraConstraint,
            ViewGenErrorCode errorCode,
            IEnumerable <LeftCellWrapper> relevantWrappers)
        {
            if (ErrorPatternMatcher.FindMappingErrors(this._viewgenContext, this._domainMap, this._errorLog))
            {
                return;
            }
            extraConstraint.ExpensiveSimplify();
            HashSet <LeftCellWrapper> leftCellWrapperSet = new HashSet <LeftCellWrapper>(relevantWrappers);

            new List <LeftCellWrapper>((IEnumerable <LeftCellWrapper>)leftCellWrapperSet).Sort(LeftCellWrapper.OriginalCellIdComparer);
            StringBuilder builder = new StringBuilder();

            builder.AppendLine(message);
            RewritingValidator.EntityConfigurationToUserString(extraConstraint, builder);
            this._errorLog.AddEntry(new ErrorLog.Record(errorCode, builder.ToString(), (IEnumerable <LeftCellWrapper>)leftCellWrapperSet, ""));
        }
        private void ReportConstraintViolation(
            string message, BoolExpression extraConstraint, ViewGenErrorCode errorCode, IEnumerable <LeftCellWrapper> relevantWrappers)
        {
            if (ErrorPatternMatcher.FindMappingErrors(_viewgenContext, _domainMap, _errorLog))
            {
                return;
            }

            extraConstraint.ExpensiveSimplify();
            // gather all relevant cell wrappers and sort them in the original input order
            var relevantCellWrappers = new HashSet <LeftCellWrapper>(relevantWrappers);
            var relevantWrapperList  = new List <LeftCellWrapper>(relevantCellWrappers);

            relevantWrapperList.Sort(LeftCellWrapper.OriginalCellIdComparer);

            var builder = new StringBuilder();

            builder.AppendLine(message);
            EntityConfigurationToUserString(extraConstraint, builder);
            _errorLog.AddEntry(new ErrorLog.Record(errorCode, builder.ToString(), relevantCellWrappers, ""));
        }
        public static bool FindMappingErrors(
            ViewgenContext context,
            MemberDomainMap domainMap,
            ErrorLog errorLog)
        {
            if (context.ViewTarget == ViewTarget.QueryView && !context.Config.IsValidationEnabled)
            {
                return(false);
            }
            ErrorPatternMatcher errorPatternMatcher = new ErrorPatternMatcher(context, domainMap, errorLog);

            errorPatternMatcher.MatchMissingMappingErrors();
            errorPatternMatcher.MatchConditionErrors();
            errorPatternMatcher.MatchSplitErrors();
            if (errorPatternMatcher.m_errorLog.Count == errorPatternMatcher.m_originalErrorCount)
            {
                errorPatternMatcher.MatchPartitionErrors();
            }
            if (errorPatternMatcher.m_errorLog.Count > errorPatternMatcher.m_originalErrorCount)
            {
                ExceptionHelpers.ThrowMappingException(errorPatternMatcher.m_errorLog, errorPatternMatcher.m_viewgenContext.Config);
            }
            return(false);
        }
        private void MatchMissingMappingErrors()
        {
            if (this.m_viewgenContext.ViewTarget != ViewTarget.QueryView)
            {
                return;
            }
            Set <EdmType> set = new Set <EdmType>(MetadataHelper.GetTypeAndSubtypesOf((EdmType)this.m_viewgenContext.Extent.ElementType, (ItemCollection)this.m_viewgenContext.EdmItemCollection, false));

            foreach (LeftCellWrapper leftCellWrapper in this.m_viewgenContext.AllWrappersForExtent)
            {
                foreach (Cell cell in leftCellWrapper.Cells)
                {
                    foreach (MemberRestriction condition in cell.CQuery.Conditions)
                    {
                        foreach (Constant constant in condition.Domain.Values)
                        {
                            TypeConstant typeConstant = constant as TypeConstant;
                            if (typeConstant != null)
                            {
                                set.Remove(typeConstant.EdmType);
                            }
                        }
                    }
                }
            }
            if (set.Count <= 0)
            {
                return;
            }
            this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternMissingMappingError, Strings.ViewGen_Missing_Type_Mapping((object)ErrorPatternMatcher.BuildCommaSeparatedErrorString <EdmType>((IEnumerable <EdmType>)set)), (IEnumerable <LeftCellWrapper>) this.m_viewgenContext.AllWrappersForExtent, ""));
        }
        private void MatchPartitionErrors()
        {
            List <LeftCellWrapper> wrappersForExtent = this.m_viewgenContext.AllWrappersForExtent;
            int num = 0;

            foreach (LeftCellWrapper leftCellWrapper1 in wrappersForExtent)
            {
                foreach (LeftCellWrapper leftCellWrapper2 in wrappersForExtent.Skip <LeftCellWrapper>(++num))
                {
                    FragmentQuery rightFragmentQuery1 = this.CreateRightFragmentQuery(leftCellWrapper1);
                    FragmentQuery rightFragmentQuery2 = this.CreateRightFragmentQuery(leftCellWrapper2);
                    bool          flag1 = this.CompareS(ErrorPatternMatcher.ComparisonOP.IsDisjointFrom, this.m_viewgenContext, leftCellWrapper1, leftCellWrapper2, rightFragmentQuery1, rightFragmentQuery2);
                    bool          flag2 = this.CompareC(ErrorPatternMatcher.ComparisonOP.IsDisjointFrom, this.m_viewgenContext, leftCellWrapper1, leftCellWrapper2, rightFragmentQuery1, rightFragmentQuery2);
                    bool          flag3;
                    bool          flag4;
                    if (flag1)
                    {
                        if (!flag2)
                        {
                            flag3 = this.CompareC(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper1, leftCellWrapper2, rightFragmentQuery1, rightFragmentQuery2);
                            flag4 = this.CompareC(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper2, leftCellWrapper1, rightFragmentQuery2, rightFragmentQuery1);
                            bool          flag5         = flag3 && flag4;
                            StringBuilder stringBuilder = new StringBuilder();
                            if (flag5)
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Disj_Eq);
                            }
                            else if (flag3 || flag4)
                            {
                                if (this.CSideHasDifferentEntitySets(leftCellWrapper1, leftCellWrapper2))
                                {
                                    stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Disj_Subs_Ref);
                                }
                                else
                                {
                                    stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Disj_Subs);
                                }
                            }
                            else
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Disj_Unk);
                            }
                            this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternInvalidPartitionError, stringBuilder.ToString(), ErrorPatternMatcher.ToIEnum(leftCellWrapper1.OnlyInputCell, leftCellWrapper2.OnlyInputCell), ""));
                            if (this.FoundTooManyErrors())
                            {
                                return;
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        flag3 = this.CompareC(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper1, leftCellWrapper2, rightFragmentQuery1, rightFragmentQuery2);
                        flag4 = this.CompareC(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper2, leftCellWrapper1, rightFragmentQuery2, rightFragmentQuery1);
                    }
                    bool flag6 = this.CompareS(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper1, leftCellWrapper2, rightFragmentQuery1, rightFragmentQuery2);
                    bool flag7 = this.CompareS(ErrorPatternMatcher.ComparisonOP.IsContainedIn, this.m_viewgenContext, leftCellWrapper2, leftCellWrapper1, rightFragmentQuery2, rightFragmentQuery1);
                    bool flag8 = flag3 && flag4;
                    if (flag6 && flag7)
                    {
                        if (!flag8)
                        {
                            StringBuilder stringBuilder = new StringBuilder();
                            if (flag2)
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Eq_Disj);
                            }
                            else if (flag3 || flag4)
                            {
                                if (this.CSideHasDifferentEntitySets(leftCellWrapper1, leftCellWrapper2))
                                {
                                    stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Eq_Subs_Ref);
                                }
                                else
                                {
                                    if (leftCellWrapper1.LeftExtent.Equals((object)leftCellWrapper2.LeftExtent))
                                    {
                                        bool           hasCondition1;
                                        List <EdmType> edmTypes1;
                                        ErrorPatternMatcher.GetTypesAndConditionForWrapper(leftCellWrapper1, out hasCondition1, out edmTypes1);
                                        bool           hasCondition2;
                                        List <EdmType> edmTypes2;
                                        ErrorPatternMatcher.GetTypesAndConditionForWrapper(leftCellWrapper2, out hasCondition2, out edmTypes2);
                                        if (!hasCondition1 && !hasCondition2 && (edmTypes1.Except <EdmType>((IEnumerable <EdmType>)edmTypes2).Count <EdmType>() != 0 || edmTypes2.Except <EdmType>((IEnumerable <EdmType>)edmTypes1).Count <EdmType>() != 0) && (!ErrorPatternMatcher.CheckForStoreConditions(leftCellWrapper1) || !ErrorPatternMatcher.CheckForStoreConditions(leftCellWrapper2)))
                                        {
                                            this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternConditionError, Strings.Viewgen_ErrorPattern_Partition_MultipleTypesMappedToSameTable_WithoutCondition((object)StringUtil.ToCommaSeparatedString((IEnumerable)edmTypes1.Select <EdmType, string>((Func <EdmType, string>)(it => it.FullName)).Union <string>(edmTypes2.Select <EdmType, string>((Func <EdmType, string>)(it => it.FullName)))), (object)leftCellWrapper1.LeftExtent), ErrorPatternMatcher.ToIEnum(leftCellWrapper1.OnlyInputCell, leftCellWrapper2.OnlyInputCell), ""));
                                            return;
                                        }
                                    }
                                    stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Eq_Subs);
                                }
                            }
                            else if (!this.IsQueryView() && (leftCellWrapper1.OnlyInputCell.CQuery.Extent is AssociationSet || leftCellWrapper2.OnlyInputCell.CQuery.Extent is AssociationSet))
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Eq_Unk_Association);
                            }
                            else
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Eq_Unk);
                            }
                            this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternInvalidPartitionError, stringBuilder.ToString(), ErrorPatternMatcher.ToIEnum(leftCellWrapper1.OnlyInputCell, leftCellWrapper2.OnlyInputCell), ""));
                            if (this.FoundTooManyErrors())
                            {
                                return;
                            }
                        }
                    }
                    else if ((flag6 || flag7) && (!flag6 || !flag3 || flag4) && (!flag7 || !flag4 || flag3))
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        if (flag2)
                        {
                            stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Sub_Disj);
                        }
                        else if (flag8)
                        {
                            if (this.CSideHasDifferentEntitySets(leftCellWrapper1, leftCellWrapper2))
                            {
                                stringBuilder.Append(" " + Strings.Viewgen_ErrorPattern_Partition_Sub_Eq_Ref);
                            }
                            else
                            {
                                stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Sub_Eq);
                            }
                        }
                        else
                        {
                            stringBuilder.Append(Strings.Viewgen_ErrorPattern_Partition_Sub_Unk);
                        }
                        this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternInvalidPartitionError, stringBuilder.ToString(), ErrorPatternMatcher.ToIEnum(leftCellWrapper1.OnlyInputCell, leftCellWrapper2.OnlyInputCell), ""));
                        if (this.FoundTooManyErrors())
                        {
                            return;
                        }
                    }
                }
            }
        }
        private void MatchConditionErrors()
        {
            List <LeftCellWrapper> wrappersForExtent             = this.m_viewgenContext.AllWrappersForExtent;
            Set <MemberPath>       mappedConditionMembers        = new Set <MemberPath>();
            Set <Dictionary <MemberPath, Set <Constant> > > set1 = new Set <Dictionary <MemberPath, Set <Constant> > >((IEqualityComparer <Dictionary <MemberPath, Set <Constant> > >) new ConditionComparer());
            Dictionary <Dictionary <MemberPath, Set <Constant> >, LeftCellWrapper> dictionary = new Dictionary <Dictionary <MemberPath, Set <Constant> >, LeftCellWrapper>((IEqualityComparer <Dictionary <MemberPath, Set <Constant> > >) new ConditionComparer());

            foreach (LeftCellWrapper leftCellWrapper in wrappersForExtent)
            {
                Dictionary <MemberPath, Set <Constant> > index = new Dictionary <MemberPath, Set <Constant> >();
                foreach (MemberRestriction memberRestriction in leftCellWrapper.OnlyInputCell.GetLeftQuery(this.m_viewgenContext.ViewTarget).GetConjunctsFromWhereClause())
                {
                    MemberPath memberPath = memberRestriction.RestrictedMemberSlot.MemberPath;
                    if (this.m_domainMap.IsConditionMember(memberPath))
                    {
                        ScalarRestriction scalarRestriction = memberRestriction as ScalarRestriction;
                        if (scalarRestriction != null && !mappedConditionMembers.Contains(memberPath) && (!leftCellWrapper.OnlyInputCell.CQuery.WhereClause.Equals((object)leftCellWrapper.OnlyInputCell.SQuery.WhereClause) && !ErrorPatternMatcher.IsMemberPartOfNotNullCondition((IEnumerable <LeftCellWrapper>)wrappersForExtent, memberPath, this.m_viewgenContext.ViewTarget)))
                        {
                            this.CheckThatConditionMemberIsNotMapped(memberPath, wrappersForExtent, mappedConditionMembers);
                        }
                        if (this.m_viewgenContext.ViewTarget == ViewTarget.UpdateView && scalarRestriction != null && memberPath.IsNullable)
                        {
                            if (ErrorPatternMatcher.IsMemberPartOfNotNullCondition((IEnumerable <LeftCellWrapper>) new LeftCellWrapper[1]
                            {
                                leftCellWrapper
                            }, memberPath, this.m_viewgenContext.ViewTarget))
                            {
                                MemberPath rightMemberPath = ErrorPatternMatcher.GetRightMemberPath(memberPath, leftCellWrapper);
                                if (rightMemberPath != null && rightMemberPath.IsNullable)
                                {
                                    if (!ErrorPatternMatcher.IsMemberPartOfNotNullCondition((IEnumerable <LeftCellWrapper>) new LeftCellWrapper[1]
                                    {
                                        leftCellWrapper
                                    }, rightMemberPath, this.m_viewgenContext.ViewTarget))
                                    {
                                        this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternConditionError, Strings.Viewgen_ErrorPattern_NotNullConditionMappedToNullableMember((object)memberPath, (object)rightMemberPath), leftCellWrapper.OnlyInputCell, ""));
                                    }
                                }
                            }
                        }
                        foreach (Constant element in memberRestriction.Domain.Values)
                        {
                            Set <Constant> set2;
                            if (!index.TryGetValue(memberPath, out set2))
                            {
                                set2 = new Set <Constant>(Constant.EqualityComparer);
                                index.Add(memberPath, set2);
                            }
                            set2.Add(element);
                        }
                    }
                }
                if (index.Count > 0)
                {
                    if (set1.Contains(index))
                    {
                        if (!this.RightSideEqual(dictionary[index], leftCellWrapper))
                        {
                            this.m_errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ErrorPatternConditionError, Strings.Viewgen_ErrorPattern_DuplicateConditionValue((object)ErrorPatternMatcher.BuildCommaSeparatedErrorString <MemberPath>((IEnumerable <MemberPath>)index.Keys)), ErrorPatternMatcher.ToIEnum(dictionary[index].OnlyInputCell, leftCellWrapper.OnlyInputCell), ""));
                        }
                    }
                    else
                    {
                        set1.Add(index);
                        dictionary.Add(index, leftCellWrapper);
                    }
                }
            }
        }