use of org.hibernate.sql.ast.tree.expression.CaseSearchedExpression in project hibernate-orm by hibernate.
the class DB2SqlAstTranslator method visitAnsiCaseSearchedExpression.
// DB2 does not allow CASE expressions where all result arms contain plain parameters.
// At least one result arm must provide some type context for inference,
// so we cast the first result arm if we encounter this condition
@Override
protected void visitAnsiCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, Consumer<Expression> resultRenderer) {
if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSearchedExpression)) {
final List<CaseSearchedExpression.WhenFragment> whenFragments = caseSearchedExpression.getWhenFragments();
final Expression firstResult = whenFragments.get(0).getResult();
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, e -> {
if (e == firstResult) {
renderCasted(e);
} else {
resultRenderer.accept(e);
}
});
} else {
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, resultRenderer);
}
}
use of org.hibernate.sql.ast.tree.expression.CaseSearchedExpression in project hibernate-orm by hibernate.
the class DerbySqlAstTranslator method visitAnsiCaseSearchedExpression.
// Derby does not allow CASE expressions where all result arms contain plain parameters.
// At least one result arm must provide some type context for inference,
// so we cast the first result arm if we encounter this condition
@Override
protected void visitAnsiCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, Consumer<Expression> resultRenderer) {
if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSearchedExpression)) {
final List<CaseSearchedExpression.WhenFragment> whenFragments = caseSearchedExpression.getWhenFragments();
final Expression firstResult = whenFragments.get(0).getResult();
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, e -> {
if (e == firstResult) {
renderCasted(e);
} else {
resultRenderer.accept(e);
}
});
} else {
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, resultRenderer);
}
}
use of org.hibernate.sql.ast.tree.expression.CaseSearchedExpression in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitAnsiCaseSearchedExpression.
protected void visitAnsiCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, Consumer<Expression> resultRenderer) {
appendSql("case");
final SqlAstNodeRenderingMode original = this.parameterRenderingMode;
for (CaseSearchedExpression.WhenFragment whenFragment : caseSearchedExpression.getWhenFragments()) {
if (original != SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS) {
this.parameterRenderingMode = SqlAstNodeRenderingMode.DEFAULT;
}
appendSql(" when ");
whenFragment.getPredicate().accept(this);
this.parameterRenderingMode = original;
appendSql(" then ");
resultRenderer.accept(whenFragment.getResult());
}
final Expression otherwise = caseSearchedExpression.getOtherwise();
if (otherwise != null) {
appendSql(" else ");
resultRenderer.accept(otherwise);
}
appendSql(" end");
}
use of org.hibernate.sql.ast.tree.expression.CaseSearchedExpression in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitDecodeCaseSearchedExpression.
protected void visitDecodeCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression) {
appendSql("decode( ");
final SqlAstNodeRenderingMode original = this.parameterRenderingMode;
final List<CaseSearchedExpression.WhenFragment> whenFragments = caseSearchedExpression.getWhenFragments();
final int caseNumber = whenFragments.size();
CaseSearchedExpression.WhenFragment firstWhenFragment = null;
for (int i = 0; i < caseNumber; i++) {
final CaseSearchedExpression.WhenFragment whenFragment = whenFragments.get(i);
Predicate predicate = whenFragment.getPredicate();
if (original != SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS) {
this.parameterRenderingMode = SqlAstNodeRenderingMode.DEFAULT;
}
if (i != 0) {
appendSql(',');
getLeftHandExpression(predicate).accept(this);
this.parameterRenderingMode = original;
appendSql(',');
whenFragment.getResult().accept(this);
} else {
getLeftHandExpression(predicate).accept(this);
firstWhenFragment = whenFragment;
}
}
this.parameterRenderingMode = original;
appendSql(',');
firstWhenFragment.getResult().accept(this);
final Expression otherwise = caseSearchedExpression.getOtherwise();
if (otherwise != null) {
appendSql(',');
otherwise.accept(this);
}
appendSql(CLOSE_PARENTHESIS);
}
use of org.hibernate.sql.ast.tree.expression.CaseSearchedExpression in project hibernate-orm by hibernate.
the class SybaseASESqlAstTranslator method visitAnsiCaseSearchedExpression.
// Sybase ASE does not allow CASE expressions where all result arms contain plain parameters.
// At least one result arm must provide some type context for inference,
// so we cast the first result arm if we encounter this condition
@Override
protected void visitAnsiCaseSearchedExpression(CaseSearchedExpression caseSearchedExpression, Consumer<Expression> resultRenderer) {
if (getParameterRenderingMode() == SqlAstNodeRenderingMode.DEFAULT && areAllResultsParameters(caseSearchedExpression)) {
final List<CaseSearchedExpression.WhenFragment> whenFragments = caseSearchedExpression.getWhenFragments();
final Expression firstResult = whenFragments.get(0).getResult();
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, e -> {
if (e == firstResult) {
renderCasted(e);
} else {
resultRenderer.accept(e);
}
});
} else {
super.visitAnsiCaseSearchedExpression(caseSearchedExpression, resultRenderer);
}
}
Aggregations