clean up obsolete code in MetadataBuildingProcess

This commit is contained in:
Gavin King 2024-09-09 08:29:51 +02:00
parent 22aba27cff
commit f25060eeac

View File

@ -51,7 +51,6 @@
import org.hibernate.boot.model.source.internal.hbm.ModelBinder; import org.hibernate.boot.model.source.internal.hbm.ModelBinder;
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor; import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
import org.hibernate.boot.models.internal.DomainModelCategorizationCollector; import org.hibernate.boot.models.internal.DomainModelCategorizationCollector;
import org.hibernate.boot.models.internal.OrmAnnotationHelper;
import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult; import org.hibernate.boot.models.xml.spi.XmlPreProcessingResult;
import org.hibernate.boot.models.xml.spi.XmlPreProcessor; import org.hibernate.boot.models.xml.spi.XmlPreProcessor;
import org.hibernate.boot.models.xml.spi.XmlProcessingResult; import org.hibernate.boot.models.xml.spi.XmlProcessingResult;
@ -73,14 +72,10 @@
import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.models.internal.jandex.JandexClassDetails;
import org.hibernate.models.internal.jandex.JandexIndexerHelper; import org.hibernate.models.internal.jandex.JandexIndexerHelper;
import org.hibernate.models.internal.jdk.JdkBuilders;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.ClassLoading; import org.hibernate.models.spi.ClassLoading;
import org.hibernate.models.spi.RegistryPrimer;
import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.SourceModelBuildingContext;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry; import org.hibernate.type.BasicTypeRegistry;
@ -101,11 +96,9 @@
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex; import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.IndexView; import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer; import org.jboss.jandex.Indexer;
import org.jboss.logging.Logger;
import jakarta.persistence.AttributeConverter; import jakarta.persistence.AttributeConverter;
@ -135,7 +128,6 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class MetadataBuildingProcess { public class MetadataBuildingProcess {
private static final Logger log = Logger.getLogger( MetadataBuildingProcess.class );
/** /**
* Unified single phase for MetadataSources to Metadata process * Unified single phase for MetadataSources to Metadata process
@ -221,16 +213,14 @@ public static MetadataImplementor complete(
// Set up the processors and start binding // Set up the processors and start binding
// NOTE : this becomes even more simplified after we move purely // NOTE : this becomes even more simplified after we move purely
// to unified model // to unified model
final IndexView jandexView = domainModelSource.getJandexIndex(); // final IndexView jandexView = domainModelSource.getJandexIndex();
coordinateProcessors( coordinateProcessors(
managedResources, managedResources,
options, options,
rootMetadataBuildingContext, rootMetadataBuildingContext,
domainModelSource, domainModelSource,
classLoaderService, metadataCollector
metadataCollector,
jandexView
); );
processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext ); processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext );
@ -245,19 +235,18 @@ private static void coordinateProcessors(
MetadataBuildingOptions options, MetadataBuildingOptions options,
MetadataBuildingContextRootImpl rootMetadataBuildingContext, MetadataBuildingContextRootImpl rootMetadataBuildingContext,
DomainModelSource domainModelSource, DomainModelSource domainModelSource,
ClassLoaderService classLoaderService, InFlightMetadataCollectorImpl metadataCollector) {
InFlightMetadataCollectorImpl metadataCollector,
IndexView jandexView) {
final MetadataSourceProcessor processor = new MetadataSourceProcessor() { final MetadataSourceProcessor processor = new MetadataSourceProcessor() {
private final MetadataSourceProcessor hbmProcessor = options.isXmlMappingEnabled() private final MetadataSourceProcessor hbmProcessor = options.isXmlMappingEnabled()
? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext ) ? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext )
: new NoOpMetadataSourceProcessorImpl(); : new NoOpMetadataSourceProcessorImpl();
private final AnnotationMetadataSourceProcessorImpl annotationProcessor = new AnnotationMetadataSourceProcessorImpl( private final AnnotationMetadataSourceProcessorImpl annotationProcessor =
managedResources, new AnnotationMetadataSourceProcessorImpl(
domainModelSource, managedResources,
rootMetadataBuildingContext domainModelSource,
); rootMetadataBuildingContext
);
@Override @Override
public void prepare() { public void prepare() {
@ -527,66 +516,51 @@ public static IndexView resolveJandexIndex(
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() ); return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
} }
//
public static void preFillRegistries(RegistryPrimer.Contributions contributions, SourceModelBuildingContext buildingContext) { // public static void preFillRegistries(RegistryPrimer.Contributions contributions, SourceModelBuildingContext buildingContext) {
OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation ); // OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation );
//
final IndexView jandexIndex = buildingContext.getJandexIndex(); // final IndexView jandexIndex = buildingContext.getJandexIndex();
if ( jandexIndex == null ) { // if ( jandexIndex == null ) {
return; // return;
} // }
//
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); // final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry(); // final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
//
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) { // for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
final String className = knownClass.name().toString(); // final String className = knownClass.name().toString();
//
if ( knownClass.isAnnotation() ) { // if ( knownClass.isAnnotation() ) {
// it is always safe to load the annotation classes - we will never be enhancing them // // it is always safe to load the annotation classes - we will never be enhancing them
//noinspection rawtypes // //noinspection rawtypes
final Class annotationClass = buildingContext // final Class annotationClass = buildingContext
.getClassLoading() // .getClassLoading()
.classForName( className ); // .classForName( className );
//noinspection unchecked // //noinspection unchecked
annotationDescriptorRegistry.resolveDescriptor( // annotationDescriptorRegistry.resolveDescriptor(
annotationClass, // annotationClass,
(t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext ) // (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
); // );
} // }
//
classDetailsRegistry.resolveClassDetails( // classDetailsRegistry.resolveClassDetails(
className, // className,
(name) -> new JandexClassDetails( knownClass, buildingContext ) // (name) -> new JandexClassDetails( knownClass, buildingContext )
); // );
} // }
} // }
private static void processAdditionalMappingContributions( private static void processAdditionalMappingContributions(
InFlightMetadataCollectorImpl metadataCollector, InFlightMetadataCollectorImpl metadataCollector,
MetadataBuildingOptions options, MetadataBuildingOptions options,
ClassLoaderService classLoaderService, ClassLoaderService classLoaderService,
MetadataBuildingContextRootImpl rootMetadataBuildingContext) { MetadataBuildingContextRootImpl rootMetadataBuildingContext) {
final MappingBinder mappingBinder;
if ( options.isXmlMappingEnabled() ) {
mappingBinder = new MappingBinder(
classLoaderService,
new MappingBinder.Options() {
@Override
public boolean validateMappings() {
return false;
}
}
);
}
else {
mappingBinder = null;
}
final AdditionalMappingContributionsImpl contributions = new AdditionalMappingContributionsImpl( final AdditionalMappingContributionsImpl contributions = new AdditionalMappingContributionsImpl(
metadataCollector, metadataCollector,
options, options,
mappingBinder, options.isXmlMappingEnabled() ? new MappingBinder( classLoaderService, () -> false ) : null,
rootMetadataBuildingContext rootMetadataBuildingContext
); );
@ -1016,29 +990,27 @@ private static void adaptTimestampTypesToDefaultTimeZoneStorage(
} }
private static JdbcType getTimeWithTimeZoneOverride(MetadataBuildingOptions options, JdbcTypeRegistry jdbcTypeRegistry) { private static JdbcType getTimeWithTimeZoneOverride(MetadataBuildingOptions options, JdbcTypeRegistry jdbcTypeRegistry) {
switch ( options.getDefaultTimeZoneStorage() ) { return switch ( options.getDefaultTimeZoneStorage() ) {
case NORMALIZE: case NORMALIZE ->
// For NORMALIZE, we replace the standard types that use TIME_WITH_TIMEZONE to use TIME // For NORMALIZE, we replace the standard types that use TIME_WITH_TIMEZONE to use TIME
return jdbcTypeRegistry.getDescriptor( Types.TIME ); jdbcTypeRegistry.getDescriptor( Types.TIME );
case NORMALIZE_UTC: case NORMALIZE_UTC ->
// For NORMALIZE_UTC, we replace the standard types that use TIME_WITH_TIMEZONE to use TIME_UTC // For NORMALIZE_UTC, we replace the standard types that use TIME_WITH_TIMEZONE to use TIME_UTC
return jdbcTypeRegistry.getDescriptor( SqlTypes.TIME_UTC ); jdbcTypeRegistry.getDescriptor( SqlTypes.TIME_UTC );
default: default -> null;
return null; };
}
} }
private static JdbcType getTimestampWithTimeZoneOverride(MetadataBuildingOptions options, JdbcTypeRegistry jdbcTypeRegistry) { private static JdbcType getTimestampWithTimeZoneOverride(MetadataBuildingOptions options, JdbcTypeRegistry jdbcTypeRegistry) {
switch ( options.getDefaultTimeZoneStorage() ) { return switch (options.getDefaultTimeZoneStorage()) {
case NORMALIZE: case NORMALIZE ->
// For NORMALIZE, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP // For NORMALIZE, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP
return jdbcTypeRegistry.getDescriptor( Types.TIMESTAMP ); jdbcTypeRegistry.getDescriptor( Types.TIMESTAMP );
case NORMALIZE_UTC: case NORMALIZE_UTC ->
// For NORMALIZE_UTC, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP_UTC // For NORMALIZE_UTC, we replace the standard types that use TIMESTAMP_WITH_TIMEZONE to use TIMESTAMP_UTC
return jdbcTypeRegistry.getDescriptor( SqlTypes.TIMESTAMP_UTC ); jdbcTypeRegistry.getDescriptor( SqlTypes.TIMESTAMP_UTC );
default: default -> null;
return null; };
}
} }
private static void addFallbackIfNecessary( private static void addFallbackIfNecessary(