mirror of
https://github.com/querydsl/querydsl.git
synced 2026-07-03 21:07:49 +08:00
Fix order by handling for subqueries
This commit is contained in:
parent
acd71883ed
commit
762cc23c49
@ -13,17 +13,22 @@
|
||||
*/
|
||||
package com.mysema.query.jpa;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mysema.query.JoinFlag;
|
||||
import com.mysema.query.QueryMetadata;
|
||||
import com.mysema.query.support.*;
|
||||
import com.mysema.query.support.Context;
|
||||
import com.mysema.query.support.PathsExtractor;
|
||||
import com.mysema.query.support.QueryMixin;
|
||||
import com.mysema.query.support.ReplaceVisitor;
|
||||
import com.mysema.query.types.*;
|
||||
import com.mysema.query.types.path.CollectionPathBase;
|
||||
|
||||
@ -170,6 +175,9 @@ public class JPAQueryMixin<T> extends QueryMixin<T> {
|
||||
public Expression<?> visit(Path<?> expr, Void context) {
|
||||
return convertPathForOrder(expr);
|
||||
}
|
||||
public Expression<?> visit(SubQueryExpression<?> expr, @Nullable Void context) {
|
||||
return expr;
|
||||
}
|
||||
};
|
||||
}
|
||||
expr = (Expression<RT>)expr.accept(replaceVisitor, null);
|
||||
|
||||
@ -20,6 +20,7 @@ import org.junit.Test;
|
||||
import com.mysema.query.domain.QCat;
|
||||
import com.mysema.query.jpa.domain.QEmployee;
|
||||
import com.mysema.query.jpa.domain.QUser;
|
||||
import com.mysema.query.types.query.NumberSubQuery;
|
||||
|
||||
public class SubQueryTest extends AbstractQueryTest{
|
||||
|
||||
@ -190,5 +191,15 @@ public class SubQueryTest extends AbstractQueryTest{
|
||||
assertToString("(select count(cat) from Cat cat where locate(?1,cat.name)-1 = ?2)",
|
||||
sub().from(cat).where(cat.name.indexOf("a").eq(1)).count());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OrderBy() {
|
||||
JPQLQuery query = query().from(cat1).where(cat1.alive);
|
||||
NumberSubQuery<Double> subquery = sub().from(cat).where(cat.mate.id.eq(cat1.id)).unique(cat.floatProperty.avg());
|
||||
query.orderBy(subquery.subtract(-1.0f).asc());
|
||||
|
||||
assertEquals("select cat1 from Cat cat1 where cat1.alive order by (select avg(cat.floatProperty) from Cat cat where cat.mate.id = cat1.id) - ?1 asc",
|
||||
query.toString().replace("\n", " "));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user