Java Examples for com.querydsl.jpa.JPQLQuery

The following java examples will help you to understand the usage of com.querydsl.jpa.JPQLQuery. These source code samples are taken from different open source projects.

Example 1
Project: owsi-core-parent-master  File: GenericLocalizedGenericListItemDaoImpl.java View source code
@Override
public <E extends GE> List<E> listByLocalizedLabel(EntityPath<E> source, Locale locale, String label) {
    JPQLQuery<E> query = new JPAQuery<E>(getEntityManager());
    QGenericLocalizedGenericListItem qLocalizedGenericListItem = new QGenericLocalizedGenericListItem(source);
    query.select(source).from(qLocalizedGenericListItem).where(qLabelTextPath(qLocalizedGenericListItem, locale).eq(label));
    return query.fetch();
}
Example 2
Project: fullstop-master  File: ViolationRepositoryImpl.java View source code
@Override
public Page<ViolationEntity> queryViolations(final List<String> accounts, final DateTime from, final DateTime to, final Long lastViolation, final boolean checked, final Integer severity, final Integer priority, final Boolean auditRelevant, final List<String> types, final boolean whitelisted, final List<String> applicationIds, final List<String> applicationVersionIds, final Pageable pageable) {
    final QViolationEntity qViolationEntity = QViolationEntity.violationEntity;
    final QViolationTypeEntity qViolationTypeEntity = QViolationTypeEntity.violationTypeEntity;
    final JPQLQuery<ViolationEntity> query = from(qViolationEntity).leftJoin(qViolationEntity.violationTypeEntity, qViolationTypeEntity);
    final List<Predicate> predicates = newArrayList();
    if (accounts != null) {
        predicates.add(qViolationEntity.accountId.in(accounts));
    }
    if (from != null) {
        predicates.add(qViolationEntity.created.after(from));
    }
    if (to != null) {
        predicates.add(qViolationEntity.created.before(to));
    }
    if (lastViolation != null) {
        predicates.add(qViolationEntity.id.goe(lastViolation));
    }
    if (whitelisted) {
        predicates.add(qViolationEntity.ruleEntity.isNotNull());
    } else if (checked) {
        predicates.add(qViolationEntity.comment.isNotNull());
        predicates.add(qViolationEntity.ruleEntity.isNull());
    } else {
        predicates.add(qViolationEntity.comment.isNull());
        predicates.add(qViolationEntity.ruleEntity.isNull());
    }
    if (severity != null) {
        predicates.add(qViolationTypeEntity.violationSeverity.eq(severity));
    }
    if (priority != null) {
        predicates.add(qViolationTypeEntity.priority.eq(priority));
    }
    if (auditRelevant != null) {
        predicates.add(qViolationTypeEntity.isAuditRelevant.eq(auditRelevant));
    }
    if (types != null && !types.isEmpty()) {
        predicates.add(qViolationEntity.violationTypeEntity.id.in(types));
    }
    if (applicationIds != null && !applicationIds.isEmpty()) {
        predicates.add(qViolationEntity.application.name.in(applicationIds));
    }
    if (applicationVersionIds != null && !applicationVersionIds.isEmpty()) {
        predicates.add(qViolationEntity.applicationVersion.name.in(applicationVersionIds));
    }
    final long total = query.where(allOf(predicates)).fetchCount();
    final Sort sort = pageable.getSort();
    final Sort fixedSort = (sort == null || isEmpty(sort)) ? SORT_BY_ID : sort;
    final PageRequest fixedPage = new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), fixedSort);
    getQuerydsl().applyPagination(fixedPage, query);
    final List<ViolationEntity> list;
    list = total > 0 ? query.where(allOf(predicates)).fetch() : emptyList();
    return new PageImpl<>(list, fixedPage, total);
}
Example 3
Project: commafeed-master  File: FeedDAO.java View source code
public List<Feed> findNextUpdatable(int count, Date lastLoginThreshold) {
    HibernateQuery<Feed> query = query().selectFrom(feed);
    query.where(feed.disabledUntil.isNull().or(feed.disabledUntil.lt(new Date())));
    if (lastLoginThreshold != null) {
        QFeedSubscription subs = QFeedSubscription.feedSubscription;
        QUser user = QUser.user;
        JPQLQuery<Integer> subQuery = JPAExpressions.selectOne().from(subs);
        subQuery.join(subs.user, user).where(user.lastLogin.gt(lastLoginThreshold));
        query.where(subQuery.exists());
    }
    return query.orderBy(feed.disabledUntil.asc()).limit(count).distinct().fetch();
}
Example 4
Project: kylo-master  File: JpaBatchJobExecutionProvider.java View source code
private Page<? extends BatchJobExecution> findAllForFeed(String feedName, List<SearchCriteria> filters, Pageable pageable) {
    QJpaBatchJobExecution jobExecution = QJpaBatchJobExecution.jpaBatchJobExecution;
    QJpaOpsManagerFeed feed = QJpaOpsManagerFeed.jpaOpsManagerFeed;
    QJpaOpsManagerFeed checkDataFeed = new QJpaOpsManagerFeed("checkDataFeed");
    QJpaBatchJobInstance jobInstance = QJpaBatchJobInstance.jpaBatchJobInstance;
    JPQLQuery checkFeedQuery = JPAExpressions.select(checkDataFeed.id).from(feed).join(feed.checkDataFeeds, checkDataFeed).where(feed.name.eq(feedName));
    JPAQuery query = factory.select(jobExecution).from(jobExecution).join(jobExecution.jobInstance, jobInstance).join(jobInstance.feed, feed).where((feed.name.eq(feedName).or(feed.id.in(checkFeedQuery))).and(GenericQueryDslFilter.buildFilter(jobExecution, filters).and(augment(feed.id)))).fetchAll();
    pageable = CommonFilterTranslations.resolveSortFilters(jobExecution, pageable);
    return findAll(query, pageable);
}
Example 5
Project: spring-data-jpa-master  File: QuerydslJpaRepository.java View source code
/*
	 * (non-Javadoc)
	 * @see org.springframework.data.querydsl.QuerydslPredicateExecutor#findAll(com.querydsl.core.types.Predicate, org.springframework.data.domain.Pageable)
	 */
