org.springframework.data.querydsl.QSort Java Examples
The following examples show how to use
org.springframework.data.querydsl.QSort.
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: KeyValueQuerydslUtils.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
/** * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. * * @param sort must not be {@literal null}. * @param builder must not be {@literal null}. * @return empty {@code OrderSpecifier<?>[]} when sort is {@literal null}. */ static OrderSpecifier<?>[] toOrderSpecifier(Sort sort, PathBuilder<?> builder) { Assert.notNull(sort, "Sort must not be null."); Assert.notNull(builder, "Builder must not be null."); List<OrderSpecifier<?>> specifiers = null; if (sort instanceof QSort) { specifiers = ((QSort) sort).getOrderSpecifiers(); } else { specifiers = new ArrayList<>(); for (Order order : sort) { specifiers.add(toOrderSpecifier(order, builder)); } } return specifiers.toArray(new OrderSpecifier<?>[specifiers.size()]); }
Example #2
Source File: QuerydslSQL.java From spring-boot-practice with Apache License 2.0 | 5 votes |
public JPASQLQuery applySorting(Sort sort, JPASQLQuery query) { if (sort == null) { return query; } if (sort instanceof QSort) { return addOrderByFrom((QSort) sort, query); } return addOrderByFrom(sort, query); }
Example #3
Source File: QuerydslSQL.java From spring-boot-practice with Apache License 2.0 | 5 votes |
public JPASQLQuery applySorting(Sort sort, JPASQLQuery query) { if (sort == null) { return query; } if (sort instanceof QSort) { return addOrderByFrom((QSort) sort, query); } return addOrderByFrom(sort, query); }
Example #4
Source File: CustomerRepositoryIntegrationTest.java From spring-data-examples with Apache License 2.0 | 5 votes |
/** * Test case to show the usage of the Querydsl-specific {@link QSort} to define the sort order in a type-safe way. */ @Test public void findCustomersUsingQuerydslSort() { QCustomer customer = QCustomer.customer; List<Customer> result = repository.findByLastname("Matthews", new QSort(customer.firstname.asc())); assertThat(result, hasSize(2)); assertThat(result.get(0), is(dave)); assertThat(result.get(1), is(oliver)); }
Example #5
Source File: QuerydslSQL.java From spring-boot-practice with Apache License 2.0 | 4 votes |
private JPASQLQuery addOrderByFrom(QSort qsort, JPASQLQuery query) { List<OrderSpecifier<?>> orderSpecifiers = qsort.getOrderSpecifiers(); return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()])); }
Example #6
Source File: QuerydslSQL.java From spring-boot-practice with Apache License 2.0 | 4 votes |
private JPASQLQuery addOrderByFrom(QSort qsort, JPASQLQuery query) { List<OrderSpecifier<?>> orderSpecifiers = qsort.getOrderSpecifiers(); return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()])); }
Example #7
Source File: QuerydslKeyValueRepositoryUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 4 votes |
@Test // DATAKV-90, DATAKV-197 public void findAllShouldRequireSort() { assertThatIllegalArgumentException().isThrownBy(() -> repository.findAll((QSort) null)); }
Example #8
Source File: QuerydslKeyValueRepositoryUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 3 votes |
@Test // DATACMNS-525 public void findAllUsingPagableWithQSortWorksCorrectly() { repository.saveAll(LENNISTERS); Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), PageRequest.of(0, 10, new QSort(QPerson.person.firstname.desc()))); assertThat(result).containsExactly(JAIME, CERSEI); }
Example #9
Source File: QuerydslKeyValueRepositoryUnitTests.java From spring-data-keyvalue with Apache License 2.0 | 3 votes |
@Test // DATAKV-90 public void findAllWithOrderSpecifierWorksCorrectly() { repository.saveAll(LENNISTERS); Iterable<Person> result = repository.findAll(new QSort(QPerson.person.firstname.desc())); assertThat(result).containsExactly(TYRION, JAIME, CERSEI); }
Example #10
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest}. Pages are zero indexed, thus providing 0 for {@code page} will return the first * page. * * @param page * @param size */ public CustomPageRequest(int page, int size) { this(page != 0 ? page - 1 : 0, size, QSort.unsorted()); }
Example #11
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest} with the given {@link OrderSpecifier}s applied. * * @param page * @param size * @param orderSpecifiers must not be {@literal null} or empty; */ public CustomPageRequest(int page, int size, OrderSpecifier<?>... orderSpecifiers) { this(page, size, new QSort(orderSpecifiers)); }
Example #12
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest} with sort parameters applied. * * @param page * @param size * @param sort */ public CustomPageRequest(int page, int size, QSort sort) { super(page, size); this.sort = sort; }
Example #13
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest}. Pages are zero indexed, thus providing 0 for {@code page} will return the first * page. * * @param page * @param size */ public CustomPageRequest(int page, int size) { this(page != 0 ? page - 1 : 0, size, QSort.unsorted()); }
Example #14
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest} with the given {@link OrderSpecifier}s applied. * * @param page * @param size * @param orderSpecifiers must not be {@literal null} or empty; */ public CustomPageRequest(int page, int size, OrderSpecifier<?>... orderSpecifiers) { this(page, size, new QSort(orderSpecifiers)); }
Example #15
Source File: CustomPageRequest.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * Creates a new {@link CustomPageRequest} with sort parameters applied. * * @param page * @param size * @param sort */ public CustomPageRequest(int page, int size, QSort sort) { super(page, size); this.sort = sort; }