Search in sources :

Example 76 with Expression

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(")");
}
Also used : Format(org.hibernate.sql.ast.tree.expression.Format) Expression(org.hibernate.sql.ast.tree.expression.Expression)

Example 77 with Expression

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);
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) CastTarget(org.hibernate.sql.ast.tree.expression.CastTarget) Expression(org.hibernate.sql.ast.tree.expression.Expression) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer) CastType(org.hibernate.query.sqm.CastType)

Example 78 with Expression

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);
}
Also used : SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) DurationUnit(org.hibernate.sql.ast.tree.expression.DurationUnit)

Example 79 with Expression

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);
    }
}
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 80 with Expression

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));
}
Also used : SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SortSpecification(org.hibernate.sql.ast.tree.select.SortSpecification) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)

Aggregations

Expression (org.hibernate.sql.ast.tree.expression.Expression)130 CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)68 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)67 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)62 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)57 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)54 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)54 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)42 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)37 SqlTuple (org.hibernate.sql.ast.tree.expression.SqlTuple)35 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)34 SelfRenderingSqlFragmentExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression)33 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)32 ArrayList (java.util.ArrayList)31 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)31 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)28 TableReference (org.hibernate.sql.ast.tree.from.TableReference)25 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)23 ComparisonPredicate (org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)23 NavigablePath (org.hibernate.query.spi.NavigablePath)21