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); }
protected bool IsSelectedForeignInfoEmpty() { if (!HasConditionBean()) { return(true); } ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.isSelectedForeignInfoEmpty()); }
// =================================================================================== // Select Index // ============ protected Map <String, int?> GetSelectIndexMap() // ResourceContext in Java { if (!HasConditionBean()) { return(null); } ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.getSelectIndexMap()); }
protected Map <String, String> GetSelectIndexReverseMap() // ResourceContext in Java { if (!ConditionBeanContext.IsExistConditionBeanOnThread()) { return(null); } ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.getSelectIndexReverseMap()); }
protected bool HasSelectedForeignInfo(RelationRowCreationResource res) { ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); if (cb.SqlClause.hasSelectedForeignInfo(res.RelationNoSuffix)) { return(true); } return(false); }
protected Map <String, int?> GetSelectIndexMap() // RelationRowCreationResource in Java { if (!ConditionBeanContext.IsExistConditionBeanOnThread()) { return(null); } ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.getSelectIndexMap()); }
// =============================================================================== // Context Helper // ============== protected void InitializeContext() { if (ConditionBeanContext.IsExistConditionBeanOnThread() || OutsideSqlContext.IsExistOutsideSqlContextOnThread() || FetchNarrowingBeanContext.IsExistFetchNarrowingBeanOnThread() || InternalMapContext.IsExistInternalMapOnThread()) // means recursive invoking { SaveAllContextOnThread(); } ClearAllCurrentContext(); }
protected void AssertAutoQueryByDtoUnsupported(MethodInfo methodInfo, Type[] argTypes) { Type firstArgType = argTypes[0]; if (!ConditionBeanContext.IsTheTypeConditionBean(firstArgType)) { String msg = "Sorry! The auto query by DTO of S2Dao is unsupported on DBFlute:"; msg = msg + " dto=" + firstArgType + " method=" + methodInfo; throw new NotSupportedException(msg); } }
// =============================================================================== // Execute // ======= public override object Execute(object[] args) { // - - - - - - - - - - - - // This is top execution. // - - - - - - - - - - - - if (!ConditionBeanContext.IsExistConditionBeanOnThread()) { // - - - - - - - - - - // Execute outsideSql. // - - - - - - - - - - if (OutsideSqlContext.IsExistOutsideSqlContextOnThread()) { OutsideSqlContext outsideSqlContext = OutsideSqlContext.GetOutsideSqlContextOnThread(); if (outsideSqlContext.IsDynamicBinding) { return(ExecuteOutsideSqlAsDynamic(args, outsideSqlContext)); } else { return(ExecuteOutsideSqlAsStatic(args, outsideSqlContext)); } } // - - - - - - - - - // Execute default. // - - - - - - - - - return(ExecuteDefault(args)); } // - - - - - - - - - - - - // Execute conditionBean. // - - - - - - - - - - - - IList <Object> bindVariableList = new System.Collections.Generic.List <Object>(); IList <Type> bindVariableTypeList = new System.Collections.Generic.List <Type>(); IList <String> bindVariableNameList = new System.Collections.Generic.List <String>(); ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); String finalClause = SetupRealClause(args, bindVariableList, bindVariableTypeList, bindVariableNameList); InternalBasicSelectHandler selectHandler = CreateBasicSelectHandler(finalClause, this.dataReaderHandler); Object[] bindVariableArray = new Object[bindVariableList.Count]; bindVariableList.CopyTo(bindVariableArray, 0); Type[] bindVariableTypeArray = new Type[bindVariableTypeList.Count]; bindVariableTypeList.CopyTo(bindVariableTypeArray, 0); String[] bindVariableNameArray = new String[bindVariableNameList.Count]; bindVariableNameList.CopyTo(bindVariableNameArray, 0); selectHandler.LoggingMessageSqlArgs = bindVariableArray; return(selectHandler.Execute(bindVariableArray, bindVariableTypeArray, bindVariableNameArray)); }
// ------------------------------------------------- // ConditionBean // ------------- protected ConditionBean PreprocessConditionBean(IMethodInvocation invocation) { OutsideSqlContext outsideSqlContext = GetOutsideSqlContext(); if (outsideSqlContext != null) { return(null); // Because it has already finished setting up fetchNarrowingBean for outsideSql here. } ConditionBean cb = null; { Object[] args = invocation.Arguments; if (args == null || !(args.Length >= 1)) { return(null); } Object arg0 = args[0]; if (arg0 == null) { return(null); } if (!ConditionBeanContext.IsTheArgumentConditionBean(arg0)) // The argument is not condition-bean... { if (FetchNarrowingBeanContext.IsTheArgumentFetchNarrowingBean(arg0) && !IsSelectCountIgnoreFetchScopeMethod(invocation)) { // Fetch-narrowing-bean and Not select count! FetchNarrowingBeanContext.SetFetchNarrowingBeanOnThread((FetchNarrowingBean)arg0); } return(null); } cb = (ConditionBean)arg0; } if (IsSelectCountIgnoreFetchScopeMethod(invocation)) { cb.xsetupSelectCountIgnoreFetchScope(); } else { FetchNarrowingBeanContext.SetFetchNarrowingBeanOnThread(cb); } ConditionBeanContext.SetConditionBeanOnThread(cb); return(cb); }
protected StatementConfig FindStatementConfigOnThread() { StatementConfig config = null; if (ConditionBeanContext.IsExistConditionBeanOnThread()) { ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); config = cb.StatementConfig; } else if (OutsideSqlContext.IsExistOutsideSqlContextOnThread()) { OutsideSqlContext context = OutsideSqlContext.GetOutsideSqlContextOnThread(); config = context.StatementConfig; } return(config); }
// ------------------------------------------------- // Setup Clause // ------------ protected String SetupRealClause(Object[] args, IList <Object> bindVariableList, IList <Type> bindVariableTypeList, IList <String> bindVariableNameList) { ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); String realClause = null; { S2DaoSelectDynamicCommand dynamicCommand = CreateMySelectDynamicCommand(); dynamicCommand.ArgNames = ArgNames; dynamicCommand.ArgTypes = ArgTypes; dynamicCommand.Sql = cb.SqlClause.getClause(); ICommandContext ctx = dynamicCommand.Apply(args); realClause = ctx.Sql; AddBindVariableInfo(ctx, bindVariableList, bindVariableTypeList, bindVariableNameList); } return(realClause); }
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(); } }
// You should call HasConditionBean() before calling this! protected bool CanRelationMappingCache() { ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.CanRelationMappingCache()); }
protected ConditionBean GetConditionBean() { return(ConditionBeanContext.GetConditionBeanOnThread()); }
// =================================================================================== // ConditionBean // ============= protected bool HasConditionBean() { return(ConditionBeanContext.IsExistConditionBeanOnThread()); }
protected void throwSelectEntityConditionNotFoundException(ConditionBean cb) { ConditionBeanContext.throwSelectEntityConditionNotFoundException(cb); }
protected void ThrowEntityDuplicatedException(String resultCountString, Object searchKey4Log, Exception cause) { ConditionBeanContext.ThrowEntityDuplicatedException(resultCountString, searchKey4Log, cause); }
protected void ThrowEntityAlreadyDeletedException(Object searchKey4Log) { ConditionBeanContext.ThrowEntityAlreadyDeletedException(searchKey4Log); }
// You should call HasConditionBean() before calling this! protected bool HasSelectedForeignInfo(String relationNoSuffix) { ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.hasSelectedForeignInfo(relationNoSuffix)); }
protected bool HasConditionBean(RelationRowCreationResource res) { return(ConditionBeanContext.IsExistConditionBeanOnThread()); }