* It recurses computing the nested mapping queries.
*/
protected void computeNestedQueriesForBatchReadExpressions(List<Expression> batchReadExpressions) {
int size = batchReadExpressions.size();
for (int index = 0; index < size; index++) {
ObjectExpression objectExpression = (ObjectExpression)batchReadExpressions.get(index);
// Expression may not have been initialized.
ExpressionBuilder builder = objectExpression.getBuilder();
if (builder.getSession() == null) {
builder.setSession(getSession().getRootSession(null));
}
if (builder.getQueryClass() == null) {
builder.setQueryClass(getReferenceClass());
}
// PERF: Cache join attribute names.
ObjectExpression baseExpression = objectExpression;
while (!baseExpression.getBaseExpression().isExpressionBuilder()) {
baseExpression = (ObjectExpression)baseExpression.getBaseExpression();
}
this.batchFetchPolicy.getAttributes().add(baseExpression.getName());
DatabaseMapping mapping = baseExpression.getMapping();
if ((mapping != null) && mapping.isAggregateObjectMapping()) {
// Also prepare the nested aggregate queries, as aggregates do not have their own query.
baseExpression = objectExpression.getFirstNonAggregateExpressionAfterExpressionBuilder(new ArrayList(2));
mapping = baseExpression.getMapping();
}
if ((mapping != null) && mapping.isForeignReferenceMapping()) {
if (!this.batchFetchPolicy.getMappingQueries().containsKey(mapping)) {
// A nested query must be built to pass to the descriptor that looks like the real query execution would.
ReadQuery nestedQuery = ((ForeignReferenceMapping)mapping).prepareNestedBatchQuery(this);