/// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="materializer">The materializer.</param>
 /// <param name="tupleParameterBindings">The tuple parameter bindings.</param>
 /// <param name="tupleParameters">The tuple parameters.</param>
 public TranslatedQuery(ExecutableProvider dataSource, Func <IEnumerable <Tuple>, Session, Dictionary <Parameter <Tuple>, Tuple>, ParameterContext, TResult> materializer, Dictionary <Parameter <Tuple>, Tuple> tupleParameterBindings, IEnumerable <Parameter <Tuple> > tupleParameters)
     : base(dataSource)
 {
     Materializer           = materializer;
     TupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(tupleParameterBindings);
     TupleParameters        = tupleParameters.ToList();
 }
 private RecordSetReader(EnumerationContext context, ExecutableProvider provider, CancellationToken token = default)
 {
     this.context  = context;
     this.provider = provider;
     this.token    = token;
     isGreedy      = context.CheckOptions(EnumerationContextOptions.GreedyEnumerator);
 }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="handlers">The handlers.</param>
        /// <param name="request">The request.</param>
        /// <param name="descriptor">The descriptor.</param>
        /// <param name="origin">The origin.</param>
        /// <param name="source">The source.</param>
        public SqlStoreProvider(
            HandlerAccessor handlers, QueryRequest request, TemporaryTableDescriptor descriptor,
            StoreProvider origin, ExecutableProvider source)
            : base(handlers, request, descriptor, origin, new[] { source })
        {
            Initialize();
        }
Example #4
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="lifetimeToken"><see cref="StateLifetimeToken"/> to be associated with the
        /// newly created <see cref="QueryTask"/>.</param>
        /// <param name="parameterContext">The parameter value context.</param>
        public QueryTask(ExecutableProvider dataSource, StateLifetimeToken lifetimeToken, ParameterContext parameterContext)
        {
            ArgumentValidator.EnsureArgumentNotNull(dataSource, "dataSource");
            DataSource       = dataSource;
            LifetimeToken    = lifetimeToken;
            ParameterContext = parameterContext;
        }
 public EntitySetTypeState(ExecutableProvider seekProvider, MapTransform seekTransform,
                           Func <Tuple, Entity> itemCtor, Func <QueryEndpoint, long> itemCountQuery)
 {
     SeekProvider   = seekProvider;
     SeekTransform  = seekTransform;
     ItemCtor       = itemCtor;
     ItemCountQuery = itemCountQuery;
 }
        /// <summary>
        /// Creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/>
        /// execution results and bound to the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param>
        /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param>
        /// <returns><see cref="RecordSetReader"/> instance ready for enumeration.
        /// This means query is already executed but no records have been read yet.</returns>
        public static RecordSetReader Create(EnumerationContext context, ExecutableProvider provider)
        {
            var recordSet = new RecordSetReader(context, provider);
            var task      = recordSet.Prepare(false);

            task.GetAwaiter().GetResult(); // Ensure exception, if any, is being thrown
            return(recordSet);
        }
        /// <summary>
        /// Asynchronously creates a <see cref="RecordSetReader"/> instance capable to read <paramref name="provider"/>
        /// execution results and bound to the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The <see cref="EnumerationContext"/> instance associated with the query execution.</param>
        /// <param name="provider">The <see cref="ExecutableProvider"/> to be processed.</param>
        /// <param name="token">The <see cref="CancellationToken"/> allowing to cancel query execution if necessary.</param>
        /// <returns><see cref="RecordSetReader"/> instance ready for enumeration.
        /// This means query is already executed but no records have been read yet.</returns>
        public static async ValueTask <RecordSetReader> CreateAsync(
            EnumerationContext context, ExecutableProvider provider, CancellationToken token)
        {
            var recordSet = new RecordSetReader(context, provider, token);
            await recordSet.Prepare(true).ConfigureAwait(false);

            return(recordSet);
        }
Example #8
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="handlers">The handlers.</param>
        /// <param name="request">The request.</param>
        /// <param name="tableDescriptor">The table descriptor.</param>
        /// <param name="filterDataSource">The filter data source.</param>
        /// <param name="origin">The origin.</param>
        /// <param name="source">The source.</param>
        public SqlIncludeProvider(
            HandlerAccessor handlers, QueryRequest request,
            TemporaryTableDescriptor tableDescriptor, Func <IEnumerable <Tuple> > filterDataSource,
            IncludeProvider origin, ExecutableProvider source)
            : base(handlers, request, tableDescriptor, origin, new [] { source })
        {
            this.filterDataSource = filterDataSource;
            Initialize();
        }
