public static void RestoreAllContextOnThreadIfExists()
        {
            if (!IsExistContextStackOnThread())
            {
                return;
            }
            Stack <ContextStack> stackOnThread = GetContextStackOnThread();

            if (stackOnThread.Count == 0)
            {
                ClearContextStackOnThread();
                return;
            }
            ContextStack  contextStack = stackOnThread.Pop();
            ConditionBean cb           = contextStack.ConditionBean;

            if (cb != null)
            {
                ConditionBeanContext.SetConditionBeanOnThread(cb);
            }
            OutsideSqlContext outsideSqlContext = contextStack.OutsideSqlContext;

            if (outsideSqlContext != null)
            {
                OutsideSqlContext.SetOutsideSqlContextOnThread(outsideSqlContext);
            }
            FetchNarrowingBean fetchNarrowingBean = contextStack.FetchNarrowingBean;

            if (fetchNarrowingBean != null)
            {
                FetchNarrowingBeanContext.SetFetchNarrowingBeanOnThread(fetchNarrowingBean);
            }
            IDictionary <String, Object> internalMap = contextStack.InternalMap;

            if (internalMap != null)
            {
                InternalMapContext.ClearInternalMapOnThread();
                foreach (String key in internalMap.Keys)
                {
                    Object value = internalMap[key];
                    InternalMapContext.SetObject(key, value);
                }
            }
        }
 public static void ClearAllCurrentContext()
 {
     if (ConditionBeanContext.IsExistConditionBeanOnThread())
     {
         ConditionBeanContext.ClearConditionBeanOnThread();
     }
     if (OutsideSqlContext.IsExistOutsideSqlContextOnThread())
     {
         OutsideSqlContext.ClearOutsideSqlContextOnThread();
     }
     if (FetchNarrowingBeanContext.IsExistFetchNarrowingBeanOnThread())
     {
         FetchNarrowingBeanContext.ClearFetchNarrowingBeanOnThread();
     }
     if (InternalMapContext.IsExistInternalMapOnThread())
     {
         InternalMapContext.ClearInternalMapOnThread();
     }
 }