use of org.hibernate.query.sqm.StrictJpaComplianceViolation in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitQueryOrder.
protected void visitQueryOrder(SqmQueryPart<?> sqmQueryPart, HqlParser.QueryOrderContext ctx) {
if (ctx == null) {
return;
}
final SqmOrderByClause orderByClause;
final HqlParser.OrderByClauseContext orderByClauseContext = (HqlParser.OrderByClauseContext) ctx.getChild(0);
if (orderByClauseContext != null) {
if (creationOptions.useStrictJpaCompliance() && processingStateStack.depth() > 1) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.SUBQUERY_ORDER_BY);
}
orderByClause = visitOrderByClause(orderByClauseContext);
sqmQueryPart.setOrderByClause(orderByClause);
} else {
orderByClause = null;
}
int currentIndex = 1;
final HqlParser.LimitClauseContext limitClauseContext;
if (currentIndex < ctx.getChildCount() && ctx.getChild(currentIndex) instanceof HqlParser.LimitClauseContext) {
limitClauseContext = (HqlParser.LimitClauseContext) ctx.getChild(currentIndex++);
} else {
limitClauseContext = null;
}
final HqlParser.OffsetClauseContext offsetClauseContext;
if (currentIndex < ctx.getChildCount() && ctx.getChild(currentIndex) instanceof HqlParser.OffsetClauseContext) {
offsetClauseContext = (HqlParser.OffsetClauseContext) ctx.getChild(currentIndex++);
} else {
offsetClauseContext = null;
}
final HqlParser.FetchClauseContext fetchClauseContext;
if (currentIndex < ctx.getChildCount() && ctx.getChild(currentIndex) instanceof HqlParser.FetchClauseContext) {
fetchClauseContext = (HqlParser.FetchClauseContext) ctx.getChild(currentIndex++);
} else {
fetchClauseContext = null;
}
if (currentIndex != 1) {
if (getCreationOptions().useStrictJpaCompliance()) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.LIMIT_OFFSET_CLAUSE);
}
if (processingStateStack.depth() > 1 && orderByClause == null) {
throw new SemanticException("limit, offset and fetch clause require an order-by clause when used in sub-query");
}
sqmQueryPart.setOffsetExpression(visitOffsetClause(offsetClauseContext));
if (limitClauseContext == null) {
sqmQueryPart.setFetchExpression(visitFetchClause(fetchClauseContext), visitFetchClauseType(fetchClauseContext));
} else if (fetchClauseContext == null) {
sqmQueryPart.setFetchExpression(visitLimitClause(limitClauseContext));
} else {
throw new SemanticException("Can't use both limit and fetch clause");
}
}
}
use of org.hibernate.query.sqm.StrictJpaComplianceViolation in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitSetQueryGroup.
@Override
public SqmQueryGroup<Object> visitSetQueryGroup(HqlParser.SetQueryGroupContext ctx) {
if (creationOptions.useStrictJpaCompliance()) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.SET_OPERATIONS);
}
final List<ParseTree> children = ctx.children;
// noinspection unchecked
final SqmQueryPart<Object> firstQueryPart = (SqmQueryPart<Object>) children.get(0).accept(this);
SqmQueryGroup<Object> queryGroup;
if (firstQueryPart instanceof SqmQueryGroup<?>) {
queryGroup = (SqmQueryGroup<Object>) firstQueryPart;
} else {
queryGroup = new SqmQueryGroup<>(firstQueryPart);
}
setCurrentQueryPart(queryGroup);
final int size = children.size();
final SqmCreationProcessingState firstProcessingState = processingStateStack.pop();
for (int i = 1; i < size; i += 2) {
final SetOperator operator = visitSetOperator((HqlParser.SetOperatorContext) children.get(i));
final HqlParser.OrderedQueryContext simpleQueryCtx = (HqlParser.OrderedQueryContext) children.get(i + 1);
final List<SqmQueryPart<Object>> queryParts;
if (queryGroup.getSetOperator() == null || queryGroup.getSetOperator() == operator) {
queryGroup.setSetOperator(operator);
queryParts = queryGroup.queryParts();
} else {
queryParts = new ArrayList<>(size - (i >> 1));
queryParts.add(queryGroup);
queryGroup = new SqmQueryGroup<>(creationContext.getNodeBuilder(), operator, queryParts);
setCurrentQueryPart(queryGroup);
}
final SqmQueryPart<Object> queryPart;
try {
processingStateStack.push(new SqmQuerySpecCreationProcessingStateStandardImpl(processingStateStack.getCurrent(), (SqmSelectQuery<?>) firstProcessingState.getProcessingQuery(), this));
final List<ParseTree> subChildren = simpleQueryCtx.children;
if (subChildren.get(0) instanceof HqlParser.QueryContext) {
final SqmQuerySpec<Object> querySpec = new SqmQuerySpec<>(creationContext.getNodeBuilder());
queryParts.add(querySpec);
visitQuerySpecExpression((HqlParser.QuerySpecExpressionContext) simpleQueryCtx);
} else {
try {
final SqmSelectStatement<Object> selectStatement = new SqmSelectStatement<>(creationContext.getNodeBuilder());
processingStateStack.push(new SqmQuerySpecCreationProcessingStateStandardImpl(processingStateStack.getCurrent(), selectStatement, this));
queryPart = visitNestedQueryExpression((HqlParser.NestedQueryExpressionContext) simpleQueryCtx);
queryParts.add(queryPart);
} finally {
processingStateStack.pop();
}
}
} finally {
processingStateStack.pop();
}
}
processingStateStack.push(firstProcessingState);
return queryGroup;
}
use of org.hibernate.query.sqm.StrictJpaComplianceViolation in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitCollectionFunctionMisuse.
@Override
public SqmPath<?> visitCollectionFunctionMisuse(HqlParser.CollectionFunctionMisuseContext ctx) {
if (getCreationOptions().useStrictJpaCompliance()) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.HQL_COLLECTION_FUNCTION);
}
final SqmPath<?> pluralAttributePath = consumeDomainPath((HqlParser.PathContext) ctx.getChild(2));
final SqmPathSource<?> referencedPathSource = pluralAttributePath.getReferencedPathSource();
final TerminalNode firstNode = (TerminalNode) ctx.getChild(0);
if (!(referencedPathSource instanceof PluralPersistentAttribute<?, ?, ?>)) {
throw new PathException(String.format("Argument of '%s' is not a plural path '%s'", firstNode.getSymbol().getText(), pluralAttributePath.getNavigablePath()));
}
CollectionPart.Nature nature;
switch(firstNode.getSymbol().getType()) {
case ELEMENTS:
nature = CollectionPart.Nature.ELEMENT;
break;
case INDICES:
nature = CollectionPart.Nature.INDEX;
break;
default:
throw new ParsingException("Impossible symbol");
}
return pluralAttributePath.resolvePathPart(nature.getName(), true, this);
}
use of org.hibernate.query.sqm.StrictJpaComplianceViolation in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitCollateFunction.
@Override
public Object visitCollateFunction(HqlParser.CollateFunctionContext ctx) {
if (creationOptions.useStrictJpaCompliance()) {
throw new StrictJpaComplianceViolation(StrictJpaComplianceViolation.Type.COLLATIONS);
}
final SqmExpression<?> expressionToCollate = (SqmExpression<?>) ctx.getChild(2).accept(this);
final SqmCollation castTargetExpression = (SqmCollation) ctx.getChild(4).accept(this);
return getFunctionDescriptor("collate").generateSqmExpression(asList(expressionToCollate, castTargetExpression), // why not string?
null, creationContext.getQueryEngine(), creationContext.getJpaMetamodel().getTypeConfiguration());
}
use of org.hibernate.query.sqm.StrictJpaComplianceViolation 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;
}
Aggregations