久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

SPB-附錄-查詢條件類在SpaceBuilder中的作用

來自站長百科
跳轉(zhuǎn)至: 導(dǎo)航、? 搜索

導(dǎo)航: 上一頁

在獲取實體集合時情況較多:

例如:以文件為例,列出一些獲取實體集合的情況:

  1. 只獲取某個每個人的文件集合
  2. 獲取每個標簽下的文件集合
  3. 獲取每個類別下的文件集合
  4. 獲取某個頁面的文件集合
  5. 獲取私有的文件集合
  6. 獲取某個人每隔標簽下的文件集合
  7. 獲取某個人每個類別下的文件集合
  8. 獲取某個標簽下某個頁面的文件結(jié)合….

以上的情況,以及他們的組合將會產(chǎn)生很多種情況,而且這些情況是變化的;所以SpaceBuilder使用了查詢條件類封裝了這些變化;我們看一下文件查詢條件類 - FileThreadQuery:

namespace SpaceBuilder.File
{
    /// <summary>
    /// 文件查詢類
    /// </summary>
    public class FileThreadQuery
    {
        #region Query Properties
        /// <summary>
        /// 擁有者UserID
        /// </summary>
        public int OwnerUserID = -1;
        /// <summary>
        ///  站點類型
        /// </summary>
        public int SiteCategoryID = -1;
        …..
        …..
        private int pageIndex = 1;
        /// <summary>
        /// 當前顯示的頁碼號
        /// </summary>

        public int PageIndex
        {
           ….
        }
        #endregion

        /// <summary>
        ///  緩存使用的標識鍵,在緩存體系中名稱唯一,以區(qū)別于其他的緩存對象
        /// </summary>
        public string CacheKey
        {
            get
            {
return string.Format("FileThreads::OwnerUserID:

{0}-SiteCategoryID{1}-IncludeSiteCategoryDescendant{2}
-UserCategoryID:{3}-OnlyPublic:{4}-AuditingStatusForDisplay:

{5}-UncategorizedOnly:{6}-TagName:{7}-SubjectKeywords:
{8}-PI:{9}-PS:{10}-SO:{11}-SB:{12}-IP:{13}-MaxRecords:{14}-IncludeTags:{15}",

OwnerUserID,SiteCategoryID,IncludeSiteCategoryDescendant, UserCategoryID, OnlyPublic, 

AuditingStatusForDisplay.ToString(), UnuserCategorizedOnly, TagName, 
SubjectKeywords, PageIndex, PageSize, (int)SortOrder, 

(int)SortBy, EnablePaging, MaxRecords, IncludeTags);
            }
        }
    }
}

由于代碼太多,只截取了部分內(nèi)容,如上面的代碼所示;實際FileThreadQuery包括哪些查詢條件請看源碼(File項目中的FileThreadQuery.cs);FileThreadQuery中的各個屬性代表了各種查詢條件,通過賦值不同的查詢條件;實現(xiàn)不同查詢條件的組合:例如,獲取某個人某個標簽下的文件集合:

FileThreadQuery query = new FileThreadQuery();
query.OwnerUserID = currentDomainUser.UserID;
query.TagName = tagName;
PagingDataSet<FileThread> threads = FileThreads.GetThreads(query);

也就是說,F(xiàn)ileThreadQuery封裝了各種查詢條件以及他們的組合;在表現(xiàn)層,我們獲取符合某些條件的文件集合只要配置查詢條件類 FileThreadQuery即可。

大家可能注意到了,在FileThreadQuery中還有個特殊的屬性:CacheKey:

/// <summary>
        ///  緩存使用的標識鍵,在緩存體系中名稱唯一,以區(qū)別于其他的緩存對象
        /// </summary>

        public string CacheKey
        {
            get
            {
                return string.Format("FileThreads::OwnerUserID:

{0}-SiteCategoryID{1}-IncludeSiteCategoryDescendant{2}
-UserCategoryID:{3}-OnlyPublic:{4}-AuditingStatusForDisplay:

{5}-UncategorizedOnly:{6}-TagName:{7}-SubjectKeywords:{8}-
PI:{9}-PS:{10}-SO:{11}-SB:{12}-IP:{13}-MaxRecords:{14}-IncludeTags:{15}",

  OwnerUserID,SiteCategoryID,IncludeSiteCategoryDescendant, UserCategoryID, OnlyPublic, 

AuditingStatusForDisplay.ToString(), UnuserCategorizedOnly, 
TagName, SubjectKeywords, PageIndex, PageSize, (int)SortOrder, 

(int)SortBy, EnablePaging, MaxRecords, IncludeTags);
            }
        }

它不是查詢條件,而是緩存標識;在從數(shù)據(jù)庫中取出數(shù)據(jù)庫后,為了減輕數(shù)據(jù)庫的負擔,我們將查詢到得內(nèi)容放入緩存;而不同的緩存塊都有唯一標識相互區(qū)別,就是使用的FileThreadQuery中的這個CacheKey。

以上介紹了,為什么使用FileThreadQuery以及如何使用;那么,在數(shù)據(jù)訪問層獲取數(shù)據(jù)集合的時候FileThreadQuery是如何起作用的?獲取文件集合的方法:GetThreads在類SqlFileThreadProvider中的實現(xiàn):(解析FileThreadQuery,組裝sql語句)

Spacebuilder0034.jpg

參考資料[ ]