Search in sources :

Example 1 with CastTarget

use of org.hibernate.sql.ast.tree.expression.CastTarget in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method renderCasted.

protected void renderCasted(Expression expression) {
    final List<SqlAstNode> arguments = new ArrayList<>(2);
    arguments.add(expression);
    if (expression instanceof SqlTypedMappingJdbcParameter) {
        final SqlTypedMappingJdbcParameter parameter = (SqlTypedMappingJdbcParameter) expression;
        final SqlTypedMapping sqlTypedMapping = parameter.getSqlTypedMapping();
        arguments.add(new CastTarget(parameter.getJdbcMapping(), sqlTypedMapping.getColumnDefinition(), sqlTypedMapping.getLength(), sqlTypedMapping.getPrecision(), sqlTypedMapping.getScale()));
    } else {
        arguments.add(new CastTarget(expression.getExpressionType().getJdbcMappings().get(0)));
    }
    castFunction().render(this, arguments, this);
}
Also used : CastTarget(org.hibernate.sql.ast.tree.expression.CastTarget) SqlTypedMappingJdbcParameter(org.hibernate.sql.exec.internal.SqlTypedMappingJdbcParameter) ArrayList(java.util.ArrayList) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) SqlTypedMapping(org.hibernate.metamodel.mapping.SqlTypedMapping)

Example 2 with CastTarget

use of org.hibernate.sql.ast.tree.expression.CastTarget 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)

Aggregations

CastTarget (org.hibernate.sql.ast.tree.expression.CastTarget)2 ArrayList (java.util.ArrayList)1 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)1 SqlTypedMapping (org.hibernate.metamodel.mapping.SqlTypedMapping)1 CastType (org.hibernate.query.sqm.CastType)1 PatternRenderer (org.hibernate.query.sqm.produce.function.internal.PatternRenderer)1 SqlAstNode (org.hibernate.sql.ast.tree.SqlAstNode)1 Expression (org.hibernate.sql.ast.tree.expression.Expression)1 SqlTypedMappingJdbcParameter (org.hibernate.sql.exec.internal.SqlTypedMappingJdbcParameter)1