/// <summary>
 ///     Creates a scalar member restriction with the meaning "<paramref name="member" /> = <paramref name="value" />".
 ///     This constructor is used for creating discriminator type conditions.
 /// </summary>
 internal ScalarRestriction(MemberPath member, Constant value)
     : base(new MemberProjectedSlot(member), value)
 {
     Debug.Assert(
         value is ScalarConstant || value.IsNull() || value.IsNotNull(), "value is expected to be ScalarConstant, NULL, or NOT_NULL.");
 }
Beispiel #2
0
        // <summary>
        // Given the <paramref name="outputMember" /> in the output extent view, generates a constructor expression for
        // <paramref name="outputMember" />'s type, i.e, an expression of the form "Type(....)"
        // If <paramref name="outputMember" /> is an association end then instead of constructing an Entity or Complex type, constructs a reference.
        // </summary>
        private void AsCql(Action <EntitySet, IList <MemberPath> > createRef, Action <IList <MemberPath> > createType, MemberPath outputMember)
        {
            var refScopeEntitySet = outputMember.GetScopeOfRelationEnd();

            if (refScopeEntitySet != null)
            {
                // Construct a scoped reference: CreateRef(CPerson1Set, NewRow(pid1, pid2), CPerson1)
                var entityType           = refScopeEntitySet.ElementType;
                var keyMemberOutputPaths = new List <MemberPath>(entityType.KeyMembers.Select(km => new MemberPath(outputMember, km)));
                createRef(refScopeEntitySet, keyMemberOutputPaths);
            }
            else
            {
                // Construct an entity/complex/Association type in the Members order for fields: CPerson(CPerson1_Pid, CPerson1_Name)
                Debug.Assert(m_edmType is StructuralType, "m_edmType must be a structural type.");
                var memberOutputPaths = new List <MemberPath>();
                foreach (EdmMember structuralMember in Helper.GetAllStructuralMembers(m_edmType))
                {
                    memberOutputPaths.Add(new MemberPath(outputMember, structuralMember));
                }
                createType(memberOutputPaths);
            }
        }
Beispiel #3
0
 internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel)
 {
     return(m_constant.AsEsql(builder, outputMember, blockAlias));
 }
 /// <summary>
 ///     Not supported in this class.
 /// </summary>
 internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
 {
     Debug.Fail("Should not be called.");
     return(null); // To keep the compiler happy
 }
Beispiel #5
0
 // <summary>
 // Searches for <paramref name="member" /> in <paramref name="slots" /> and returns the corresponding slot. If none is found, returns null.
 // </summary>
 internal static MemberProjectedSlot GetSlotForMember(IEnumerable <ProjectedSlot> slots, MemberPath member)
 {
     foreach (MemberProjectedSlot slot in slots)
     {
         if (MemberPath.EqualityComparer.Equals(slot.MemberPath, member))
         {
             return(slot);
         }
     }
     return(null);
 }
 // <summary>
 // Given the slot and the <paramref name="blockAlias" />, generates eSQL corresponding to the slot.
 // If slot is a qualified slot, <paramref name="blockAlias" /> is ignored. Returns the modified
 // <paramref
 //     name="builder" />
 // .
 // </summary>
 // <param name="outputMember"> outputMember is non-null if this slot is not a constant slot </param>
 // <param name="indentLevel"> indicates the appropriate indentation level (method can ignore it) </param>
 internal abstract StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias, int indentLevel);
Beispiel #7
0
 internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
 {
     return(this.m_constant.AsCqt(row, outputMember));
 }
Beispiel #8
0
 // <summary>
 // Creates an incomplete type restriction of the form "<paramref name="member" /> = <paramref name="value" />".
 // </summary>
 internal TypeRestriction(MemberPath member, Constant value)
     : base(new MemberProjectedSlot(member), value)
 {
     Debug.Assert(value is TypeConstant || value.IsNull(), "Type or NULL expected.");
 }
 internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
 {
     return((DbExpression)TypeUsage.Create(Helper.GetModelTypeUsage(outputMember.LeafEdmMember).EdmType).Null());
 }
Beispiel #10
0
 internal TypeRestriction(MemberPath member, Constant value)
     : base(new MemberProjectedSlot(member), value)
 {
 }
Beispiel #11
0
 // <summary>
 // Creates an incomplete type restriction of the form "<paramref name="member" /> in <paramref name="values" />".
 // </summary>
 internal TypeRestriction(MemberPath member, IEnumerable <EdmType> values)
     : base(new MemberProjectedSlot(member), CreateTypeConstants(values))
 {
 }