Example #9
0
        public ExecutableProvider Process(ExecutableProvider rootProvider)
        {
            var sqlProvider = rootProvider as SqlProvider;

            if (sqlProvider != null)
            {
                SqlSelectProcessor.Process(sqlProvider.Request.Statement, providerInfo);
            }
            return(rootProvider);
        }
        public ExecutableProvider Process(ExecutableProvider rootProvider)
        {
            var provider = rootProvider;

            foreach (var item in Items)
            {
                provider = item.Process(provider);
            }
            return(provider);
        }
 /// <summary>
 /// Initializes a new instance of this class.
 /// </summary>
 /// <param name="dataSource">The data source.</param>
 /// <param name="materializer">The materializer.</param>
 /// <param name="resultAccessMethod">The value describing how it is supposed to access query result.</param>
 /// <param name="tupleParameterBindings">The tuple parameter bindings.</param>
 /// <param name="tupleParameters">The tuple parameters.</param>
 public TranslatedQuery(ExecutableProvider dataSource,
                        Materializer materializer,
                        ResultAccessMethod resultAccessMethod,
                        Dictionary <Parameter <Tuple>, Tuple> tupleParameterBindings, IEnumerable <Parameter <Tuple> > tupleParameters)
 {
     DataSource             = dataSource;
     Materializer           = materializer;
     ResultAccessMethod     = resultAccessMethod;
     TupleParameterBindings = new Dictionary <Parameter <Tuple>, Tuple>(tupleParameterBindings);
     TupleParameters        = tupleParameters.ToList();
 }
        public ExecutableProvider Process(ExecutableProvider rootProvider)
        {
            var sqlProvider = rootProvider as SqlProvider;

            if (sqlProvider == null)
            {
                return(rootProvider);
            }
            var request = sqlProvider.Request;

            // Nessesary part - prepare request for execution.
            request.Prepare();
            // Optional part - remove all underlying providers to save memory.
            return(request.CheckOptions(QueryRequestOptions.AllowOptimization)
        ? new SqlProvider(handlers, request, sqlProvider.Origin.MakeVoid(), new ExecutableProvider[0])
        : rootProvider);
        }
        /// <summary>
        /// Gets the references to specified entity.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="association">The association.</param>
        /// <returns>References.</returns>
        public virtual IEnumerable <ReferenceInfo> GetReferencesTo(Entity target, AssociationInfo association)
        {
            if (association.IsPaired)
            {
                return(FindReferences(target, association, true));
            }
            object key = new Pair <object, AssociationInfo>(CachingRegion, association);
            Func <object, object> generator = p => BuildReferencingQuery(((Pair <object, AssociationInfo>)p).Second);
            var pair             = (Pair <CompilableProvider, Parameter <Tuple> >)Session.StorageNode.InternalQueryCache.GetOrAdd(key, generator);
            var recordSet        = pair.First;
            var parameter        = pair.Second;
            var parameterContext = new ParameterContext();

            parameterContext.SetValue(parameter, target.Key.Value);
            ExecutableProvider executableProvider = Session.Compile(recordSet);

            var queryTask = new QueryTask(executableProvider, Session.GetLifetimeToken(), parameterContext);

            Session.RegisterInternalDelayedQuery(queryTask);

            return(GetReferencesToInternal(association, target, recordSet.Header, queryTask));
        }
Example #14
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="dataSource">The <see cref="DataSource"/> property value.</param>
        protected TranslatedQuery(ExecutableProvider dataSource)
        {
            DataSource = dataSource;
        }
Example #15
0
        // Constructors

        public RecordSet(EnumerationContext context, ExecutableProvider source)
        {
            Context = context;
            Source  = source;
        }
        // Constructors

        /// <summary>
        ///	Initializes a new instance of this class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="materializer">The materializer.</param>
        public TranslatedQuery(ExecutableProvider dataSource, Func <IEnumerable <Tuple>, Session, Dictionary <Parameter <Tuple>, Tuple>, ParameterContext, TResult> materializer)
            : this(dataSource, materializer, new Dictionary <Parameter <Tuple>, Tuple>(), EnumerableUtils <Parameter <Tuple> > .Empty)
        {
        }
 /// <summary>
 /// Gets <see cref="RecordSet"/> bound to the specified <paramref name="provider"/>.
 /// </summary>
 /// <param name="provider">Provider to get <see cref="RecordSet"/> for.</param>
 /// <param name="session">Session to bind.</param>
 /// <returns>New <see cref="RecordSet"/> bound to specified <paramref name="session"/>.</returns>
 public static RecordSet GetRecordSet(this ExecutableProvider provider, Session session)
 {
     ArgumentValidator.EnsureArgumentNotNull(provider, "provider");
     ArgumentValidator.EnsureArgumentNotNull(session, "session");
     return(new RecordSet(session.CreateEnumerationContext(), provider));
 }
 public ExecutableProvider Process(ExecutableProvider rootProvider)
 {
     return(rootProvider);
 }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="materializer">The materializer.</param>
        /// <param name="resultAccessMethod">The value describing how it is supposed to access query result.</param>
        public TranslatedQuery(ExecutableProvider dataSource, Materializer materializer, ResultAccessMethod resultAccessMethod)
            : this(dataSource, materializer, resultAccessMethod, new Dictionary <Parameter <Tuple>, Tuple>(), Enumerable.Empty <Parameter <Tuple> >())
        {
        }
 /// <summary>
 /// Asynchrously gets <see cref="RecordSet"/> bound to the specified <paramref name="provider"/>.
 /// </summary>
 /// <param name="provider">Provider to get <see cref="RecordSet"/> for.</param>
 /// <param name="session">Session to bind.</param>
 /// <param name="token">Token to cancel operation.</param>
 /// <returns>Task performing this operation.</returns>
 public static async Task <RecordSet> GetRecordSetForAsyncQuery(this ExecutableProvider provider, Session session, CancellationToken token)
 {
     ArgumentValidator.EnsureArgumentNotNull(provider, "provider");
     ArgumentValidator.EnsureArgumentNotNull(session, "session");
     return(new RecordSet(await session.CreateEnumerationContextForAsyncQuery(token).ConfigureAwait(false), provider));
 }