#810835 : added support for tuples in WHERE part

This commit is contained in:
Timo Westkämper 2011-08-05 06:41:17 +00:00
parent d80be58e19
commit cbf05c121f
2 changed files with 46 additions and 1 deletions

View File

@ -72,6 +72,8 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
private final JPQLTemplates templates;
private boolean inProjection = false;
static{
joinTypes.put(JoinType.DEFAULT, COMMA);
joinTypes.put(JoinType.FULLJOIN, "\n full join ");
@ -119,6 +121,8 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
List<OrderSpecifier<?>> orderBy = metadata.getOrderBy();
// select
boolean inProjectionOrig = inProjection;
inProjection = true;
if (projection != null){
append(SELECT).append(projection).append("\n");
@ -144,6 +148,7 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
handle(COMMA, select).append("\n");
}
inProjection = inProjectionOrig;
// from
append(FROM);
@ -270,7 +275,13 @@ public class JPQLSerializer extends SerializerBase<JPQLSerializer> {
@Override
public Void visit(FactoryExpression<?> expr, Void context) {
super.visit(expr, context);
if (!inProjection) {
append("(");
super.visit(expr, context);
append(")");
} else {
super.visit(expr, context);
}
return null;
}

View File

@ -0,0 +1,34 @@
package com.mysema.query.jpa;
import org.junit.Test;
import com.mysema.query.jpa.domain.QCat;
import com.mysema.query.jpa.hibernate.HibernateSubQuery;
import com.mysema.query.types.QTuple;
import com.mysema.query.types.SubQueryExpression;
public class TupleTest extends AbstractQueryTest {
@Test
public void test() {
QCat cat = QCat.cat;
SubQueryExpression<?> subQuery = subQuery().from(cat)
.where(subQuery()
.from(cat)
.groupBy(cat.mate)
.list(new QTuple(cat.mate, cat.birthdate.max()))
.contains(new QTuple(cat.mate, cat.birthdate)))
.list(new QTuple(cat.birthdate, cat.name, cat.mate));
assertToString(
"(select cat.birthdate, cat.name, cat.mate from Cat cat " +
"where (cat.mate, cat.birthdate) in " +
"(select cat.mate, max(cat.birthdate) from Cat cat group by cat.mate))", subQuery);
}
private HibernateSubQuery subQuery() {
return new HibernateSubQuery();
}
}