From ec5bbe4546be3f8f5279166ada03b37ebf374b6a Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 22 Nov 2024 13:26:49 -0600 Subject: [PATCH] HHH-18534 - Remove the org.hibernate.boot.models.categorize package --- .../InFlightMetadataCollectorImpl.java | 2 +- .../process/spi/MetadataBuildingProcess.java | 3 +- .../boot/models/AttributeNature.java | 21 + .../org/hibernate/boot/models/Copied.java | 21 - .../spi => }/JpaEventListenerStyle.java | 2 +- .../MultipleAttributeNaturesException.java | 15 +- .../ModelCategorizationLogging.java | 21 - .../AbstractIdentifiableTypeMetadata.java | 244 ------------ .../internal/AbstractManagedTypeMetadata.java | 176 --------- ...ractPersistentAttributeMemberResolver.java | 99 ----- .../internal/AggregatedKeyMappingImpl.java | 26 -- .../internal/AttributeMetadataImpl.java | 43 -- .../internal/BasicKeyMappingImpl.java | 24 -- .../internal/CategorizationHelper.java | 234 ----------- .../internal/CategorizedDomainModelImpl.java | 81 ---- .../internal/EntityHierarchyBuilder.java | 238 ----------- .../internal/EntityHierarchyImpl.java | 318 --------------- .../internal/EntityTypeMetadataImpl.java | 369 ------------------ .../internal/HierarchyMetadataCollector.java | 310 --------------- .../internal/HierarchyTypeConsumer.java | 17 - .../internal/LifecycleCallbackCollector.java | 129 ------ .../MappedSuperclassTypeMetadataImpl.java | 88 ----- .../ModelCategorizationContextImpl.java | 67 ---- .../internal/NonAggregatedKeyMappingImpl.java | 57 --- ...dardPersistentAttributeMemberResolver.java | 315 --------------- .../boot/models/categorize/package-info.java | 26 -- .../categorize/spi/AggregatedKeyMapping.java | 15 - .../categorize/spi/AllMemberConsumer.java | 15 - .../categorize/spi/AttributeConsumer.java | 15 - .../categorize/spi/AttributeMetadata.java | 46 --- .../categorize/spi/BasicKeyMapping.java | 11 - .../models/categorize/spi/CacheRegion.java | 130 ------ .../spi/CategorizedDomainModel.java | 101 ----- .../spi/ClassAttributeAccessType.java | 56 --- .../categorize/spi/CompositeKeyMapping.java | 14 - .../categorize/spi/EntityHierarchy.java | 82 ---- .../categorize/spi/EntityTypeMetadata.java | 87 ----- .../spi/IdentifiableTypeMetadata.java | 71 ---- .../models/categorize/spi/KeyMapping.java | 18 - .../spi/ManagedResourcesProcessor.java | 230 ----------- .../categorize/spi/ManagedTypeMetadata.java | 50 --- .../spi/MappedSuperclassTypeMetadata.java | 17 - .../spi/ModelCategorizationContext.java | 33 -- .../categorize/spi/NaturalIdCacheRegion.java | 39 -- .../spi/NonAggregatedKeyMapping.java | 34 -- .../PersistentAttributeMemberResolver.java | 41 -- .../spi/SingleAttributeKeyMapping.java | 32 -- .../models/categorize/spi/TableOwner.java | 13 - .../internal/ClassLoaderServiceLoading.java | 2 +- .../DomainModelCategorizationCollector.java | 50 +-- .../internal/GlobalRegistrationsImpl.java | 2 +- .../models/spi/ConversionRegistration.java | 21 +- .../boot/models/spi/JpaEventListener.java | 2 +- .../xml/internal/XmlAnnotationHelper.java | 2 +- .../boot/models/SourceModelTestHelper.java | 2 +- .../xml/globals/JpaEventListenerTests.java | 76 +++- 56 files changed, 118 insertions(+), 4135 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/AttributeNature.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/Copied.java rename hibernate-core/src/main/java/org/hibernate/boot/models/{categorize/spi => }/JpaEventListenerStyle.java (92%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/ModelCategorizationLogging.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractManagedTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AggregatedKeyMappingImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AttributeMetadataImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/BasicKeyMappingImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyBuilder.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityHierarchyImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/EntityTypeMetadataImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyMetadataCollector.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/HierarchyTypeConsumer.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/LifecycleCallbackCollector.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/MappedSuperclassTypeMetadataImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/ModelCategorizationContextImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/NonAggregatedKeyMappingImpl.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/StandardPersistentAttributeMemberResolver.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/package-info.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/AggregatedKeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/AllMemberConsumer.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/AttributeConsumer.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/AttributeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/BasicKeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CacheRegion.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ClassAttributeAccessType.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CompositeKeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/EntityHierarchy.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/EntityTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/IdentifiableTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/KeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/MappedSuperclassTypeMetadata.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ModelCategorizationContext.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NaturalIdCacheRegion.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/NonAggregatedKeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/PersistentAttributeMemberResolver.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/SingleAttributeKeyMapping.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/TableOwner.java rename hibernate-core/src/main/java/org/hibernate/boot/models/{categorize => }/internal/ClassLoaderServiceLoading.java (96%) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java index f39b55bf76..0d61ce73ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java @@ -59,7 +59,7 @@ import org.hibernate.boot.model.relational.QualifiedTableName; import org.hibernate.boot.model.relational.SqlStringGenerationContext; import org.hibernate.boot.model.source.internal.ImplicitColumnNamingSecondPass; import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext; -import org.hibernate.boot.models.categorize.internal.ClassLoaderServiceLoading; +import org.hibernate.boot.models.internal.ClassLoaderServiceLoading; import org.hibernate.boot.models.internal.GlobalRegistrationsImpl; import org.hibernate.boot.models.internal.ModelsHelper; import org.hibernate.boot.models.spi.GlobalRegistrations; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java index e69c8fddfb..2ed3821bb1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java @@ -230,7 +230,8 @@ public class MetadataBuildingProcess { return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext ); } - private static void coordinateProcessors( + @Internal + public static void coordinateProcessors( ManagedResources managedResources, MetadataBuildingOptions options, MetadataBuildingContextRootImpl rootMetadataBuildingContext, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/AttributeNature.java b/hibernate-core/src/main/java/org/hibernate/boot/models/AttributeNature.java new file mode 100644 index 0000000000..b4502957ac --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/AttributeNature.java @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-or-later + * Copyright Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.boot.models; + +/** + * An enum defining the nature (categorization) of a persistent attribute. + * + * @see jakarta.persistence.metamodel.Attribute.PersistentAttributeType + */ +public enum AttributeNature { + BASIC, + EMBEDDED, + ANY, + TO_ONE, + ELEMENT_COLLECTION, + MANY_TO_ANY, + MANY_TO_MANY, + ONE_TO_MANY +} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/Copied.java b/hibernate-core/src/main/java/org/hibernate/boot/models/Copied.java deleted file mode 100644 index bcc2cfc805..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/Copied.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the class is copied from hibernate-core and should ultimately use that one - * - * @author Steve Ebersole - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface Copied { - Class value() default void.class; -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListenerStyle.java b/hibernate-core/src/main/java/org/hibernate/boot/models/JpaEventListenerStyle.java similarity index 92% rename from hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListenerStyle.java rename to hibernate-core/src/main/java/org/hibernate/boot/models/JpaEventListenerStyle.java index a3ff3aab3f..32ec2d0bfd 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListenerStyle.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/JpaEventListenerStyle.java @@ -2,7 +2,7 @@ * SPDX-License-Identifier: LGPL-2.1-or-later * Copyright Red Hat Inc. and Hibernate Authors */ -package org.hibernate.boot.models.categorize.spi; +package org.hibernate.boot.models; /** * JPA defines 2 ways events callbacks can happen... diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/MultipleAttributeNaturesException.java b/hibernate-core/src/main/java/org/hibernate/boot/models/MultipleAttributeNaturesException.java index 321039ac19..5a6ce0b629 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/MultipleAttributeNaturesException.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/MultipleAttributeNaturesException.java @@ -6,20 +6,21 @@ package org.hibernate.boot.models; import java.util.EnumSet; -import org.hibernate.MappingException; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; +import org.hibernate.AnnotationException; +import org.hibernate.Incubating; /** - * Condition where an attribute indicates multiple {@linkplain AttributeMetadata.AttributeNature natures} + * Condition where an attribute indicates multiple {@linkplain AttributeNature natures} * * @author Steve Ebersole */ -public class MultipleAttributeNaturesException extends MappingException { +@Incubating +public class MultipleAttributeNaturesException extends AnnotationException { private final String attributeName; public MultipleAttributeNaturesException( String attributeName, - EnumSet natures) { + EnumSet natures) { super( craftMessage( attributeName, natures ) ); this.attributeName = attributeName; } @@ -28,12 +29,12 @@ public class MultipleAttributeNaturesException extends MappingException { return attributeName; } - private static String craftMessage(String attributeName, EnumSet natures) { + private static String craftMessage(String attributeName, EnumSet natures) { final StringBuilder buffer = new StringBuilder( "Attribute `" ) .append( attributeName ) .append( "` expressed multiple natures [" ); String separator = ""; - for ( AttributeMetadata.AttributeNature nature : natures ) { + for ( AttributeNature nature : natures ) { buffer.append( separator ); buffer.append( nature.name() ); separator = ","; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/ModelCategorizationLogging.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/ModelCategorizationLogging.java deleted file mode 100644 index 5c00e56da2..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/ModelCategorizationLogging.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize; - -import org.hibernate.Internal; - -import org.jboss.logging.Logger; - -/** - * todo : find the proper min/max id range - * - * @author Steve Ebersole - */ -@Internal -public interface ModelCategorizationLogging { - String NAME = "org.hibernate.models.orm"; - - Logger MODEL_CATEGORIZATION_LOGGER = Logger.getLogger( NAME ); -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java deleted file mode 100644 index 8628772a52..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractIdentifiableTypeMetadata.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; - -import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; -import org.hibernate.boot.models.categorize.spi.EntityHierarchy; -import org.hibernate.boot.models.categorize.spi.IdentifiableTypeMetadata; -import org.hibernate.boot.models.spi.JpaEventListener; -import org.hibernate.boot.models.categorize.spi.JpaEventListenerStyle; -import org.hibernate.boot.models.categorize.spi.MappedSuperclassTypeMetadata; -import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; -import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.ClassDetailsRegistry; - -import jakarta.persistence.AccessType; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.ExcludeDefaultListeners; -import jakarta.persistence.ExcludeSuperclassListeners; - - -/** - * @author Steve Ebersole - */ -public abstract class AbstractIdentifiableTypeMetadata - extends AbstractManagedTypeMetadata - implements IdentifiableTypeMetadata { - private final EntityHierarchy hierarchy; - private final IdentifiableTypeMetadata superType; - private final Set subTypes = new HashSet<>(); - private final ClassAttributeAccessType classLevelAccessType; - - /** - * Used when creating the hierarchy root-root - * - * @param implicitAccessType This is the hierarchy default - */ - public AbstractIdentifiableTypeMetadata( - ClassDetails classDetails, - EntityHierarchy hierarchy, - MappedSuperclassTypeMetadata superTypeMetadata, - AccessType implicitAccessType, - ModelCategorizationContext processingContext) { - super( classDetails, processingContext ); - - this.hierarchy = hierarchy; - this.superType = superTypeMetadata; - - this.classLevelAccessType = CategorizationHelper.determineAccessType( classDetails, implicitAccessType ); - } - - - public AbstractIdentifiableTypeMetadata( - ClassDetails classDetails, - EntityHierarchy hierarchy, - IdentifiableTypeMetadata superType, - ModelCategorizationContext processingContext) { - super( classDetails, processingContext ); - - assert superType != null; - - this.hierarchy = hierarchy; - this.superType = superType; - - // this is arguably more logical, but the specification is very clear that this should come - // from the hierarchy default not the super in section _2.3.2 Explicit Access Type_ - //this.accessType = CategorizationHelper.determineAccessType( classDetails, superType.getAccessType() ); - this.classLevelAccessType = CategorizationHelper.determineAccessType( classDetails, hierarchy.getDefaultAccessType() ); - } - - protected void postInstantiate(boolean rootEntityOrSubclass, HierarchyTypeConsumer typeConsumer) { - typeConsumer.acceptType( this ); - - // now we can effectively walk subs, although we skip that for the mapped-superclasses - // "above" the root entity - if ( rootEntityOrSubclass ) { - walkSubclasses( typeConsumer ); - } - - // the idea here is to collect up class-level annotations and to apply - // the maps from supers - collectConversionInfo(); - collectAttributeOverrides(); - collectAssociationOverrides(); - } - - private void walkSubclasses(HierarchyTypeConsumer typeConsumer) { - walkSubclasses( getClassDetails(), typeConsumer ); - } - - private void walkSubclasses(ClassDetails base, HierarchyTypeConsumer typeConsumer) { - final ClassDetailsRegistry classDetailsRegistry = getModelContext().getClassDetailsRegistry(); - classDetailsRegistry.forEachDirectSubType( base.getName(), (subClassDetails) -> { - final AbstractIdentifiableTypeMetadata subTypeMetadata; - if ( CategorizationHelper.isEntity( subClassDetails ) ) { - subTypeMetadata = new EntityTypeMetadataImpl( - subClassDetails, - getHierarchy(), - this, - typeConsumer, - getModelContext() - ); - addSubclass( subTypeMetadata ); - } - else if ( CategorizationHelper.isMappedSuperclass( subClassDetails ) ) { - subTypeMetadata = new MappedSuperclassTypeMetadataImpl( - subClassDetails, - getHierarchy(), - this, - typeConsumer, - getModelContext() - ); - addSubclass( subTypeMetadata ); - } - else { - // skip over "intermediate" sub-types - walkSubclasses( subClassDetails, typeConsumer ); - } - } ); - - } - - protected void addSubclass(IdentifiableTypeMetadata subclass) { - subTypes.add( subclass ); - } - - @Override - public EntityHierarchy getHierarchy() { - return hierarchy; - } - - @Override - public IdentifiableTypeMetadata getSuperType() { - return superType; - } - - @Override - public boolean isAbstract() { - return getClassDetails().isAbstract(); - } - - @Override - public boolean hasSubTypes() { - // assume this is called only after its constructor is complete - return !subTypes.isEmpty(); - } - - @Override - public int getNumberOfSubTypes() { - return subTypes.size(); - } - - @Override - public void forEachSubType(Consumer consumer) { - // assume this is called only after its constructor is complete - subTypes.forEach( consumer ); - } - - @Override - public Iterable getSubTypes() { - // assume this is called only after its constructor is complete - return subTypes; - } - - @Override - public ClassAttributeAccessType getClassLevelAccessType() { - return classLevelAccessType; - } - - protected void collectConversionInfo() { - // we only need to do this on root - } - - protected void collectAttributeOverrides() { - // we only need to do this on root - } - - protected void collectAssociationOverrides() { - // we only need to do this on root - } - - protected List collectHierarchyEventListeners(JpaEventListener localCallback) { - final ClassDetails classDetails = getClassDetails(); - - final List combined = new ArrayList<>(); - - if ( !classDetails.hasDirectAnnotationUsage( ExcludeSuperclassListeners.class ) ) { - final IdentifiableTypeMetadata superType = getSuperType(); - if ( superType != null ) { - combined.addAll( superType.getHierarchyJpaEventListeners() ); - } - } - - applyLocalEventListeners( combined::add ); - - if ( localCallback != null ) { - combined.add( localCallback ); - } - - return combined; - } - - private void applyLocalEventListeners(Consumer consumer) { - final ClassDetails classDetails = getClassDetails(); - - final EntityListeners entityListenersAnnotation = classDetails.getDirectAnnotationUsage( EntityListeners.class ); - if ( entityListenersAnnotation == null ) { - return; - } - - final Class>[] entityListenerClasses = entityListenersAnnotation.value(); - if ( CollectionHelper.isEmpty( entityListenerClasses ) ) { - return; - } - - ArrayHelper.forEach( entityListenerClasses, (listenerClass) -> { - consumer.accept( JpaEventListener.from( - JpaEventListenerStyle.LISTENER, - getModelContext().getClassDetailsRegistry().findClassDetails( listenerClass.getName() ) - ) ); - } ); - } - - protected List collectCompleteEventListeners(ModelCategorizationContext modelContext) { - final ClassDetails classDetails = getClassDetails(); - if ( classDetails.hasDirectAnnotationUsage( ExcludeDefaultListeners.class ) ) { - return getHierarchyJpaEventListeners(); - } - - final List combined = new ArrayList<>(); - combined.addAll( modelContext.getDefaultEventListeners() ); - combined.addAll( getHierarchyJpaEventListeners() ); - return combined; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractManagedTypeMetadata.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractManagedTypeMetadata.java deleted file mode 100644 index dcd62f6364..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractManagedTypeMetadata.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import java.util.Collection; -import java.util.List; -import java.util.Objects; - -import org.hibernate.boot.model.source.spi.AttributePath; -import org.hibernate.boot.model.source.spi.AttributeRole; -import org.hibernate.boot.model.source.spi.NaturalIdMutability; -import org.hibernate.boot.models.categorize.spi.AllMemberConsumer; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.ManagedTypeMetadata; -import org.hibernate.boot.models.categorize.spi.ModelCategorizationContext; -import org.hibernate.internal.util.IndexedConsumer; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.MemberDetails; - -import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; - -/** - * Models metadata about a JPA {@linkplain jakarta.persistence.metamodel.ManagedType managed-type}. - * - * @author Hardy Ferentschik - * @author Steve Ebersole - * @author Brett Meyer - */ -public abstract class AbstractManagedTypeMetadata implements ManagedTypeMetadata { - private final ClassDetails classDetails; - private final ModelCategorizationContext modelContext; - - private final AttributePath attributePathBase; - private final AttributeRole attributeRoleBase; - - /** - * This form is intended for construction of the root of an entity hierarchy - * and its mapped-superclasses - */ - public AbstractManagedTypeMetadata(ClassDetails classDetails, ModelCategorizationContext modelContext) { - this.classDetails = classDetails; - this.modelContext = modelContext; - this.attributeRoleBase = new AttributeRole( classDetails.getName() ); - this.attributePathBase = new AttributePath(); - } - - /** - * This form is used to create Embedded references - * - * @param classDetails The Embeddable descriptor - * @param attributeRoleBase The base for the roles of attributes created *from* here - * @param attributePathBase The base for the paths of attributes created *from* here - */ - public AbstractManagedTypeMetadata( - ClassDetails classDetails, - AttributeRole attributeRoleBase, - AttributePath attributePathBase, - ModelCategorizationContext modelContext) { - this.classDetails = classDetails; - this.modelContext = modelContext; - this.attributeRoleBase = attributeRoleBase; - this.attributePathBase = attributePathBase; - } - - public ClassDetails getClassDetails() { - return classDetails; - } - - public ModelCategorizationContext getModelContext() { - return modelContext; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - AbstractManagedTypeMetadata that = (AbstractManagedTypeMetadata) o; - return Objects.equals( classDetails.getName(), that.classDetails.getName() ); - } - - @Override - public int hashCode() { - return Objects.hash( classDetails ); - } - - @Override - public String toString() { - return "ManagedTypeMetadata(" + classDetails.getName() + ")"; - } - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // attribute handling - - protected abstract List attributeList(); - - @Override - public int getNumberOfAttributes() { - return attributeList().size(); - } - - @Override - public Collection getAttributes() { - return attributeList(); - } - - @Override - public AttributeMetadata findAttribute(String name) { - final List attributeList = attributeList(); - for ( int i = 0; i < attributeList.size(); i++ ) { - final AttributeMetadata attribute = attributeList.get( i ); - if ( attribute.getName().equals( name ) ) { - return attribute; - } - } - return null; - } - - @Override - public void forEachAttribute(IndexedConsumer consumer) { - for ( int i = 0; i < attributeList().size(); i++ ) { - consumer.accept( i, attributeList().get( i ) ); - } - } - - protected List resolveAttributes(AllMemberConsumer memberConsumer) { - final List backingMembers = getModelContext() - .getPersistentAttributeMemberResolver() - .resolveAttributesMembers( classDetails, getClassLevelAccessType(), memberConsumer ); - - final List attributeList = arrayList( backingMembers.size() ); - - for ( MemberDetails backingMember : backingMembers ) { - final AttributeMetadata attribute = new AttributeMetadataImpl( - backingMember.resolveAttributeName(), - CategorizationHelper.determineAttributeNature( classDetails, backingMember ), - backingMember - ); - attributeList.add( attribute ); - } - - return attributeList; - } - - // @Override -// public List> findAnnotations(AnnotationDescriptor type) { -// return classDetails.getAnnotations( type ); -// } -// -// @Override -// public void forEachAnnotation(AnnotationDescriptor type, Consumer> consumer) { -// classDetails.forEachAnnotation( type, consumer ); -// } - - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // Stuff affecting attributes built from this managed type. - - public boolean canAttributesBeInsertable() { - return true; - } - - public boolean canAttributesBeUpdatable() { - return true; - } - - public NaturalIdMutability getContainerNaturalIdMutability() { - return NaturalIdMutability.NOT_NATURAL_ID; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java deleted file mode 100644 index 05b24c1790..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AbstractPersistentAttributeMemberResolver.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.function.Consumer; -import java.util.function.Function; - -import org.hibernate.boot.models.categorize.spi.AllMemberConsumer; -import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; -import org.hibernate.boot.models.categorize.spi.PersistentAttributeMemberResolver; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.FieldDetails; -import org.hibernate.models.spi.MemberDetails; -import org.hibernate.models.spi.MethodDetails; - -import jakarta.persistence.Transient; - -/** - * "Template" support for writing PersistentAttributeMemberResolver - * implementations. - * - * @author Steve Ebersole - */ -public abstract class AbstractPersistentAttributeMemberResolver implements PersistentAttributeMemberResolver { - - /** - * This is the call that represents the bulk of the work needed to resolve - * the persistent attribute members. It is the strategy specific portion - * for sure. - * - * The expectation is to - * Here is the call that most likely changes per strategy. This occurs - * immediately after we have determined all the fields and methods marked as - * transient. The expectation is to - * - * @param transientFieldChecker Check whether a field is annotated as @Transient - * @param transientMethodChecker Check whether a method is annotated as @Transient - * @param classDetails The Jandex ClassInfo describing the type for which to resolve members - * @param classLevelAccessType The AccessType determined for the class default - */ - protected abstract List resolveAttributesMembers( - Function transientFieldChecker, - Function transientMethodChecker, - ClassDetails classDetails, - ClassAttributeAccessType classLevelAccessType); - - @Override - public List resolveAttributesMembers( - ClassDetails classDetails, - ClassAttributeAccessType classLevelAccessType, - AllMemberConsumer memberConsumer) { - - final Set transientFields = new HashSet<>(); - final Set transientMethods = new HashSet<>(); - collectMembersMarkedTransient( - transientFields::add, - transientMethods::add, - classDetails, - memberConsumer - ); - - return resolveAttributesMembers( - transientFields::contains, - transientMethods::contains, - classDetails, - classLevelAccessType - ); - } - - protected void collectMembersMarkedTransient( - final Consumer transientFieldConsumer, - final Consumer transientMethodConsumer, - ClassDetails classDetails, - AllMemberConsumer memberConsumer) { - final List fields = classDetails.getFields(); - for ( int i = 0; i < fields.size(); i++ ) { - final FieldDetails fieldDetails = fields.get( i ); - memberConsumer.acceptMember( fieldDetails ); - if ( fieldDetails.hasDirectAnnotationUsage( Transient.class ) ) { - transientFieldConsumer.accept( fieldDetails ); - } - } - - final List methods = classDetails.getMethods(); - for ( int i = 0; i < methods.size(); i++ ) { - final MethodDetails methodDetails = methods.get( i ); - memberConsumer.acceptMember( methodDetails ); - if ( methodDetails.hasDirectAnnotationUsage( Transient.class ) ) { - transientMethodConsumer.accept( methodDetails ); - } - } - } - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AggregatedKeyMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AggregatedKeyMappingImpl.java deleted file mode 100644 index 1e4d8799a7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AggregatedKeyMappingImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import org.hibernate.boot.models.categorize.spi.AggregatedKeyMapping; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; - -/** - * @author Steve Ebersole - */ -public class AggregatedKeyMappingImpl implements AggregatedKeyMapping { - private final AttributeMetadata attribute; - - public AggregatedKeyMappingImpl(AttributeMetadata attribute) { - this.attribute = attribute; - } - - @Override - public AttributeMetadata getAttribute() { - return attribute; - } - - -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AttributeMetadataImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AttributeMetadataImpl.java deleted file mode 100644 index 216b80d7ae..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/AttributeMetadataImpl.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.models.spi.MemberDetails; - -/** - * @author Steve Ebersole - */ -public class AttributeMetadataImpl implements AttributeMetadata { - private final String name; - private final AttributeNature nature; - private final MemberDetails member; - - public AttributeMetadataImpl(String name, AttributeNature nature, MemberDetails member) { - this.name = name; - this.nature = nature; - this.member = member; - } - - @Override - public String getName() { - return name; - } - - @Override - public AttributeNature getNature() { - return nature; - } - - @Override - public MemberDetails getMember() { - return member; - } - - @Override - public String toString() { - return "AttributeMetadata(`" + name + "`)"; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/BasicKeyMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/BasicKeyMappingImpl.java deleted file mode 100644 index edbb21553e..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/BasicKeyMappingImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.BasicKeyMapping; - -/** - * @author Steve Ebersole - */ -public class BasicKeyMappingImpl implements BasicKeyMapping { - private final AttributeMetadata attribute; - - public BasicKeyMappingImpl(AttributeMetadata attribute) { - this.attribute = attribute; - } - - @Override - public AttributeMetadata getAttribute() { - return attribute; - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java deleted file mode 100644 index f46399f411..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizationHelper.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.boot.models.categorize.internal; - -import java.util.EnumSet; - -import org.hibernate.annotations.Any; -import org.hibernate.annotations.AnyDiscriminator; -import org.hibernate.annotations.AnyKeyJavaClass; -import org.hibernate.annotations.AnyKeyJavaType; -import org.hibernate.annotations.AnyKeyJdbcType; -import org.hibernate.annotations.AnyKeyJdbcTypeCode; -import org.hibernate.annotations.CompositeType; -import org.hibernate.annotations.EmbeddableInstantiator; -import org.hibernate.annotations.JavaType; -import org.hibernate.annotations.JdbcType; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.annotations.ManyToAny; -import org.hibernate.annotations.Nationalized; -import org.hibernate.annotations.TenantId; -import org.hibernate.annotations.TimeZoneColumn; -import org.hibernate.annotations.TimeZoneStorage; -import org.hibernate.annotations.Type; -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.boot.models.MultipleAttributeNaturesException; -import org.hibernate.boot.models.categorize.spi.AttributeMetadata; -import org.hibernate.boot.models.categorize.spi.ClassAttributeAccessType; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.ClassDetailsRegistry; -import org.hibernate.models.spi.MemberDetails; - -import jakarta.persistence.Access; -import jakarta.persistence.AccessType; -import jakarta.persistence.Basic; -import jakarta.persistence.ElementCollection; -import jakarta.persistence.Embeddable; -import jakarta.persistence.Embedded; -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Entity; -import jakarta.persistence.Enumerated; -import jakarta.persistence.Lob; -import jakarta.persistence.ManyToMany; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.MappedSuperclass; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Temporal; -import jakarta.persistence.Version; - -import static org.hibernate.boot.models.categorize.ModelCategorizationLogging.MODEL_CATEGORIZATION_LOGGER; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.BASIC; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.ELEMENT_COLLECTION; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.EMBEDDED; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.MANY_TO_ANY; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.MANY_TO_MANY; -import static org.hibernate.boot.models.categorize.spi.AttributeMetadata.AttributeNature.ONE_TO_MANY; - -/** - * @author Steve Ebersole - */ -public class CategorizationHelper { - public static ClassDetails toClassDetails(Class> clazz, ClassDetailsRegistry classDetailsRegistry) { - return classDetailsRegistry.resolveClassDetails( clazz.getName() ); - } - - public static boolean isMappedSuperclass(ClassDetails classDetails) { - return classDetails.hasDirectAnnotationUsage( MappedSuperclass.class ); - } - - public static boolean isEntity(ClassDetails classDetails) { - return classDetails.getDirectAnnotationUsage( Entity.class ) != null; - } - - public static boolean isIdentifiable(ClassDetails classDetails) { - return isEntity( classDetails ) || isMappedSuperclass( classDetails ); - } - - public static ClassAttributeAccessType determineAccessType(ClassDetails classDetails, AccessType implicitAccessType) { - final Access annotation = classDetails.getDirectAnnotationUsage( Access.class ); - if ( annotation != null ) { - final AccessType explicitValue = annotation.value(); - assert explicitValue != null; - return explicitValue == AccessType.FIELD - ? ClassAttributeAccessType.EXPLICIT_FIELD - : ClassAttributeAccessType.EXPLICIT_PROPERTY; - } - - return implicitAccessType == AccessType.FIELD - ? ClassAttributeAccessType.IMPLICIT_FIELD - : ClassAttributeAccessType.IMPLICIT_PROPERTY; - } - - /** - * Determine the attribute's nature - is it a basic mapping, an embeddable, ...? - *