Java Code Examples for com.querydsl.jpa.JPQLQuery#groupBy()
The following examples show how to use
com.querydsl.jpa.JPQLQuery#groupBy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViolationRepositoryImpl.java From fullstop with Apache License 2.0 | 5 votes |
@Override public List<CountByAccountAndType> countByAccountAndType(final Set<String> accountIds, final Optional<DateTime> fromDate, final Optional<DateTime> toDate, final boolean resolved, final boolean whitelisted) { final QViolationEntity qViolation = new QViolationEntity("v"); final QViolationTypeEntity qType = new QViolationTypeEntity("t"); final JPQLQuery<ViolationEntity> query = from(qViolation); query.join(qViolation.violationTypeEntity, qType); final Collection<Predicate> whereClause = newArrayList(); if (!accountIds.isEmpty()) { whereClause.add(qViolation.accountId.in(accountIds)); } fromDate.map(qViolation.created::after).ifPresent(whereClause::add); toDate.map(qViolation.created::before).ifPresent(whereClause::add); if (whitelisted) { whereClause.add(qViolation.ruleEntity.isNotNull()); } else if (resolved) { whereClause.add(qViolation.comment.isNotNull()); whereClause.add(qViolation.ruleEntity.isNull()); } else { whereClause.add(qViolation.comment.isNull()); whereClause.add(qViolation.ruleEntity.isNull()); } query.where(allOf(whereClause)); query.groupBy(qViolation.accountId, qType.id); query.orderBy(qViolation.accountId.asc(), qType.id.asc()); return query.select(Projections.constructor(CountByAccountAndType.class, qViolation.accountId, qType.id, qViolation.id.count())).fetch(); }
Example 2
Source File: LifecycleRepositoryImpl.java From fullstop with Apache License 2.0 | 2 votes |
@Override public Page<LifecycleEntity> findByApplicationNameAndVersion(final String name, final String version, final Pageable pageable) { final QLifecycleEntity qLifecycleEntity = QLifecycleEntity.lifecycleEntity; final QApplicationEntity qApplicationEntity = QApplicationEntity.applicationEntity; final QVersionEntity qVersionEntity = QVersionEntity.versionEntity; final JPQLQuery<LifecycleEntity> query = from(qLifecycleEntity).leftJoin(qLifecycleEntity.applicationEntity, qApplicationEntity); if (version != null && isNotEmpty(version)) { query.join(qLifecycleEntity.versionEntity, qVersionEntity); query.where(qVersionEntity.name.eq(version)); } query.where(qApplicationEntity.name.eq(name)); final long total = query.fetchCount(); query.groupBy(qLifecycleEntity.versionEntity, qLifecycleEntity.instanceId, qLifecycleEntity.created, qLifecycleEntity.id, qApplicationEntity.id); if (version != null && isNotEmpty(version)) { query.groupBy(qVersionEntity.id); } final Sort sort = pageable.getSort(); final Sort fixedSort = (sort == null || isEmpty(sort)) ? SORT_BY_CREATED : sort; final PageRequest pageRequest = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), fixedSort); getQuerydsl().applyPagination(pageRequest, query); final List<LifecycleEntity> lifecycleEntities = total > 0 ? query.fetch() : emptyList(); return new PageImpl<>(lifecycleEntities, pageRequest, total); }