@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); }
/** * Setter to inject {@link EntityManager}. * * @param entityManager must not be {@literal null}. */ @Autowired public void setEntityManager(EntityManager entityManager) { Assert.notNull(entityManager, "EntityManager must not be null!"); this.querydsl = new Querydsl(entityManager, builder); this.entityManager = entityManager; }
/** * Creates the {@link JPQLQuery} instance based on the configured {@link EntityManager}. * * @return */ public AbstractJPAQuery<Object, JPAQuery<Object>> createQuery(EntityPath<?>... paths) { return createQuery().from(paths); }
/** * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. * * @param order must not be {@literal null}. * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) private OrderSpecifier<?> toOrderSpecifier(Order order) { return new OrderSpecifier( order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, buildOrderPropertyPathFrom(order), toQueryDslNullHandling(order.getNullHandling())); }
public Page<CardCategoryLevel> findAll(Predicate predicate, Pageable pageable) { JPAQuery countQuery = createQuery(predicate); JPAQuery query = (JPAQuery) querydsl.applyPagination(pageable, createQuery(predicate)); return querydsl.createQuery(path).where(predicate);
/** * Executes the given {@link JPQLQuery} after applying the given {@link Sort}. * * @param query must not be {@literal null}. * @param sort must not be {@literal null}. * @return */ private List<T> executeSorted(JPQLQuery<T> query, Sort sort) { return querydsl.applySorting(sort, query).fetch(); } }
/** * Applies sorting to the given {@link JPQLQuery}. * * @param sort * @param query must not be {@literal null}. * @return the Querydsl {@link JPQLQuery} */ public <T> JPQLQuery<T> applySorting(Sort sort, JPQLQuery<T> query) { if (sort.isUnsorted()) { return query; } if (sort instanceof QSort) { return addOrderByFrom((QSort) sort, query); } return addOrderByFrom(sort, query); }
/** * Executes the given {@link JPQLQuery} after applying the given {@link Sort}. * * @param query must not be {@literal null}. * @param sort must not be {@literal null}. * @return */ private List<T> executeSorted(JPQLQuery<T> query, Sort sort) { return querydsl.applySorting(sort, query).fetch(); } }
/** * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. * * @param order must not be {@literal null}. * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) private OrderSpecifier<?> toOrderSpecifier(Order order) { return new OrderSpecifier( order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC, buildOrderPropertyPathFrom(order), toQueryDslNullHandling(order.getNullHandling())); }
/** * Applies sorting to the given {@link JPQLQuery}. * * @param sort * @param query must not be {@literal null}. * @return the Querydsl {@link JPQLQuery} */ public <T> JPQLQuery<T> applySorting(Sort sort, JPQLQuery<T> query) { if (sort.isUnsorted()) { return query; } if (sort instanceof QSort) { return addOrderByFrom((QSort) sort, query); } return addOrderByFrom(sort, query); }
@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); }
/** * Returns a fresh {@link JPQLQuery}. * * @param paths must not be {@literal null}. * @return the Querydsl {@link JPQLQuery}. */ protected JPQLQuery<Object> from(EntityPath<?>... paths) { return getRequiredQuerydsl().createQuery(paths); }
/** * Creates a new {@link QuerydslJpaPredicateExecutor} from the given domain class and {@link EntityManager} and uses * the given {@link EntityPathResolver} to translate the domain class into an {@link EntityPath}. * * @param entityInformation must not be {@literal null}. * @param entityManager must not be {@literal null}. * @param resolver must not be {@literal null}. * @param metadata maybe {@literal null}. */ public QuerydslJpaPredicateExecutor(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager, EntityPathResolver resolver, @Nullable CrudMethodMetadata metadata) { this.entityInformation = entityInformation; this.metadata = metadata; this.path = resolver.createPath(entityInformation.getJavaType()); this.querydsl = new Querydsl(entityManager, new PathBuilder<T>(path.getType(), path.getMetadata())); this.entityManager = entityManager; }
/** * Applies the given {@link Pageable} to the given {@link JPQLQuery}. * * @param pageable * @param query must not be {@literal null}. * @return the Querydsl {@link JPQLQuery}. */ public <T> JPQLQuery<T> applyPagination(Pageable pageable, JPQLQuery<T> query) { if (pageable.isUnpaged()) { return query; } query.offset(pageable.getOffset()); query.limit(pageable.getPageSize()); return applySorting(pageable.getSort(), query); }
@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); }
private AbstractJPAQuery<?, ?> doCreateQuery(QueryHints hints, @Nullable Predicate... predicate) { AbstractJPAQuery<?, ?> query = querydsl.createQuery(path); if (predicate != null) { query = query.where(predicate); } for (Entry<String, Object> hint : hints) { query.setHint(hint.getKey(), hint.getValue()); } return query; }
/** * Creates a new {@link QuerydslJpaRepository} from the given domain class and {@link EntityManager} and uses the * given {@link EntityPathResolver} to translate the domain class into an {@link EntityPath}. * * @param entityInformation must not be {@literal null}. * @param entityManager must not be {@literal null}. * @param resolver must not be {@literal null}. */ public QuerydslJpaRepository(JpaEntityInformation<T, ID> entityInformation, EntityManager entityManager, EntityPathResolver resolver) { super(entityInformation, entityManager); this.path = resolver.createPath(entityInformation.getJavaType()); this.builder = new PathBuilder<T>(path.getType(), path.getMetadata()); this.querydsl = new Querydsl(entityManager, builder); this.entityManager = entityManager; }
/** * Executes the given {@link JPQLQuery} after applying the given {@link Sort}. * * @param query must not be {@literal null}. * @param sort must not be {@literal null}. * @return */ private List<T> executeSorted(JPQLQuery<T> query, Sort sort) { return querydsl.applySorting(sort, query).fetch(); } }
@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); }
private AbstractJPAQuery<?, ?> doCreateQuery(QueryHints hints, @Nullable Predicate... predicate) { AbstractJPAQuery<?, ?> query = querydsl.createQuery(path); if (predicate != null) { query = query.where(predicate); } for (Entry<String, Object> hint : hints) { query.setHint(hint.getKey(), hint.getValue()); } return query; }