use of org.hibernate.sql.ast.SqlAstNodeRenderingMode 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.SqlAstNodeRenderingMode 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.SqlAstNodeRenderingMode in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitSqlSelections.
protected void visitSqlSelections(SelectClause selectClause) {
final List<SqlSelection> sqlSelections = selectClause.getSqlSelections();
final int size = sqlSelections.size();
final SelectItemReferenceStrategy referenceStrategy = getDialect().getGroupBySelectItemReferenceStrategy();
// When the dialect needs to render the aliased expression and there are aliased group by items,
// we need to inline parameters as the database would otherwise not be able to match the group by item
// to the select item, ultimately leading to a query error
final BitSet selectItemsToInline;
if (referenceStrategy == SelectItemReferenceStrategy.EXPRESSION) {
selectItemsToInline = getSelectItemsToInline();
} else {
selectItemsToInline = null;
}
final SqlAstNodeRenderingMode original = parameterRenderingMode;
if (needsSelectAliases || referenceStrategy == SelectItemReferenceStrategy.ALIAS && hasSelectAliasInGroupByClause()) {
String separator = NO_SEPARATOR;
if (columnAliases == null) {
for (int i = 0; i < size; i++) {
final SqlSelection sqlSelection = sqlSelections.get(i);
appendSql(separator);
if (selectItemsToInline != null && selectItemsToInline.get(i)) {
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
} else {
parameterRenderingMode = SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER;
}
visitSqlSelection(sqlSelection);
parameterRenderingMode = original;
appendSql(" c");
appendSql(i);
separator = COMA_SEPARATOR;
}
} else {
for (int i = 0; i < size; i++) {
final SqlSelection sqlSelection = sqlSelections.get(i);
appendSql(separator);
if (selectItemsToInline != null && selectItemsToInline.get(i)) {
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
} else {
parameterRenderingMode = SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER;
}
visitSqlSelection(sqlSelection);
parameterRenderingMode = original;
appendSql(WHITESPACE);
appendSql(columnAliases.get(i));
separator = COMA_SEPARATOR;
}
}
if (queryPartForRowNumbering != null) {
renderRowNumberingSelectItems(selectClause, queryPartForRowNumbering);
}
} else if (columnAliases == null) {
String separator = NO_SEPARATOR;
for (int i = 0; i < size; i++) {
final SqlSelection sqlSelection = sqlSelections.get(i);
appendSql(separator);
if (selectItemsToInline != null && selectItemsToInline.get(i)) {
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
} else {
parameterRenderingMode = SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER;
}
visitSqlSelection(sqlSelection);
parameterRenderingMode = original;
separator = COMA_SEPARATOR;
}
} else {
String separator = NO_SEPARATOR;
for (int i = 0; i < size; i++) {
final SqlSelection sqlSelection = sqlSelections.get(i);
appendSql(separator);
if (selectItemsToInline != null && selectItemsToInline.get(i)) {
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
} else {
parameterRenderingMode = SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER;
}
visitSqlSelection(sqlSelection);
appendSql(WHITESPACE);
appendSql(columnAliases.get(i));
parameterRenderingMode = original;
separator = COMA_SEPARATOR;
}
}
}
use of org.hibernate.sql.ast.SqlAstNodeRenderingMode 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");
}
use of org.hibernate.sql.ast.SqlAstNodeRenderingMode in project hibernate-orm by hibernate.
the class AbstractSqlAstTranslator method visitPartitionExpressions.
protected final void visitPartitionExpressions(List<Expression> partitionExpressions, Function<Expression, Expression> resolveAliasExpression, boolean inlineParametersOfAliasedExpressions) {
String separator = "";
for (Expression partitionExpression : partitionExpressions) {
final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple(partitionExpression);
if (sqlTuple != null) {
for (Expression e : sqlTuple.getExpressions()) {
appendSql(separator);
final Expression resolved = resolveAliasExpression.apply(e);
if (inlineParametersOfAliasedExpressions && resolved != e) {
final SqlAstNodeRenderingMode original = parameterRenderingMode;
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
renderPartitionItem(resolved);
parameterRenderingMode = original;
} else {
renderPartitionItem(resolved);
}
separator = COMA_SEPARATOR;
}
} else {
appendSql(separator);
final Expression resolved = resolveAliasExpression.apply(partitionExpression);
if (inlineParametersOfAliasedExpressions && resolved != partitionExpression) {
final SqlAstNodeRenderingMode original = parameterRenderingMode;
parameterRenderingMode = SqlAstNodeRenderingMode.INLINE_ALL_PARAMETERS;
renderPartitionItem(resolved);
parameterRenderingMode = original;
} else {
renderPartitionItem(resolved);
}
}
separator = COMA_SEPARATOR;
}
}
Aggregations