use of org.hibernate.type.descriptor.converter.AttributeConverterJdbcTypeAdapter in project hibernate-orm by hibernate.
the class SimpleValue method buildAttributeConverterTypeAdapter.
private <T> AttributeConverterTypeAdapter<T> buildAttributeConverterTypeAdapter(JpaAttributeConverter<T, ?> jpaAttributeConverter) {
JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType();
JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType();
// build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String
// conversions. This is the more complicated piece. First we need to determine the JDBC type code
// corresponding to the AttributeConverter's declared "databaseColumnJavaType" (how we read that value out
// of ResultSets). See JdbcTypeJavaClassMappings for details. Again, given example, this should return
// VARCHAR/CHAR
final JdbcType recommendedJdbcType = relationalJavaType.getRecommendedJdbcType(// todo (6.0) : handle the other JdbcRecommendedSqlTypeMappingContext methods
new JdbcTypeIndicators() {
@Override
public TypeConfiguration getTypeConfiguration() {
return metadata.getTypeConfiguration();
}
@Override
public TimeZoneStorageStrategy getDefaultTimeZoneStorageStrategy() {
return buildingContext.getBuildingOptions().getDefaultTimeZoneStorage();
}
});
int jdbcTypeCode = recommendedJdbcType.getDefaultSqlTypeCode();
if (isLob()) {
if (LobTypeMappings.isMappedToKnownLobCode(jdbcTypeCode)) {
jdbcTypeCode = LobTypeMappings.getLobCodeTypeMapping(jdbcTypeCode);
} else {
if (Serializable.class.isAssignableFrom(domainJavaType.getJavaTypeClass())) {
jdbcTypeCode = Types.BLOB;
} else {
throw new IllegalArgumentException(String.format(Locale.ROOT, "JDBC type-code [%s (%s)] not known to have a corresponding LOB equivalent, and Java type is not Serializable (to use BLOB)", jdbcTypeCode, JdbcTypeNameMapper.getTypeName(jdbcTypeCode)));
}
}
}
if (isNationalized()) {
jdbcTypeCode = NationalizedTypeMappings.toNationalizedTypeCode(jdbcTypeCode);
}
// todo : cache the AttributeConverterTypeAdapter in case that AttributeConverter is applied multiple times.
return new AttributeConverterTypeAdapter<>(ConverterDescriptor.TYPE_NAME_PREFIX + jpaAttributeConverter.getConverterJavaType().getJavaType().getTypeName(), String.format("BasicType adapter for AttributeConverter<%s,%s>", domainJavaType.getJavaType().getTypeName(), relationalJavaType.getJavaType().getTypeName()), jpaAttributeConverter, // calls into the binding/extraction process...
new AttributeConverterJdbcTypeAdapter(jpaAttributeConverter, metadata.getTypeConfiguration().getJdbcTypeRegistry().getDescriptor(jdbcTypeCode), relationalJavaType), relationalJavaType, domainJavaType, null);
}
Aggregations