Search in sources :

Example 1 with SqmQuerySpecCreationProcessingStateStandardImpl

use of org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl 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;
}
Also used : SqmCreationProcessingState(org.hibernate.query.hql.spi.SqmCreationProcessingState) SqmQueryGroup(org.hibernate.query.sqm.tree.select.SqmQueryGroup) SqmQuerySpecCreationProcessingStateStandardImpl(org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl) SetOperator(org.hibernate.query.sqm.SetOperator) SqmSelectQuery(org.hibernate.query.sqm.tree.select.SqmSelectQuery) AbstractSqmSelectQuery(org.hibernate.query.sqm.tree.select.AbstractSqmSelectQuery) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) SqmQueryPart(org.hibernate.query.sqm.tree.select.SqmQueryPart) HqlParser(org.hibernate.grammars.hql.HqlParser) StrictJpaComplianceViolation(org.hibernate.query.sqm.StrictJpaComplianceViolation) SqmQuerySpec(org.hibernate.query.sqm.tree.select.SqmQuerySpec) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 2 with SqmQuerySpecCreationProcessingStateStandardImpl

use of org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl in project hibernate-orm by hibernate.

the class SemanticQueryBuilder method visitSubquery.

@Override
public SqmSubQuery<?> visitSubquery(HqlParser.SubqueryContext ctx) {
    final HqlParser.QueryExpressionContext queryExpressionContext = (HqlParser.QueryExpressionContext) ctx.getChild(0);
    final SqmSubQuery<?> subQuery = new SqmSubQuery<>(processingStateStack.getCurrent().getProcessingQuery(), creationContext.getNodeBuilder());
    processingStateStack.push(new SqmQuerySpecCreationProcessingStateStandardImpl(processingStateStack.getCurrent(), subQuery, this));
    try {
        queryExpressionContext.accept(this);
        final List<SqmSelection<?>> selections = subQuery.getQuerySpec().getSelectClause().getSelections();
        if (selections.size() == 1) {
            subQuery.applyInferableType(selections.get(0).getNodeType());
        }
        return subQuery;
    } finally {
        processingStateStack.pop();
    }
}
Also used : SqmSubQuery(org.hibernate.query.sqm.tree.select.SqmSubQuery) SqmSelection(org.hibernate.query.sqm.tree.select.SqmSelection) HqlParser(org.hibernate.grammars.hql.HqlParser) SqmQuerySpecCreationProcessingStateStandardImpl(org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl)

Example 3 with SqmQuerySpecCreationProcessingStateStandardImpl

use of org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl in project hibernate-orm by hibernate.

the class SemanticQueryBuilder method visitSelectStatement.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Top-level statements
@Override
public SqmSelectStatement<R> visitSelectStatement(HqlParser.SelectStatementContext ctx) {
    final HqlParser.QueryExpressionContext queryExpressionContext = ctx.queryExpression();
    final SqmSelectStatement<R> selectStatement = new SqmSelectStatement<>(creationContext.getNodeBuilder());
    parameterCollector = selectStatement;
    processingStateStack.push(new SqmQuerySpecCreationProcessingStateStandardImpl(processingStateStack.getCurrent(), selectStatement, this));
    try {
        queryExpressionContext.accept(this);
    } finally {
        processingStateStack.pop();
    }
    return selectStatement;
}
Also used : SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) TIMEZONE_HOUR(org.hibernate.query.sqm.TemporalUnit.TIMEZONE_HOUR) WEEK_OF_YEAR(org.hibernate.query.sqm.TemporalUnit.WEEK_OF_YEAR) DAY_OF_YEAR(org.hibernate.query.sqm.TemporalUnit.DAY_OF_YEAR) IDENTIFIER(org.hibernate.grammars.hql.HqlParser.IDENTIFIER) HqlParser(org.hibernate.grammars.hql.HqlParser) SqmQuerySpecCreationProcessingStateStandardImpl(org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl)

Aggregations

HqlParser (org.hibernate.grammars.hql.HqlParser)3 SqmQuerySpecCreationProcessingStateStandardImpl (org.hibernate.query.sqm.internal.SqmQuerySpecCreationProcessingStateStandardImpl)3 SqmSelectStatement (org.hibernate.query.sqm.tree.select.SqmSelectStatement)2 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 IDENTIFIER (org.hibernate.grammars.hql.HqlParser.IDENTIFIER)1 SqmCreationProcessingState (org.hibernate.query.hql.spi.SqmCreationProcessingState)1 SetOperator (org.hibernate.query.sqm.SetOperator)1 StrictJpaComplianceViolation (org.hibernate.query.sqm.StrictJpaComplianceViolation)1 DAY_OF_YEAR (org.hibernate.query.sqm.TemporalUnit.DAY_OF_YEAR)1 TIMEZONE_HOUR (org.hibernate.query.sqm.TemporalUnit.TIMEZONE_HOUR)1 WEEK_OF_YEAR (org.hibernate.query.sqm.TemporalUnit.WEEK_OF_YEAR)1 AbstractSqmSelectQuery (org.hibernate.query.sqm.tree.select.AbstractSqmSelectQuery)1 SqmQueryGroup (org.hibernate.query.sqm.tree.select.SqmQueryGroup)1 SqmQueryPart (org.hibernate.query.sqm.tree.select.SqmQueryPart)1 SqmQuerySpec (org.hibernate.query.sqm.tree.select.SqmQuerySpec)1 SqmSelectQuery (org.hibernate.query.sqm.tree.select.SqmSelectQuery)1 SqmSelection (org.hibernate.query.sqm.tree.select.SqmSelection)1 SqmSubQuery (org.hibernate.query.sqm.tree.select.SqmSubQuery)1