javax.jdo.Query.setGrouping()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(1.4k)|赞(0)|评价(0)|浏览(110)

本文整理了Java中javax.jdo.Query.setGrouping方法的一些代码示例,展示了Query.setGrouping的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setGrouping方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:setGrouping

Query.setGrouping介绍

[英]Set the grouping expressions, optionally including a "having" clause. When grouping is specified, each result expression must either be an expression contained in the grouping, or an aggregate evaluated once per group.
[中]设置分组表达式,可选地包括“having”子句。指定分组时,每个结果表达式必须是分组中包含的表达式,或者是每个组计算一次的聚合。

代码示例

代码示例来源:origin: org.apache.continuum/continuum-store

public Map<Integer, ProjectGroupSummary> getProjectsSummary()
{
  PersistenceManager pm = getPersistenceManager();
  Transaction tx = pm.currentTransaction();
  try
  {
    tx.begin();
    Extent extent = pm.getExtent( Project.class );
    Query query = pm.newQuery( extent );
    query.setResult( "projectGroup.id as projectGroupId, state as projectState, count(state) as size" );
    query.setResultClass( ProjectSummaryResult.class );
    query.setGrouping( "projectGroup.id, state" );
    List<ProjectSummaryResult> results = (List<ProjectSummaryResult>) query.execute();
    Map<Integer, ProjectGroupSummary> summaries = processProjectGroupSummary( results );
    tx.commit();
    return summaries;
  }
  finally
  {
    rollback( tx );
  }
}

代码示例来源:origin: tzaeschke/zoodb

q.setGrouping("dept.name having count(dept.name) > 1");
Collection<Object[]> results = (Collection<Object[]>)q.execute();
Iterator<Object[]> it = results.iterator();

相关文章