QueryExpressionsState[] states, ExpContext ctx, int subclassMode) {
Number optHint = (Number) ctx.fetch.getHint
(QueryHints.HINT_RESULT_COUNT);
ClassMapping[] verts;
boolean unionable = true;
Select sel;
for (int i = 0; i < mappings.length; i++) {
// determine vertical mappings to select separately
verts = getVerticalMappings(mappings[i], subclasses, exps[i],
subclassMode);
if (verts.length == 1 && subclasses)
subclassBits.set(sels.size());
Discriminator disc = mappings[i].getDiscriminator();
if (mappings.length > 1 && disc != null && disc.getColumns().length == 0 &&
disc.getStrategy() instanceof NoneDiscriminatorStrategy)
ctx.tpcMeta = mappings[i];
// create criteria select and clone for each vert mapping
sel = ((JDBCExpressionFactory) facts[i]).getSelectConstructor().
evaluate(ctx, null, null, exps[i], states[i]);
if (optHint != null)
sel.setExpectedResultCount(optHint.intValue(), true);
else if (this.ctx.isUnique())
sel.setExpectedResultCount(1, false);
List selectFrom = getJoinedTableMeta(sel);
int size = 0;
if (selectFrom != null) {
size = selectFrom.size();
for (int j = 0; j < size; j++) {
ClassMapping vert = (ClassMapping)selectFrom.get(j);
selMappings.add(vert);
if (j == size - 1) {
nextBits.set(sels.size());
sel.select(vert.getPrimaryKeyColumns(), null);
sels.add(sel);
} else {
SelectImpl selClone = (SelectImpl)sel.fullClone(1);
selClone.select(vert.getPrimaryKeyColumns(), null);
sels.add(selClone);
}
}
} else {
for (int j = 0; j < verts.length; j++) {
selMappings.add(verts[j]);
if (j == verts.length - 1) {
nextBits.set(sels.size());
sels.add(sel);
} else
sels.add(sel.fullClone(1));
}
}
// turn off unioning if a given independent mapping requires
// multiple selects, or if we're using FROM selects
if (verts.length > 1 || size > 1 || sel.getFromSelect() != null)
unionable = false;
}
return unionable;
}