@SuppressWarnings("unchecked") @Test public void applyPageableToQuery() { Pageable pageable = PageRequest.of(1, 3, Sort.by("name", "email")); Return<? extends Result<BasicUser>> query = (Return<? extends Result<BasicUser>>) RequeryUtils.applyPageable(BasicUser.class, (QueryElement<? extends Result<BasicUser>>) dataStore.select(BasicUser.class), pageable); assertThat(query).isInstanceOf(QueryElement.class); assertThat(query).isInstanceOf(Limit.class); assertThat(query).isInstanceOf(Offset.class); QueryElement<? extends Result<BasicUser>> queryElement = (QueryElement<? extends Result<BasicUser>>) query; assertThat(queryElement).isNotNull(); assertThat(queryElement.getOrderByExpressions()).isNotEmpty(); for (Expression<?> expr : queryElement.getOrderByExpressions()) { log.debug("order by {}", expr); } }
@SuppressWarnings("unchecked") @Nonnull public static <E> QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass, @Nonnull final QueryElement<?> baseQuery, @Nonnull final Pageable pageable) { Assert.notNull(domainClass, "domainClass must not be null!"); Assert.notNull(baseQuery, "baseQuery must not be null!"); Assert.notNull(pageable, "pageable must not be null!"); if (pageable.isUnpaged()) { return baseQuery; } log.trace("Apply paging, domainClass={}, pageable={}", domainClass.getSimpleName(), pageable); QueryElement<?> query = baseQuery; if (pageable.getSort().isSorted()) { query = applySort(domainClass, query, pageable.getSort()); } if (pageable.getPageSize() > 0 && query.getLimit() == null) { query = unwrap(query.limit(pageable.getPageSize())); } if (pageable.getOffset() > 0 && query.getOffset() == null) { query = unwrap(query.offset((int) pageable.getOffset())); } return query; }
RequeryUtils { @SuppressWarnings("unchecked") @Nonnull public static <E> QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass, @Nonnull final QueryElement<?> baseQuery, @Nonnull final Pageable pageable) { Assert.notNull(domainClass, "domainClass must not be null!"); Assert.notNull(baseQuery, "baseQuery must not be null!"); Assert.notNull(pageable, "pageable must not be null!"); if (pageable.isUnpaged()) { return baseQuery; } log.trace("Apply paging, domainClass={}, pageable={}", domainClass.getSimpleName(), pageable); QueryElement<?> query = baseQuery; if (pageable.getSort().isSorted()) { query = applySort(domainClass, query, pageable.getSort()); } if (pageable.getPageSize() > 0 && query.getLimit() == null) { query = unwrap(query.limit(pageable.getPageSize())); } if (pageable.getOffset() > 0 && query.getOffset() == null) { query = unwrap(query.offset((int) pageable.getOffset())); } return query; } }
RequeryUtils { @SuppressWarnings("unchecked") @Nonnull public static <E> QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass, @Nonnull final QueryElement<?> baseQuery, @Nonnull final Pageable pageable) { Assert.notNull(domainClass, "domainClass must not be null!"); Assert.notNull(baseQuery, "baseQuery must not be null!"); Assert.notNull(pageable, "pageable must not be null!"); if (pageable.isUnpaged()) { return baseQuery; } log.trace("Apply paging, domainClass={}, pageable={}", domainClass.getSimpleName(), pageable); QueryElement<?> query = baseQuery; if (pageable.getSort().isSorted()) { query = applySort(domainClass, query, pageable.getSort()); } if (pageable.getPageSize() > 0 && query.getLimit() == null) { query = unwrap(query.limit(pageable.getPageSize())); } if (pageable.getOffset() > 0 && query.getOffset() == null) { query = unwrap(query.offset((int) pageable.getOffset())); } return query; }  }
RequeryUtils { @SuppressWarnings("unchecked") @Nonnull public static <E> QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass, @Nonnull final QueryElement<?> baseQuery, @Nonnull final Pageable pageable) { Assert.notNull(domainClass, "domainClass must not be null!"); Assert.notNull(baseQuery, "baseQuery must not be null!"); Assert.notNull(pageable, "pageable must not be null!"); if (pageable.isUnpaged()) { return baseQuery; } log.trace("Apply paging, domainClass={}, pageable={}", domainClass.getSimpleName(), pageable); QueryElement<?> query = baseQuery; if (pageable.getSort().isSorted()) { query = applySort(domainClass, query, pageable.getSort()); } if (pageable.getPageSize() > 0 && query.getLimit() == null) { query = unwrap(query.limit(pageable.getPageSize())); } if (pageable.getOffset() > 0 && query.getOffset() == null) { query = unwrap(query.offset((int) pageable.getOffset())); } return query; }  @Nonnull static NamedExpression<?> getKeyExpression(@Nonnull final Class<?> domainClass); @SuppressWarnings("ConstantConditions") @Nonnull static EntityContext getEntityContext(@Nonnull final EntityDataStore entityDataStore); @SuppressWarnings("ConstantConditions") @Nonnull static EntityModel getEntityModel(@Nonnull final EntityDataStore entityDataStore); @Nonnull static Set<Type<?>> getEntityTypes(@Nonnull final EntityDataStore entityDataStore); @Nonnull static List<Class<?>> getEntityClasses(@Nonnull final EntityDataStore entityDataStore); @SuppressWarnings("unchecked") @Nullable static Type<E> getType(@Nonnull final EntityDataStore entityDataStore,
                                      @Nonnull final Class<E> entityClass); static Set<? extends Attribute<E, ?>> getKeyAttributes(@Nonnull final EntityDataStore entityDataStore,
                                                                      @Nonnull final Class<E> entityClass); @Nullable static Attribute<E, ?> getSingleKeyAttribute(@Nonnull final EntityDataStore entityDataStore,
                                                            @Nonnull final Class<E> entityClass); @SuppressWarnings("ConstantConditions") @Nonnull static QueryElement<?> unwrap(@Nonnull final Return<?> wrapper); @SuppressWarnings("unchecked") @Nonnull static QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass,
                                                    @Nonnull final QueryElement<?> baseQuery,
                                                    @Nonnull final Pageable pageable); @SuppressWarnings("unchecked") static QueryElement<?> applySort(@Nonnull final Class<E> domainClass,
                                                @Nonnull final QueryElement<?> baseQuery,
                                                @Nonnull final Sort sort); static @Nonnull OrderingExpression<?>[] getOrderingExpressions(@Nonnull final Class<?> domainClass,
                                                   @Nullable final Sort sort); @SuppressWarnings("unchecked") @Nullable static LogicalCondition<E, ?> foldConditions(@Nonnull final Iterable<Condition<E, ?>> conditions); @SuppressWarnings("unchecked") @Nullable static LogicalCondition<E, ?> foldConditions(@Nonnull final Iterable<Condition<E, ?>> conditions,
                                                            @Nonnull final LogicalOperator operator); @Nonnull static QueryElement<?> applyWhereClause(@Nonnull final QueryElement<?> baseQuery,
                                                   @Nonnull final Set<WhereConditionElement<?>> conditionElements); @Nullable static Field findField(@Nonnull final Class<?> domainClass,
                                  @Nonnull final String fieldName); @Nonnull static List<Field> findFields(@Nonnull final Class<?> domainClass,
                                         @Nonnull final Predicate<Field> fieldPredicate); @Nullable static Field findFirstField(@Nonnull final Class<?> domainClass,
                                       @Nonnull final Predicate<Field> fieldPredicate); @Nonnull static List<Field> findEntityFields(@Nonnull final Class<?> domainClass); static boolean isRequeryEntityField(@Nonnull final Field field); static boolean isRequeryGeneratedField(@Nonnull final Field field); static boolean isTransientField(@Nonnull final Field field); static boolean isEmbededField(@Nonnull final Field field); static boolean isAssociationField(@Nonnull final Field field); }
