DATACMNS-566 - Allow sorting by QueryDsl operator expressions.

Previously we only allowed to sort by QueryDsl path expressions. With this change we now also support ordering by operator expressions, e.g. yearMonth() on a date property.

Original pull request: #94.
This commit is contained in:
Thomas Darimont
2014-08-26 13:38:19 +02:00
committed by Oliver Gierke
parent edfd341d64
commit 9fc57ea3bf
3 changed files with 26 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors.
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.springframework.util.Assert;
import com.mysema.query.types.Expression;
import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.Path;
/**
* Sort option for queries that wraps a querydsl {@link OrderSpecifier}.
@@ -86,7 +87,8 @@ public class QSort extends Sort implements Serializable {
Assert.notNull(orderSpecifier, "Order specifier must not be null!");
Expression<?> target = orderSpecifier.getTarget();
Object targetElement = ((com.mysema.query.types.Path<?>) target).getMetadata().getElement();
Object targetElement = target instanceof Path ? ((com.mysema.query.types.Path<?>) target).getMetadata()
.getElement() : target;
Assert.notNull(targetElement, "Target element must not be null!");