Beispiel #12
0
 /// <summary>
 ///     Creates a case statement for the <paramref name="memberPath" /> with no clauses.
 /// </summary>
 internal CaseStatement(MemberPath memberPath)
 {
     m_memberPath = memberPath;
     m_clauses    = new List <WhenThen>();
 }
        private CqlBlock UnionToCqlBlock(
            bool[] requiredSlots,
            CqlIdentifiers identifiers,
            ref int blockAliasNum,
            ref List <WithRelationship> withRelationships)
        {
            List <CqlBlock> children = new List <CqlBlock>();
            List <Tuple <CqlBlock, SlotInfo> > tupleList = new List <Tuple <CqlBlock, SlotInfo> >();
            int length1 = requiredSlots.Length;

            foreach (CellTreeNode child in this.Children)
            {
                bool[] projectedSlots = child.GetProjectedSlots();
                OpCellTreeNode.AndWith(projectedSlots, requiredSlots);
                CqlBlock cqlBlock = child.ToCqlBlock(projectedSlots, identifiers, ref blockAliasNum, ref withRelationships);
                for (int length2 = projectedSlots.Length; length2 < cqlBlock.Slots.Count; ++length2)
                {
                    tupleList.Add(Tuple.Create <CqlBlock, SlotInfo>(cqlBlock, cqlBlock.Slots[length2]));
                }
                SlotInfo[] slotInfoArray = new SlotInfo[cqlBlock.Slots.Count];
                for (int slotNum = 0; slotNum < length1; ++slotNum)
                {
                    if (requiredSlots[slotNum] && !projectedSlots[slotNum])
                    {
                        if (this.IsBoolSlot(slotNum))
                        {
                            slotInfoArray[slotNum] = new SlotInfo(true, true, (ProjectedSlot) new BooleanProjectedSlot(BoolExpression.False, identifiers, this.SlotToBoolIndex(slotNum)), (MemberPath)null);
                        }
                        else
                        {
                            MemberPath outputMember = cqlBlock.MemberPath(slotNum);
                            slotInfoArray[slotNum] = new SlotInfo(true, true, (ProjectedSlot) new ConstantProjectedSlot(Constant.Null), outputMember);
                        }
                    }
                    else
                    {
                        slotInfoArray[slotNum] = cqlBlock.Slots[slotNum];
                    }
                }
                cqlBlock.Slots = new ReadOnlyCollection <SlotInfo>((IList <SlotInfo>)slotInfoArray);
                children.Add(cqlBlock);
            }
            if (tupleList.Count != 0)
            {
                foreach (CqlBlock cqlBlock in children)
                {
                    SlotInfo[] array = new SlotInfo[length1 + tupleList.Count];
                    cqlBlock.Slots.CopyTo(array, 0);
                    int index = length1;
                    foreach (Tuple <CqlBlock, SlotInfo> tuple in tupleList)
                    {
                        SlotInfo slotInfo = tuple.Item2;
                        array[index] = !tuple.Item1.Equals((object)cqlBlock) ? new SlotInfo(true, true, (ProjectedSlot) new ConstantProjectedSlot(Constant.Null), slotInfo.OutputMember) : new SlotInfo(true, true, slotInfo.SlotValue, slotInfo.OutputMember);
                        ++index;
                    }
                    cqlBlock.Slots = new ReadOnlyCollection <SlotInfo>((IList <SlotInfo>)array);
                }
            }
            SlotInfo[] slotInfos = new SlotInfo[length1 + tupleList.Count];
            CqlBlock   cqlBlock1 = children[0];

            for (int index = 0; index < length1; ++index)
            {
                SlotInfo slot         = cqlBlock1.Slots[index];
                bool     requiredSlot = requiredSlots[index];
                slotInfos[index] = new SlotInfo(requiredSlot, requiredSlot, slot.SlotValue, slot.OutputMember);
            }
            for (int index = length1; index < length1 + tupleList.Count; ++index)
            {
                SlotInfo slot = cqlBlock1.Slots[index];
                slotInfos[index] = new SlotInfo(true, true, slot.SlotValue, slot.OutputMember);
            }
            return((CqlBlock) new UnionCqlBlock(slotInfos, children, identifiers, ++blockAliasNum));
        }
Beispiel #14
0
 // <summary>
 // Creates a projected slot that references the relevant celltree node.
 // </summary>
 internal MemberProjectedSlot(MemberPath node)
 {
     m_memberPath = node;
 }
 /// <summary>
 ///     Creates a scalar member restriction with the meaning "<paramref name="member" /> in <paramref name="values" />".
 /// </summary>
 internal ScalarRestriction(MemberPath member, IEnumerable <Constant> values, IEnumerable <Constant> possibleValues)
     : base(new MemberProjectedSlot(member), values, possibleValues)
 {
 }
 internal override DbExpression AsCqt(DbExpression row, MemberPath outputMember)
 {
     throw new NotSupportedException();
 }
 // <summary>
 // Returns the alias corresponding to the slot based on the <paramref name="outputMember" />, e.g., "CPerson1_pid".
 // Derived classes may override this behavior and produce aliases that don't depend on <paramref name="outputMember" />.
 // </summary>
 internal virtual string GetCqlFieldAlias(MemberPath outputMember)
 {
     return(outputMember.CqlFieldAlias);
 }
 internal abstract StringBuilder AsEsql(
     StringBuilder builder,
     MemberPath outputMember,
     string blockAlias);
 // <summary>
 // Given the slot and the input <paramref name="row" />, generates CQT corresponding to the slot.
 // </summary>
 internal abstract DbExpression AsCqt(DbExpression row, MemberPath outputMember);
