Class<?> resultClass = null;
ResultShape<?> resultShape = null;
if (count > 1) {
// muti-selection
resultClass = Object[].class;
resultShape = new ResultShape(resultClass, new FillStrategy.Array<Object[]>(Object[].class));
}
for (int i = 0; i < count; i++) {
JPQLNode parent = selectionsNode.getChild(i);
JPQLNode node = firstChild(parent);
if (node.id == JJTCONSTRUCTOR) {
// build up the fully-qualified result class name by
// appending together the components of the children
String resultClassName = assemble(left(node));
Class<?> constructor = resolver.classForName(resultClassName, null);
if (constructor == null) {
// try resolve it again using simple name
int n = left(node).getChildCount();
String baseName = left(node).getChild(n-1).text;
constructor = resolver.classForName(baseName, null);
}
if (constructor == null)
throw parseException(EX_USER, "no-constructor",
new Object[]{ resultClassName }, null);
List<Value> terms = new ArrayList<Value>();
List<String> aliases = new ArrayList<String>();
List<String> clauses = new ArrayList<String>();
// now assign the arguments to the select clause as the projections
assignProjections(right(node), exps, terms, aliases, clauses);
FillStrategy fill = new FillStrategy.NewInstance(constructor);
ResultShape<?> cons = new ResultShape(constructor, fill);
for (Value val : terms) {
Class<?> type = val.getType();
cons.nest(new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive()));
}
if (count == 1) {
resultClass = constructor;
resultShape = cons;
}
else
resultShape.nest(cons);
projections.addAll(terms);
projectionAliases.addAll(aliases);
projectionClauses.addAll(clauses);
} else {
JPQLNode aliasNode = parent.children.length > 1 ? right(parent)
: null;
Value proj = getValue(node);
String alias = aliasNode != null ? aliasNode.text :
projectionClause(node.id == JJTSCALAREXPRESSION ?
firstChild(node) : node);
if (aliasNode != null)
proj.setAlias(alias);
projections.add(proj);
projectionClauses.add(alias);
projectionAliases.add(alias);
Class<?> type = proj.getType();
ResultShape<?> projShape = new ResultShape(type, new FillStrategy.Assign(), type.isPrimitive());
if (count == 1)
resultShape = projShape;
else
resultShape.nest(projShape);