diff --git a/querydsl-core/src/main/java/com/mysema/query/grammar/types/Projection.java b/querydsl-core/src/main/java/com/mysema/query/grammar/types/Projection.java index d986a264a..e97202366 100644 --- a/querydsl-core/src/main/java/com/mysema/query/grammar/types/Projection.java +++ b/querydsl-core/src/main/java/com/mysema/query/grammar/types/Projection.java @@ -1,9 +1,16 @@ +/* + * Copyright (c) 2009 Mysema Ltd. + * All rights reserved. + * + */ package com.mysema.query.grammar.types; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; +import java.util.HashSet; +import java.util.Set; /** * Projection provides @@ -13,6 +20,8 @@ import java.lang.reflect.ParameterizedType; */ public class Projection extends Path.PEntity{ + private Set fields = new HashSet(); + private String entityName; private static Method _numberMethod, _comparableMethod; @@ -37,6 +46,7 @@ public class Projection extends Path.PEntity{ for (Field field : cl.getDeclaredFields()){ if (Expr.class.isAssignableFrom(field.getType()) && field.getGenericType() instanceof ParameterizedType){ field.setAccessible(true); + fields.add(field.getName()); handleField(field); } } @@ -71,4 +81,8 @@ public class Projection extends Path.PEntity{ return entityName; } + public void accept(SubQuery query){ + // TODO : validate that the given SubQuery can be projected + } + } diff --git a/querydsl-core/src/main/java/com/mysema/query/grammar/types/SubQuery.java b/querydsl-core/src/main/java/com/mysema/query/grammar/types/SubQuery.java index 2712c6c5d..a924c6b8c 100644 --- a/querydsl-core/src/main/java/com/mysema/query/grammar/types/SubQuery.java +++ b/querydsl-core/src/main/java/com/mysema/query/grammar/types/SubQuery.java @@ -38,11 +38,15 @@ public class SubQuery extends Expr implements Query>, Co public SubQuery join(EEntity o) {query.join(o); return this;} public SubQuery leftJoin(EEntity o) {query.leftJoin(o); return this;} public SubQuery orderBy(OrderSpecifier... o) {query.orderBy(o); return this;} - public SubQuery select(Expr... o) {query.s(o); return this;} + public SubQuery select(Expr... o) { + query.s(o); return this;} public SubQuery where(EBoolean... o) {query.where(o); return this;} public SubQuery with(EBoolean o) {query.with(o); return this;} // TODO : add some validation that the given Projection is valid for this subquery - public Alias.ASimple as(Projection to) { return new Alias.ASimple(this, to.getName()); } + public Alias.ASimple as(Projection to) { + to.accept(this); + return new Alias.ASimple(this, to.getName()); + } public Alias.ASimple as(String to) { return new Alias.ASimple(this, to); } private static class QueryWithPublicSelect extends QueryBase>{