@Override
public Page<T> findAll(Predicate predicate, Pageable pageable) {
    Assert.notNull(pageable, "Pageable must not be null!");
    final JPQLQuery<?> countQuery = createCountQuery(predicate);
    JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path));
    return PageableExecutionUtils.getPage(query.fetch(), pageable, () -> countQuery.fetchCount());
}
Example 6
Project: spring-roo-master  File: RepositoryJpaCustomImplMetadata.java View source code
/**
   * Method that generates implementation methods for each count method, associated
   * to each custom finder.
   *
   * @param methodInfo
   * @param validFields
   * @return
   */
private MethodMetadata getCustomCountImpl(Pair<MethodMetadata, PartTree> methodInfo) {
    final MethodMetadata method = methodInfo.getLeft();
    // Define method name
    JavaSymbolName methodName = method.getMethodName();
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = method.getParameterTypes();
    // Define method parameter names
    List<JavaSymbolName> parameterNames = method.getParameterNames();
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    // Generate body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // Getting variable names to use in the code
    String entity = this.entity.getSimpleTypeName();
    String entityVariable = StringUtils.uncapitalize(entity);
    JavaType finderParamType = parameterTypes.get(0).getJavaType();
    String finderParamName = parameterNames.get(0).getSymbolName();
    // Types to import
    bodyBuilder.newLine();
    // QEntity qEntity = QEntity.entity;
    bodyBuilder.appendFormalLine(String.format("%1$s %2$s = %1$s.%2$s;", getNameOfJavaType(entityQtype), entityVariable));
    bodyBuilder.newLine();
    // JPQLQuery query = from(qEntity);
    bodyBuilder.appendFormalLine(String.format("%s query = from(%s);", getNameOfJavaType(getJPQLQueryFor(this.entity)), entityVariable));
    bodyBuilder.newLine();
    buildFormBeanFilterBody(bodyBuilder, finderParamType, finderParamName, entityVariable, methodInfo.getRight());
    // return query.fetchCount();
    bodyBuilder.appendFormalLine("return query.fetchCount();");
    // Use provided finder method to generate its implementation
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, method.getReturnType(), parameterTypes, parameterNames, bodyBuilder);
    return methodBuilder.build();
}
Example 7
Project: querydsl-master  File: PackagelessEntityTest.java View source code
@SuppressWarnings("unchecked")
@Test
public void packageLess_path() {
    PathBuilder<PackagelessEntityTest> builder = new PathBuilder(PackagelessEntityTest.class, "entity");
    JPQLQuery<?> query = select(builder).from(builder);
    assertEquals("select entity\nfrom PackagelessEntityTest entity", query.toString());
}