本文整理汇总了Java中javax.persistence.criteria.Subquery.groupBy方法的典型用法代码示例。如果您正苦于以下问题:Java Subquery.groupBy方法的具体用法?Java Subquery.groupBy怎么用?Java Subquery.groupBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.Subquery
的用法示例。
在下文中一共展示了Subquery.groupBy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getChanges
import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public List<RegistryOperation> getChanges(Date from, Date until) {
CriteriaQuery<RegistryOperation> query = criteriaBuilder.createQuery(RegistryOperation.class);
Root<RegistryOperation> root = query.from(clazz);
Subquery<Long> subquery = query.subquery(Long.class);
Root<RegistryOperation> subqueryRoot = subquery.from(clazz);
subquery = subquery.select(criteriaBuilder.max(subqueryRoot.get(RegistryOperation_.id)));
Predicate subqueryPredicate = criteriaBuilder.isTrue(subqueryRoot.get(RegistryOperation_.exposed));
subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
criteriaBuilder.lessThanOrEqualTo(subqueryRoot.get(RegistryOperation_.date), until));
if (from != null) {
subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
criteriaBuilder.greaterThanOrEqualTo(subqueryRoot.get(RegistryOperation_.date), from));
}
subquery = subquery.where(subqueryPredicate);
subquery = subquery.groupBy(subqueryRoot.get(RegistryOperation_.target).get(SemanticDescriptor_.id));
query = query.where(root.get(RegistryOperation_.id).in(subquery));
query.orderBy(criteriaBuilder.asc(root.get(RegistryOperation_.date)));
return entityManager.createQuery(query).getResultList();
}
示例2: hasProperties
import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
public WordTemplateQuery hasProperties(Map<String, String> someProperties) {
Subquery<Long> subQuery = query.subquery(Long.class);
Root<PersistentTemplate> fromSubQuery = subQuery
.from(PersistentTemplate.class);
Path<Long> id = fromSubQuery.get("id");
subQuery.select(id);
MapJoin<PersistentTemplate, String, String> propertiesMap = fromSubQuery
.joinMap("properties", JoinType.INNER);
subQuery.where(buildPropertyRestriction(propertiesMap, someProperties));
subQuery.groupBy(id);
subQuery.having(criteriaBuilder.equal(criteriaBuilder.count(id),
someProperties.size()));
restrictions.add(persistentTemplate.get("id").in(subQuery));
return this;
}
示例3: getChanges
import javax.persistence.criteria.Subquery; //导入方法依赖的package包/类
@Override
public List<Operation> getChanges(Date from, Date until, NamespaceType prefix, ObjectType set, int offset,
int pageSize) {
CriteriaQuery<Operation> query = criteriaBuilder.createQuery(Operation.class);
Root<Operation> root = query.from(clazz);
Subquery<Long> subquery = query.subquery(Long.class);
Root<Operation> subqueryRoot = subquery.from(clazz);
subquery = subquery.select(criteriaBuilder.max(subqueryRoot.get(Operation_.id)));
Predicate subqueryPredicate = criteriaBuilder.greaterThanOrEqualTo(subqueryRoot.get(Operation_.date), from);
subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
criteriaBuilder.lessThanOrEqualTo(subqueryRoot.get(Operation_.date), until));
subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
criteriaBuilder.equal(subqueryRoot.get(Operation_.metadataType), prefix));
if (set != null) {
Join<Operation, DigitalObject> operationToObject = subqueryRoot.join(Operation_.object);
subqueryPredicate = criteriaBuilder.and(subqueryPredicate,
criteriaBuilder.equal(operationToObject.get(DigitalObject_.type), set));
}
subquery = subquery.where(subqueryPredicate);
subquery = subquery.groupBy(subqueryRoot.get(Operation_.object).get(DigitalObject_.id));
query = query.where(root.get(Operation_.id).in(subquery));
query.orderBy(criteriaBuilder.asc(root.get(Operation_.id)));
return entityManager.createQuery(query).setFirstResult(offset).setMaxResults(pageSize).getResultList();
}