コード例 #1
0
ファイル: OpCellTreeNode.cs プロジェクト: yz1988computer/ef6
        // requires: caseForOuterJoins corresponds the slot "slotNum"
        // effects: Adds a WhenThen corresponding to child to caseForOuterJoins.
        private void AddCaseForOuterJoins(CaseStatement caseForOuterJoins, CqlBlock child, int slotNum, CqlIdentifiers identifiers)
        {
            // Determine the cells that the slot comes from
            // and make an OR expression, e.g., WHEN _from0 or _from2 or ... THEN child[slotNum]

            var childSlot    = child.SlotValue(slotNum);
            var constantSlot = childSlot as ConstantProjectedSlot;

            if (constantSlot != null &&
                constantSlot.CellConstant.IsNull())
            {
                // NULL being generated by a child - don't need to project
                return;
            }

            var originBool = BoolExpression.False;

            for (var i = 0; i < NumBoolSlots; i++)
            {
                var boolSlotNum = BoolIndexToSlot(i);
                if (child.IsProjected(boolSlotNum))
                {
                    // OR it to the expression
                    var boolExpr = new QualifiedCellIdBoolean(child, identifiers, i);
                    originBool = BoolExpression.CreateOr(originBool, BoolExpression.CreateLiteral(boolExpr, RightDomainMap));
                }
            }
            // Qualify the slotNum with the child.CqlAlias for the THEN
            var slot = child.QualifySlotWithBlockAlias(slotNum);

            caseForOuterJoins.AddWhenThen(originBool, slot);
        }
コード例 #2
0
            internal override bool VisitTerm(
                TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                MemberRestriction boolLiteral = BoolExpression.GetBoolLiteral(expression) as MemberRestriction;

                return(boolLiteral == null || boolLiteral.IsComplete);
            }
コード例 #3
0
        internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            List <BoolExpression> boolExpressionList = new List <BoolExpression>();

            foreach (BoolExpression atom in this.WhereClause.Atoms)
            {
                MemberRestriction      asLiteral         = atom.AsLiteral as MemberRestriction;
                IEnumerable <Constant> domain            = domainMap.GetDomain(asLiteral.RestrictedMemberSlot.MemberPath);
                MemberRestriction      memberRestriction = asLiteral.CreateCompleteMemberRestriction(domain);
                ScalarRestriction      scalarRestriction = asLiteral as ScalarRestriction;
                bool flag = scalarRestriction != null && !scalarRestriction.Domain.Contains(Constant.Null) && !scalarRestriction.Domain.Contains(Constant.NotNull) && !scalarRestriction.Domain.Contains(Constant.Undefined);
                if (flag)
                {
                    domainMap.AddSentinel(memberRestriction.RestrictedMemberSlot.MemberPath);
                }
                boolExpressionList.Add(BoolExpression.CreateLiteral((BoolLiteral)memberRestriction, domainMap));
                if (flag)
                {
                    domainMap.RemoveSentinel(memberRestriction.RestrictedMemberSlot.MemberPath);
                }
            }
            if (boolExpressionList.Count <= 0)
            {
                return;
            }
            this.m_whereClause = BoolExpression.CreateAnd(boolExpressionList.ToArray());
        }
コード例 #4
0
 internal static BoolExpression CreateNot(BoolExpression expression)
 {
     return(new BoolExpression(ExprType.Not, (IEnumerable <BoolExpression>) new BoolExpression[1]
     {
         expression
     }));
 }
コード例 #5
0
        private void AddCaseForOuterJoins(
            CaseStatement caseForOuterJoins,
            CqlBlock child,
            int slotNum,
            CqlIdentifiers identifiers)
        {
            ConstantProjectedSlot constantProjectedSlot = child.SlotValue(slotNum) as ConstantProjectedSlot;

            if (constantProjectedSlot != null && constantProjectedSlot.CellConstant.IsNull())
            {
                return;
            }
            BoolExpression or = BoolExpression.False;

            for (int index = 0; index < this.NumBoolSlots; ++index)
            {
                int slot = this.BoolIndexToSlot(index);
                if (child.IsProjected(slot))
                {
                    QualifiedCellIdBoolean qualifiedCellIdBoolean = new QualifiedCellIdBoolean(child, identifiers, index);
                    or = BoolExpression.CreateOr(or, BoolExpression.CreateLiteral((BoolLiteral)qualifiedCellIdBoolean, this.RightDomainMap));
                }
            }
            QualifiedSlot qualifiedSlot = child.QualifySlotWithBlockAlias(slotNum);

            caseForOuterJoins.AddWhenThen(or, (ProjectedSlot)qualifiedSlot);
        }
