Example #1
0
        private QueryRewriter GenerateDirectionalViewsForExtent(
            ViewTarget viewTarget,
            EntitySetBase extent,
            CqlIdentifiers identifiers,
            KeyToListMap <EntitySetBase, GeneratedView> views)
        {
            ViewgenContext viewgenContext = this.CreateViewgenContext(extent, viewTarget, identifiers);
            QueryRewriter  queryRewriter  = (QueryRewriter)null;

            if (this.m_config.GenerateViewsForEachType)
            {
                foreach (EdmType generatedType in MetadataHelper.GetTypeAndSubtypesOf((EdmType)extent.ElementType, (ItemCollection)this.m_entityContainerMapping.StorageMappingItemCollection.EdmItemCollection, false))
                {
                    if (this.m_config.IsViewTracing && !generatedType.Equals((object)extent.ElementType))
                    {
                        Helpers.FormatTraceLine("CQL View for {0} and type {1}", (object)extent.Name, (object)generatedType.Name);
                    }
                    queryRewriter = this.GenerateViewsForExtentAndType(generatedType, viewgenContext, identifiers, views, ViewGenMode.OfTypeViews);
                }
            }
            else
            {
                queryRewriter = this.GenerateViewsForExtentAndType((EdmType)extent.ElementType, viewgenContext, identifiers, views, ViewGenMode.OfTypeViews);
            }
            if (viewTarget == ViewTarget.QueryView)
            {
                this.m_config.SetTimeForFinishedActivity(PerfType.QueryViews);
            }
            else
            {
                this.m_config.SetTimeForFinishedActivity(PerfType.UpdateViews);
            }
            this.m_queryRewriterCache[extent] = queryRewriter;
            return(queryRewriter);
        }
Example #2
0
        private ErrorLog GenerateQueryViewForExtentAndType(
            CqlIdentifiers identifiers,
            KeyToListMap <EntitySetBase, GeneratedView> views,
            EntitySetBase entity,
            EntityTypeBase type,
            ViewGenMode mode)
        {
            ErrorLog errorLog = new ErrorLog();

            if (this.m_config.IsViewTracing)
            {
                Helpers.StringTraceLine(string.Empty);
                Helpers.StringTraceLine(string.Empty);
                Helpers.FormatTraceLine("================= Generating {0} Query View for: {1} ===========================", mode == ViewGenMode.OfTypeViews ? (object)"OfType" : (object)"OfTypeOnly", (object)entity.Name);
                Helpers.StringTraceLine(string.Empty);
                Helpers.StringTraceLine(string.Empty);
            }
            try
            {
                ViewgenContext viewgenContext = this.CreateViewgenContext(entity, ViewTarget.QueryView, identifiers);
                this.GenerateViewsForExtentAndType((EdmType)type, viewgenContext, identifiers, views, mode);
            }
            catch (InternalMappingException ex)
            {
                errorLog.Merge(ex.ErrorLog);
            }
            return(errorLog);
        }
Example #3
0
        private QueryRewriter GenerateViewsForExtentAndType(
            EdmType generatedType, ViewgenContext context, CqlIdentifiers identifiers, ViewSet views, ViewGenMode mode)
        {
            Debug.Assert(mode != ViewGenMode.GenerateAllViews, "By definition this method can not handle generating views for all extents");

            var queryRewriter = new QueryRewriter(generatedType, context, mode);

            queryRewriter.GenerateViewComponents();

            // Get the basic view
            var basicView = queryRewriter.BasicView;

            if (m_config.IsNormalTracing)
            {
                Helpers.StringTrace("Basic View: ");
                Helpers.StringTraceLine(basicView.ToString());
            }

            var simplifiedView = GenerateSimplifiedView(basicView, queryRewriter.UsedCells);

            if (m_config.IsNormalTracing)
            {
                Helpers.StringTraceLine(String.Empty);
                Helpers.StringTrace("Simplified View: ");
                Helpers.StringTraceLine(simplifiedView.ToString());
            }

            var cqlGen = new CqlGenerator(
                simplifiedView,
                queryRewriter.CaseStatements,
                identifiers,
                context.MemberMaps.ProjectedSlotMap,
                queryRewriter.UsedCells.Count,
                queryRewriter.TopLevelWhereClause,
                m_entityContainerMapping.StorageMappingItemCollection);

            string             eSQLView;
            DbQueryCommandTree commandTree;

            if (m_config.GenerateEsql)
            {
                eSQLView    = cqlGen.GenerateEsql();
                commandTree = null;
            }
            else
            {
                eSQLView    = null;
                commandTree = cqlGen.GenerateCqt();
            }

            var generatedView = GeneratedView.CreateGeneratedView(
                context.Extent, generatedType, commandTree, eSQLView, m_entityContainerMapping.StorageMappingItemCollection, m_config);

            views.Add(context.Extent, generatedView);

            return(queryRewriter);
        }
Example #4
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;
 }
 // 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 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;
 }
