mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-27 21:01:15 +08:00
Improve QBean alias handling
This commit is contained in:
parent
60c46b1d71
commit
ef9a74a80e
@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.primitives.Primitives;
|
||||
import com.querydsl.core.group.GroupExpression;
|
||||
|
||||
/**
|
||||
* {@code QBean} is a JavaBean populating projection type
|
||||
@ -61,7 +62,11 @@ public class QBean<T> extends FactoryExpressionBase<T> {
|
||||
Operation<?> operation = (Operation<?>) expr;
|
||||
if (operation.getOperator() == Ops.ALIAS && operation.getArg(1) instanceof Path<?>) {
|
||||
Path<?> path = (Path<?>) operation.getArg(1);
|
||||
rv.put(path.getMetadata().getName(), operation.getArg(0));
|
||||
if (isCompoundExpression(operation.getArg(0))) {
|
||||
rv.put(path.getMetadata().getName(), operation.getArg(0));
|
||||
} else {
|
||||
rv.put(path.getMetadata().getName(), operation);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported expression " + expr);
|
||||
}
|
||||
@ -73,6 +78,10 @@ public class QBean<T> extends FactoryExpressionBase<T> {
|
||||
return rv.build();
|
||||
}
|
||||
|
||||
private static boolean isCompoundExpression(Expression<?> expr) {
|
||||
return expr instanceof FactoryExpression || expr instanceof GroupExpression;
|
||||
}
|
||||
|
||||
private static Class<?> normalize(Class<?> cl) {
|
||||
return cl.isPrimitive() ? Primitives.wrap(cl) : cl;
|
||||
}
|
||||
|
||||
@ -180,4 +180,10 @@ public class QBeanTest {
|
||||
assertFalse(bean.equals(bean.skipNulls()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Alias() {
|
||||
QBean<Entity> beanProjection = new QBean<Entity>(Entity.class, name.as("name2"));
|
||||
assertEquals(name.as("name2"), beanProjection.getArgs().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user