private static ProjectionExpression PrepareCachedQuery(
     ProjectionExpression origin, CompiledQueryProcessingScope compiledQueryScope)
 {
     if (compiledQueryScope.QueryParameter != null)
     {
         var result = compiledQueryScope.QueryParameterReplacer.Replace(origin);
         return((ProjectionExpression)result);
     }
     return(origin);
 }
Пример #2
0
        private QueryTask CreateQueryTask()
        {
            var parameterContext = new ParameterContext();

            parameterContext.SetValue(ownerParameter, ownerKey.Value);
            if (ItemCountLimit != null)
            {
                parameterContext.SetValue(itemCountLimitParameter, ItemCountLimit.Value);
            }

            object key = new Pair <object, CacheKey>(itemsQueryCachingRegion, cacheKey);
            Func <object, object> generator = CreateRecordSetLoadingItems;
            var session = manager.Owner.Session;
            var scope   = new CompiledQueryProcessingScope(null, null, parameterContext, false);

            QueryProvider = (CompilableProvider)session.StorageNode.InternalQueryCache.GetOrAdd(key, generator);
            ExecutableProvider executableProvider;

            using (scope.Enter()) {
                executableProvider = session.Compile(QueryProvider);
            }
            return(new QueryTask(executableProvider, session.GetLifetimeToken(), parameterContext));
        }
Пример #3
0
        // Constructors

        public TranslatorContext(Session session, CompilerConfiguration rseCompilerConfiguration, Expression query,
                                 CompiledQueryProcessingScope compiledQueryScope)
        {
            ArgumentValidator.EnsureArgumentNotNull(session, nameof(session));
            ArgumentValidator.EnsureArgumentNotNull(rseCompilerConfiguration, nameof(rseCompilerConfiguration));
            ArgumentValidator.EnsureArgumentNotNull(query, nameof(query));

            Domain = session.Domain;
            RseCompilerConfiguration = rseCompilerConfiguration;

            // Applying query preprocessors
            query = Domain.Handler.QueryPreprocessors
                    .Aggregate(query, (current, preprocessor) => ApplyPreprocessor(preprocessor, session, current));

            // Built-in preprocessors
            query     = AggregateOptimizer.Rewrite(query);
            query     = ClosureAccessRewriter.Rewrite(query, compiledQueryScope);
            query     = EqualityRewriter.Rewrite(query);
            query     = EntitySetAccessRewriter.Rewrite(query);
            query     = SubqueryDefaultResultRewriter.Rewrite(query);
            Evaluator = new ExpressionEvaluator(query);
            query     = PersistentIndexerRewriter.Rewrite(query, this);
            Query     = query;

            resultAliasGenerator   = AliasGenerator.Create("#{0}{1}");
            columnAliasGenerator   = AliasGenerator.Create(new[] { "c01umn" });
            CustomCompilerProvider = Domain.Handler.GetMemberCompilerProvider <Expression>();
            Model               = Domain.Model;
            TypeIdRegistry      = session.StorageNode.TypeIdRegistry;
            ProviderInfo        = Domain.Handlers.ProviderInfo;
            Translator          = new Translator(this, compiledQueryScope);
            ParameterExtractor  = new ParameterExtractor(Evaluator);
            Bindings            = new LinqBindingCollection();
            applyParameters     = new Dictionary <CompilableProvider, ApplyParameter>();
            tupleParameters     = new Dictionary <ParameterExpression, Parameter <Tuple> >();
            boundItemProjectors = new Dictionary <ParameterExpression, ItemProjectorExpression>();
        }
        // Constructors

        private ClosureAccessRewriter(CompiledQueryProcessingScope compiledQueryScope)
        {
            this.compiledQueryScope = compiledQueryScope;
        }
 public static Expression Rewrite(Expression e, CompiledQueryProcessingScope compiledQueryScope) =>
 new ClosureAccessRewriter(compiledQueryScope).Visit(e);
        // Constructors

        /// <exception cref="InvalidOperationException">There is no current <see cref="Session"/>.</exception>
        internal Translator(TranslatorContext context, CompiledQueryProcessingScope compiledQueryScope)
        {
            this.compiledQueryScope = compiledQueryScope;
            this.context            = context;
            state = new TranslatorState(this);
        }