示例#1
0
        private string BuildSql(CohortQueryBuilderDependency dependency, ParameterManager parameterManager)
        {
            //if we are fully cached on everything
            if (dependency.SqlFullyCached != null)
            {
                SetTargetServer(GetCacheServer(), " dependency is cached"); //run on the cache server
                CountOfCachedSubQueries++;                                  //it is cached
                return(dependency.SqlFullyCached.Use(parameterManager));    //run the fully cached sql
            }

            switch (CacheUsageDecision)
            {
            case CacheUsage.MustUse:
                throw new QueryBuildingException("Could not build final SQL because " + dependency + " is not fully cached and CacheUsageDecision is " + CacheUsageDecision);

            case CacheUsage.Opportunistic:

                //The cache and dataset are on the same server so run it
                SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "data and cache are on the same server");
                return(dependency.SqlPartiallyCached?.Use(parameterManager) ?? dependency.SqlCacheless.Use(parameterManager));

            case CacheUsage.AllOrNothing:

                //It's not fully cached so we have to run it entirely uncached
                SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "cache and data are on seperate servers / access credentials and not all datasets are in the cache");
                return(dependency.SqlCacheless.Use(parameterManager));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#2
0
        private string BuildSql(CohortAggregateContainer container, ParameterManager parameterManager)
        {
            Dictionary <CohortQueryBuilderDependency, string> sqlDictionary;

            //if we are fully cached on everything
            if (Dependencies.All(d => d.SqlFullyCached != null))
            {
                SetTargetServer(GetCacheServer(), "all dependencies are fully cached"); //run on the cache server

                //all are cached
                CountOfCachedSubQueries = CountOfSubQueries;

                sqlDictionary = Dependencies.ToDictionary(k => k, v => v.SqlFullyCached.Use(parameterManager)); //run the fully cached sql
            }
            else
            {
                string uncached = "CacheUsageDecision is " + CacheUsageDecision +
                                  " and the following were not cached:" + string.Join(Environment.NewLine,
                                                                                      Dependencies.Where(d => d.SqlFullyCached == null));

                switch (CacheUsageDecision)
                {
                case CacheUsage.MustUse:
                    throw new QueryBuildingException(
                              "Could not build final SQL because some queries are not fully cached and " + uncached);

                case CacheUsage.Opportunistic:

                    //The cache and dataset are on the same server so run it
                    SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "not all dependencies are cached while " + uncached);

                    CountOfCachedSubQueries = Dependencies.Count(d => d.SqlFullyCached != null);

                    sqlDictionary =
                        Dependencies.ToDictionary(k => k,
                                                  v => v.SqlFullyCached?.Use(parameterManager) ??
                                                  v.SqlPartiallyCached?.Use(parameterManager) ??
                                                  v.SqlCacheless.Use(parameterManager)); //run the fully cached sql
                    break;

                case CacheUsage.AllOrNothing:

                    //It's not fully cached so we have to run it entirely uncached
                    SetTargetServer(DependenciesSingleServer.GetDistinctServer(), "not all dependencies are cached while " + uncached);

                    //cannot use any of the caches because it's all or nothing
                    CountOfCachedSubQueries = 0;
                    sqlDictionary           =
                        Dependencies.ToDictionary(k => k, v => v.SqlCacheless.Use(parameterManager));     //run the fully uncached sql
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            return(WriteContainers(container, TargetServer.GetQuerySyntaxHelper(), sqlDictionary, 0));
        }