HHH-16027 add TypeContributions.contributeAttributeConverter()
This commit is contained in:
parent
7444b26db4
commit
2e84d51838
|
@ -287,16 +287,19 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void contributeType(BasicType<?> type) {
|
public void contributeType(BasicType<?> type) {
|
||||||
options.basicTypeRegistrations.add( new BasicTypeRegistration( type ) );
|
options.basicTypeRegistrations.add( new BasicTypeRegistration( type ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void contributeType(BasicType<?> type, String... keys) {
|
public void contributeType(BasicType<?> type, String... keys) {
|
||||||
options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys ) );
|
options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public void contributeType(UserType<?> type, String[] keys) {
|
public void contributeType(UserType<?> type, String[] keys) {
|
||||||
options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys, getTypeConfiguration() ) );
|
options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys, getTypeConfiguration() ) );
|
||||||
}
|
}
|
||||||
|
@ -306,6 +309,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
||||||
return bootstrapContext.getTypeConfiguration();
|
return bootstrapContext.getTypeConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contributeAttributeConverter(Class<? extends AttributeConverter<?, ?>> converterClass) {
|
||||||
|
bootstrapContext.addAttributeConverterDescriptor(
|
||||||
|
new ClassBasedConverterDescriptor( converterClass, bootstrapContext.getClassmateContext() )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
|
public MetadataBuilder applyCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) {
|
||||||
this.bootstrapContext.addCacheRegionDefinition( cacheRegionDefinition );
|
this.bootstrapContext.addCacheRegionDefinition( cacheRegionDefinition );
|
||||||
|
@ -319,6 +329,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Deprecated
|
||||||
public MetadataBuilder applySourceProcessOrdering(MetadataSourceType... sourceTypes) {
|
public MetadataBuilder applySourceProcessOrdering(MetadataSourceType... sourceTypes) {
|
||||||
Collections.addAll( options.sourceProcessOrdering, sourceTypes );
|
Collections.addAll( options.sourceProcessOrdering, sourceTypes );
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.model;
|
package org.hibernate.boot.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
import org.hibernate.Incubating;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.CustomType;
|
import org.hibernate.type.CustomType;
|
||||||
import org.hibernate.type.StandardBasicTypeTemplate;
|
import org.hibernate.type.StandardBasicTypeTemplate;
|
||||||
|
@ -21,11 +23,13 @@ import org.hibernate.usertype.UserType;
|
||||||
* {@link TypeConfiguration}, either by a {@link org.hibernate.dialect.Dialect}
|
* {@link TypeConfiguration}, either by a {@link org.hibernate.dialect.Dialect}
|
||||||
* or by a {@link TypeContributor}.
|
* or by a {@link TypeContributor}.
|
||||||
*
|
*
|
||||||
* @see TypeContributor
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
* @see TypeContributor
|
||||||
*/
|
*/
|
||||||
public interface TypeContributions {
|
public interface TypeContributions {
|
||||||
|
/**
|
||||||
|
* The {@link TypeConfiguration} to contribute to
|
||||||
|
*/
|
||||||
TypeConfiguration getTypeConfiguration();
|
TypeConfiguration getTypeConfiguration();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,12 +50,23 @@ public interface TypeContributions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a {@link UserType} as the implicit (auto-applied)
|
* Register a {@link UserType} as the implicit (auto-applied)
|
||||||
* type for values of type {@link UserType#returnedClass()}
|
* type for values of type {@link UserType#returnedClass()}.
|
||||||
*/
|
*/
|
||||||
default <T> void contributeType(UserType<T> type) {
|
default void contributeType(UserType<?> type) {
|
||||||
contributeType( type, type.returnedClass().getName() );
|
contributeType( type, type.returnedClass().getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an {@link AttributeConverter} class.
|
||||||
|
*
|
||||||
|
* @since 6.2
|
||||||
|
*/
|
||||||
|
@Incubating
|
||||||
|
default void contributeAttributeConverter(Class<? extends AttributeConverter<?, ?>> converterClass) {
|
||||||
|
// default implementation for backward compatibility
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated See discussion of {@code TypeContributor} in User Guide.
|
* @deprecated See discussion of {@code TypeContributor} in User Guide.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,9 +11,11 @@ import org.hibernate.Incubating;
|
||||||
import jakarta.persistence.AttributeConverter;
|
import jakarta.persistence.AttributeConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AttributeConverter registrations
|
* A registry for JPA {@linkplain AttributeConverter converters}.
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
|
* @see AttributeConverter
|
||||||
|
* @since 6.2
|
||||||
*/
|
*/
|
||||||
@Incubating
|
@Incubating
|
||||||
public interface ConverterRegistry {
|
public interface ConverterRegistry {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jakarta.persistence.AttributeConverter;
|
||||||
import org.hibernate.boot.MetadataSources;
|
import org.hibernate.boot.MetadataSources;
|
||||||
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
|
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
|
||||||
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
||||||
|
@ -23,6 +24,7 @@ import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||||
import org.hibernate.boot.model.TypeContributions;
|
import org.hibernate.boot.model.TypeContributions;
|
||||||
import org.hibernate.boot.model.TypeContributor;
|
import org.hibernate.boot.model.TypeContributor;
|
||||||
|
import org.hibernate.boot.model.convert.spi.ConverterRegistry;
|
||||||
import org.hibernate.boot.model.process.internal.ManagedResourcesImpl;
|
import org.hibernate.boot.model.process.internal.ManagedResourcesImpl;
|
||||||
import org.hibernate.boot.model.process.internal.ScanningCoordinator;
|
import org.hibernate.boot.model.process.internal.ScanningCoordinator;
|
||||||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||||
|
@ -154,7 +156,7 @@ public class MetadataBuildingProcess {
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
handleTypes( bootstrapContext, options );
|
handleTypes( bootstrapContext, options, metadataCollector );
|
||||||
|
|
||||||
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );
|
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService( ClassLoaderService.class );
|
||||||
|
|
||||||
|
@ -520,13 +522,26 @@ public class MetadataBuildingProcess {
|
||||||
// return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
|
// return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private static void handleTypes(BootstrapContext bootstrapContext, MetadataBuildingOptions options) {
|
private static void handleTypes(
|
||||||
|
BootstrapContext bootstrapContext,
|
||||||
|
MetadataBuildingOptions options,
|
||||||
|
ConverterRegistry converterRegistry) {
|
||||||
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
|
final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);
|
||||||
|
|
||||||
final TypeConfiguration typeConfiguration = bootstrapContext.getTypeConfiguration();
|
final TypeConfiguration typeConfiguration = bootstrapContext.getTypeConfiguration();
|
||||||
final StandardServiceRegistry serviceRegistry = bootstrapContext.getServiceRegistry();
|
final StandardServiceRegistry serviceRegistry = bootstrapContext.getServiceRegistry();
|
||||||
final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry();
|
final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry();
|
||||||
final TypeContributions typeContributions = () -> typeConfiguration;
|
final TypeContributions typeContributions = new TypeContributions() {
|
||||||
|
@Override
|
||||||
|
public TypeConfiguration getTypeConfiguration() {
|
||||||
|
return typeConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contributeAttributeConverter(Class<? extends AttributeConverter<?, ?>> converterClass) {
|
||||||
|
converterRegistry.addAttributeConverter( converterClass );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// add Dialect contributed types
|
// add Dialect contributed types
|
||||||
final Dialect dialect = options.getServiceRegistry().getService( JdbcServices.class ).getDialect();
|
final Dialect dialect = options.getServiceRegistry().getService( JdbcServices.class ).getDialect();
|
||||||
|
|
Loading…
Reference in New Issue