use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class DB2FormatEmulation method render.
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final Expression datetime = (Expression) arguments.get(0);
final boolean isTime = TypeConfiguration.getSqlTemporalType(datetime.getExpressionType()) == TemporalType.TIME;
final Format format = (Format) arguments.get(1);
sqlAppender.appendSql("(");
String[] bits = OracleDialect.datetimeFormat(format.getFormat(), false, false).result().split("\"");
boolean first = true;
for (int i = 0; i < bits.length; i++) {
String bit = bits[i];
if (!bit.isEmpty()) {
if (first) {
first = false;
} else {
sqlAppender.appendSql("||");
}
if (i % 2 == 0) {
sqlAppender.appendSql("varchar_format(");
// Times need to be wrapped into a timestamp to be able to use formatting
if (isTime) {
sqlAppender.appendSql("timestamp(current_date,");
datetime.accept(walker);
sqlAppender.appendSql(")");
} else {
datetime.accept(walker);
}
sqlAppender.appendSql(",'");
sqlAppender.appendSql(bit);
sqlAppender.appendSql("')");
} else {
sqlAppender.appendSql("'");
sqlAppender.appendSql(bit);
sqlAppender.appendSql("'");
}
}
}
if (first) {
sqlAppender.appendSql("''");
}
sqlAppender.appendSql(")");
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class CastFunction method render.
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final Expression source = (Expression) arguments.get(0);
final JdbcMapping sourceMapping = source.getExpressionType().getJdbcMappings().get(0);
final CastType sourceType = getCastType(sourceMapping);
final CastTarget castTarget = (CastTarget) arguments.get(1);
final JdbcMapping targetJdbcMapping = castTarget.getExpressionType().getJdbcMappings().get(0);
final CastType targetType = getCastType(targetJdbcMapping);
String cast = dialect.castPattern(sourceType, targetType);
new PatternRenderer(cast).render(sqlAppender, arguments, walker);
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class TimestampaddFunction method render.
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final DurationUnit field = (DurationUnit) arguments.get(0);
final Expression magnitude = (Expression) arguments.get(1);
final Expression to = (Expression) arguments.get(2);
patternRenderer(field.getUnit(), magnitude, to).render(sqlAppender, arguments, walker);
}
use of org.hibernate.sql.ast.tree.expression.Expression 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);
}
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class FunctionExpression method apply.
@Override
public void apply(QuerySpec ast, TableGroup tableGroup, String collation, String modelPartName, SortOrder sortOrder, NullPrecedence nullPrecedence, SqlAstCreationState creationState) {
final SelfRenderingFunctionSqlAstExpression expression = resolve(ast, tableGroup, modelPartName, creationState);
final Expression sortExpression = OrderingExpression.applyCollation(expression, collation, creationState);
ast.addSortSpecification(new SortSpecification(sortExpression, sortOrder, nullPrecedence));
}
Aggregations