use of org.hibernate.metamodel.model.domain.ListPersistentAttribute in project hibernate-orm by hibernate.
the class SqmPluralValuedSimplePath method resolveIndexedAccess.
@Override
public SqmPath<?> resolveIndexedAccess(SqmExpression<?> selector, boolean isTerminal, SqmCreationState creationState) {
final SqmPathRegistry pathRegistry = creationState.getCurrentProcessingState().getPathRegistry();
final String alias = selector.toHqlString();
final NavigablePath navigablePath = getNavigablePath().getParent().append(getNavigablePath().getUnaliasedLocalName(), alias).append(CollectionPart.Nature.ELEMENT.getName());
final SqmFrom<?, ?> indexedPath = pathRegistry.findFromByPath(navigablePath);
if (indexedPath != null) {
return indexedPath;
}
SqmFrom<?, ?> path = pathRegistry.findFromByPath(navigablePath.getParent());
if (path == null) {
final PluralPersistentAttribute<?, ?, E> referencedPathSource = getReferencedPathSource();
final SqmFrom<?, Object> parent = pathRegistry.resolveFrom(getLhs());
final SqmQualifiedJoin<Object, ?> join;
final SqmExpression<?> index;
if (referencedPathSource instanceof ListPersistentAttribute<?, ?>) {
// noinspection unchecked
join = new SqmListJoin<>(parent, (ListPersistentAttribute<Object, ?>) referencedPathSource, alias, SqmJoinType.INNER, false, parent.nodeBuilder());
index = ((SqmListJoin<?, ?>) join).index();
} else if (referencedPathSource instanceof MapPersistentAttribute<?, ?, ?>) {
// noinspection unchecked
join = new SqmMapJoin<>(parent, (MapPersistentAttribute<Object, ?, ?>) referencedPathSource, alias, SqmJoinType.INNER, false, parent.nodeBuilder());
index = ((SqmMapJoin<?, ?, ?>) join).key();
} else {
throw new SemanticException("Index access is only supported on list or map attributes: " + getNavigablePath());
}
join.setJoinPredicate(creationState.getCreationContext().getNodeBuilder().equal(index, selector));
parent.addSqmJoin(join);
pathRegistry.register(path = join);
}
final SqmIndexedCollectionAccessPath<Object> result = new SqmIndexedCollectionAccessPath<>(navigablePath, path, selector);
pathRegistry.register(result);
return result;
}
Aggregations