Search in sources :

Example 1 with PatternRenderer

use of org.hibernate.query.sqm.produce.function.internal.PatternRenderer in project hibernate-orm by hibernate.

the class CastingConcatFunction method renderAsString.

private void renderAsString(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression expression) {
    final JdbcMapping sourceMapping = expression.getExpressionType().getJdbcMappings().get(0);
    // No need to cast if we already have a string
    if (sourceMapping.getCastType() == CastType.STRING) {
        translator.render(expression, argumentRenderingMode);
    } else {
        final String cast = dialect.castPattern(sourceMapping.getCastType(), CastType.STRING);
        new PatternRenderer(cast.replace("?2", concatArgumentCastType), argumentRenderingMode).render(sqlAppender, Collections.singletonList(expression), translator);
    }
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer)

Example 2 with PatternRenderer

use of org.hibernate.query.sqm.produce.function.internal.PatternRenderer in project hibernate-orm by hibernate.

the class TimestampaddFunction method patternRenderer.

PatternRenderer patternRenderer(TemporalUnit unit, Expression interval, Expression to) {
    TemporalType temporalType = getSqlTemporalType(to.getExpressionType());
    IntervalType intervalType = getSqlIntervalType(interval.getExpressionType().getJdbcMappings().get(0));
    return new PatternRenderer(dialect.timestampaddPattern(unit, temporalType, intervalType));
}
Also used : IntervalType(org.hibernate.query.sqm.IntervalType) TypeConfiguration.getSqlIntervalType(org.hibernate.type.spi.TypeConfiguration.getSqlIntervalType) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer) TemporalType(jakarta.persistence.TemporalType) TypeConfiguration.getSqlTemporalType(org.hibernate.type.spi.TypeConfiguration.getSqlTemporalType)

Example 3 with PatternRenderer

use of org.hibernate.query.sqm.produce.function.internal.PatternRenderer in project hibernate-orm by hibernate.

the class TimestampdiffFunction method patternRenderer.

private PatternRenderer patternRenderer(TemporalUnit unit, Expression from, Expression to) {
    TemporalType lhsTemporalType = getSqlTemporalType(from.getExpressionType());
    TemporalType rhsTemporalType = getSqlTemporalType(to.getExpressionType());
    return new PatternRenderer(dialect.timestampdiffPattern(unit, lhsTemporalType, rhsTemporalType));
}
Also used : PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer) TypeConfiguration.getSqlTemporalType(org.hibernate.type.spi.TypeConfiguration.getSqlTemporalType) TemporalType(jakarta.persistence.TemporalType)

Example 4 with PatternRenderer

use of org.hibernate.query.sqm.produce.function.internal.PatternRenderer in project hibernate-orm by hibernate.

the class TrimFunction method render.

@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
    final TrimSpec specification = ((TrimSpecification) sqlAstArguments.get(0)).getSpecification();
    final Object trimCharacter = ((Literal) sqlAstArguments.get(1)).getLiteralValue();
    final Expression sourceExpr = (Expression) sqlAstArguments.get(2);
    String trim = dialect.trimPattern(specification, (char) trimCharacter);
    new PatternRenderer(trim).render(sqlAppender, Collections.singletonList(sourceExpr), walker);
}
Also used : TrimSpec(org.hibernate.query.sqm.TrimSpec) Expression(org.hibernate.sql.ast.tree.expression.Expression) Literal(org.hibernate.sql.ast.tree.expression.Literal) TrimSpecification(org.hibernate.sql.ast.tree.expression.TrimSpecification) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer)

Example 5 with PatternRenderer

use of org.hibernate.query.sqm.produce.function.internal.PatternRenderer in project hibernate-orm by hibernate.

the class CountFunction method renderCastedArgument.

private boolean renderCastedArgument(SqlAppender sqlAppender, SqlAstTranslator<?> translator, Expression realArg) {
    if (concatArgumentCastType == null) {
        translator.render(realArg, defaultArgumentRenderingMode);
        return true;
    } else {
        final JdbcMapping sourceMapping = realArg.getExpressionType().getJdbcMappings().get(0);
        // No need to cast if we already have a string
        if (sourceMapping.getCastType() == CastType.STRING) {
            translator.render(realArg, defaultArgumentRenderingMode);
            return false;
        } else {
            final String cast = dialect.castPattern(sourceMapping.getCastType(), CastType.STRING);
            new PatternRenderer(cast.replace("?2", concatArgumentCastType)).render(sqlAppender, Collections.singletonList(realArg), translator);
            return false;
        }
    }
}
Also used : JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) PatternRenderer(org.hibernate.query.sqm.produce.function.internal.PatternRenderer)

Aggregations

PatternRenderer (org.hibernate.query.sqm.produce.function.internal.PatternRenderer)6 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)3 TemporalType (jakarta.persistence.TemporalType)2 Expression (org.hibernate.sql.ast.tree.expression.Expression)2 TypeConfiguration.getSqlTemporalType (org.hibernate.type.spi.TypeConfiguration.getSqlTemporalType)2 CastType (org.hibernate.query.sqm.CastType)1 IntervalType (org.hibernate.query.sqm.IntervalType)1 TrimSpec (org.hibernate.query.sqm.TrimSpec)1 CastTarget (org.hibernate.sql.ast.tree.expression.CastTarget)1 Literal (org.hibernate.sql.ast.tree.expression.Literal)1 TrimSpecification (org.hibernate.sql.ast.tree.expression.TrimSpecification)1 TypeConfiguration.getSqlIntervalType (org.hibernate.type.spi.TypeConfiguration.getSqlIntervalType)1