Example #7
0
        private QueryRewriter GenerateViewsForExtentAndType(
            EdmType generatedType,
            ViewgenContext context,
            CqlIdentifiers identifiers,
            KeyToListMap <EntitySetBase, GeneratedView> views,
            ViewGenMode mode)
        {
            QueryRewriter queryRewriter = new QueryRewriter(generatedType, context, mode);

            queryRewriter.GenerateViewComponents();
            CellTreeNode basicView = queryRewriter.BasicView;

            if (this.m_config.IsNormalTracing)
            {
                Helpers.StringTrace("Basic View: ");
                Helpers.StringTraceLine(basicView.ToString());
            }
            CellTreeNode simplifiedView = ViewGenerator.GenerateSimplifiedView(basicView, queryRewriter.UsedCells);

            if (this.m_config.IsNormalTracing)
            {
                Helpers.StringTraceLine(string.Empty);
                Helpers.StringTrace("Simplified View: ");
                Helpers.StringTraceLine(simplifiedView.ToString());
            }
            CqlGenerator       cqlGenerator = new CqlGenerator(simplifiedView, queryRewriter.CaseStatements, identifiers, context.MemberMaps.ProjectedSlotMap, queryRewriter.UsedCells.Count, queryRewriter.TopLevelWhereClause, this.m_entityContainerMapping.StorageMappingItemCollection);
            string             eSQL;
            DbQueryCommandTree commandTree;

            if (this.m_config.GenerateEsql)
            {
                eSQL        = cqlGenerator.GenerateEsql();
                commandTree = (DbQueryCommandTree)null;
            }
            else
            {
                eSQL        = (string)null;
                commandTree = cqlGenerator.GenerateCqt();
            }
            GeneratedView generatedView = GeneratedView.CreateGeneratedView(context.Extent, generatedType, commandTree, eSQL, this.m_entityContainerMapping.StorageMappingItemCollection, this.m_config);

            views.Add(context.Extent, generatedView);
            return(queryRewriter);
        }
        private bool CreateLeftCellWrappers(IList <Cell> extentCells, ViewTarget viewTarget)
        {
            List <Cell> cellList = ViewgenContext.AlignFields((IEnumerable <Cell>)extentCells, this.m_memberMaps.ProjectedSlotMap, viewTarget);

            this.m_cellWrappers = new List <LeftCellWrapper>();
            for (int index = 0; index < cellList.Count; ++index)
            {
                Cell             cell          = cellList[index];
                CellQuery        leftQuery     = cell.GetLeftQuery(viewTarget);
                CellQuery        rightQuery    = cell.GetRightQuery(viewTarget);
                Set <MemberPath> nonNullSlots  = leftQuery.GetNonNullSlots();
                FragmentQuery    fragmentQuery = FragmentQuery.Create(BoolExpression.CreateLiteral((BoolLiteral) new CellIdBoolean(this.m_identifiers, extentCells[index].CellNumber), this.m_memberMaps.LeftDomainMap), leftQuery);
                if (viewTarget == ViewTarget.UpdateView)
                {
                    fragmentQuery = this.m_leftFragmentQP.CreateDerivedViewBySelectingConstantAttributes(fragmentQuery) ?? fragmentQuery;
                }
                this.m_cellWrappers.Add(new LeftCellWrapper(this.m_viewTarget, nonNullSlots, fragmentQuery, leftQuery, rightQuery, this.m_memberMaps, extentCells[index]));
            }
            return(true);
        }
Example #9
0
        private QueryRewriter GenerateViewsForExtentAndType(
            EdmType generatedType, ViewgenContext context, CqlIdentifiers identifiers, ViewSet views, ViewGenMode mode)
        {
            Debug.Assert(mode != ViewGenMode.GenerateAllViews, "By definition this method can not handle generating views for all extents");

            var queryRewriter = new QueryRewriter(generatedType, context, mode);
            queryRewriter.GenerateViewComponents();

            // Get the basic view
            var basicView = queryRewriter.BasicView;

            if (m_config.IsNormalTracing)
            {
                Helpers.StringTrace("Basic View: ");
                Helpers.StringTraceLine(basicView.ToString());
            }

            var simplifiedView = GenerateSimplifiedView(basicView, queryRewriter.UsedCells);

            if (m_config.IsNormalTracing)
            {
                Helpers.StringTraceLine(String.Empty);
                Helpers.StringTrace("Simplified View: ");
                Helpers.StringTraceLine(simplifiedView.ToString());
            }

            var cqlGen = new CqlGenerator(
                simplifiedView,
                queryRewriter.CaseStatements,
                identifiers,
                context.MemberMaps.ProjectedSlotMap,
                queryRewriter.UsedCells.Count,
                queryRewriter.TopLevelWhereClause,
                m_entityContainerMapping.StorageMappingItemCollection);

            string eSQLView;
            DbQueryCommandTree commandTree;
            if (m_config.GenerateEsql)
            {
                eSQLView = cqlGen.GenerateEsql();
                commandTree = null;
            }
            else
            {
                eSQLView = null;
                commandTree = cqlGen.GenerateCqt();
            }

            var generatedView = GeneratedView.CreateGeneratedView(
                context.Extent, generatedType, commandTree, eSQLView, m_entityContainerMapping.StorageMappingItemCollection, m_config);
            views.Add(context.Extent, generatedView);

            return queryRewriter;
        }
Example #10
0
 private CellTreeSimplifier(ViewgenContext context)
 {
     m_viewgenContext = context;
 }
 private CellTreeSimplifier(ViewgenContext context)
 {
     m_viewgenContext = context;
 }