RequeryUtils { @SuppressWarnings("unchecked") @Nonnull public static <E> QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass, @Nonnull final QueryElement<?> baseQuery, @Nonnull final Pageable pageable) { Assert.notNull(domainClass, "domainClass must not be null!"); Assert.notNull(baseQuery, "baseQuery must not be null!"); Assert.notNull(pageable, "pageable must not be null!"); if (pageable.isUnpaged()) { return baseQuery; } log.trace("Apply paging, domainClass={}, pageable={}", domainClass.getSimpleName(), pageable); QueryElement<?> query = baseQuery; if (pageable.getSort().isSorted()) { query = applySort(domainClass, query, pageable.getSort()); } if (pageable.getPageSize() > 0 && query.getLimit() == null) { query = unwrap(query.limit(pageable.getPageSize())); } if (pageable.getOffset() > 0 && query.getOffset() == null) { query = unwrap(query.offset((int) pageable.getOffset())); } return query; }  @Nonnull static NamedExpression<?> getKeyExpression(@Nonnull final Class<?> domainClass); @SuppressWarnings("ConstantConditions") @Nonnull static EntityContext getEntityContext(@Nonnull final EntityDataStore entityDataStore); @SuppressWarnings("ConstantConditions") @Nonnull static EntityModel getEntityModel(@Nonnull final EntityDataStore entityDataStore); @Nonnull static Set<Type<?>> getEntityTypes(@Nonnull final EntityDataStore entityDataStore); @Nonnull static List<Class<?>> getEntityClasses(@Nonnull final EntityDataStore entityDataStore); @SuppressWarnings("unchecked") @Nullable static Type<E> getType(@Nonnull final EntityDataStore entityDataStore,
                                      @Nonnull final Class<E> entityClass); static Set<? extends Attribute<E, ?>> getKeyAttributes(@Nonnull final EntityDataStore entityDataStore,
                                                                      @Nonnull final Class<E> entityClass); @Nullable static Attribute<E, ?> getSingleKeyAttribute(@Nonnull final EntityDataStore entityDataStore,
                                                            @Nonnull final Class<E> entityClass); @SuppressWarnings("ConstantConditions") @Nonnull static QueryElement<?> unwrap(@Nonnull final Return<?> wrapper); @SuppressWarnings("unchecked") @Nonnull static QueryElement<?> applyPageable(@Nonnull final Class<E> domainClass,
                                                    @Nonnull final QueryElement<?> baseQuery,
                                                    @Nonnull final Pageable pageable); @SuppressWarnings("unchecked") static QueryElement<?> applySort(@Nonnull final Class<E> domainClass,
                                                @Nonnull final QueryElement<?> baseQuery,
                                                @Nonnull final Sort sort); static @Nonnull OrderingExpression<?>[] getOrderingExpressions(@Nonnull final Class<?> domainClass,
                                                   @Nullable final Sort sort); @SuppressWarnings("unchecked") @Nullable static LogicalCondition<E, ?> foldConditions(@Nonnull final Iterable<Condition<E, ?>> conditions); @SuppressWarnings("unchecked") @Nullable static LogicalCondition<E, ?> foldConditions(@Nonnull final Iterable<Condition<E, ?>> conditions,
                                                            @Nonnull final LogicalOperator operator); @Nonnull static QueryElement<?> applyWhereClause(@Nonnull final QueryElement<?> baseQuery,
                                                   @Nonnull final Set<WhereConditionElement<?>> conditionElements); @Nullable static Field findField(@Nonnull final Class<?> domainClass,
                                  @Nonnull final String fieldName); @Nonnull static List<Field> findFields(@Nonnull final Class<?> domainClass,
                                         @Nonnull final Predicate<Field> fieldPredicate); @Nullable static Field findFirstField(@Nonnull final Class<?> domainClass,
                                       @Nonnull final Predicate<Field> fieldPredicate); @Nonnull static List<Field> findEntityFields(@Nonnull final Class<?> domainClass); static boolean isRequeryEntityField(@Nonnull final Field field); static boolean isRequeryGeneratedField(@Nonnull final Field field); static boolean isTransientField(@Nonnull final Field field); static boolean isEmbededField(@Nonnull final Field field); static boolean isAssociationField(@Nonnull final Field field); static final NamedExpression<?> UNKNOWN_KEY_EXPRESSION; }