コード例 #6
0
        // <summary>
        // Adds an expression of the form "WHEN <paramref name="condition" /> THEN <paramref name="value" />".
        // This operation is not allowed after the <see cref="Simplify" /> call.
        // </summary>
        internal void AddWhenThen(BoolExpression condition, ProjectedSlot value)
        {
            Debug.Assert(!m_simplified, "Attempt to modify a simplified case statement");
            DebugCheck.NotNull(value);

            condition.ExpensiveSimplify();
            m_clauses.Add(new WhenThen(condition, value));
        }
コード例 #7
0
 internal CellQuery(
     List <ProjectedSlot> slots,
     BoolExpression whereClause,
     MemberPath rootMember,
     CellQuery.SelectDistinct eliminateDuplicates)
     : this(slots.ToArray(), whereClause, new List <BoolExpression>(), eliminateDuplicates, rootMember)
 {
 }
コード例 #8
0
 // <summary>
 // Copy Constructor
 // </summary>
 internal CellQuery(CellQuery source)
 {
     m_basicCellRelation   = source.m_basicCellRelation;
     m_boolExprs           = source.m_boolExprs;
     m_selectDistinct      = source.m_selectDistinct;
     m_extentMemberPath    = source.m_extentMemberPath;
     m_originalWhereClause = source.m_originalWhereClause;
     m_projectedSlots      = source.m_projectedSlots;
     m_whereClause         = source.m_whereClause;
 }
コード例 #9
0
            internal override StringBuilder VisitTerm(
                TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                BoolLiteral boolLiteral = BoolExpression.GetBoolLiteral(expression);

                if (boolLiteral is ScalarRestriction || boolLiteral is TypeRestriction)
                {
                    return(boolLiteral.AsUserString(this.m_builder, Strings.ViewGen_EntityInstanceToken, this.m_skipIsNotNull));
                }
                return(boolLiteral.AsUserString(this.m_builder, this.m_blockAlias, this.m_skipIsNotNull));
            }
コード例 #10
0
 private static IEnumerable <MemberRestriction> GetConjunctsFromWhereClause(
     BoolExpression whereClause)
 {
     foreach (BoolExpression atom in whereClause.Atoms)
     {
         if (!atom.IsTrue)
         {
             MemberRestriction result = atom.AsLiteral as MemberRestriction;
             yield return(result);
         }
     }
 }
コード例 #11
0
 internal BoolExpression RemapLiterals(Dictionary <BoolLiteral, BoolLiteral> remap)
 {
     return(new BoolExpression(this.m_tree.Accept <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >((Visitor <DomainConstraint <BoolLiteral, Constant>, BoolExpr <DomainConstraint <BoolLiteral, Constant> > >) new BooleanExpressionTermRewriter <DomainConstraint <BoolLiteral, Constant>, DomainConstraint <BoolLiteral, Constant> >((Func <TermExpr <DomainConstraint <BoolLiteral, Constant> >, BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)(term =>
     {
         BoolLiteral boolLiteral;
         if (!remap.TryGetValue(BoolExpression.GetBoolLiteral(term), out boolLiteral))
         {
             return (BoolExpr <DomainConstraint <BoolLiteral, Constant> >)term;
         }
         return boolLiteral.GetDomainBoolExpression(this.m_memberDomainMap);
     }))), this.m_memberDomainMap));
 }
コード例 #12
0
 private IEnumerable <MemberRestriction> GetConjunctsFromWhereClause(BoolExpression whereClause)
 {
     foreach (var boolExpr in whereClause.Atoms)
     {
         if (boolExpr.IsTrue)
         {
             continue;
         }
         var result = boolExpr.AsLiteral as MemberRestriction;
         Debug.Assert(result != null, "Atom must be restriction");
         yield return(result);
     }
 }
コード例 #13
0
 // effects: Given all the fields, just sets them.
 internal CellQuery(
     ProjectedSlot[] projectedSlots,
     BoolExpression whereClause,
     List <BoolExpression> boolExprs,
     SelectDistinct elimDupl, MemberPath rootMember)
 {
     m_boolExprs           = boolExprs;
     m_projectedSlots      = projectedSlots;
     m_whereClause         = whereClause;
     m_originalWhereClause = whereClause;
     m_selectDistinct      = elimDupl;
     m_extentMemberPath    = rootMember;
 }
コード例 #14
0
            internal override StringBuilder VisitNot(
                NotExpr <DomainConstraint <BoolLiteral, Constant> > expression)
            {
                this.m_skipIsNotNull = false;
                TermExpr <DomainConstraint <BoolLiteral, Constant> > child = expression.Child as TermExpr <DomainConstraint <BoolLiteral, Constant> >;

                if (child != null)
                {
                    return(BoolExpression.GetBoolLiteral(child).AsNegatedUserString(this.m_builder, this.m_blockAlias, this.m_skipIsNotNull));
                }
                this.m_builder.Append("NOT(");
                expression.Child.Accept <StringBuilder>((Visitor <DomainConstraint <BoolLiteral, Constant>, StringBuilder>) this);
                this.m_builder.Append(")");
                return(this.m_builder);
            }
