use of org.hibernate.query.hql.spi.SqmCreationProcessingState in project hibernate-orm by hibernate.
the class SqmPathRegistryImpl method findFromByAlias.
@Override
public <X extends SqmFrom<?, ?>> X findFromByAlias(String alias, boolean searchParent) {
final String localAlias = jpaCompliance.isJpaQueryComplianceEnabled() ? alias.toLowerCase(Locale.getDefault()) : alias;
final SqmFrom<?, ?> registered = sqmFromByAlias.get(localAlias);
if (registered != null) {
// noinspection unchecked
return (X) registered;
}
SqmCreationProcessingState parentProcessingState = associatedProcessingState.getParentProcessingState();
if (searchParent && parentProcessingState != null) {
X parentRegistered;
do {
parentRegistered = parentProcessingState.getPathRegistry().findFromByAlias(alias, false);
parentProcessingState = parentProcessingState.getParentProcessingState();
} while (parentProcessingState != null && parentRegistered == null);
if (parentRegistered != null) {
// If a parent query contains the alias, we need to create a correlation on the subquery
final SqmSubQuery<?> selectQuery = (SqmSubQuery<?>) associatedProcessingState.getProcessingQuery();
SqmFrom<?, ?> correlated;
if (parentRegistered instanceof Root<?>) {
correlated = selectQuery.correlate((Root<?>) parentRegistered);
} else if (parentRegistered instanceof Join<?, ?>) {
correlated = selectQuery.correlate((Join<?, ?>) parentRegistered);
} else if (parentRegistered instanceof SqmCrossJoin<?>) {
correlated = selectQuery.correlate((SqmCrossJoin<?>) parentRegistered);
} else if (parentRegistered instanceof SqmEntityJoin<?>) {
correlated = selectQuery.correlate((SqmEntityJoin<?>) parentRegistered);
} else {
throw new UnsupportedOperationException("Can't correlate from node: " + parentRegistered);
}
register(correlated);
// noinspection unchecked
return (X) correlated;
}
}
return null;
}
Aggregations