示例#1
0
 private void DisposeCachedPlan(ServerProcess process, ServerPlan plan)
 {
     try
     {
         plan.BindToProcess(process.ServerSession.Server._systemProcess);
         plan.Dispose();
     }
     catch
     {
         // ignore disposal exceptions
     }
 }
示例#2
0
        /// <summary>Gets a cached plan for the given statement, if available.</summary>
        /// <remarks>
        /// If a plan is found, it is referenced for the LRU, and disowned by the cache.
        /// The client must call Release to return the plan to the cache.
        /// If no plan is found, null is returned and the cache is unaffected.
        /// </remarks>
        public ServerPlan Get(ServerProcess process, string statement, int contextHashCode)
        {
            ServerPlan       plan   = null;
            CachedPlanHeader header = GetPlanHeader(process, statement, contextHashCode);
            CachedPlans      bumped = null;

            lock (this)
            {
                if (_plans != null)
                {
                    CachedPlans plans;
                    if (_plans.TryGetValue(header, out plans))
                    {
                        for (int planIndex = plans.Count - 1; planIndex >= 0; planIndex--)
                        {
                            plan = plans[planIndex];
                            plans.RemoveAt(planIndex);
                            if (process.Catalog.PlanCacheTimeStamp > plan.PlanCacheTimeStamp)
                            {
                                DisposeCachedPlan(process, plan);
                                plan = null;
                            }
                            else
                            {
                                bumped = _plans.Reference(header, plans);
                                break;
                            }
                        }
                    }
                }
            }

            if (bumped != null)
            {
                DisposeCachedPlans(process, bumped);
            }

            if (plan != null)
            {
                plan.BindToProcess(process);
            }

            return(plan);
        }