use of org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath in project hibernate-orm by hibernate.
the class SqmMappingModelHelper method resolveSqmPath.
private static ModelPart resolveSqmPath(SqmPath<?> sqmPath, MappingMetamodel domainModel, Function<NavigablePath, TableGroup> tableGroupLocator) {
if (sqmPath instanceof SqmTreatedPath) {
final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath;
final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
return domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
}
// see if the LHS is treated
if (sqmPath.getLhs() instanceof SqmTreatedPath) {
final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath.getLhs();
final EntityDomainType treatTargetType = treatedPath.getTreatTarget();
final EntityPersister container = domainModel.findEntityDescriptor(treatTargetType.getHibernateEntityName());
return container.findSubPart(sqmPath.getNavigablePath().getLocalName(), container);
}
// Plural path parts are not joined and thus also have no table group
if (sqmPath instanceof AbstractSqmSpecificPluralPartPath<?>) {
final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getLhs().getNavigablePath());
final ModelPartContainer pluralPart = (ModelPartContainer) lhsTableGroup.getModelPart().findSubPart(sqmPath.getLhs().getReferencedPathSource().getPathName(), null);
final CollectionPart collectionPart = (CollectionPart) pluralPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
// as that is the mapping type of the expression
if (collectionPart instanceof EntityCollectionPart) {
return ((EntityCollectionPart) collectionPart).getEntityMappingType();
}
return collectionPart;
}
if (sqmPath.getLhs() == null) {
final EntityDomainType<?> entityDomainType = (EntityDomainType<?>) sqmPath.getReferencedPathSource();
return domainModel.findEntityDescriptor(entityDomainType.getHibernateEntityName());
}
final TableGroup lhsTableGroup = tableGroupLocator.apply(sqmPath.getLhs().getNavigablePath());
final ModelPartContainer modelPart;
if (lhsTableGroup == null) {
modelPart = (ModelPartContainer) resolveSqmPath(sqmPath.getLhs(), domainModel, tableGroupLocator);
} else {
modelPart = lhsTableGroup.getModelPart();
}
return modelPart.findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
}
use of org.hibernate.query.sqm.tree.domain.AbstractSqmSpecificPluralPartPath in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method prepareForSelection.
private void prepareForSelection(SqmPath<?> selectionPath) {
final SqmPath<?> path;
// through a cardinality preserving mechanism in visitIndexAggregateFunction/visitElementAggregateFunction
if (selectionPath instanceof AbstractSqmSpecificPluralPartPath<?>) {
path = selectionPath.getLhs().getLhs();
} else {
path = selectionPath;
}
final FromClauseIndex fromClauseIndex = getFromClauseIndex();
final TableGroup tableGroup = fromClauseIndex.findTableGroup(path.getNavigablePath());
if (tableGroup == null) {
prepareReusablePath(path, () -> null);
final NavigablePath navigablePath;
if (CollectionPart.Nature.fromNameExact(path.getNavigablePath().getUnaliasedLocalName()) != null) {
navigablePath = path.getLhs().getLhs().getNavigablePath();
} else if (path instanceof SqmTreatedRoot<?, ?>) {
navigablePath = ((SqmTreatedRoot<?, ?>) path).getWrappedPath().getNavigablePath();
} else {
navigablePath = path.getLhs().getNavigablePath();
}
final TableGroup createdTableGroup = createTableGroup(fromClauseIndex.getTableGroup(navigablePath), path);
if (createdTableGroup != null) {
if (path instanceof SqmTreatedPath<?, ?>) {
fromClauseIndex.register(path, createdTableGroup);
}
if (path instanceof SqmFrom<?, ?>) {
registerTreatUsage((SqmFrom<?, ?>) path, createdTableGroup);
}
}
} else if (path instanceof SqmFrom<?, ?>) {
registerTreatUsage((SqmFrom<?, ?>) path, tableGroup);
}
}
Aggregations