Ejemplo n.º 1
0
        // effects: Align the fields of each cell in mapping using projectedSlotMap that has a mapping
        // for each member of this extent to the slot number of that member in the projected slots
        // example:
        //    input:  Proj[A,B,"5"] = Proj[F,"7",G]
        //            Proj[C,B]     = Proj[H,I]
        //   output:  m_projectedSlotMap: A -> 0, B -> 1, C -> 2
        //            Proj[A,B,null] = Proj[F,"7",null]
        //            Proj[null,B,C] = Proj[null,I,H]
        private static List <Cell> AlignFields(
            IEnumerable <Cell> cells, MemberProjectionIndex projectedSlotMap,
            ViewTarget viewTarget)
        {
            var outputCells = new List <Cell>();

            // Determine the aligned field for each cell
            // The new cells have ProjectedSlotMap.Count number of fields
            foreach (var cell in cells)
            {
                // If isQueryView is true, we need to consider the C side of
                // the cells; otherwise, we look at the S side. Note that we
                // CANNOT use cell.LeftQuery since that is determined by
                // cell's isQueryView

                // The query for which we are constructing the extent
                var mainQuery  = cell.GetLeftQuery(viewTarget);
                var otherQuery = cell.GetRightQuery(viewTarget);

                CellQuery newMainQuery;
                CellQuery newOtherQuery;
                // Create both queries where the projected slot map is used
                // to determine the order of the fields of the mainquery (of
                // course, the otherQuery's fields are aligned automatically)
                mainQuery.CreateFieldAlignedCellQueries(
                    otherQuery, projectedSlotMap,
                    out newMainQuery, out newOtherQuery);

                var outputCell = viewTarget == ViewTarget.QueryView
                                     ? Cell.CreateCS(newMainQuery, newOtherQuery, cell.CellLabel, cell.CellNumber)
                                     : Cell.CreateCS(newOtherQuery, newMainQuery, cell.CellLabel, cell.CellNumber);
                outputCells.Add(outputCell);
            }
            return(outputCells);
        }
Ejemplo n.º 2
0
 internal MemberMaps(
     ViewTarget viewTarget,
     MemberProjectionIndex projectedSlotMap,
     MemberDomainMap queryDomainMap,
     MemberDomainMap updateDomainMap)
 {
     this.m_projectedSlotMap = projectedSlotMap;
     this.m_queryDomainMap   = queryDomainMap;
     this.m_updateDomainMap  = updateDomainMap;
     this.m_viewTarget       = viewTarget;
 }
