query.setShouldFilterDuplicates(false);
}
query.setExpressionBuilder(((InternalSelection)selection).getCurrentNode().getBuilder());
} else {
query = new ReportQuery();
query.setReferenceClass(((SelectionImpl) this.selection).getCurrentNode().getBuilder().getQueryClass());
if (!this.selection.isCompoundSelection() && ((InternalExpression) this.selection).isCompoundExpression()) {
if (((FunctionExpressionImpl) this.selection).getOperation() == CriteriaBuilderImpl.SIZE) {
//selecting size not all databases support subselect in select clause so convert to count/groupby
PathImpl collectionExpression = (PathImpl) ((FunctionExpressionImpl) this.selection).getChildExpressions().get(0);
ExpressionImpl fromExpression = (ExpressionImpl) collectionExpression.getParentPath();
((ReportQuery) query).addAttribute(this.selection.getAlias(), collectionExpression.getCurrentNode().count(), ClassConstants.INTEGER);
((ReportQuery) query).addGrouping(fromExpression.getCurrentNode());
}
((ReportQuery) query).addAttribute(this.selection.getAlias(), ((FunctionExpressionImpl) this.selection).getCurrentNode(), this.selection.getJavaType());
} else {
((ReportQuery) query).addItem(this.selection.getAlias(), ((SelectionImpl) this.selection).getCurrentNode());
((ReportQuery) query).setShouldReturnSingleAttribute(true);
}
}
}
} else if (this.queryResult.equals(ResultType.ENTITY)) {
if (this.selection != null && (!((InternalSelection) this.selection).isRoot())) {
query = new ReportQuery();
query.setReferenceClass(this.queryType);
((ReportQuery) query).addItem(this.selection.getAlias(), ((SelectionImpl) this.selection).getCurrentNode(), ((FromImpl) this.selection).findJoinFetches());
((ReportQuery) query).setShouldReturnSingleAttribute(true);
} else {
query = new ReadAllQuery(this.queryType);
if (this.roots != null && !this.roots.isEmpty()) {
List<org.eclipse.persistence.expressions.Expression> list = ((FromImpl) this.roots.iterator().next()).findJoinFetches();
if (!list.isEmpty()) {
query.setShouldFilterDuplicates(false);
query.setExpressionBuilder(list.get(0).getBuilder()); // set the builder to one of the fetches bases.
}
for (org.eclipse.persistence.expressions.Expression fetch : list) {
query.addJoinedAttribute(fetch);
}
}
if (selection != null) {
query.setExpressionBuilder(this.selection.currentNode.getBuilder());
}
}
} else {
ReportQuery reportQuery = null;
if (this.queryResult.equals(ResultType.TUPLE)) {
List list = new ArrayList();
list.add(this.selection);
reportQuery = new TupleQuery(list);
} else {
reportQuery = new ReportQuery();
reportQuery.setShouldReturnWithoutReportQueryResult(true);
}
if (this.selection != null) {
if (!this.selection.isCompoundSelection() && ((InternalExpression)this.selection).isCompoundExpression()){
if(((FunctionExpressionImpl)this.selection).getOperation() == CriteriaBuilderImpl.SIZE){
//selecting size not all databases support subselect in select clause so convert to count/groupby
PathImpl collectionExpression = (PathImpl) ((FunctionExpressionImpl)this.selection).getChildExpressions().get(0);
ExpressionImpl fromExpression = (ExpressionImpl) collectionExpression.getParentPath();
reportQuery.addAttribute(this.selection.getAlias(), collectionExpression.getCurrentNode().count(), ClassConstants.INTEGER);
reportQuery.addGrouping(fromExpression.getCurrentNode());
}else{
reportQuery.addAttribute(this.selection.getAlias(), ((FunctionExpressionImpl)this.selection).getCurrentNode(), this.selection.getJavaType());
}}else{
if (((InternalSelection) selection).isFrom()) {
reportQuery.addItem(selection.getAlias(), ((SelectionImpl) selection).getCurrentNode(), ((FromImpl) selection).findJoinFetches());
} else {
reportQuery.addAttribute(selection.getAlias(), ((SelectionImpl) selection).getCurrentNode(), selection.getJavaType());
}}
reportQuery.setReferenceClass(((InternalSelection) this.selection).getCurrentNode().getBuilder().getQueryClass());
reportQuery.setExpressionBuilder(((InternalSelection) this.selection).getCurrentNode().getBuilder());
}
query = reportQuery;
if (this.groupBy != null && !this.groupBy.isEmpty()) {
for (Expression<?> exp : this.groupBy) {
reportQuery.addGrouping(((InternalSelection) exp).getCurrentNode());
}
}
if (this.havingClause != null) {
reportQuery.setHavingExpression(((InternalSelection) this.havingClause).getCurrentNode());
}
}
if (query.getReferenceClass() == null){
if (this.where != null && ((InternalSelection) this.where).getCurrentNode() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder() != null && ((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass() != null) {
query.setReferenceClass(((InternalSelection) this.where).getCurrentNode().getBuilder().getQueryClass());