// =============================================================================== // Load Referrer Internal Helper // ============================= /** * Help load referrer internally. * About internal policy, the value of primary key(and others too) is treated as CaseInsensitive. * @param <LOCAL_ENTITY> The type of base entity. * @param <PK> The type of primary key. * @param <REFERRER_CB> The type of referrer condition-bean. * @param <REFERRER_ENTITY> The type of referrer entity. * @param localEntityList The list of local entity. (NotNull) * @param loadReferrerOption The option of loadReferrer. (NotNull) * @param callback The internal call-back of loadReferrer. (NotNull) */ protected virtual void HelpLoadReferrerInternally <LOCAL_ENTITY, PK, REFERRER_CB, REFERRER_ENTITY>( IList <LOCAL_ENTITY> localEntityList , LoadReferrerOption <REFERRER_CB, REFERRER_ENTITY> loadReferrerOption , InternalLoadReferrerCallback <LOCAL_ENTITY, PK, REFERRER_CB, REFERRER_ENTITY> callback) where LOCAL_ENTITY : Entity where REFERRER_CB : ConditionBean where REFERRER_ENTITY : Entity { DoHelpLoadReferrerInternally(localEntityList, loadReferrerOption, callback); }
/** * Help load referrer internally. * About internal policy, the value of primary key(and others too) is treated as CaseInsensitive. * @param <LOCAL_ENTITY> The type of base entity. * @param <PK> The type of primary key. * @param <REFERRER_CB> The type of referrer condition-bean. * @param <REFERRER_ENTITY> The type of referrer entity. * @param localEntityList The list of local entity. (NotNull) * @param loadReferrerOption The option of loadReferrer. (NotNull) * @param callback The internal call-back of loadReferrer. (NotNull) */ protected virtual void DoHelpLoadReferrerInternally <LOCAL_ENTITY, PK, REFERRER_CB, REFERRER_ENTITY>( IList <LOCAL_ENTITY> localEntityList , LoadReferrerOption <REFERRER_CB, REFERRER_ENTITY> loadReferrerOption , InternalLoadReferrerCallback <LOCAL_ENTITY, PK, REFERRER_CB, REFERRER_ENTITY> callback) where LOCAL_ENTITY : Entity where REFERRER_CB : ConditionBean where REFERRER_ENTITY : Entity { // - - - - - - - - - - - // Assert pre-condition // - - - - - - - - - - - AssertBehaviorSelectorNotNull("loadReferrer"); AssertObjectNotNull("localEntityList", localEntityList); AssertObjectNotNull("loadReferrerOption", loadReferrerOption); if (localEntityList.Count == 0) { return; } // - - - - - - - - - - - - - - // Prepare temporary container // - - - - - - - - - - - - - - IDictionary <PK, LOCAL_ENTITY> pkLocalEntityMap = new Dictionary <PK, LOCAL_ENTITY>(); IList <PK> pkList = new List <PK>(); foreach (LOCAL_ENTITY localEntity in localEntityList) { PK primaryKeyValue = callback.getPKVal(localEntity); if (primaryKeyValue == null) { String msg = "PK value of local entity should not be null: " + localEntity; throw new SystemException(msg); } pkList.Add(primaryKeyValue); if (!pkLocalEntityMap.ContainsKey(primaryKeyValue)) { pkLocalEntityMap.Add(ToLoadReferrerMappingKey(primaryKeyValue), localEntity); } } // - - - - - - - - - - - - - - - - // Prepare referrer condition bean // - - - - - - - - - - - - - - - - REFERRER_CB cb; if (loadReferrerOption.ReferrerConditionBean != null) { cb = loadReferrerOption.ReferrerConditionBean; } else { cb = callback.newMyCB(); } // - - - - - - - - - - - - - - // Select the list of referrer // - - - - - - - - - - - - - - callback.qyFKIn(cb, pkList); cb.xregisterUnionQuerySynchronizer(delegate(ConditionBean unionCB) { REFERRER_CB referrerUnionCB = (REFERRER_CB)unionCB; // for when application uses union query in condition-bean set-upper. callback.qyFKIn(referrerUnionCB, pkList); }); if (pkList.Count > 1) { callback.qyOdFKAsc(cb); cb.SqlComponentOfOrderByClause.exchangeFirstOrderByElementForLastOne(); } loadReferrerOption.delegateConditionBeanSettingUp(cb); if (cb.SqlClause.hasSpecifiedSelectColumn(cb.SqlClause.getBasePointAliasName())) { callback.spFKCol(cb); // specify required columns } IList <REFERRER_ENTITY> referrerList = callback.selRfLs(cb); loadReferrerOption.delegateEntitySettingUp(referrerList); // - - - - - - - - - - - - - - - - - - - - - - - - // Create the map of {primary key / referrer list} // - - - - - - - - - - - - - - - - - - - - - - - - IDictionary <PK, List <REFERRER_ENTITY> > pkReferrerListMap = new Dictionary <PK, List <REFERRER_ENTITY> >(); foreach (REFERRER_ENTITY referrerEntity in referrerList) { PK referrerListKey; { PK foreignKeyValue = callback.getFKVal(referrerEntity); referrerListKey = ToLoadReferrerMappingKey(foreignKeyValue); } if (!pkReferrerListMap.ContainsKey(referrerListKey)) { pkReferrerListMap.Add(referrerListKey, new List <REFERRER_ENTITY>()); } pkReferrerListMap[referrerListKey].Add(referrerEntity); // for Reverse Reference. LOCAL_ENTITY localEntity = pkLocalEntityMap[referrerListKey]; callback.setlcEt(referrerEntity, localEntity); } // - - - - - - - - - - - - - - - - - - // Relate referrer list to base entity // - - - - - - - - - - - - - - - - - - foreach (LOCAL_ENTITY localEntity in localEntityList) { PK referrerListKey; { PK primaryKey = callback.getPKVal(localEntity); referrerListKey = ToLoadReferrerMappingKey(primaryKey); } if (pkReferrerListMap.ContainsKey(referrerListKey)) { callback.setRfLs(localEntity, pkReferrerListMap[referrerListKey]); } else { callback.setRfLs(localEntity, new List <REFERRER_ENTITY>()); } } }