use of org.hibernate.query.sqm.tree.select.SqmQueryGroup 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.tree.select.SqmQueryGroup in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method visitQueryGroup.
@Override
public QueryGroup visitQueryGroup(SqmQueryGroup<?> queryGroup) {
final List<? extends SqmQueryPart<?>> queryParts = queryGroup.getQueryParts();
final int size = queryParts.size();
final List<QueryPart> newQueryParts = new ArrayList<>(size);
final QueryGroup group = new QueryGroup(getProcessingStateStack().isEmpty(), queryGroup.getSetOperator(), newQueryParts);
if (queryGroup.getOrderByClause() != null && queryGroup.getOrderByClause().hasPositionalSortItem()) {
trackSelectionsForGroup = true;
}
final SqlAstQueryPartProcessingStateImpl processingState = new SqlAstQueryPartProcessingStateImpl(group, getCurrentProcessingState(), this, DelegatingSqmAliasedNodeCollector::new, currentClauseStack::getCurrent, deduplicateSelectionItems);
final DelegatingSqmAliasedNodeCollector collector = (DelegatingSqmAliasedNodeCollector) processingState.getSqlExpressionResolver();
final SqmQueryPart<?> sqmQueryPart = currentSqmQueryPart;
currentSqmQueryPart = queryGroup;
pushProcessingState(processingState);
try {
newQueryParts.add(visitQueryPart(queryParts.get(0)));
collector.setSqmAliasedNodeCollector((SqmAliasedNodeCollector) lastPoppedProcessingState.getSqlExpressionResolver());
visitOrderByOffsetAndFetch(queryGroup, group);
trackSelectionsForGroup = false;
for (int i = 1; i < size; i++) {
newQueryParts.add(visitQueryPart(queryParts.get(i)));
}
return group;
} finally {
popProcessingStateStack();
currentSqmQueryPart = sqmQueryPart;
}
}
Aggregations