Beispiel #20
0
        // effects: Returns an error record if the keys of the extent/associationSet being mapped  are
        // present in the projected slots of this query. Returns null
        // otherwise. ownerCell indicates the cell that owns this and
        // resourceString is a resource used for error messages
        internal ErrorLog.Record VerifyKeysPresent(
            Cell ownerCell, Func <object, object, string> formatEntitySetMessage,
            Func <object, object, object, string> formatAssociationSetMessage, ViewGenErrorCode errorCode)
        {
            var prefixes = new List <MemberPath>(1);
            // Keep track of the key corresponding to each prefix
            var keys = new List <ExtentKey>(1);

            if (Extent is EntitySet)
            {
                // For entity set just get the full path of the key properties
                var prefix = new MemberPath(Extent);
                prefixes.Add(prefix);
                var entityType    = (EntityType)Extent.ElementType;
                var entitySetKeys = ExtentKey.GetKeysForEntityType(prefix, entityType);
                Debug.Assert(entitySetKeys.Count == 1, "Currently, we only support primary keys");
                keys.Add(entitySetKeys[0]);
            }
            else
            {
                var relationshipSet = (AssociationSet)Extent;
                // For association set, get the full path of the key
                // properties of each end

                foreach (var relationEnd in relationshipSet.AssociationSetEnds)
                {
                    var assocEndMember = relationEnd.CorrespondingAssociationEndMember;
                    var prefix         = new MemberPath(relationshipSet, assocEndMember);
                    prefixes.Add(prefix);
                    var endKeys = ExtentKey.GetKeysForEntityType(
                        prefix,
                        MetadataHelper.GetEntityTypeForEnd(assocEndMember));
                    Debug.Assert(endKeys.Count == 1, "Currently, we only support primary keys");
                    keys.Add(endKeys[0]);
                }
            }

            for (var i = 0; i < prefixes.Count; i++)
            {
                var prefix = prefixes[i];
                // Get all or none key slots that are being projected in this cell query
                var keySlots = MemberProjectedSlot.GetKeySlots(GetMemberProjectedSlots(), prefix);
                if (keySlots == null)
                {
                    var    key = keys[i];
                    string message;
                    if (Extent is EntitySet)
                    {
                        var keyPropertiesString = MemberPath.PropertiesToUserString(key.KeyFields, true);
                        message = formatEntitySetMessage(keyPropertiesString, Extent.Name);
                    }
                    else
                    {
                        var endName             = prefix.RootEdmMember.Name;
                        var keyPropertiesString = MemberPath.PropertiesToUserString(key.KeyFields, false);
                        message = formatAssociationSetMessage(keyPropertiesString, endName, Extent.Name);
                    }
                    var error = new ErrorLog.Record(errorCode, message, ownerCell, String.Empty);
                    return(error);
                }
            }
            return(null);
        }
 /// <summary>
 ///     Not supported in this class.
 /// </summary>
 internal override StringBuilder AsEsql(StringBuilder builder, MemberPath outputMember, string blockAlias)
 {
     Debug.Fail("Should not be called.");
     return(null); // To keep the compiler happy
 }
Beispiel #22
0
 // effects: Creates a cell query with the given projection (slots),
 // from part (joinTreeRoot) and the predicate (whereClause)
 // Used for cell creation
 internal CellQuery(List <ProjectedSlot> slots, BoolExpression whereClause, MemberPath rootMember, SelectDistinct eliminateDuplicates)
     : this(slots.ToArray(), whereClause, new List <BoolExpression>(), eliminateDuplicates, rootMember)
 {
 }
 internal StringBuilder AsEsql(
     StringBuilder builder, string blockAlias, IEnumerable <Constant> constants, MemberPath outputMember, bool skipIsNotNull)
 {
     return(ToStringHelper(builder, blockAlias, constants, outputMember, skipIsNotNull, false));
 }
Beispiel #24
0
        // <summary>
        // Given the <paramref name="prefix" />, determines the slots in <paramref name="slots" /> that correspond to the entity key for the entity set or the
        // association set end. Returns the list of slots.  Returns null if even one of the key slots is not present in slots.
        // </summary>
        // <param name="prefix"> corresponds to an entity set or an association end </param>
        internal static List <MemberProjectedSlot> GetKeySlots(IEnumerable <MemberProjectedSlot> slots, MemberPath prefix)
        {
            // Get the entity type of the hosted end or entity set
            var entitySet = prefix.EntitySet;

            Debug.Assert(entitySet != null, "Prefix must have associated entity set");

            var keys = ExtentKey.GetKeysForEntityType(prefix, entitySet.ElementType);

            Debug.Assert(keys.Count > 0, "No keys for entity?");
            Debug.Assert(keys.Count == 1, "Currently, we only support primary keys");
            // Get the slots for the key
            var keySlots = GetSlots(slots, keys[0].KeyFields);

            return(keySlots);
        }