From 1c16c8fec2f9662c2e059b728fd78244f780ef8d Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 21 Oct 2023 15:43:33 -0500 Subject: [PATCH] General refactoring --- .../orm/{spi => }/HibernateAnnotations.java | 2 +- .../models/orm/{spi => }/JpaAnnotations.java | 2 +- .../AbstractIdentifiableTypeMetadata.java | 2 +- .../internal/AbstractManagedTypeMetadata.java | 4 +- ...ractPersistentAttributeMemberResolver.java | 2 +- .../orm/internal/EntityHierarchyBuilder.java | 2 +- .../orm/internal/EntityHierarchyImpl.java | 2 +- .../orm/internal/EntityTypeMetadataImpl.java | 2 +- ...ions.java => GlobalRegistrationsImpl.java} | 71 ++++++++---- .../orm/internal/NamedQueryRegistration.java | 12 +- .../orm/internal/OrmAnnotationHelper.java | 4 +- .../orm/internal/ProcessResultCollector.java | 22 +--- .../orm/internal/ProcessResultImpl.java | 103 ++---------------- ...dardPersistentAttributeMemberResolver.java | 2 +- .../ConversionRegistration.java | 21 +++- .../EntityListenerRegistration.java | 2 +- .../models/orm/spi/GlobalRegistrations.java | 50 +++++++++ .../JavaTypeRegistration.java | 2 +- .../JdbcTypeRegistration.java | 2 +- .../models/orm/spi/ProcessResult.java | 31 +----- .../hibernate/models/orm/spi/Processor.java | 1 + .../UserTypeRegistration.java | 2 +- .../orm/xml/spi/PersistenceUnitMetadata.java | 4 + .../models/orm/xml/spi/XmlResources.java | 13 +++ .../orm/process/SimpleProcessorTests.java | 3 +- .../orm/xml/XmlProcessingSmokeTests.java | 4 +- .../models/source/SourceModelTestHelper.java | 4 +- 27 files changed, 178 insertions(+), 193 deletions(-) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{spi => }/HibernateAnnotations.java (99%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{spi => }/JpaAnnotations.java (99%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/{GlobalRegistrations.java => GlobalRegistrationsImpl.java} (90%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{internal => spi}/ConversionRegistration.java (88%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{internal => spi}/EntityListenerRegistration.java (99%) create mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{internal => spi}/JavaTypeRegistration.java (94%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{internal => spi}/JdbcTypeRegistration.java (93%) rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/{internal => spi}/UserTypeRegistration.java (93%) diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/HibernateAnnotations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/HibernateAnnotations.java similarity index 99% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/HibernateAnnotations.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/HibernateAnnotations.java index e380045..e1a5b48 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/HibernateAnnotations.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/HibernateAnnotations.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.spi; +package org.hibernate.models.orm; import java.lang.annotation.Annotation; import java.util.function.Consumer; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JpaAnnotations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/JpaAnnotations.java similarity index 99% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JpaAnnotations.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/JpaAnnotations.java index 21d1dca..d69e408 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JpaAnnotations.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/JpaAnnotations.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.spi; +package org.hibernate.models.orm; import java.lang.annotation.Annotation; import java.util.function.Consumer; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractIdentifiableTypeMetadata.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractIdentifiableTypeMetadata.java index 1c87f52..bdfd2eb 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractIdentifiableTypeMetadata.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractIdentifiableTypeMetadata.java @@ -14,7 +14,7 @@ import org.hibernate.MappingException; import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractManagedTypeMetadata.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractManagedTypeMetadata.java index 52e3702..03ecffe 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractManagedTypeMetadata.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractManagedTypeMetadata.java @@ -19,8 +19,8 @@ import org.hibernate.models.internal.IndexedConsumer; import org.hibernate.models.orm.MultipleAttributeNaturesException; import org.hibernate.models.orm.spi.AttributeMetadata; -import org.hibernate.models.orm.spi.HibernateAnnotations; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.HibernateAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.ManagedTypeMetadata; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationUsage; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractPersistentAttributeMemberResolver.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractPersistentAttributeMemberResolver.java index 4d73ea3..1bc69f0 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractPersistentAttributeMemberResolver.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/AbstractPersistentAttributeMemberResolver.java @@ -12,7 +12,7 @@ import java.util.function.Consumer; import java.util.function.Function; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.orm.spi.PersistentAttributeMemberResolver; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyBuilder.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyBuilder.java index c7e8ec4..0b959ca 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyBuilder.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyBuilder.java @@ -15,7 +15,7 @@ import org.hibernate.models.orm.AccessTypeDeterminationException; import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationTarget; import org.hibernate.models.source.spi.AnnotationUsage; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyImpl.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyImpl.java index 6c7b10d..d4822f4 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyImpl.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityHierarchyImpl.java @@ -12,7 +12,7 @@ import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.EntityTypeMetadata; import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityTypeMetadataImpl.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityTypeMetadataImpl.java index 3830de6..8bfc652 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityTypeMetadataImpl.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityTypeMetadataImpl.java @@ -15,7 +15,7 @@ import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.EntityTypeMetadata; import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java similarity index 90% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java index d1c6e6c..e68a018 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java @@ -35,6 +35,12 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.CollectionClassification; import org.hibernate.models.internal.StringHelper; +import org.hibernate.models.orm.spi.ConversionRegistration; +import org.hibernate.models.orm.spi.EntityListenerRegistration; +import org.hibernate.models.orm.spi.GlobalRegistrations; +import org.hibernate.models.orm.spi.JavaTypeRegistration; +import org.hibernate.models.orm.spi.JdbcTypeRegistration; +import org.hibernate.models.orm.spi.UserTypeRegistration; import org.hibernate.models.source.internal.dynamic.DynamicAnnotationUsage; import org.hibernate.models.source.spi.AnnotationDescriptorRegistry; import org.hibernate.models.source.spi.AnnotationTarget; @@ -48,24 +54,23 @@ import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; -import static org.hibernate.models.orm.spi.HibernateAnnotations.COLLECTION_TYPE_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.COMPOSITE_TYPE_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.CONVERTER_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.FILTER_DEF; -import static org.hibernate.models.orm.spi.HibernateAnnotations.JAVA_TYPE_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.JDBC_TYPE_REG; -import static org.hibernate.models.orm.spi.HibernateAnnotations.TYPE_REG; +import static org.hibernate.models.orm.HibernateAnnotations.COLLECTION_TYPE_REG; +import static org.hibernate.models.orm.HibernateAnnotations.COMPOSITE_TYPE_REG; +import static org.hibernate.models.orm.HibernateAnnotations.CONVERTER_REG; +import static org.hibernate.models.orm.HibernateAnnotations.EMBEDDABLE_INSTANTIATOR_REG; +import static org.hibernate.models.orm.HibernateAnnotations.FILTER_DEF; +import static org.hibernate.models.orm.HibernateAnnotations.JAVA_TYPE_REG; +import static org.hibernate.models.orm.HibernateAnnotations.JDBC_TYPE_REG; +import static org.hibernate.models.orm.HibernateAnnotations.TYPE_REG; /** * @author Steve Ebersole */ -public class GlobalRegistrations { +public class GlobalRegistrationsImpl implements GlobalRegistrations { private final ClassDetailsRegistry classDetailsRegistry; private final AnnotationDescriptorRegistry annotationDescriptorRegistry; private List entityListenerRegistrations; - private List autoAppliedConverters; private List converterRegistrations; private List javaTypeRegistrations; private List jdbcTypeRegistrations; @@ -79,59 +84,75 @@ public class GlobalRegistrations { private Map tableGeneratorRegistrations; private Map genericGeneratorRegistrations; - private Map jpaNamedQueries; - private Map hibernateNamedHqlQueries; - private Map hibernateNamedNativeQueries; - - public GlobalRegistrations(SourceModelBuildingContext sourceModelBuildingContext) { + public GlobalRegistrationsImpl(SourceModelBuildingContext sourceModelBuildingContext) { this( sourceModelBuildingContext.getClassDetailsRegistry(), sourceModelBuildingContext.getAnnotationDescriptorRegistry() ); } - public GlobalRegistrations(ClassDetailsRegistry classDetailsRegistry, AnnotationDescriptorRegistry annotationDescriptorRegistry) { + public GlobalRegistrationsImpl(ClassDetailsRegistry classDetailsRegistry, AnnotationDescriptorRegistry annotationDescriptorRegistry) { this.classDetailsRegistry = classDetailsRegistry; this.annotationDescriptorRegistry = annotationDescriptorRegistry; } + @Override public List getEntityListenerRegistrations() { return entityListenerRegistrations; } + @Override public List getConverterRegistrations() { return converterRegistrations == null ? emptyList() : converterRegistrations; } - public List getAutoAppliedConverters() { - return autoAppliedConverters == null ? emptyList() : autoAppliedConverters; - } - + @Override public List getJavaTypeRegistrations() { return javaTypeRegistrations == null ? emptyList() : javaTypeRegistrations; } + @Override public List getJdbcTypeRegistrations() { return jdbcTypeRegistrations == null ? emptyList() : jdbcTypeRegistrations; } + @Override public List getUserTypeRegistrations() { return userTypeRegistrations == null ? emptyList() : userTypeRegistrations; } + @Override public List getCompositeUserTypeRegistrations() { return compositeUserTypeRegistrations == null ? emptyList() : compositeUserTypeRegistrations; } + @Override public List getCollectionTypeRegistrations() { return collectionTypeRegistrations == null ? emptyList() : collectionTypeRegistrations; } + @Override public List getEmbeddableInstantiatorRegistrations() { return embeddableInstantiatorRegistrations == null ? emptyList() : embeddableInstantiatorRegistrations; } + @Override public Map getFilterDefRegistrations() { return filterDefRegistrations == null ? emptyMap() : filterDefRegistrations; } + @Override + public Map getSequenceGeneratorRegistrations() { + return sequenceGeneratorRegistrations == null ? emptyMap() : sequenceGeneratorRegistrations; + } + + @Override + public Map getTableGeneratorRegistrations() { + return tableGeneratorRegistrations == null ? emptyMap() : tableGeneratorRegistrations; + } + + @Override + public Map getGenericGeneratorRegistrations() { + return genericGeneratorRegistrations == null ? emptyMap() : genericGeneratorRegistrations; + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JavaTypeRegistration @@ -154,10 +175,14 @@ public void collectJavaTypeRegistrations(List registra } public void collectJavaTypeRegistration(ClassDetails javaType, ClassDetails descriptor) { + collectJavaTypeRegistration( new JavaTypeRegistration( javaType, descriptor ) ); + } + + public void collectJavaTypeRegistration(JavaTypeRegistration registration) { if ( javaTypeRegistrations == null ) { javaTypeRegistrations = new ArrayList<>(); } - javaTypeRegistrations.add( new JavaTypeRegistration( javaType, descriptor ) ); + javaTypeRegistrations.add( registration ); } @@ -198,7 +223,7 @@ public void collectConverterRegistrations(AnnotationTarget annotationTarget) { final ClassDetails domainType = usage.getAttributeValue( "domainType" ); final ClassDetails converterType = usage.getAttributeValue( "converter" ); final boolean autoApply = usage.getAttributeValue( "autoApply" ); - collectConverterRegistration( new ConversionRegistration( domainType, converterType, autoApply ) ); + collectConverterRegistration( new ConversionRegistration( domainType, converterType, autoApply, CONVERTER_REG ) ); } ); } @@ -218,7 +243,7 @@ public void collectConverterRegistrations(List regist } final ClassDetails converterType = classDetailsRegistry.resolveClassDetails( registration.getConverter() ); final boolean autoApply = registration.isAutoApply(); - collectConverterRegistration( new ConversionRegistration( explicitDomainType, converterType, autoApply ) ); + collectConverterRegistration( new ConversionRegistration( explicitDomainType, converterType, autoApply, CONVERTER_REG ) ); } ); } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/NamedQueryRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/NamedQueryRegistration.java index 545fffd..5b01bd5 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/NamedQueryRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/NamedQueryRegistration.java @@ -8,14 +8,16 @@ import java.lang.annotation.Annotation; +import org.hibernate.models.orm.HibernateAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.source.spi.AnnotationUsage; /** - * @see org.hibernate.models.orm.spi.JpaAnnotations#NAMED_QUERY - * @see org.hibernate.models.orm.spi.JpaAnnotations#NAMED_NATIVE_QUERY - * @see org.hibernate.models.orm.spi.JpaAnnotations#NAMED_STORED_PROCEDURE_QUERY - * @see org.hibernate.models.orm.spi.HibernateAnnotations#NAMED_QUERY - * @see org.hibernate.models.orm.spi.HibernateAnnotations#NAMED_NATIVE_QUERY + * @see JpaAnnotations#NAMED_QUERY + * @see JpaAnnotations#NAMED_NATIVE_QUERY + * @see JpaAnnotations#NAMED_STORED_PROCEDURE_QUERY + * @see HibernateAnnotations#NAMED_QUERY + * @see HibernateAnnotations#NAMED_NATIVE_QUERY * * @author Steve Ebersole */ diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/OrmAnnotationHelper.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/OrmAnnotationHelper.java index 31b1fae..61b0925 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/OrmAnnotationHelper.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/OrmAnnotationHelper.java @@ -10,8 +10,8 @@ import java.util.Locale; import java.util.function.Consumer; -import org.hibernate.models.orm.spi.HibernateAnnotations; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.HibernateAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.source.AnnotationAccessException; import org.hibernate.models.source.spi.AnnotationDescriptor; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java index 9689895..40adf9f 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java @@ -29,15 +29,15 @@ * @author Steve Ebersole */ public class ProcessResultCollector { - private final GlobalRegistrations globalRegistrations; + private final GlobalRegistrationsImpl globalRegistrations; private final boolean areIdGeneratorsGlobal; public ProcessResultCollector(boolean areIdGeneratorsGlobal, SourceModelBuildingContext sourceModelBuildingContext) { - this.globalRegistrations = new GlobalRegistrations( sourceModelBuildingContext ); + this.globalRegistrations = new GlobalRegistrationsImpl( sourceModelBuildingContext ); this.areIdGeneratorsGlobal = areIdGeneratorsGlobal; } - public GlobalRegistrations getGlobalRegistrations() { + public GlobalRegistrationsImpl getGlobalRegistrations() { return globalRegistrations; } @@ -116,21 +116,7 @@ public ProcessResult createResult( entityHierarchies, mappedSuperclasses, embeddables, - getGlobalRegistrations().getJavaTypeRegistrations(), - getGlobalRegistrations().getJdbcTypeRegistrations(), - getGlobalRegistrations().getConverterRegistrations(), - getGlobalRegistrations().getAutoAppliedConverters(), - getGlobalRegistrations().getUserTypeRegistrations(), - getGlobalRegistrations().getCompositeUserTypeRegistrations(), - getGlobalRegistrations().getCollectionTypeRegistrations(), - getGlobalRegistrations().getEmbeddableInstantiatorRegistrations(), - getGlobalRegistrations().getFilterDefRegistrations(), -// jpaNamedQueries == null ? emptyMap() : jpaNamedQueries, -// hibernateNamedHqlQueries == null ? emptyMap() : hibernateNamedHqlQueries, -// hibernateNamedNativeQueries == null ? emptyMap() : hibernateNamedNativeQueries - emptyMap(), - emptyMap(), - emptyMap() + getGlobalRegistrations() ); } } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java index 3b64486..2182415 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java @@ -6,12 +6,12 @@ */ package org.hibernate.models.orm.internal; -import java.util.List; import java.util.Map; import java.util.Set; -import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.orm.spi.EntityHierarchy; +import org.hibernate.models.orm.spi.GlobalRegistrations; +import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.source.spi.ClassDetails; /** @@ -19,53 +19,19 @@ */ public class ProcessResultImpl implements ProcessResult { private final Set entityHierarchies; - private final Map mappedSuperclasses; private final Map embeddables; - private final List javaTypeRegistrations; - private final List jdbcTypeRegistrations; - private final List converterRegistrations; - private final List autoAppliedConverters; - private final List userTypeRegistrations; - private final List compositeUserTypeRegistrations; - private final List collectionTypeRegistrations; - private final List embeddableInstantiatorRegistrations; - private final Map filterDefRegistrations; - private final Map jpaNamedQueries; - private final Map hibernateNamedHqlQueries; - private final Map hibernateNamedNativeQueries; + private final GlobalRegistrations globalRegistrations; public ProcessResultImpl( Set entityHierarchies, Map mappedSuperclasses, Map embeddables, - List javaTypeRegistrations, - List jdbcTypeRegistrations, - List converterRegistrations, - List autoAppliedConverters, - List userTypeRegistrations, - List compositeUserTypeRegistrations, - List collectionTypeRegistrations, - List embeddableInstantiatorRegistrations, - Map filterDefRegistrations, - Map jpaNamedQueries, - Map hibernateNamedHqlQueries, - Map hibernateNamedNativeQueries) { + GlobalRegistrations globalRegistrations) { this.entityHierarchies = entityHierarchies; this.mappedSuperclasses = mappedSuperclasses; this.embeddables = embeddables; - this.javaTypeRegistrations = javaTypeRegistrations; - this.jdbcTypeRegistrations = jdbcTypeRegistrations; - this.converterRegistrations = converterRegistrations; - this.autoAppliedConverters = autoAppliedConverters; - this.userTypeRegistrations = userTypeRegistrations; - this.compositeUserTypeRegistrations = compositeUserTypeRegistrations; - this.collectionTypeRegistrations = collectionTypeRegistrations; - this.embeddableInstantiatorRegistrations = embeddableInstantiatorRegistrations; - this.filterDefRegistrations = filterDefRegistrations; - this.jpaNamedQueries = jpaNamedQueries; - this.hibernateNamedHqlQueries = hibernateNamedHqlQueries; - this.hibernateNamedNativeQueries = hibernateNamedNativeQueries; + this.globalRegistrations = globalRegistrations; } @Override @@ -83,62 +49,7 @@ public Map getEmbeddables() { } @Override - public List getJavaTypeRegistrations() { - return javaTypeRegistrations; - } - - @Override - public List getJdbcTypeRegistrations() { - return jdbcTypeRegistrations; - } - - @Override - public List getConverterRegistrations() { - return converterRegistrations; - } - - @Override - public List getAutoAppliedConverters() { - return autoAppliedConverters; - } - - @Override - public List getUserTypeRegistrations() { - return userTypeRegistrations; - } - - @Override - public List getCompositeUserTypeRegistrations() { - return compositeUserTypeRegistrations; - } - - @Override - public List getCollectionTypeRegistrations() { - return collectionTypeRegistrations; - } - - @Override - public List getEmbeddableInstantiatorRegistrations() { - return embeddableInstantiatorRegistrations; - } - - @Override - public Map getFilterDefRegistrations() { - return filterDefRegistrations; - } - - @Override - public Map getJpaNamedQueries() { - return jpaNamedQueries; - } - - @Override - public Map getHibernateNamedHqlQueries() { - return hibernateNamedHqlQueries; - } - - @Override - public Map getHibernateNamedNativeQueries() { - return hibernateNamedNativeQueries; + public GlobalRegistrations getGlobalRegistrations() { + return globalRegistrations; } } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/StandardPersistentAttributeMemberResolver.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/StandardPersistentAttributeMemberResolver.java index 2ee0690..dd8fc59 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/StandardPersistentAttributeMemberResolver.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/StandardPersistentAttributeMemberResolver.java @@ -13,7 +13,7 @@ import java.util.function.Function; import org.hibernate.models.orm.AccessTypePlacementException; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.spi.OrmModelBuildingContext; import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ConversionRegistration.java similarity index 88% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ConversionRegistration.java index bbbefd0..ff4ad34 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ConversionRegistration.java @@ -5,8 +5,9 @@ * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.internal; +package org.hibernate.models.orm.spi; +import java.lang.annotation.Annotation; import java.util.List; import java.util.Objects; @@ -19,6 +20,7 @@ import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext; import org.hibernate.boot.model.convert.spi.RegisteredConversion; import org.hibernate.models.Copied; +import org.hibernate.models.source.spi.AnnotationDescriptor; import org.hibernate.models.source.spi.ClassDetails; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.type.descriptor.converter.internal.JpaAttributeConverterImpl; @@ -41,13 +43,19 @@ public class ConversionRegistration { private final ClassDetails explicitDomainType; private final ClassDetails converterType; private final boolean autoApply; + private final AnnotationDescriptor source; - public ConversionRegistration(ClassDetails explicitDomainType, ClassDetails converterType, boolean autoApply) { + public ConversionRegistration( + ClassDetails explicitDomainType, + ClassDetails converterType, + boolean autoApply, + AnnotationDescriptor source) { assert converterType != null; this.explicitDomainType = explicitDomainType; this.converterType = converterType; this.autoApply = autoApply; + this.source = source; } @Override @@ -81,6 +89,15 @@ public boolean isAutoApply() { return autoApply; } + public AnnotationDescriptor getSource() { + return source; + } + + @Override + public String toString() { + return "ConversionRegistration( " + converterType.getClassName() + ", " + source.getAnnotationType().getSimpleName() + ", " + autoApply + ")"; + } + public ConverterDescriptor makeConverterDescriptor(ClassmateContext classmateContext) { final Class explicitDomainType = this.explicitDomainType.toJavaClass(); final Class> converterType = this.converterType.toJavaClass(); diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/EntityListenerRegistration.java similarity index 99% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/EntityListenerRegistration.java index ff0b7ed..46a8093 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/EntityListenerRegistration.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.internal; +package org.hibernate.models.orm.spi; import org.hibernate.boot.jaxb.mapping.JaxbEntityListener; import org.hibernate.internal.util.MutableObject; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java new file mode 100644 index 0000000..d8fb1bc --- /dev/null +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java @@ -0,0 +1,50 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright: Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.models.orm.spi; + +import java.util.List; +import java.util.Map; + +import org.hibernate.models.orm.internal.CollectionTypeRegistration; +import org.hibernate.models.orm.internal.CompositeUserTypeRegistration; +import org.hibernate.models.orm.internal.EmbeddableInstantiatorRegistration; +import org.hibernate.models.orm.internal.FilterDefRegistration; +import org.hibernate.models.orm.internal.GenericGeneratorRegistration; +import org.hibernate.models.orm.internal.SequenceGeneratorRegistration; +import org.hibernate.models.orm.internal.TableGeneratorRegistration; + +/** + * @author Steve Ebersole + */ +public interface GlobalRegistrations { + List getEntityListenerRegistrations(); + + List getConverterRegistrations(); + + List getJavaTypeRegistrations(); + + List getJdbcTypeRegistrations(); + + List getUserTypeRegistrations(); + + List getCompositeUserTypeRegistrations(); + + List getCollectionTypeRegistrations(); + + List getEmbeddableInstantiatorRegistrations(); + + Map getFilterDefRegistrations(); + + Map getSequenceGeneratorRegistrations(); + + Map getTableGeneratorRegistrations(); + + Map getGenericGeneratorRegistrations(); + + // todo : named entity graphs + // todo : named queries +} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JavaTypeRegistration.java similarity index 94% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JavaTypeRegistration.java index ee73d37..f78ba08 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JavaTypeRegistration.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.internal; +package org.hibernate.models.orm.spi; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JdbcTypeRegistration.java similarity index 93% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JdbcTypeRegistration.java index 0a5aab5..cfb2d0e 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/JdbcTypeRegistration.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.internal; +package org.hibernate.models.orm.spi; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java index fa07f01..f0505d1 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java @@ -12,13 +12,9 @@ import org.hibernate.models.orm.internal.CollectionTypeRegistration; import org.hibernate.models.orm.internal.CompositeUserTypeRegistration; -import org.hibernate.models.orm.internal.ConversionRegistration; import org.hibernate.models.orm.internal.EmbeddableInstantiatorRegistration; import org.hibernate.models.orm.internal.FilterDefRegistration; -import org.hibernate.models.orm.internal.JavaTypeRegistration; -import org.hibernate.models.orm.internal.JdbcTypeRegistration; import org.hibernate.models.orm.internal.NamedQueryRegistration; -import org.hibernate.models.orm.internal.UserTypeRegistration; import org.hibernate.models.source.spi.ClassDetails; /** @@ -42,27 +38,8 @@ public interface ProcessResult { */ Map getEmbeddables(); - List getJavaTypeRegistrations(); - - List getJdbcTypeRegistrations(); - - List getConverterRegistrations(); - - List getAutoAppliedConverters(); - - List getUserTypeRegistrations(); - - List getCompositeUserTypeRegistrations(); - - List getCollectionTypeRegistrations(); - - List getEmbeddableInstantiatorRegistrations(); - - Map getFilterDefRegistrations(); - - Map getJpaNamedQueries(); - - Map getHibernateNamedHqlQueries(); - - Map getHibernateNamedNativeQueries(); + /** + * Global registrations collected while processing the persistence-unit. + */ + GlobalRegistrations getGlobalRegistrations(); } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/Processor.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/Processor.java index 8dc46eb..fe351b9 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/Processor.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/Processor.java @@ -21,6 +21,7 @@ import org.hibernate.boot.jaxb.mapping.ManagedType; import org.hibernate.models.internal.CollectionHelper; import org.hibernate.models.internal.StringHelper; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.orm.internal.EntityHierarchyBuilder; import org.hibernate.models.orm.internal.OrmModelBuildingContextImpl; import org.hibernate.models.orm.internal.OrmModelLogging; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/UserTypeRegistration.java similarity index 93% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/UserTypeRegistration.java index 9f47d6f..de11d8e 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/UserTypeRegistration.java @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 * Copyright: Red Hat Inc. and Hibernate Authors */ -package org.hibernate.models.orm.internal; +package org.hibernate.models.orm.spi; import org.hibernate.models.source.spi.ClassDetails; diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/PersistenceUnitMetadata.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/PersistenceUnitMetadata.java index 094adcc..191febe 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/PersistenceUnitMetadata.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/PersistenceUnitMetadata.java @@ -16,6 +16,10 @@ import jakarta.persistence.AccessType; /** + * Aggregator of information from {@code entity-mappings/persistence-unit-metadata} + * and {@code entity-mappings/persistence-unit-metadata/persistence-unit-defaults} + * across all mapping XML files in the persistence-unit. + * * @author Steve Ebersole */ public interface PersistenceUnitMetadata { diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/XmlResources.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/XmlResources.java index f08dbe9..6b907df 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/XmlResources.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/spi/XmlResources.java @@ -28,6 +28,9 @@ import static org.hibernate.boot.jaxb.internal.MappingBinder.NON_VALIDATING; /** + * Keeps track of collected/aggregated {@linkplain #getPersistenceUnitMetadata() metadata} + * across all {@linkplain #getDocuments() mapping documents} in the persistence-unit + * * @author Steve Ebersole */ public class XmlResources { @@ -37,6 +40,9 @@ public class XmlResources { public XmlResources() { } + /** + * Build an XmlResources reference based on the given {@code managedResources} + */ public static XmlResources collectXmlResources( ManagedResources managedResources, SourceModelBuildingContext sourceModelBuildingContext) { @@ -67,10 +73,17 @@ public static XmlResources collectXmlResources( return collected; } + /** + * The metadata collected/aggregated across all of the {@linkplain #getDocuments() mapping documents} + * in the persistence-unit. + */ public PersistenceUnitMetadata getPersistenceUnitMetadata() { return persistenceUnitMetadata; } + /** + * All documents in the persistence-unit + */ public List getDocuments() { return documents; } diff --git a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java index 8225c14..720f43a 100644 --- a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java +++ b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java @@ -13,7 +13,6 @@ import org.hibernate.models.orm.internal.ManagedResourcesImpl; import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.EntityTypeMetadata; -import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; import org.hibernate.models.orm.spi.ManagedResources; import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.orm.spi.Processor; @@ -115,7 +114,7 @@ public boolean shouldIgnoreUnlistedClasses() { validateJoinedHierarchy( one ); } - validateFilterDefs( processResult.getFilterDefRegistrations() ); + validateFilterDefs( processResult.getGlobalRegistrations().getFilterDefRegistrations() ); } private void validatePersonHierarchy(EntityHierarchy hierarchy) { diff --git a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java index a267f92..01a739f 100644 --- a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java +++ b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java @@ -11,7 +11,7 @@ import org.hibernate.boot.jaxb.mapping.JaxbEntityMappings; import org.hibernate.models.orm.internal.FilterDefRegistration; -import org.hibernate.models.orm.internal.GlobalRegistrations; +import org.hibernate.models.orm.internal.GlobalRegistrationsImpl; import org.hibernate.models.orm.internal.ProcessResultCollector; import org.hibernate.models.orm.xml.internal.XmlDocumentImpl; import org.hibernate.models.orm.xml.spi.XmlResources; @@ -121,7 +121,7 @@ void testSimpleGlobalXmlProcessing() { final ProcessResultCollector processResultCollector = new ProcessResultCollector( false, buildingContext ); collectedXmlResources.getDocuments().forEach( processResultCollector::apply ); - final GlobalRegistrations globalRegistrations = processResultCollector.getGlobalRegistrations(); + final GlobalRegistrationsImpl globalRegistrations = processResultCollector.getGlobalRegistrations(); assertThat( globalRegistrations.getJavaTypeRegistrations() ).hasSize( 1 ); assertThat( globalRegistrations.getJavaTypeRegistrations().get(0).getDescriptor().getClassName() ) .isEqualTo( StringTypeDescriptor.class.getName() ); diff --git a/hibernate-models-testing/src/main/java/org/hibernate/models/source/SourceModelTestHelper.java b/hibernate-models-testing/src/main/java/org/hibernate/models/source/SourceModelTestHelper.java index 3ebdd30..327b048 100644 --- a/hibernate-models-testing/src/main/java/org/hibernate/models/source/SourceModelTestHelper.java +++ b/hibernate-models-testing/src/main/java/org/hibernate/models/source/SourceModelTestHelper.java @@ -10,8 +10,8 @@ import java.lang.annotation.Annotation; import org.hibernate.models.orm.internal.OrmAnnotationHelper; -import org.hibernate.models.orm.spi.HibernateAnnotations; -import org.hibernate.models.orm.spi.JpaAnnotations; +import org.hibernate.models.orm.HibernateAnnotations; +import org.hibernate.models.orm.JpaAnnotations; import org.hibernate.models.source.internal.AnnotationDescriptorRegistryImpl; import org.hibernate.models.source.internal.BaseLineJavaTypes; import org.hibernate.models.source.internal.SourceModelBuildingContextImpl;