Java Examples for com.querydsl.core.types.OrderSpecifier
The following java examples will help you to understand the usage of com.querydsl.core.types.OrderSpecifier. These source code samples are taken from different open source projects.
Example 1
| Project: spring-data-keyvalue-master File: KeyValueQuerydslUtilsUnitTests.java View source code |
// DATACMNS-525
@Test
public void toOrderSpecifierConvertsSortCorrectlyAndRetainsArgumentOrder() {
Sort sort = Sort.by(Direction.DESC, "firstname").and(Sort.by(Direction.ASC, "age"));
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
assertThat(specifiers, IsArrayContainingInOrder.<OrderSpecifier<?>>arrayContaining(QPerson.person.firstname.desc(), QPerson.person.age.asc()));
}Example 2
| Project: owsi-core-parent-master File: JpaDaoSupport.java View source code |
public <T> List<T> listEntity(Class<T> objectClass) {
PathBuilder<T> pathBuilder = new PathBuilder<T>(objectClass, "rootAlias");
OrderSpecifier<?> order = null;
if (GenericEntity.class.isAssignableFrom(objectClass)) {
// cast possible puisqu'on vient de vérifier le type de objectclass
@SuppressWarnings("unchecked") QGenericEntity qGenericEntity = new QGenericEntity((Path<? extends GenericEntity<?, ?>>) (Object) pathBuilder);
order = qGenericEntity.id.asc();
}
return queryByPredicateOrdered(pathBuilder, null, order).fetch();
}Example 3
| Project: querydsl-master File: LuceneSerializer.java View source code |
public Sort toSort(List<? extends OrderSpecifier<?>> orderBys) { List<SortField> sorts = new ArrayList<SortField>(orderBys.size()); for (OrderSpecifier<?> order : orderBys) { if (!(order.getTarget() instanceof Path<?>)) { throw new IllegalArgumentException("argument was not of type Path."); } Class<?> type = order.getTarget().getType(); boolean reverse = !order.isAscending(); Path<?> path = getPath(order.getTarget()); if (Number.class.isAssignableFrom(type)) { sorts.add(new SortedNumericSortField(toField(path), sortFields.get(type), reverse)); } else { sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse)); } } Sort sort = new Sort(); sort.setSort(sorts.toArray(new SortField[sorts.size()])); return sort; }
Example 4
| Project: spring-data-commons-master File: QSort.java View source code |
/**
* Converts the given {@link OrderSpecifier} into an {@link Order}.
*
* @param orderSpecifier must not be {@literal null}.
* @return
*/
private static Order toOrder(OrderSpecifier<?> orderSpecifier) {
Assert.notNull(orderSpecifier, "Order specifier must not be null!");
Expression<?> target = orderSpecifier.getTarget();
Object targetElement = target instanceof Path ? preparePropertyPath((Path<?>) target) : target;
Assert.notNull(targetElement, "Target element must not be null!");
return Order.by(targetElement.toString()).with(orderSpecifier.isAscending() ? Direction.ASC : Direction.DESC);
}Example 5
| Project: SmallMind-master File: HibernateQueryUtility.java View source code |
public static HibernateQuery<?> apply(HibernateQuery<?> query, Sort sort) {
if ((sort != null) && (!sort.isEmpty())) {
OrderSpecifier[] orderSpecifiers;
LinkedList<OrderSpecifier<?>> orderSpecifierList = new LinkedList<>();
for (SortField sortField : sort.getFields()) {
switch(sortField.getDirection()) {
case ASC:
orderSpecifierList.add(new OrderSpecifier<>(Order.ASC, Expressions.path(String.class, sortField.getName())));
break;
case DESC:
orderSpecifierList.add(new OrderSpecifier<>(Order.DESC, Expressions.path(String.class, sortField.getName())));
break;
default:
throw new UnknownSwitchCaseException(sortField.getDirection().name());
}
}
orderSpecifiers = new OrderSpecifier[orderSpecifierList.size()];
orderSpecifierList.toArray(orderSpecifiers);
query.orderBy(orderSpecifiers);
}
return query;
}Example 6
| Project: spring-data-mongodb-master File: QueryDslMongoRepository.java View source code |
/**
* Applies the given {@link Sort} to the given {@link MongodbQuery}.
*
* @param query
* @param sort
* @return
*/
private AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> applySorting(AbstractMongodbQuery<T, SpringDataMongodbQuery<T>> query, Sort sort) {
// TODO: find better solution than instanceof check
if (sort instanceof QSort) {
List<OrderSpecifier<?>> orderSpecifiers = ((QSort) sort).getOrderSpecifiers();
query.orderBy(orderSpecifiers.toArray(new OrderSpecifier<?>[orderSpecifiers.size()]));
return query;
}
sort.stream().map(this::toOrder).forEach( it -> query.orderBy(it));
return query;
}Example 7
| Project: timetracker-master File: WorklogDetailsReportQueryBuilder.java View source code |
@Override
public List<WorklogDetailsDTO> call(final Connection connection, final Configuration configuration) throws SQLException {
SQLQuery<WorklogDetailsDTO> query = new SQLQuery<WorklogDetailsDTO>(connection, configuration).select(createQuerySelectProjection());
appendBaseFromAndJoin(query);
appendBaseWhere(query);
appendQueryRange(query);
Expression<?> expression = orderByMap.get(orderBy.columnName);
Order order = Order.DESC;
if (expression == null) {
expression = orderByMap.get(OrderBy.DEFAULT.columnName);
order = Order.ASC;
} else {
if (orderBy.asc) {
order = Order.ASC;
}
}
query.orderBy(new OrderSpecifier(order, expression));
List<WorklogDetailsDTO> result = query.fetch();
extendResult(connection, configuration, result);
return result;
}Example 8
| Project: javersion-master File: AbstractVersionStoreJdbc.java View source code |
protected List<Group> fetchVersionsAndParents(boolean optimized, BooleanExpression predicate, OrderSpecifier<?> orderBy) {
SQLQuery<?> qry = options.queryFactory.from(options.version).where(predicate).orderBy(orderBy);
if (optimized) {
qry.leftJoin(options.parent).on(options.parent.revision.eq(options.version.revision), options.parent.status.goe(ACTIVE));
qry.where(options.version.status.goe(ACTIVE));
} else {
qry.leftJoin(options.parent).on(options.parent.revision.eq(options.version.revision), options.parent.status.loe(ACTIVE));
qry.where(options.version.status.loe(ACTIVE));
}
return qry.transform(versionAndParents);
}Example 9
| Project: querydsl-contrib-master File: AbstractIMapQuery.java View source code |
@Override
public AbstractIMapQuery<Q> orderBy(OrderSpecifier<?>... o) {
return queryMixin.orderBy(o);
}Example 10
| Project: spring-data-jpa-master File: Querydsl.java View source code |
/**
* Applies the given {@link OrderSpecifier}s to the given {@link JPQLQuery}. Potentially transforms the given
* {@code OrderSpecifier}s to be able to injection potentially necessary left-joins.
*
* @param qsort must not be {@literal null}.
* @param query must not be {@literal null}.
*/
private <T> JPQLQuery<T> addOrderByFrom(QSort qsort, JPQLQuery<T> query) {
List<OrderSpecifier<?>> orderSpecifiers = qsort.getOrderSpecifiers();
return query.orderBy(orderSpecifiers.toArray(new OrderSpecifier[orderSpecifiers.size()]));
}