use of org.hibernate.sql.ast.tree.expression.Format in project hibernate-orm by hibernate.
the class SQLServerFormatEmulation 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("format(");
if (isTime) {
sqlAppender.appendSql("cast(");
datetime.accept(walker);
sqlAppender.appendSql(" as datetime)");
} else {
datetime.accept(walker);
}
sqlAppender.appendSql(",'");
dialect.appendDatetimeFormat(sqlAppender, format.getFormat());
sqlAppender.appendSql("')");
}
use of org.hibernate.sql.ast.tree.expression.Format 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(")");
}
Aggregations