Search in sources :

Example 1 with ConvertedQueryLiteral

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

the class BaseSqmToSqlAstConverter method visitEnumLiteral.

@SuppressWarnings({ "raw", "unchecked" })
@Override
public Object visitEnumLiteral(SqmEnumLiteral<?> sqmEnumLiteral) {
    final BasicValuedMapping inferrableType = (BasicValuedMapping) resolveInferredType();
    if (inferrableType instanceof ConvertibleModelPart) {
        final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType;
        final BasicValueConverter<Enum<?>, ?> valueConverter = inferredPart.getValueConverter();
        final Object jdbcValue = valueConverter.toRelationalValue(sqmEnumLiteral.getEnumValue());
        return new QueryLiteral<>(jdbcValue, inferredPart);
    }
    final EnumJavaType<?> enumJtd = sqmEnumLiteral.getExpressibleJavaType();
    final JdbcType jdbcType = getTypeConfiguration().getJdbcTypeRegistry().getDescriptor(SqlTypes.TINYINT);
    final BasicJavaType<Integer> relationalJtd = (BasicJavaType) getTypeConfiguration().getJavaTypeRegistry().getDescriptor(Integer.class);
    final BasicType<?> jdbcMappingType = getTypeConfiguration().getBasicTypeRegistry().resolve(relationalJtd, jdbcType);
    return new ConvertedQueryLiteral(sqmEnumLiteral.getEnumValue(), new OrdinalEnumValueConverter<>(enumJtd, jdbcType, relationalJtd), jdbcMappingType);
}
Also used : JdbcType(org.hibernate.type.descriptor.jdbc.JdbcType) ConvertedQueryLiteral(org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral) BasicValuedMapping(org.hibernate.metamodel.mapping.BasicValuedMapping) BigInteger(java.math.BigInteger) QueryLiteral(org.hibernate.sql.ast.tree.expression.QueryLiteral) ConvertedQueryLiteral(org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) ConvertibleModelPart(org.hibernate.metamodel.mapping.ConvertibleModelPart)

Aggregations

BigInteger (java.math.BigInteger)1 BasicValuedMapping (org.hibernate.metamodel.mapping.BasicValuedMapping)1 ConvertibleModelPart (org.hibernate.metamodel.mapping.ConvertibleModelPart)1 ConvertedQueryLiteral (org.hibernate.sql.ast.tree.expression.ConvertedQueryLiteral)1 QueryLiteral (org.hibernate.sql.ast.tree.expression.QueryLiteral)1 BasicJavaType (org.hibernate.type.descriptor.java.BasicJavaType)1 JdbcType (org.hibernate.type.descriptor.jdbc.JdbcType)1