QuerySpec queryspec = new QuerySpec(PBIResourceCategory.class);
queryspec.setAdvancedQueryEnabled(true);
QuerySpec subQueryspec = new QuerySpec();
int parentIndex = subQueryspec.appendClassList(ResourceCategory.class, false);
int linkIndex = subQueryspec.appendClassList(ResourceCategoryLink.class, false);
int childIndex = subQueryspec.appendClassList(ResourceCategory.class, false);
subQueryspec.appendSelect(new ClassAttribute(ResourceCategory.class,
ResourceCategory.RESERV1), new int[] { childIndex }, false);
WhereExpression where = new SearchCondition(ResourceCategory.class,
ResourceCategory.RESERV1, "=", reserv1);
subQueryspec.appendWhere(where, new int[] { parentIndex });
subQueryspec.appendJoin(linkIndex, ResourceCategoryLink.CATEGORY_ROLE, parentIndex);
subQueryspec.appendJoin(linkIndex, ResourceCategoryLink.SUB_CATEGORY_ROLE, childIndex);
ClassAttribute pbiID = new ClassAttribute(PBIResourceCategory.class,
PBIResourceCategory.PBI_ID);
where = new SearchCondition(pbiID, SearchCondition.IN, new SubSelectExpression(
subQueryspec));
queryspec.appendWhere(where, new int[]{0});
QueryResult result = PersistenceHelper.manager.find((StatementSpec) queryspec);
本文介绍了一个复杂的查询构造过程,通过创建QuerySpec实例并设置高级查询功能实现特定资源类别的检索。利用子查询的方式,结合资源类别及其链接角色,最终通过PersistenceHelper完成数据查找。
1397

被折叠的 条评论
为什么被折叠?