コード例 #15
0
        internal override CqlBlock ToCqlBlock(
            bool[] requiredSlots,
            CqlIdentifiers identifiers,
            ref int blockAliasNum,
            ref List <WithRelationship> withRelationships)
        {
            int       length         = requiredSlots.Length;
            CellQuery rightCellQuery = this.LeftCellWrapper.RightCellQuery;

            SlotInfo[] slotInfoArray = new SlotInfo[length];
            for (int index = 0; index < rightCellQuery.NumProjectedSlots; ++index)
            {
                ProjectedSlot slotValue = rightCellQuery.ProjectedSlotAt(index);
                if (requiredSlots[index] && slotValue == null)
                {
                    ConstantProjectedSlot slot = new ConstantProjectedSlot(Domain.GetDefaultValueForMemberPath(this.ProjectedSlotMap[index], (IEnumerable <LeftCellWrapper>) this.GetLeaves(), this.ViewgenContext.Config));
                    rightCellQuery.FixMissingSlotAsDefaultConstant(index, slot);
                    slotValue = (ProjectedSlot)slot;
                }
                SlotInfo slotInfo = new SlotInfo(requiredSlots[index], slotValue != null, slotValue, this.ProjectedSlotMap[index]);
                slotInfoArray[index] = slotInfo;
            }
            for (int index = 0; index < rightCellQuery.NumBoolVars; ++index)
            {
                BoolExpression       boolVar = rightCellQuery.GetBoolVar(index);
                BooleanProjectedSlot booleanProjectedSlot = boolVar == null ? new BooleanProjectedSlot(BoolExpression.False, identifiers, index) : new BooleanProjectedSlot(boolVar, identifiers, index);
                int      slot     = this.BoolIndexToSlot(index);
                SlotInfo slotInfo = new SlotInfo(requiredSlots[slot], boolVar != null, (ProjectedSlot)booleanProjectedSlot, (MemberPath)null);
                slotInfoArray[slot] = slotInfo;
            }
            IEnumerable <SlotInfo> source = (IEnumerable <SlotInfo>)slotInfoArray;

            if (rightCellQuery.Extent.EntityContainer.DataSpace == DataSpace.SSpace && this.m_cellWrapper.LeftExtent.BuiltInTypeKind == BuiltInTypeKind.EntitySet)
            {
                IEnumerable <AssociationSetMapping> relationshipSetMappingsFor = this.ViewgenContext.EntityContainerMapping.GetRelationshipSetMappingsFor(this.m_cellWrapper.LeftExtent, rightCellQuery.Extent);
                List <SlotInfo> foreignKeySlots = new List <SlotInfo>();
                foreach (AssociationSetMapping colocatedAssociationSetMap in relationshipSetMappingsFor)
                {
                    WithRelationship withRelationship;
                    if (LeafCellTreeNode.TryGetWithRelationship(colocatedAssociationSetMap, this.m_cellWrapper.LeftExtent, rightCellQuery.SourceExtentMemberPath, ref foreignKeySlots, out withRelationship))
                    {
                        withRelationships.Add(withRelationship);
                        source = ((IEnumerable <SlotInfo>)slotInfoArray).Concat <SlotInfo>((IEnumerable <SlotInfo>)foreignKeySlots);
                    }
                }
            }
            return((CqlBlock) new ExtentCqlBlock(rightCellQuery.Extent, rightCellQuery.SelectDistinctFlag, source.ToArray <SlotInfo>(), rightCellQuery.WhereClause, identifiers, ++blockAliasNum));
        }
コード例 #16
0
        internal static List <BoolExpression> AddConjunctionToBools(
            List <BoolExpression> bools,
            BoolExpression conjunct)
        {
            List <BoolExpression> boolExpressionList = new List <BoolExpression>();

            foreach (BoolExpression boolExpression in bools)
            {
                if (boolExpression == null)
                {
                    boolExpressionList.Add((BoolExpression)null);
                }
                else
                {
                    boolExpressionList.Add(BoolExpression.CreateAnd(boolExpression, conjunct));
                }
            }
            return(boolExpressionList);
        }
