use of org.hibernate.type.descriptor.jdbc.JdbcType 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);
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class FunctionReturnImpl method toJdbcFunctionReturn.
@Override
public JdbcCallFunctionReturn toJdbcFunctionReturn(SharedSessionContractImplementor persistenceContext) {
final BindableType<T> ormType;
final JdbcCallRefCursorExtractorImpl refCursorExtractor;
final JdbcCallParameterExtractorImpl<T> parameterExtractor;
if (getJdbcTypeCode() == Types.REF_CURSOR) {
refCursorExtractor = new JdbcCallRefCursorExtractorImpl(null, 1);
ormType = null;
parameterExtractor = null;
} else {
final TypeConfiguration typeConfiguration = persistenceContext.getFactory().getTypeConfiguration();
final JdbcType sqlTypeDescriptor = typeConfiguration.getJdbcTypeRegistry().getDescriptor(getJdbcTypeCode());
final BasicJavaType<?> javaTypeMapping = sqlTypeDescriptor.getJdbcRecommendedJavaTypeMapping(null, null, typeConfiguration);
// noinspection unchecked
ormType = (BindableType<T>) typeConfiguration.standardBasicTypeForJavaType(javaTypeMapping.getJavaTypeClass());
parameterExtractor = new JdbcCallParameterExtractorImpl<>(procedureCall.getProcedureName(), null, 1, ormType);
refCursorExtractor = null;
}
return new JdbcCallFunctionReturnImpl(ormType, parameterExtractor, refCursorExtractor);
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class ResultSetAccess method resolveType.
@Override
default <J> BasicType<J> resolveType(int position, JavaType<J> explicitJavaType, SessionFactoryImplementor sessionFactory) {
final TypeConfiguration typeConfiguration = getFactory().getTypeConfiguration();
final JdbcServices jdbcServices = getFactory().getJdbcServices();
try {
final ResultSetMetaData metaData = getResultSet().getMetaData();
final String columnTypeName = metaData.getColumnTypeName(position);
final int columnType = metaData.getColumnType(position);
final int scale = metaData.getScale(position);
final int precision = metaData.getPrecision(position);
final int displaySize = metaData.getColumnDisplaySize(position);
final Dialect dialect = jdbcServices.getDialect();
final int length = dialect.resolveSqlTypeLength(columnTypeName, columnType, precision, scale, displaySize);
final JdbcType resolvedJdbcType = dialect.resolveSqlTypeDescriptor(columnTypeName, columnType, length, scale, typeConfiguration.getJdbcTypeRegistry());
final JavaType<J> javaType;
final JdbcType jdbcType;
// If there is an explicit JavaType, then prefer its recommended JDBC type
if (explicitJavaType != null) {
javaType = explicitJavaType;
jdbcType = explicitJavaType.getRecommendedJdbcType(new JdbcTypeIndicators() {
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
@Override
public long getColumnLength() {
return length;
}
@Override
public int getColumnPrecision() {
return precision;
}
@Override
public int getColumnScale() {
return scale;
}
@Override
public EnumType getEnumeratedType() {
return resolvedJdbcType.isNumber() ? EnumType.ORDINAL : EnumType.STRING;
}
});
} else {
jdbcType = resolvedJdbcType;
javaType = jdbcType.getJdbcRecommendedJavaTypeMapping(length, scale, typeConfiguration);
}
return typeConfiguration.getBasicTypeRegistry().resolve(javaType, jdbcType);
} catch (SQLException e) {
throw jdbcServices.getSqlExceptionHelper().convert(e, "Unable to determine JDBC type code for ResultSet position " + position);
}
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class JdbcTypeRegistry method getDescriptor.
public JdbcType getDescriptor(int jdbcTypeCode) {
JdbcType descriptor = descriptorMap.get(jdbcTypeCode);
if (descriptor != null) {
return descriptor;
}
if (JdbcTypeNameMapper.isStandardTypeCode(jdbcTypeCode)) {
log.debugf("A standard JDBC type code [%s] was not defined in SqlTypeDescriptorRegistry", jdbcTypeCode);
}
// see if the typecode is part of a known type family...
JdbcTypeFamilyInformation.Family family = JdbcTypeFamilyInformation.INSTANCE.locateJdbcTypeFamilyByTypeCode(jdbcTypeCode);
if (family != null) {
for (int potentialAlternateTypeCode : family.getTypeCodes()) {
if (potentialAlternateTypeCode != jdbcTypeCode) {
final JdbcType potentialAlternateDescriptor = descriptorMap.get(potentialAlternateTypeCode);
if (potentialAlternateDescriptor != null) {
// todo (6.0) : add a SqlTypeDescriptor#canBeAssignedFrom method ?
return potentialAlternateDescriptor;
}
if (JdbcTypeNameMapper.isStandardTypeCode(potentialAlternateTypeCode)) {
log.debugf("A standard JDBC type code [%s] was not defined in SqlTypeDescriptorRegistry", potentialAlternateTypeCode);
}
}
}
}
// finally, create a new descriptor mapping to getObject/setObject for this type code...
final ObjectJdbcType fallBackDescriptor = new ObjectJdbcType(jdbcTypeCode);
addDescriptor(fallBackDescriptor);
return fallBackDescriptor;
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class YesNoBinder method bind.
@Override
public void bind(YesNo annotation, MetadataBuildingContext buildingContext, PersistentClass persistentClass, Property property) {
final BasicValue booleanValueMapping = (BasicValue) property.getValue();
final BasicJavaType<?> javaType = (BasicJavaType<?>) buildingContext.getBootstrapContext().getTypeConfiguration().getJavaTypeRegistry().getDescriptor(Boolean.class);
final JdbcType jdbcType = buildingContext.getBootstrapContext().getTypeConfiguration().getJdbcTypeRegistry().getDescriptor(Types.CHAR);
final InstanceBasedConverterDescriptor converter = new InstanceBasedConverterDescriptor(YesNoConverter.INSTANCE, buildingContext.getBootstrapContext().getClassmateContext());
booleanValueMapping.setExplicitJavaTypeAccess((typeConfiguration) -> javaType);
booleanValueMapping.setExplicitJdbcTypeAccess((typeConfiguration) -> jdbcType);
booleanValueMapping.setJpaAttributeConverterDescriptor(converter);
}
Aggregations