AliasResolutionContextImpl aliasResolutionContext,
QueryBuildingParameters buildingParameters,
SessionFactoryImplementor factory) {
// Should be just one querySpace (of type EntityQuerySpace) in querySpaces. Should we validate that?
// Should we make it a util method on Helper like we do for extractRootReturn ?
final EntityQuerySpace rootQuerySpace = Helper.INSTANCE.extractRootQuerySpace(
querySpaces,
EntityQuerySpace.class
);
final EntityReferenceAliases entityReferenceAliases = aliasResolutionContext.generateEntityReferenceAliases(
rootQuerySpace.getUid(),
rootQuerySpace.getEntityPersister()
);
final String rootTableAlias = entityReferenceAliases.getTableAlias();
applyTableFragments(
select,
factory,
buildingParameters,
rootTableAlias,
(OuterJoinLoadable) rootQuerySpace.getEntityPersister()
);
// add restrictions...
// first, the load key restrictions (which entity(s) do we want to load?)
applyKeyRestriction(
select,
entityReferenceAliases.getTableAlias(),
keyColumnNamesToUse,
buildingParameters.getBatchSize()
);
// don't quite remember why these 2 anymore, todo : research that and document this code or remove it etc..
final OuterJoinLoadable rootLoadable = (OuterJoinLoadable) rootQuerySpace.getEntityPersister();
final Queryable rootQueryable = (Queryable) rootQuerySpace.getEntityPersister();
select.appendRestrictions(
rootQueryable.filterFragment(
entityReferenceAliases.getTableAlias(),
Collections.emptyMap()
)