コード例 #17
0
        // requires: The CellConstantDomains in the OneOfConsts of the where
        // clause are partially done
        // effects: Given the domains of different variables in domainMap,
        // fixes the whereClause of this such that all the
        // CellConstantDomains in OneOfConsts are complete
        internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            var atoms = new List <BoolExpression>();

            foreach (var atom in WhereClause.Atoms)
            {
                var literal     = atom.AsLiteral;
                var restriction = literal as MemberRestriction;
                Debug.Assert(restriction != null, "All bool literals must be OneOfConst at this point");
                // The oneOfConst needs to be fixed with the new possible values from the domainMap.
                var possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath);
                var newOneOf       = restriction.CreateCompleteMemberRestriction(possibleValues);

                // Prevent optimization of single constraint e.g: "300 in (300)"
                // But we want to optimize type constants e.g: "category in (Category)"
                // To prevent optimization of bool expressions we add a Sentinel OneOF

                var scalarConst = restriction as ScalarRestriction;
                var addSentinel =
                    scalarConst != null &&
                    !scalarConst.Domain.Contains(Constant.Null) &&
                    !scalarConst.Domain.Contains(Constant.NotNull) &&
                    !scalarConst.Domain.Contains(Constant.Undefined);

                if (addSentinel)
                {
                    domainMap.AddSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }

                atoms.Add(BoolExpression.CreateLiteral(newOneOf, domainMap));

                if (addSentinel)
                {
                    domainMap.RemoveSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }
            }
            // We create a new whereClause that has the memberDomainMap set
            if (atoms.Count > 0)
            {
                m_whereClause = BoolExpression.CreateAnd(atoms.ToArray());
            }
        }
コード例 #18
0
        // effects: Given a list of bools, returns a list of boolean expressions where each
        // boolean in bools has been ANDed with conjunct
        // CHANGE_ADYA_IMPROVE: replace with lambda pattern
        internal static List <BoolExpression> AddConjunctionToBools(
            List <BoolExpression> bools,
            BoolExpression conjunct)
        {
            var result = new List <BoolExpression>();

            // Go through the list -- AND each non-null boolean with conjunct
            foreach (var b in bools)
            {
                if (null == b)
                {
                    // unused boolean -- leave as it is
                    result.Add(null);
                }
                else
                {
                    result.Add(CreateAnd(b, conjunct));
                }
            }
            return(result);
        }
コード例 #19
0
 // effects: Create a boolean expression of the form "NOT expression"
 internal static BoolExpression CreateNot(BoolExpression expression)
 {
     return(new BoolExpression(ExprType.Not, new[] { expression }));
 }
コード例 #20
0
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(BoolExpression.GetBoolLiteral(expression).RemapBool(this.m_remap).GetDomainBoolExpression(this.m_memberDomainMap));
 }
コード例 #21
0
 // <summary>
 // Creates WHEN condition THEN value.
 // </summary>
 internal WhenThen(BoolExpression condition, ProjectedSlot value)
 {
     m_condition = condition;
     m_value     = value;
 }
コード例 #22
0
 internal void AddWhenThen(BoolExpression condition, ProjectedSlot value)
 {
     condition.ExpensiveSimplify();
     this.m_clauses.Add(new CaseStatement.WhenThen(condition, value));
 }
コード例 #23
0
 internal override StringBuilder VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     BoolExpression.GetBoolLiteral(expression).ToCompactString(this.m_builder);
     return(this.m_builder);
 }
コード例 #24
0
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(BoolExpression.GetBoolLiteral(expression).FixRange(expression.Identifier.Range, this.m_memberDomainMap));
 }
コード例 #25
0
 internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     BoolExpression.GetBoolLiteral(expression).GetRequiredSlots(this.m_projectedSlotMap, this.m_requiredSlots);
     return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)expression);
 }
コード例 #26
0
 internal static BoolExpression CreateAndNot(BoolExpression e1, BoolExpression e2)
 {
     return(BoolExpression.CreateAnd(e1, BoolExpression.CreateNot(e2)));
 }
コード例 #27
0
 internal override T_Return VisitTerm(
     TermExpr <DomainConstraint <BoolLiteral, Constant> > expression)
 {
     return(this.BooleanLiteralAsCql(BoolExpression.GetBoolLiteral(expression), this.m_skipIsNotNull));
 }
コード例 #28
0
        private BoolExpression(ExprType opType, IEnumerable <BoolExpression> children)
        {
            List <BoolExpression> boolExpressionList = new List <BoolExpression>(children);

            foreach (BoolExpression child in children)
            {
                if (child.m_memberDomainMap != null)
                {
                    this.m_memberDomainMap = child.m_memberDomainMap;
                    break;
                }
            }
            switch (opType)
            {
            case ExprType.And:
                this.m_tree = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(BoolExpression.ToBoolExprList((IEnumerable <BoolExpression>)boolExpressionList));
                break;

            case ExprType.Not:
                this.m_tree = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new NotExpr <DomainConstraint <BoolLiteral, Constant> >(boolExpressionList[0].m_tree);
                break;

            case ExprType.Or:
                this.m_tree = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >(BoolExpression.ToBoolExprList((IEnumerable <BoolExpression>)boolExpressionList));
                break;
            }
        }