Search in sources :

Example 6 with CaseSimpleExpression

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

the class SybaseAnywhereSqlAstTranslator 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 7 with CaseSimpleExpression

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

the class SybaseASESqlAstTranslator 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 8 with CaseSimpleExpression

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

the class AbstractSqlAstTranslator method areAllResultsParameters.

protected boolean areAllResultsParameters(CaseSimpleExpression caseSimpleExpression) {
    final List<CaseSimpleExpression.WhenFragment> whenFragments = caseSimpleExpression.getWhenFragments();
    final Expression firstResult = whenFragments.get(0).getResult();
    if (isParameter(firstResult)) {
        for (int i = 1; i < whenFragments.size(); i++) {
            if (!isParameter(whenFragments.get(i).getResult())) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) OrderedSetAggregateFunctionExpression(org.hibernate.sql.ast.tree.expression.OrderedSetAggregateFunctionExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)

Example 9 with CaseSimpleExpression

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

the class AbstractSqlAstTranslator method visitAnsiCaseSimpleExpression.

protected void visitAnsiCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, Consumer<Expression> resultRenderer) {
    appendSql("case ");
    final SqlAstNodeRenderingMode original = this.parameterRenderingMode;
    if (original != SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS) {
        this.parameterRenderingMode = SqlAstNodeRenderingMode.DEFAULT;
    }
    caseSimpleExpression.getFixture().accept(this);
    for (CaseSimpleExpression.WhenFragment whenFragment : caseSimpleExpression.getWhenFragments()) {
        if (original != SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS) {
            this.parameterRenderingMode = SqlAstNodeRenderingMode.DEFAULT;
        }
        appendSql(" when ");
        whenFragment.getCheckValue().accept(this);
        this.parameterRenderingMode = original;
        appendSql(" then ");
        resultRenderer.accept(whenFragment.getResult());
    }
    this.parameterRenderingMode = original;
    final Expression otherwise = caseSimpleExpression.getOtherwise();
    if (otherwise != null) {
        appendSql(" else ");
        resultRenderer.accept(otherwise);
    }
    appendSql(" end");
}
Also used : Expression(org.hibernate.sql.ast.tree.expression.Expression) BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) OrderedSetAggregateFunctionExpression(org.hibernate.sql.ast.tree.expression.OrderedSetAggregateFunctionExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlAstNodeRenderingMode(org.hibernate.sql.ast.SqlAstNodeRenderingMode)

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