SPB-附录-查询条件类在SpaceBuilder中的作用
查看全部词条命名空间:Main
导航: 上一页
在获取实体集合时情况较多:
例如:以文件为例,列出一些获取实体集合的情况:
- 只获取某个每个人的文件集合
- 获取每个标签下的文件集合
- 获取每个类别下的文件集合
- 获取某个页面的文件集合
- 获取私有的文件集合
- 获取某个人每隔标签下的文件集合
- 获取某个人每个类别下的文件集合
- 获取某个标签下某个页面的文件结合….
以上的情况,以及他们的组合将会产生很多种情况,而且这些情况是变化的;所以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>
/// 缓存使用的标识键,在缓存体系中名称唯一,以区别于其他的缓存对象
/// </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);
}
}
}
}
由于代码太多,只截取了部分内容,如上面的代码所示;实际FileThreadQuery包括哪些查询条件请看源码(File项目中的FileThreadQuery.cs);FileThreadQuery中的各个属性代表了各种查询条件,通过赋值不同的查询条件;实现不同查询条件的组合:例如,获取某个人某个标签下的文件集合:
FileThreadQuery query = new FileThreadQuery(); query.OwnerUserID = currentDomainUser.UserID; query.TagName = tagName; PagingDataSet<FileThread> threads = FileThreads.GetThreads(query);
也就是说,FileThreadQuery封装了各种查询条件以及他们的组合;在表现层,我们获取符合某些条件的文件集合只要配置查询条件类 FileThreadQuery即可。
大家可能注意到了,在FileThreadQuery中还有个特殊的属性:CacheKey:
/// <summary>
/// 缓存使用的标识键,在缓存体系中名称唯一,以区别于其他的缓存对象
/// </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);
}
}
它不是查询条件,而是缓存标识;在从数据库中取出数据库后,为了减轻数据库的负担,我们将查询到得内容放入缓存;而不同的缓存块都有唯一标识相互区别,就是使用的FileThreadQuery中的这个CacheKey。
以上介绍了,为什么使用FileThreadQuery以及如何使用;那么,在数据访问层获取数据集合的时候FileThreadQuery是如何起作用的?获取文件集合的方法:GetThreads在类SqlFileThreadProvider中的实现:(解析FileThreadQuery,组装sql语句)
