use of org.hibernate.type.internal.NamedBasicTypeImpl in project hibernate-orm by hibernate.
the class MetadataBuildingProcess method handleTypes.
// todo (7.0) : buildJandexInitializer
// private static JandexInitManager buildJandexInitializer(
// MetadataBuildingOptions options,
// ClassLoaderAccess classLoaderAccess) {
// final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
// org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
// options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
// false
// );
//
// return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
// }
private static void handleTypes(BootstrapContext bootstrapContext, MetadataBuildingOptions options) {
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
final TypeConfiguration typeConfiguration = bootstrapContext.getTypeConfiguration();
final TypeContributions typeContributions = new TypeContributions() {
@Override
public void contributeType(BasicType type) {
getBasicTypeRegistry().register(type);
conditionallyRegisterJtd(type.getJavaTypeDescriptor());
}
private void conditionallyRegisterJtd(JavaType jtd) {
final JavaTypeRegistry jtdRegistry = getTypeConfiguration().getJavaTypeRegistry();
jtdRegistry.resolveDescriptor(jtd.getJavaTypeClass(), () -> jtd);
}
@Override
public void contributeType(BasicType type, String... keys) {
getBasicTypeRegistry().register(type, keys);
conditionallyRegisterJtd(type.getJavaTypeDescriptor());
}
@Override
public void contributeType(UserType type, String[] keys) {
contributeType(new CustomType<Object>(type, keys, getTypeConfiguration()));
}
@Override
public void contributeJavaType(JavaType<?> descriptor) {
typeConfiguration.getJavaTypeRegistry().addDescriptor(descriptor);
}
@Override
public void contributeJdbcType(JdbcType descriptor) {
typeConfiguration.getJdbcTypeRegistry().addDescriptor(descriptor);
}
@Override
public <T> void contributeType(UserType<T> descriptor) {
typeConfiguration.getBasicTypeRegistry().register(descriptor, descriptor.returnedClass().getName());
}
@Override
public TypeConfiguration getTypeConfiguration() {
return typeConfiguration;
}
final BasicTypeRegistry getBasicTypeRegistry() {
return getTypeConfiguration().getBasicTypeRegistry();
}
};
// add Dialect contributed types
final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect();
dialect.contributeTypes(typeContributions, options.getServiceRegistry());
// add TypeContributor contributed types.
for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) {
contributor.contribute(typeContributions, options.getServiceRegistry());
}
// add fallback type descriptors
final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry();
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.UUID, SqlTypes.BINARY);
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.JSON, SqlTypes.VARBINARY);
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.INET, SqlTypes.VARBINARY);
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.INTERVAL_SECOND, SqlTypes.NUMERIC);
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.GEOMETRY, SqlTypes.VARBINARY);
addFallbackIfNecessary(jdbcTypeRegistry, SqlTypes.POINT, SqlTypes.VARBINARY);
// add explicit application registered types
typeConfiguration.addBasicTypeRegistrationContributions(options.getBasicTypeRegistrations());
// For NORMALIZE, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP
if (options.getDefaultTimeZoneStorage() == TimeZoneStorageStrategy.NORMALIZE) {
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final JdbcType timestampDescriptor = jdbcTypeRegistry.getDescriptor(Types.TIMESTAMP);
final BasicTypeRegistry basicTypeRegistry = typeConfiguration.getBasicTypeRegistry();
final BasicType<?> offsetDateTimeType = new NamedBasicTypeImpl<>(javaTypeRegistry.getDescriptor(OffsetDateTime.class), timestampDescriptor, "OffsetDateTime");
final BasicType<?> zonedDateTimeType = new NamedBasicTypeImpl<>(javaTypeRegistry.getDescriptor(ZonedDateTime.class), timestampDescriptor, "ZonedDateTime");
basicTypeRegistry.register(offsetDateTimeType, "org.hibernate.type.OffsetDateTimeType", OffsetDateTime.class.getSimpleName(), OffsetDateTime.class.getName());
basicTypeRegistry.register(zonedDateTimeType, "org.hibernate.type.ZonedDateTimeType", ZonedDateTime.class.getSimpleName(), ZonedDateTime.class.getName());
}
}
Aggregations