Search in sources :

Example 1 with CaseSimpleExpression

use of org.hibernate.sql.ast.tree.expression.CaseSimpleExpression in project hibernate-orm by hibernate.

the class DB2SqlAstTranslator method visitAnsiCaseSimpleExpression.

@Override
protected void visitAnsiCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, Consumer<Expression> resultRenderer) {
    if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSimpleExpression)) {
        final List<CaseSimpleExpression.WhenFragment> whenFragments = caseSimpleExpression.getWhenFragments();
        final Expression firstResult = whenFragments.get(0).getResult();
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, e -> {
            if (e == firstResult) {
                renderCasted(e);
            } else {
                resultRenderer.accept(e);
            }
        });
    } else {
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, resultRenderer);
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)

Example 2 with CaseSimpleExpression

use of org.hibernate.sql.ast.tree.expression.CaseSimpleExpression in project hibernate-orm by hibernate.

the class SybaseSqlAstTranslator method visitAnsiCaseSimpleExpression.

@Override
protected void visitAnsiCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, Consumer<Expression> resultRenderer) {
    if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSimpleExpression)) {
        final List<CaseSimpleExpression.WhenFragment> whenFragments = caseSimpleExpression.getWhenFragments();
        final Expression firstResult = whenFragments.get(0).getResult();
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, e -> {
            if (e == firstResult) {
                renderCasted(e);
            } else {
                resultRenderer.accept(e);
            }
        });
    } else {
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, resultRenderer);
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)

Example 3 with CaseSimpleExpression

use of org.hibernate.sql.ast.tree.expression.CaseSimpleExpression in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method visitSimpleCaseExpression.

@Override
public CaseSimpleExpression visitSimpleCaseExpression(SqmCaseSimple<?, ?> expression) {
    final List<CaseSimpleExpression.WhenFragment> whenFragments = new ArrayList<>(expression.getWhenFragments().size());
    final Supplier<MappingModelExpressible<?>> inferenceSupplier = inferrableTypeAccessStack.getCurrent();
    inferrableTypeAccessStack.push(() -> {
        for (SqmCaseSimple.WhenFragment<?, ?> whenFragment : expression.getWhenFragments()) {
            final MappingModelExpressible<?> resolved = determineCurrentExpressible(whenFragment.getCheckValue());
            if (resolved != null) {
                return resolved;
            }
        }
        return null;
    });
    final Expression fixture = (Expression) expression.getFixture().accept(this);
    final MappingModelExpressible<?> fixtureType = (MappingModelExpressible<?>) fixture.getExpressionType();
    inferrableTypeAccessStack.pop();
    MappingModelExpressible<?> resolved = determineCurrentExpressible(expression);
    Expression otherwise = null;
    for (SqmCaseSimple.WhenFragment<?, ?> whenFragment : expression.getWhenFragments()) {
        inferrableTypeAccessStack.push(() -> fixtureType);
        final Expression checkValue = (Expression) whenFragment.getCheckValue().accept(this);
        inferrableTypeAccessStack.pop();
        final MappingModelExpressible<?> alreadyKnown = resolved;
        inferrableTypeAccessStack.push(() -> alreadyKnown == null && inferenceSupplier != null ? inferenceSupplier.get() : alreadyKnown);
        final Expression resultExpression = (Expression) whenFragment.getResult().accept(this);
        inferrableTypeAccessStack.pop();
        resolved = (MappingModelExpressible<?>) highestPrecedence(resolved, resultExpression.getExpressionType());
        whenFragments.add(new CaseSimpleExpression.WhenFragment(checkValue, resultExpression));
    }
    if (expression.getOtherwise() != null) {
        final MappingModelExpressible<?> alreadyKnown = resolved;
        inferrableTypeAccessStack.push(() -> alreadyKnown == null && inferenceSupplier != null ? inferenceSupplier.get() : alreadyKnown);
        otherwise = (Expression) expression.getOtherwise().accept(this);
        inferrableTypeAccessStack.pop();
        resolved = (MappingModelExpressible<?>) highestPrecedence(resolved, otherwise.getExpressionType());
    }
    return new CaseSimpleExpression(resolved, fixture, whenFragments, otherwise);
}
Also used : SqmCaseSimple(org.hibernate.query.sqm.tree.expression.SqmCaseSimple) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) ArrayList(java.util.ArrayList)

Example 4 with CaseSimpleExpression

use of org.hibernate.sql.ast.tree.expression.CaseSimpleExpression in project hibernate-orm by hibernate.

the class HSQLSqlAstTranslator method visitAnsiCaseSimpleExpression.

@Override
protected void visitAnsiCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, Consumer<Expression> resultRenderer) {
    if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSimpleExpression)) {
        final List<CaseSimpleExpression.WhenFragment> whenFragments = caseSimpleExpression.getWhenFragments();
        final Expression firstResult = whenFragments.get(0).getResult();
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, e -> {
            if (e == firstResult) {
                renderCasted(e);
            } else {
                resultRenderer.accept(e);
            }
        });
    } else {
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, resultRenderer);
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)

Example 5 with CaseSimpleExpression

use of org.hibernate.sql.ast.tree.expression.CaseSimpleExpression in project hibernate-orm by hibernate.

the class DerbySqlAstTranslator method visitAnsiCaseSimpleExpression.

@Override
protected void visitAnsiCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, Consumer<Expression> resultRenderer) {
    if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSimpleExpression)) {
        final List<CaseSimpleExpression.WhenFragment> whenFragments = caseSimpleExpression.getWhenFragments();
        final Expression firstResult = whenFragments.get(0).getResult();
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, e -> {
            if (e == firstResult) {
                renderCasted(e);
            } else {
                resultRenderer.accept(e);
            }
        });
    } else {
        super.visitAnsiCaseSimpleExpression(caseSimpleExpression, resultRenderer);
    }
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)

Aggregations

CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)9 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)9 Expression (org.hibernate.sql.ast.tree.expression.Expression)9 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)5 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)3 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)3 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)3 OrderedSetAggregateFunctionExpression (org.hibernate.sql.ast.tree.expression.OrderedSetAggregateFunctionExpression)2 ArrayList (java.util.ArrayList)1 MappingModelExpressible (org.hibernate.metamodel.mapping.MappingModelExpressible)1 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)1 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)1 SqmCaseSimple (org.hibernate.query.sqm.tree.expression.SqmCaseSimple)1 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)1 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)1 SqlAstNodeRenderingMode (org.hibernate.sql.ast.SqlAstNodeRenderingMode)1 SelfRenderingSqlFragmentExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression)1