Ejemplo n.º 3
0
 // effects: Creates a view generator object that can be used to generate views
 // based on usedCells (projectedSlotMap are useful for deciphering the fields)
 internal BasicViewGenerator(MemberProjectionIndex projectedSlotMap, List <LeftCellWrapper> usedCells, FragmentQuery activeDomain,
                             ViewgenContext context, MemberDomainMap domainMap, ErrorLog errorLog, ConfigViewGenerator config)
 {
     Debug.Assert(usedCells.Count > 0, "No used cells");
     m_projectedSlotMap = projectedSlotMap;
     m_usedCells        = usedCells;
     m_viewgenContext   = context;
     m_activeDomain     = activeDomain;
     m_errorLog         = errorLog;
     m_config           = config;
     m_domainMap        = domainMap;
 }
        internal ViewgenContext(
            ViewTarget viewTarget,
            EntitySetBase extent,
            IList <Cell> extentCells,
            CqlIdentifiers identifiers,
            ConfigViewGenerator config,
            MemberDomainMap queryDomainMap,
            MemberDomainMap updateDomainMap,
            EntityContainerMapping entityContainerMapping)
        {
            foreach (Cell extentCell in (IEnumerable <Cell>)extentCells)
            {
                ;
            }
            this.m_extent                 = extent;
            this.m_viewTarget             = viewTarget;
            this.m_config                 = config;
            this.m_edmItemCollection      = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection;
            this.m_entityContainerMapping = entityContainerMapping;
            this.m_identifiers            = identifiers;
            updateDomainMap               = updateDomainMap.MakeCopy();
            MemberDomainMap domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap;

            this.m_memberMaps = new MemberMaps(viewTarget, MemberProjectionIndex.Create(extent, this.m_edmItemCollection), queryDomainMap, updateDomainMap);
            FragmentQueryKBChaseSupport kb1 = new FragmentQueryKBChaseSupport();

            kb1.CreateVariableConstraints(extent, domainMap, this.m_edmItemCollection);
            this.m_leftFragmentQP = new FragmentQueryProcessor(kb1);
            this.m_rewritingCache = new Dictionary <FragmentQuery, Tile <FragmentQuery> >(FragmentQuery.GetEqualityComparer(this.m_leftFragmentQP));
            if (!this.CreateLeftCellWrappers(extentCells, viewTarget))
            {
                return;
            }
            FragmentQueryKBChaseSupport kb2             = new FragmentQueryKBChaseSupport();
            MemberDomainMap             memberDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap;

            foreach (LeftCellWrapper cellWrapper in this.m_cellWrappers)
            {
                EntitySetBase rightExtent = cellWrapper.RightExtent;
                kb2.CreateVariableConstraints(rightExtent, memberDomainMap, this.m_edmItemCollection);
                kb2.CreateAssociationConstraints(rightExtent, memberDomainMap, this.m_edmItemCollection);
            }
            if (this.m_viewTarget == ViewTarget.UpdateView)
            {
                this.CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper((FragmentQueryKB)kb2, memberDomainMap);
            }
            this.m_rightFragmentQP = new FragmentQueryProcessor(kb2);
            if (this.m_viewTarget == ViewTarget.QueryView)
            {
                this.CheckConcurrencyControlTokens();
            }
            this.m_cellWrappers.Sort(LeftCellWrapper.Comparer);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Given the generated <paramref name="view"/>, the <paramref name="caseStatements"/> for the multiconstant fields,
 /// the <paramref name="projectedSlotMap"/> that maps different paths of the entityset (for which the view is being generated) to slot indexes in the view,
 /// creates an object that is capable of generating the Cql for <paramref name="view"/>.
 /// </summary>
 internal CqlGenerator(CellTreeNode view,
                       Dictionary <MemberPath,
                                   CaseStatement> caseStatements,
                       CqlIdentifiers identifiers,
                       MemberProjectionIndex projectedSlotMap,
                       int numCellsInView,
                       BoolExpression topLevelWhereClause,
                       StorageMappingItemCollection mappingItemCollection)
 {
     m_view                  = view;
     m_caseStatements        = caseStatements;
     m_projectedSlotMap      = projectedSlotMap;
     m_numBools              = numCellsInView; // We have that many booleans
     m_topLevelWhereClause   = topLevelWhereClause;
     m_identifiers           = identifiers;
     m_mappingItemCollection = mappingItemCollection;
 }
        private static List <Cell> AlignFields(
            IEnumerable <Cell> cells,
            MemberProjectionIndex projectedSlotMap,
            ViewTarget viewTarget)
        {
            List <Cell> cellList = new List <Cell>();

            foreach (Cell cell1 in cells)
            {
                CellQuery newMainQuery;
                CellQuery newOtherQuery;
                cell1.GetLeftQuery(viewTarget).CreateFieldAlignedCellQueries(cell1.GetRightQuery(viewTarget), projectedSlotMap, out newMainQuery, out newOtherQuery);
                Cell cell2 = viewTarget == ViewTarget.QueryView ? Cell.CreateCS(newMainQuery, newOtherQuery, cell1.CellLabel, cell1.CellNumber) : Cell.CreateCS(newOtherQuery, newMainQuery, cell1.CellLabel, cell1.CellNumber);
                cellList.Add(cell2);
            }
            return(cellList);
        }
 internal BasicViewGenerator(
     MemberProjectionIndex projectedSlotMap,
     List <LeftCellWrapper> usedCells,
     FragmentQuery activeDomain,
     ViewgenContext context,
     MemberDomainMap domainMap,
     ErrorLog errorLog,
     ConfigViewGenerator config)
 {
     this.m_projectedSlotMap = projectedSlotMap;
     this.m_usedCells        = usedCells;
     this.m_viewgenContext   = context;
     this.m_activeDomain     = activeDomain;
     this.m_errorLog         = errorLog;
     this.m_config           = config;
     this.m_domainMap        = domainMap;
 }
Ejemplo n.º 8
0
        internal ViewgenContext(
            ViewTarget viewTarget, EntitySetBase extent, IList <Cell> extentCells,
            CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap,
            MemberDomainMap updateDomainMap, StorageEntityContainerMapping entityContainerMapping)
        {
            foreach (var cell in extentCells)
            {
                Debug.Assert(extent.Equals(cell.GetLeftQuery(viewTarget).Extent));
                Debug.Assert(cell.CQuery.NumProjectedSlots == cell.SQuery.NumProjectedSlots);
            }

            m_extent                 = extent;
            m_viewTarget             = viewTarget;
            m_config                 = config;
            m_edmItemCollection      = entityContainerMapping.StorageMappingItemCollection.EdmItemCollection;
            m_entityContainerMapping = entityContainerMapping;
            m_identifiers            = identifiers;

            // create a copy of updateDomainMap so generation of query views later on is not affected
            // it is modified in QueryRewriter.AdjustMemberDomainsForUpdateViews
            updateDomainMap = updateDomainMap.MakeCopy();

            // Create a signature generator that handles all the
            // multiconstant work and generating the signatures
            var domainMap = viewTarget == ViewTarget.QueryView ? queryDomainMap : updateDomainMap;

            m_memberMaps = new MemberMaps(
                viewTarget, MemberProjectionIndex.Create(extent, m_edmItemCollection), queryDomainMap, updateDomainMap);

            // Create left fragment KB: includes constraints for the extent to be constructed
            var leftKB = new FragmentQueryKBChaseSupport();

            leftKB.CreateVariableConstraints(extent, domainMap, m_edmItemCollection);
            m_leftFragmentQP = new FragmentQueryProcessor(leftKB);
            m_rewritingCache = new Dictionary <FragmentQuery, Tile <FragmentQuery> >(
                FragmentQuery.GetEqualityComparer(m_leftFragmentQP));

            // Now using the signatures, create new cells such that
            // "extent's" query (C or S) is described in terms of multiconstants
            if (!CreateLeftCellWrappers(extentCells, viewTarget))
            {
                return;
            }

            // Create right fragment KB: includes constraints for all extents and association roles of right queries
            var rightKB        = new FragmentQueryKBChaseSupport();
            var rightDomainMap = viewTarget == ViewTarget.QueryView ? updateDomainMap : queryDomainMap;

            foreach (var leftCellWrapper in m_cellWrappers)
            {
                var rightExtent = leftCellWrapper.RightExtent;
                rightKB.CreateVariableConstraints(rightExtent, rightDomainMap, m_edmItemCollection);
                rightKB.CreateAssociationConstraints(rightExtent, rightDomainMap, m_edmItemCollection);
            }

            if (m_viewTarget == ViewTarget.UpdateView)
            {
                CreateConstraintsForForeignKeyAssociationsAffectingThisWrapper(rightKB, rightDomainMap);
            }

            m_rightFragmentQP = new FragmentQueryProcessor(rightKB);

            // Check for concurrency control tokens
            if (m_viewTarget == ViewTarget.QueryView)
            {
                CheckConcurrencyControlTokens();
            }
            // For backward compatibility -
            // order wrappers by increasing domain size, decreasing number of attributes
            m_cellWrappers.Sort(LeftCellWrapper.Comparer);
        }