// ----------------------------------------------------- // Internal Helper // --------------- protected int xcheckSafetyResultAsOne(ConditionBean cb) { int safetyMaxResultSize = cb.SafetyMaxResultSize; cb.CheckSafetyResult(1); return(safetyMaxResultSize); }
// =================================================================================== // Exception Handling // ================== public static void ThrowEntityAlreadyDeletedException(Object searchKey4Log) { String msg = "Look! Read the message below." + ln(); msg = msg + "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" + ln(); msg = msg + "The entity was Not Found! it has already been deleted!" + ln(); msg = msg + ln(); msg = msg + "[Advice]" + ln(); msg = msg + "Please confirm the existence of your target record on your database." + ln(); msg = msg + "Does the target record really created before this operation?" + ln(); msg = msg + "Has the target record been deleted by other thread?" + ln(); msg = msg + "It is precondition that the record exists on your database." + ln(); msg = msg + ln(); if (searchKey4Log != null && searchKey4Log is ConditionBean) { ConditionBean cb = (ConditionBean)searchKey4Log; String dispalySql = cb.ToDisplaySql(); msg = msg + "[Display SQL]" + ln() + dispalySql + ln(); } else { msg = msg + "[Search Condition]" + ln() + searchKey4Log + ln(); } msg = msg + "* * * * * * * * * */"; throw new EntityAlreadyDeletedException(msg); }
public static void ThrowEntityDuplicatedException(String resultCountString, Object searchKey4Log, Exception cause) { String msg = "Look! Read the message below." + ln(); msg = msg + "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" + ln(); msg = msg + "The entity was Too Many! it has been duplicated. It should be the only one! But the resultCount=" + resultCountString + ln(); msg = msg + ln(); msg = msg + "[Advice]" + ln(); msg = msg + "Please confirm your search condition. Does it really select the only one?" + ln(); msg = msg + "Please confirm your database. Does it really exist the only one?" + ln(); msg = msg + ln(); if (searchKey4Log != null && searchKey4Log is ConditionBean) { ConditionBean cb = (ConditionBean)searchKey4Log; String dispalySql = cb.ToDisplaySql(); msg = msg + "[Display SQL]" + ln() + dispalySql + ln(); } else { msg = msg + "[Search Condition]" + ln() + searchKey4Log + ln(); } msg = msg + "* * * * * * * * * */"; if (cause != null) { throw new EntityDuplicatedException(msg, cause); } else { throw new EntityDuplicatedException(msg); } }
// [DBFlute-0.8.9.2] // =============================================================================== // Query Synchronizer // ================== protected void xsyncUQ(ConditionBean unionCB) // synchronizeUnionQuery() { if (_unionQuerySynchronizer != null) { _unionQuerySynchronizer.Invoke(unionCB); } }
public static void SetConditionBeanOnThread(ConditionBean cb) { if (cb == null) { String msg = "The argument[cb] must not be null."; throw new ArgumentNullException(msg); } Thread.SetData(_slot, cb); }
protected bool IsSelectedForeignInfoEmpty() { if (!HasConditionBean()) { return(true); } ConditionBean cb = ConditionBeanContext.GetConditionBeanOnThread(); return(cb.SqlClause.isSelectedForeignInfoEmpty()); }
protected AbstractSpecification(ConditionBean baseCB, HpSpQyCall <CQ> qyCall , bool forDerivedReferrer, bool forScalarSelect, bool forScalarSubQuery, bool forColumnQuery) { _baseCB = baseCB; _qyCall = qyCall; _forDerivedReferrer = forDerivedReferrer; _forScalarSelect = forScalarSelect; _forScalarCondition = forScalarSubQuery; _forColumnQuery = forColumnQuery; }
// =================================================================================== // 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()); }
public ListResultBean <ENTITY> BuildListResultBean(ConditionBean ob, IList <ENTITY> selectedList) { ListResultBean <ENTITY> rb = new ListResultBean <ENTITY>(); rb.TableDbName = _tableDbName; rb.AllRecordCount = selectedList.Count; rb.SelectedList = selectedList; rb.OrderByClause = ob.SqlComponentOfOrderByClause; return(rb); }
public void PostprocessConditionBean(IMethodInvocation invocation, ConditionBean cb) { if (cb == null) { return; } if (IsSelectCountIgnoreFetchScopeMethod(invocation)) { cb.xafterCareSelectCountIgnoreFetchScope(); } }
public static void throwSelectEntityConditionNotFoundException(ConditionBean cb) { String msg = "Look! Read the message below." + ln(); msg = msg + "/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" + ln(); msg = msg + "The condition for selecting an entity was not found!" + ln(); msg = msg + ln(); msg = msg + "[Advice]" + ln(); msg = msg + "Confirm your search condition. Does it really select the only one?" + ln(); msg = msg + "You have to set a valid query or fetch-first as 1." + ln(); msg = msg + "For example:" + ln(); msg = msg + " (x):" + ln(); msg = msg + " MemberCB cb = MemberCB();" + ln(); msg = msg + " ... = memberBhv.SelectEntity(cb); // exception" + ln(); msg = msg + " (x):" + ln(); msg = msg + " MemberCB cb = MemberCB();" + ln(); msg = msg + " cb.Query().SetMemberId_Equal(null);" + ln(); msg = msg + " ... = memberBhv.SelectEntity(cb); // exception" + ln(); msg = msg + " (o):" + ln(); msg = msg + " MemberCB cb = MemberCB();" + ln(); msg = msg + " cb.Query().SetMemberId_Equal(3);" + ln(); msg = msg + " ... = memberBhv.SelectEntity(cb);" + ln(); msg = msg + " (o):" + ln(); msg = msg + " MemberCB cb = MemberCB();" + ln(); msg = msg + " cb.FetchFirst(1);" + ln(); msg = msg + " ... = memberBhv.SelectEntity(cb);" + ln(); msg = msg + ln(); msg = msg + "[Invalid Query]" + ln(); Map <String, ConditionKey> invalidQueryColumnMap = cb.SqlClause.getInvalidQueryColumnMap(); if (invalidQueryColumnMap != null && !invalidQueryColumnMap.isEmpty()) { Set <String> keySet = invalidQueryColumnMap.keySet(); foreach (String columnFullName in keySet) { ConditionKey key = invalidQueryColumnMap.get(columnFullName); msg = msg + columnFullName + " : " + key.getConditionKey() + ln(); } } else { msg = msg + "*no invalid" + ln(); } msg = msg + ln(); msg = msg + "[Fetch Size]" + ln(); msg = msg + cb.FetchSize + ln(); msg = msg + ln(); msg = msg + "[Display SQL]" + ln(); msg = msg + cb.ToDisplaySql() + ln(); msg = msg + "* * * * * * * * * */"; throw new SelectEntityConditionNotFoundException(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)); }
// =================================================================================== // Execute // ======= public Object Execute(Object[] args) { ConditionBean cb = extractConditionBeanWithCheck(args); String[] argNames = new String[] { "pmb" }; Type[] argTypes = new Type[] { cb.GetType() }; String twoWaySql = buildQueryDeleteTwoWaySql(cb); ICommandContext context = createCommandContext(twoWaySql, argNames, argTypes, args); InternalCommandContextHandler handler = createCommandContextHandler(context); handler.LoggingMessageSqlArgs = context.BindVariables; int rows = handler.Execute(args); return(rows); }
// ------------------------------------------------- // 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); } } }
/** * @param cb Condition-bean. (NotNull) * @param entity Entity. (NotNull) * @return The two-way SQL of query update. (NullAllowed: If the set of modified properties is empty, return null.) */ protected String buildQueryUpdateTwoWaySql(ConditionBean cb, Entity entity) { Map <String, String> columnParameterMap = new LinkedHashMap <String, String>(); DBMeta dbmeta = DBMetaInstanceHandler.FindDBMeta(entity.TableDbName); System.Collections.Generic.IDictionary <String, Object> modifiedPropertyNames = entity.ModifiedPropertyNames; if (modifiedPropertyNames.Count == 0) { return(null); } String currentPropertyName = null; foreach (String propertyName in modifiedPropertyNames.Keys) { currentPropertyName = propertyName; ColumnInfo columnInfo = dbmeta.FindColumnInfo(propertyName); String columnName = columnInfo.ColumnDbName; PropertyInfo getter = columnInfo.FindProperty(); Object value = getter.GetValue(entity, null); if (value != null) { columnParameterMap.put(columnName, "/*entity." + propertyName + "*/null"); } else { columnParameterMap.put(columnName, "null"); } } if (dbmeta.HasVersionNo) { ColumnInfo columnInfo = dbmeta.VersionNoColumnInfo; String columnName = columnInfo.ColumnDbName; columnParameterMap.put(columnName, columnName + " + 1"); } if (dbmeta.HasUpdateDate) { ColumnInfo columnInfo = dbmeta.UpdateDateColumnInfo; PropertyInfo setter = columnInfo.FindProperty(); setter.SetValue(entity, DateTime.Now, null); String columnName = columnInfo.ColumnDbName; columnParameterMap.put(columnName, "/*entity." + columnInfo.PropertyName + "*/null"); } return(cb.SqlClause.getClauseQueryUpdate(columnParameterMap)); }
// =================================================================================== // Execute // ======= public Object Execute(Object[] args) { ConditionBean cb = extractConditionBeanWithCheck(args); Entity entity = extractEntityWithCheck(args); String[] argNames = new String[] { "pmb", "entity" }; Type[] argTypes = new Type[] { cb.GetType(), entity.GetType() }; String twoWaySql = buildQueryUpdateTwoWaySql(cb, entity); if (twoWaySql == null) { return(0);// No execute! } ICommandContext context = createCommandContext(twoWaySql, argNames, argTypes, args); InternalCommandContextHandler handler = createCommandContextHandler(context); handler.LoggingMessageSqlArgs = context.BindVariables; return(handler.Execute(args)); }
protected Mst客室マスタCB Downcast(ConditionBean cb) { return((Mst客室マスタCB)cb); }
protected override Entity DoReadEntityWithDeletedCheck(ConditionBean cb) { return(SelectEntityWithDeletedCheck(Downcast(cb))); }
protected override Entity DoReadEntity(ConditionBean cb) { return(SelectEntity(Downcast(cb))); }
protected override int DoReadCount(ConditionBean cb) { return(SelectCount(Downcast(cb))); }
public DmyプロシージャCBSpecification(ConditionBean baseCB, HpSpQyCall <DmyプロシージャCQ> qyCall , bool forDerivedReferrer, bool forScalarSelect, bool forScalarSubQuery, bool forColumnQuery) : base(baseCB, qyCall, forDerivedReferrer, forScalarSelect, forScalarSubQuery, forColumnQuery) { }
public RAFunction(ConditionBean baseCB, LOCAL_CQ localCQ, RAQSetupper <REFERRER_CB, LOCAL_CQ> querySetupper) { _baseCB = baseCB; _localCQ = localCQ; _querySetupper = querySetupper; }
// [DBFlute-0.7.4] // =============================================================================== // Purpose Type // ============ // /- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // very internal (super very important) // these are called immediate after creation of condition-bean // because there are important initializations here // - - - - - - - - - -/ public void xsetupForUnion(ConditionBean mainCB) { xinheritSubQueryInfo(mainCB.LocalCQ); _forUnion = true; }
protected DmyプロシージャCB Downcast(ConditionBean cb) { return((DmyプロシージャCB)cb); }