// 2612538 - the default size of Map (32) is appropriate
Map clonedExpressions = new IdentityHashMap();
SQLSelectStatement selectStatement = buildBaseSelectStatement(false, clonedExpressions);
ClassDescriptor descriptor = getDescriptor();
InheritancePolicy policy = descriptor.getInheritancePolicy();
// The onlyInstances expression is only included on leaf descriptor base select,
// so if a root or branch (!shouldReadSubclasses means leaf), then it must be appended.
if (policy.shouldReadSubclasses()) {
Expression indicatorExpression = null;
// If the descriptor is a single table branch, then select the whole branch in a single query.
if (this.query.isReadAllQuery() && policy.hasChildren() && !policy.hasMultipleTableChild()) {
indicatorExpression = policy.getWithAllSubclassesExpression();
} else {
indicatorExpression = policy.getOnlyInstancesExpression();
}
if ((indicatorExpression != null) && (selectStatement.getWhereClause() != null)) {
selectStatement.setWhereClause(selectStatement.getWhereClause().and(indicatorExpression));
} else if (indicatorExpression != null) {
selectStatement.setWhereClause((Expression)indicatorExpression.clone());