private BoolExpression CreateMemberCondition( MemberPath path, Constant domainValue) { return(FragmentQuery.CreateMemberCondition(path, domainValue, this._domainMap)); }
private static TileNamed <FragmentQuery> CreateTile(FragmentQuery query) { return(new TileNamed <FragmentQuery>(query)); }
private bool RewriteQuery( Tile <FragmentQuery> toFill, Tile <FragmentQuery> toAvoid, out Tile <FragmentQuery> rewriting, out IEnumerable <MemberPath> notCoveredAttributes, bool isRelaxed) { notCoveredAttributes = (IEnumerable <MemberPath>) new List <MemberPath>(); FragmentQuery query1 = toFill.Query; if (this._context.TryGetCachedRewriting(query1, out rewriting)) { return(true); } IEnumerable <Tile <FragmentQuery> > relevantViews = this.GetRelevantViews(query1); FragmentQuery query2 = query1; if (!this.RewriteQueryCached((Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create(query1.Condition)), toAvoid, relevantViews, out rewriting)) { if (!isRelaxed) { return(false); } query1 = FragmentQuery.Create((IEnumerable <MemberPath>)query1.Attributes, BoolExpression.CreateAndNot(query1.Condition, rewriting.Query.Condition)); if (this._qp.IsEmpty((Tile <FragmentQuery>)QueryRewriter.CreateTile(query1)) || !this.RewriteQueryCached((Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create(query1.Condition)), toAvoid, relevantViews, out rewriting)) { return(false); } } if (query1.Attributes.Count == 0) { return(true); } Dictionary <MemberPath, FragmentQuery> attributeConditions = new Dictionary <MemberPath, FragmentQuery>(); foreach (MemberPath nonKey in QueryRewriter.NonKeys((IEnumerable <MemberPath>)query1.Attributes)) { attributeConditions[nonKey] = query1; } if (attributeConditions.Count == 0 || this.CoverAttributes(ref rewriting, attributeConditions)) { this.GetUsedViewsAndRemoveTrueSurrogate(ref rewriting); this._context.SetCachedRewriting(query2, rewriting); return(true); } if (isRelaxed) { foreach (MemberPath nonKey in QueryRewriter.NonKeys((IEnumerable <MemberPath>)query1.Attributes)) { FragmentQuery fragmentQuery; attributeConditions[nonKey] = !attributeConditions.TryGetValue(nonKey, out fragmentQuery) ? query1 : FragmentQuery.Create(BoolExpression.CreateAndNot(query1.Condition, fragmentQuery.Condition)); } if (this.CoverAttributes(ref rewriting, attributeConditions)) { this.GetUsedViewsAndRemoveTrueSurrogate(ref rewriting); this._context.SetCachedRewriting(query2, rewriting); return(true); } } notCoveredAttributes = (IEnumerable <MemberPath>)attributeConditions.Keys; return(false); }
private bool FindRewriting( IEnumerable <MemberPath> attributes, BoolExpression whereClause, out Tile <FragmentQuery> rewriting, out IEnumerable <MemberPath> notCoveredAttributes) { Tile <FragmentQuery> tile1 = (Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create(attributes, whereClause)); Tile <FragmentQuery> tile2 = (Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create((IEnumerable <MemberPath>) this._keyAttributes, BoolExpression.CreateNot(whereClause))); bool isRelaxed = this._context.ViewTarget == ViewTarget.UpdateView; return(this.RewriteQuery(tile1, tile2, out rewriting, out notCoveredAttributes, isRelaxed)); }
internal void EnsureExtentIsFullyMapped(HashSet <FragmentQuery> outputUsedViews) { if (this._context.ViewTarget == ViewTarget.QueryView && this._config.IsValidationEnabled) { this.EnsureConfigurationIsFullyMapped(this._extentPath, BoolExpression.True, outputUsedViews, this._errorLog); if (this._errorLog.Count <= 0) { return; } ExceptionHelpers.ThrowMappingException(this._errorLog, this._config); } else { if (this._config.IsValidationEnabled) { foreach (MemberPath member in this._context.MemberMaps.ProjectedSlotMap.Members) { Constant defaultConstant; if (member.IsScalarType() && !member.IsPartOfKey && (!this._domainMap.IsConditionMember(member) && !Domain.TryGetDefaultValueForMemberPath(member, out defaultConstant))) { HashSet <MemberPath> memberPathSet = new HashSet <MemberPath>((IEnumerable <MemberPath>) this._keyAttributes); memberPathSet.Add(member); foreach (LeftCellWrapper leftCellWrapper in this._context.AllWrappersForExtent) { FragmentQuery fragmentQuery = leftCellWrapper.FragmentQuery; Tile <FragmentQuery> rewriting; IEnumerable <MemberPath> notCoveredAttributes; if (!this.RewriteQuery((Tile <FragmentQuery>)QueryRewriter.CreateTile(new FragmentQuery(fragmentQuery.Description, fragmentQuery.FromVariable, (IEnumerable <MemberPath>)memberPathSet, fragmentQuery.Condition)), (Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create((IEnumerable <MemberPath>) this._keyAttributes, BoolExpression.CreateNot(fragmentQuery.Condition))), out rewriting, out notCoveredAttributes, false)) { Domain.GetDefaultValueForMemberPath(member, (IEnumerable <LeftCellWrapper>) new LeftCellWrapper[1] { leftCellWrapper }, this._config); } } } } } foreach (Tile <FragmentQuery> view in this._views) { Tile <FragmentQuery> toFill = view; Tile <FragmentQuery> tile = (Tile <FragmentQuery>)QueryRewriter.CreateTile(FragmentQuery.Create((IEnumerable <MemberPath>) this._keyAttributes, BoolExpression.CreateNot(toFill.Query.Condition))); Tile <FragmentQuery> rewriting; IEnumerable <MemberPath> notCoveredAttributes; if (!this.RewriteQuery(toFill, tile, out rewriting, out notCoveredAttributes, true)) { LeftCellWrapper leftCellWrapper = this._context.AllWrappersForExtent.First <LeftCellWrapper>((Func <LeftCellWrapper, bool>)(lcr => lcr.FragmentQuery.Equals((object)toFill.Query))); this._errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.ImpopssibleCondition, Strings.Viewgen_QV_RewritingNotFound((object)leftCellWrapper.RightExtent.ToString()), leftCellWrapper.Cells, string.Empty)); } else { outputUsedViews.UnionWith(rewriting.GetNamedQueries()); } } } }
private void GenerateCaseStatements( IEnumerable <MemberPath> members, HashSet <FragmentQuery> outputUsedViews) { CellTreeNode rightDomainQuery = (CellTreeNode) new OpCellTreeNode(this._context, CellTreeOpType.Union, (CellTreeNode[])this._context.AllWrappersForExtent.Where <LeftCellWrapper>((Func <LeftCellWrapper, bool>)(w => this._usedViews.Contains(w.FragmentQuery))).Select <LeftCellWrapper, LeafCellTreeNode>((Func <LeftCellWrapper, LeafCellTreeNode>)(wrapper => new LeafCellTreeNode(this._context, wrapper))).ToArray <LeafCellTreeNode>()); foreach (MemberPath member in members) { List <Constant> list = this.GetDomain(member).ToList <Constant>(); CaseStatement caseStatement = new CaseStatement(member); Tile <FragmentQuery> tile = (Tile <FragmentQuery>)null; bool flag = list.Count != 2 || !list.Contains <Constant>(Constant.Null, Constant.EqualityComparer) || !list.Contains <Constant>(Constant.NotNull, Constant.EqualityComparer); foreach (Constant domainValue in list) { if (domainValue == Constant.Undefined && this._context.ViewTarget == ViewTarget.QueryView) { caseStatement.AddWhenThen(BoolExpression.False, (ProjectedSlot) new ConstantProjectedSlot(Constant.Undefined)); } else { FragmentQuery memberConditionQuery = this.CreateMemberConditionQuery(member, domainValue); Tile <FragmentQuery> rewriting; if (this.FindRewritingAndUsedViews((IEnumerable <MemberPath>)memberConditionQuery.Attributes, memberConditionQuery.Condition, outputUsedViews, out rewriting)) { if (this._context.ViewTarget == ViewTarget.UpdateView) { tile = tile != null?this._qp.Union(tile, rewriting) : rewriting; } if (flag) { if (this.AddRewritingToCaseStatement(rewriting, caseStatement, member, domainValue)) { break; } } } else if (!QueryRewriter.IsDefaultValue(domainValue, member) && !ErrorPatternMatcher.FindMappingErrors(this._context, this._domainMap, this._errorLog)) { StringBuilder builder = new StringBuilder(); string str1 = StringUtil.FormatInvariant("{0}", (object)this._extentPath); string str2 = this._context.ViewTarget == ViewTarget.QueryView ? Strings.ViewGen_Entities : Strings.ViewGen_Tuples; if (this._context.ViewTarget == ViewTarget.QueryView) { builder.AppendLine(Strings.Viewgen_CannotGenerateQueryViewUnderNoValidation((object)str1)); } else { builder.AppendLine(Strings.ViewGen_Cannot_Disambiguate_MultiConstant((object)str2, (object)str1)); } RewritingValidator.EntityConfigurationToUserString(memberConditionQuery.Condition, builder, this._context.ViewTarget == ViewTarget.UpdateView); this._errorLog.AddEntry(new ErrorLog.Record(ViewGenErrorCode.AmbiguousMultiConstants, builder.ToString(), (IEnumerable <LeftCellWrapper>) this._context.AllWrappersForExtent, string.Empty)); } } } if (this._errorLog.Count == 0) { if (this._context.ViewTarget == ViewTarget.UpdateView && flag) { this.AddElseDefaultToCaseStatement(member, caseStatement, list, rightDomainQuery, tile); } if (caseStatement.Clauses.Count > 0) { this._caseStatements[member] = caseStatement; } } } }
private bool IsTrue(FragmentQuery query) { return(!this._context.LeftFragmentQP.IsSatisfiable(FragmentQuery.Create(BoolExpression.CreateNot(query.Condition)))); }