use of org.hibernate.query.sqm.tree.domain.SqmMapJoin in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitMapKeyNavigablePath.
@Override
public SqmPath<?> visitMapKeyNavigablePath(HqlParser.MapKeyNavigablePathContext ctx) {
final DotIdentifierConsumer consumer = dotIdentifierConsumerStack.getCurrent();
final boolean madeNested;
if (consumer instanceof QualifiedJoinPathConsumer) {
final QualifiedJoinPathConsumer qualifiedJoinPathConsumer = (QualifiedJoinPathConsumer) consumer;
madeNested = !qualifiedJoinPathConsumer.isNested();
if (madeNested) {
qualifiedJoinPathConsumer.setNested(true);
}
} else {
madeNested = false;
}
final SqmPath<?> sqmPath = consumeDomainPath((HqlParser.PathContext) ctx.getChild(2));
final boolean hasContinuation = ctx.getChildCount() == 5;
final SqmPathSource<?> referencedPathSource = sqmPath.getReferencedPathSource();
final TerminalNode firstNode = (TerminalNode) ctx.getChild(0);
checkPluralPath(sqmPath, referencedPathSource, firstNode);
if (getCreationOptions().useStrictJpaCompliance()) {
final PluralPersistentAttribute<?, ?, ?> attribute = (PluralPersistentAttribute<?, ?, ?>) referencedPathSource;
if (attribute.getCollectionClassification() != CollectionClassification.MAP && firstNode.getSymbol().getType() == HqlParser.KEY) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.KEY_FUNCTION_ON_NON_MAP);
}
}
SqmPath<?> result;
if (sqmPath instanceof SqmMapJoin) {
final SqmMapJoin<?, ?, ?> sqmMapJoin = (SqmMapJoin<?, ?, ?>) sqmPath;
if (consumer instanceof QualifiedJoinPathConsumer) {
if (madeNested && !hasContinuation) {
// Reset the nested state before consuming the terminal identifier
((QualifiedJoinPathConsumer) consumer).setNested(false);
}
consumer.consumeIdentifier(CollectionPart.Nature.INDEX.getName(), false, !hasContinuation);
result = (SqmPath<?>) consumer.getConsumedPart();
} else {
result = sqmMapJoin.key();
}
} else if (sqmPath instanceof SqmListJoin) {
if (hasContinuation) {
throw new SemanticException("list index may not be dereferenced");
}
SqmListJoin<?, ?> listJoin = (SqmListJoin<?, ?>) sqmPath;
result = listJoin.resolvePathPart(CollectionPart.Nature.INDEX.getName(), true, this);
} else {
assert sqmPath instanceof SqmPluralValuedSimplePath;
final SqmPluralValuedSimplePath<?> mapPath = (SqmPluralValuedSimplePath<?>) sqmPath;
result = mapPath.resolvePathPart(CollectionPart.Nature.INDEX.getName(), !hasContinuation, this);
}
if (hasContinuation) {
if (madeNested) {
// Reset the nested state before consuming the terminal identifier
((QualifiedJoinPathConsumer) consumer).setNested(false);
}
final HqlParser.SimplePathContext identCtx = (HqlParser.SimplePathContext) ctx.getChild(4).getChild(1);
if (consumer instanceof QualifiedJoinPathConsumer) {
result = consumeDomainPath(identCtx);
} else {
dotIdentifierConsumerStack.push(new BasicDotIdentifierConsumer(result, this) {
@Override
protected void reset() {
}
});
try {
result = consumeDomainPath(identCtx);
} finally {
dotIdentifierConsumerStack.pop();
}
}
}
return result;
}
Aggregations