protected String ExtractBehaviorInvokeName() { Object behaviorInvokeName = InternalMapContext.GetObject("df:BehaviorInvokeName"); if (behaviorInvokeName == null) { return(null); } Object clientInvokeName = InternalMapContext.GetObject("df:ClientInvokeName"); Object byPassInvokeName = InternalMapContext.GetObject("df:ByPassInvokeName"); StringBuilder sb = new StringBuilder(); bool existsPath = false; if (clientInvokeName != null) { existsPath = true; sb.Append(clientInvokeName); } if (byPassInvokeName != null) { existsPath = true; sb.Append(byPassInvokeName); } sb.Append(behaviorInvokeName); if (existsPath) { sb.Append("..."); } return(sb.ToString()); }
public static void SaveAllContextOnThread() { if (!IsExistContextStackOnThread()) { Thread.SetData(_slot, new Stack <ContextStack>()); } ContextStack contextStack = new ContextStack(); if (ConditionBeanContext.IsExistConditionBeanOnThread()) { contextStack.ConditionBean = ConditionBeanContext.GetConditionBeanOnThread(); } if (OutsideSqlContext.IsExistOutsideSqlContextOnThread()) { contextStack.OutsideSqlContext = OutsideSqlContext.GetOutsideSqlContextOnThread(); } if (FetchNarrowingBeanContext.IsExistFetchNarrowingBeanOnThread()) { contextStack.FetchNarrowingBean = FetchNarrowingBeanContext.GetFetchNarrowingBeanOnThread(); } if (InternalMapContext.IsExistInternalMapOnThread()) { contextStack.InternalMap = InternalMapContext.GetInternalMap(); } GetContextStackOnThread().Push(contextStack); }
// =============================================================================== // Context Helper // ============== protected void InitializeContext() { if (ConditionBeanContext.IsExistConditionBeanOnThread() || OutsideSqlContext.IsExistOutsideSqlContextOnThread() || FetchNarrowingBeanContext.IsExistFetchNarrowingBeanOnThread() || InternalMapContext.IsExistInternalMapOnThread()) // means recursive invoking { SaveAllContextOnThread(); } ClearAllCurrentContext(); }
protected static DBMeta FindCachedDBMeta(Type rowType) { System.Collections.Generic.IDictionary <Type, DBMeta> dbmetaCache = FindDBMetaCache(); if (dbmetaCache == null) { dbmetaCache = new System.Collections.Generic.Dictionary <Type, DBMeta>(); InternalMapContext.SetObject(DBMETA_CACHE_KEY, dbmetaCache); } if (dbmetaCache.ContainsKey(rowType)) { return(dbmetaCache[rowType]); } return(null); }
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(); } }
protected virtual object DispatchInvoking(IMethodInvocation invocation) { MethodBase method = invocation.Method; if (!method.IsAbstract) { return(invocation.Proceed()); } bool logEnabled = IsLogEnabled(); // - - - - - - - - - - - - - // Initialize DAO meta data // - - - - - - - - - - - - - if (method.Name.Equals("InitializeDaoMetaData")) { InitializeSqlCommand(invocation); return(null); // The end! (Initilization Only) } // - - - - - - - - - - - // Preprocess outsideSql // - - - - - - - - - - - PreprocessOutsideSql(invocation); // - - - - - - - - - - - - - // Preprocess conditionBean // - - - - - - - - - - - - - ConditionBean cb = PreprocessConditionBean(invocation); // - - - - - - - - - // Set up sqlCommand // - - - - - - - - - ISqlCommand cmd = null; try { DateTime?beforeCmd = null; if (logEnabled) { beforeCmd = DateTime.Now; } cmd = FindSqlCommand(invocation); if (logEnabled) { DateTime afterCmd = DateTime.Now; if (!afterCmd.Equals(beforeCmd.Value)) { LogSqlCommand(invocation, cmd, beforeCmd.Value, afterCmd); } } } finally { if (IsLogEnabled()) { LogInvocation(invocation); } } SqlResultHandler sqlResultHandler = GetSqlResultHander(); bool existsSqlResultHandler = sqlResultHandler != null; DateTime? before = null; if (logEnabled || existsSqlResultHandler) { before = DateTime.Now; // for performance view } // - - - - - - - - - - // Execute sqlCommand! // - - - - - - - - - - object ret = null; try { ret = cmd.Execute(invocation.Arguments); } catch (Exception e) { if (e.GetType().Equals(typeof(NotSingleRowUpdatedRuntimeException))) { throw new EntityAlreadyUpdatedException((NotSingleRowUpdatedRuntimeException)e); } throw; } finally { PostprocessConditionBean(invocation, cb); } // - - - - - - - - - - // Convert and Return! // - - - - - - - - - - Type retType = ((MethodInfo)method).ReturnType; ret = Seasar.Framework.Util.ConversionUtil.ConvertTargetType(ret, retType); if (logEnabled || existsSqlResultHandler) { DateTime after = DateTime.Now; // for performance view if (logEnabled) { LogReturn(invocation, retType, ret, before.Value, after); } if (existsSqlResultHandler) { SqlResultInfo info = new SqlResultInfo(); info.Result = ret; info.CommandName = method.Name; info.DisplaySql = (String)InternalMapContext.GetObject("df:DisplaySql"); info.BeforeDateTime = before.Value; info.AfterDateTime = after; sqlResultHandler.Invoke(info); } } return(ret); }
protected void PutObjectToMapContext(String key, Object value) { InternalMapContext.SetObject(key, value); }
protected static System.Collections.Generic.IDictionary <Type, DBMeta> FindDBMetaCache() { return((System.Collections.Generic.IDictionary <Type, DBMeta>)InternalMapContext.GetObject(DBMETA_CACHE_KEY)); }