*/
private int selectBaseMappings(Select sel, ClassMapping mapping,
ClassMapping orig, OpenJPAStateManager sm, BitSet fields,
JDBCFetchConfiguration fetch, int eager, FieldMapping eagerToMany,
boolean ident, boolean joined) {
ClassMapping parent = mapping.getJoinablePCSuperclassMapping();
if (parent == null && !mapping.isMapped())
throw new InvalidStateException(_loc.get("virtual-mapping", mapping.
getDescribedType()));
int seld = -1;
int pseld = -1;
// base class selects pks, etc
if (parent == null) {
// if no instance, select pks
if (sm == null) {
if (ident)
sel.selectIdentifier(mapping.getPrimaryKeyColumns());
else
sel.select(mapping.getPrimaryKeyColumns());
seld = 1;
}
// if no instance or not initialized and not exact oid, select type
if ((sm == null || (sm.getPCState() == PCState.TRANSIENT
&& (!(sm.getObjectId() instanceof OpenJPAId)
|| ((OpenJPAId) sm.getObjectId()).hasSubclasses())))
&& mapping.getDiscriminator().select(sel, orig))
seld = 1;
// if no instance or no version, select version
if ((sm == null || sm.getVersion() == null)
&& mapping.getVersion().select(sel, orig))
seld = 1;
} else {
// recurse on parent
pseld = selectBaseMappings(sel, parent, orig, sm, fields,
fetch, eager, eagerToMany, ident, joined);
}
// select the mappings in the given fields set, or based on fetch
// configuration if no fields given
FieldMapping[] fms = mapping.getDefinedFieldMappings();
SelectExecutor esel;
int fseld;
for (int i = 0; i < fms.length; i++) {
// skip eager to-many select; we do that separately in calling
// method
if (fms[i] == eagerToMany)
continue;
// check for eager select
esel = sel.getEager(fms[i]);
if (esel != null) {
if (esel == sel)
fms[i].selectEagerJoin(sel, sm, this,
fetch.traverseJDBC(fms[i]), eager);
else
fms[i].selectEagerParallel(esel, sm, this,
fetch.traverseJDBC(fms[i]), eager);
seld = Math.max(0, seld);
} else if (requiresSelect(fms[i], sm, fields, fetch)) {
fseld = fms[i].select(sel, sm, this,
fetch.traverseJDBC(fms[i]), eager);
seld = Math.max(fseld, seld);
} else if (optSelect(fms[i], sel, sm, fetch)) {
fseld = fms[i].select(sel, sm, this,
fetch.traverseJDBC(fms[i]), fetch.EAGER_NONE);
// don't upgrade seld to > 0 based on these fields, since
// they're not in the calculated field set
if (fseld >= 0 && seld < 0)
seld = 0;
}
}
// join to parent table if the parent / any ancestors have selected
// anything
if (!joined && pseld >= 0 && parent.getTable() != mapping.getTable())
sel.where(mapping.joinSuperclass(sel.newJoins(), false));
// return the highest value
return Math.max(pseld, seld);
}