use of org.hibernate.query.hql.spi.DotIdentifierConsumer in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method resolveOrderByOrGroupByExpression.
private SqmExpression<?> resolveOrderByOrGroupByExpression(ParseTree child, boolean definedCollate) {
if (child instanceof TerminalNode) {
if (definedCollate) {
// This is syntactically disallowed
throw new ParsingException("COLLATE is not allowed for position based order-by or group-by items");
}
final int position = Integer.parseInt(child.getText());
// make sure this selection exists
final SqmAliasedNode<?> nodeByPosition = getCurrentProcessingState().getPathRegistry().findAliasedNodeByPosition(position);
if (nodeByPosition == null) {
throw new ParsingException("Numeric literal '" + position + "' used in group-by does not match a registered select-item");
}
return new SqmAliasedNodeRef(position, integerDomainType, creationContext.getNodeBuilder());
} else if (child instanceof HqlParser.IdentifierContext) {
final String identifierText = visitIdentifier((HqlParser.IdentifierContext) child);
final Integer correspondingPosition = getCurrentProcessingState().getPathRegistry().findAliasedNodePosition(identifierText);
if (correspondingPosition != null) {
if (definedCollate) {
// This is syntactically disallowed
throw new ParsingException("COLLATE is not allowed for alias based order-by or group-by items");
}
return new SqmAliasedNodeRef(correspondingPosition, integerDomainType, creationContext.getNodeBuilder());
}
final SqmFrom<?, ?> sqmFrom = getCurrentProcessingState().getPathRegistry().findFromByAlias(identifierText, true);
if (sqmFrom != null) {
if (definedCollate) {
// This is syntactically disallowed
throw new ParsingException("COLLATE is not allowed for alias based order-by or group-by items");
}
// this will group-by all of the sub-parts in the from-element's model part
return sqmFrom;
}
final DotIdentifierConsumer dotIdentifierConsumer = dotIdentifierConsumerStack.getCurrent();
dotIdentifierConsumer.consumeIdentifier(identifierText, true, true);
return (SqmExpression<?>) dotIdentifierConsumer.getConsumedPart();
}
return (SqmExpression<?>) child.accept(this);
}
use of org.hibernate.query.hql.spi.DotIdentifierConsumer in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitTreatedNavigablePath.
@Override
public SqmPath<?> visitTreatedNavigablePath(HqlParser.TreatedNavigablePathContext 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;
}
consumeManagedTypeReference((HqlParser.PathContext) ctx.getChild(2));
final String treatTargetName = ctx.getChild(4).getText();
final String treatTargetEntityName = getCreationContext().getJpaMetamodel().qualifyImportableName(treatTargetName);
final boolean hasContinuation = ctx.getChildCount() == 7;
consumer.consumeTreat(treatTargetEntityName, !hasContinuation);
SqmPath<?> result = (SqmPath<?>) consumer.getConsumedPart();
if (hasContinuation) {
if (madeNested) {
// Reset the nested state before consuming the terminal identifier
((QualifiedJoinPathConsumer) consumer).setNested(false);
}
final boolean addConsumer = !(consumer instanceof QualifiedJoinPathConsumer);
if (addConsumer) {
dotIdentifierConsumerStack.push(new BasicDotIdentifierConsumer(result, this) {
@Override
protected void reset() {
}
});
}
try {
result = consumeDomainPath((HqlParser.SimplePathContext) ctx.getChild(6).getChild(1));
} finally {
if (addConsumer) {
dotIdentifierConsumerStack.pop();
}
}
}
return result;
}
use of org.hibernate.query.hql.spi.DotIdentifierConsumer in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitSimplePath.
@Override
public SemanticPathPart visitSimplePath(HqlParser.SimplePathContext ctx) {
final int numberOfContinuations = ctx.getChildCount() - 1;
final boolean hasContinuations = numberOfContinuations != 0;
final DotIdentifierConsumer dotIdentifierConsumer = dotIdentifierConsumerStack.getCurrent();
final HqlParser.IdentifierContext identifierContext = (HqlParser.IdentifierContext) ctx.getChild(0);
assert identifierContext.getChildCount() == 1;
dotIdentifierConsumer.consumeIdentifier(visitIdentifier(identifierContext), true, !hasContinuations);
if (hasContinuations) {
for (int i = 1; i < ctx.getChildCount(); i++) {
final HqlParser.SimplePathElementContext continuation = (HqlParser.SimplePathElementContext) ctx.getChild(i);
final HqlParser.IdentifierContext identifier = (HqlParser.IdentifierContext) continuation.getChild(1);
assert identifier.getChildCount() == 1;
dotIdentifierConsumer.consumeIdentifier(visitIdentifier(identifier), false, i >= numberOfContinuations);
}
}
return dotIdentifierConsumer.getConsumedPart();
}
use of org.hibernate.query.hql.spi.DotIdentifierConsumer in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitCollectionValueNavigablePath.
@Override
public SqmPath<?> visitCollectionValueNavigablePath(HqlParser.CollectionValueNavigablePathContext 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.VALUE) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.VALUE_FUNCTION_ON_NON_MAP);
}
}
SqmPath<?> result;
if (consumer instanceof QualifiedJoinPathConsumer) {
if (madeNested && !hasContinuation) {
// Reset the nested state before consuming the terminal identifier
((QualifiedJoinPathConsumer) consumer).setNested(false);
}
consumer.consumeIdentifier(CollectionPart.Nature.ELEMENT.getName(), false, !hasContinuation);
result = (SqmPath<?>) consumer.getConsumedPart();
} else {
result = sqmPath.resolvePathPart(CollectionPart.Nature.ELEMENT.getName(), true, 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;
}
use of org.hibernate.query.hql.spi.DotIdentifierConsumer in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method resolveEnumShorthandLiteral.
private SqmExpression<?> resolveEnumShorthandLiteral(HqlParser.ExpressionContext expressionContext, Map<Class<?>, Enum<?>> possibleEnumValues, Class<?> enumType) {
final Enum<?> enumValue;
if (possibleEnumValues != null && (enumValue = possibleEnumValues.get(enumType)) != null) {
DotIdentifierConsumer dotIdentifierConsumer = dotIdentifierConsumerStack.getCurrent();
dotIdentifierConsumer.consumeIdentifier(enumValue.getClass().getCanonicalName(), true, false);
dotIdentifierConsumer.consumeIdentifier(enumValue.name(), false, true);
return (SqmExpression<?>) dotIdentifierConsumerStack.getCurrent().getConsumedPart();
} else {
return (SqmExpression<?>) expressionContext.accept(this);
}
}
Aggregations