Exemplo n.º 1
0
        /// <summary>
        /// Prepares the statement if the <see cref="IQueryRequest"/> is not ad-hoc and caches it for reuse.asynchronously.
        /// </summary>
        /// <param name="originalRequest">The original query request.</param>
        async Task PrepareStatementIfNotAdHocAsync(IQueryRequest originalRequest)
        {
            if (originalRequest.IsAdHoc)
            {
                return;
            }

            var statement = originalRequest.GetStatement();

            if (statement == null)
            {
                statement = originalRequest.GetPreparedPayload().Text;
            }
            QueryPlan queryPlan;

            if (_queryCache.TryGetValue(statement, out queryPlan))
            {
                originalRequest.Prepared(queryPlan);
            }
            else
            {
                var result = await PrepareAsync(originalRequest);

                if (!result.Success)
                {
                    return;                  //FIXME propagate the error somehow
                }
                queryPlan      = result.Rows.First();
                queryPlan.Text = originalRequest.GetStatement();
                if (_queryCache.TryAdd(statement, queryPlan))
                {
                    originalRequest.Prepared(queryPlan);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepares the statement if the <see cref="IQueryRequest"/> is not ad-hoc and caches it for reuse.
        /// </summary>
        /// <param name="originalRequest">The original query request.</param>
        void PrepareStatementIfNotAdHoc(IQueryRequest originalRequest)
        {
            if (originalRequest.IsAdHoc)
            {
                return;
            }

            var statement = originalRequest.GetStatement();

            if (statement == null)
            {
                statement = originalRequest.GetPreparedPayload().Text;
            }
            QueryPlan queryPlan;

            if (_queryCache.TryGetValue(statement, out queryPlan))
            {
                originalRequest.Prepared(queryPlan);
            }
            else
            {
                var result = Prepare(originalRequest);
                //FIXME throw an exception?
                if (!result.Success)
                {
                    return;
                }
                queryPlan      = result.Rows.First();
                queryPlan.Text = originalRequest.GetStatement(); //the plan Text will be used if we reprepare it
                if (_queryCache.TryAdd(statement, queryPlan))
                {
                    originalRequest.Prepared(queryPlan);
                }
            }
        }