From 62178086a65f840febead1a708d50b8f3bd615a8 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 23 Apr 2024 18:32:40 -0500 Subject: [PATCH] HHH-18000 : Remove XmlProcessingHelper methods for creating AnnotationUsage instances --- .../xml/internal/XmlAnnotationHelper.java | 7 +- .../xml/internal/XmlProcessingHelper.java | 78 ++-------------- .../attr/AnyMappingAttributeProcessing.java | 65 +++++++++---- .../attr/BasicAttributeProcessing.java | 17 +++- .../attr/BasicIdAttributeProcessing.java | 8 +- .../attr/CommonAttributeProcessing.java | 31 +++++-- .../attr/CommonPluralAttributeProcessing.java | 93 ++++++++++--------- .../ElementCollectionAttributeProcessing.java | 7 +- .../attr/EmbeddedAttributeProcessing.java | 12 ++- .../attr/EmbeddedIdAttributeProcessing.java | 14 ++- .../attr/ManyToManyAttributeProcessing.java | 22 ++--- .../attr/ManyToOneAttributeProcessing.java | 36 +++---- .../attr/OneToManyAttributeProcessing.java | 32 ++++--- .../xml/internal/db/ColumnProcessing.java | 8 +- .../xml/internal/db/JoinColumnProcessing.java | 8 +- .../xml/internal/db/TableProcessing.java | 18 ---- 16 files changed, 225 insertions(+), 231 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java index d53d2d6cbf..cd9bb56610 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlAnnotationHelper.java @@ -1202,15 +1202,10 @@ public class XmlAnnotationHelper { JaxbEntityListenerImpl jaxbEntityListener, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage applied = classDetails.applyAnnotationUsage( + final MutableAnnotationUsage listenersUsage = classDetails.applyAnnotationUsage( JpaAnnotations.ENTITY_LISTENERS, xmlDocumentContext.getModelBuildingContext() ); - final MutableAnnotationUsage listenersUsage = XmlProcessingHelper.getOrMakeAnnotation( - EntityListeners.class, - classDetails, - xmlDocumentContext - ); final MutableClassDetails entityListenerClass = xmlDocumentContext.resolveJavaType( jaxbEntityListener.getClazz() ); applyLifecycleCallbacks( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java index ecec1b9da5..8962a759c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/XmlProcessingHelper.java @@ -15,8 +15,6 @@ import org.hibernate.boot.models.MemberResolutionException; import org.hibernate.boot.models.internal.AnnotationUsageHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage; -import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.MethodDetails; @@ -111,70 +109,6 @@ public class XmlProcessingHelper { return null; } - /** - * Find an existing annotation, or create one. - * Used when applying XML in override mode. - */ - public static MutableAnnotationUsage getOrMakeAnnotation( - Class annotationType, - MutableAnnotationTarget target, - XmlDocumentContext xmlDocumentContext) { - final AnnotationUsage existing = target.getAnnotationUsage( annotationType ); - if ( existing != null ) { - return (MutableAnnotationUsage) existing; - } - - return makeAnnotation( annotationType, target, xmlDocumentContext ); - } - - public static MutableAnnotationUsage getOrMakeAnnotation( - Class annotationType, - XmlDocumentContext xmlDocumentContext) { - - return makeAnnotation( annotationType, xmlDocumentContext ); - } - - /** - * Make a nested AnnotationUsage. The usage is created with the given target, - * but it is not added to the target's annotations. - */ - public static MutableAnnotationUsage makeNestedAnnotation( - Class annotationType, - AnnotationTarget target, - XmlDocumentContext xmlDocumentContext) { - return new DynamicAnnotationUsage<>( - xmlDocumentContext.getModelBuildingContext() - .getAnnotationDescriptorRegistry() - .getDescriptor( annotationType ), - xmlDocumentContext.getModelBuildingContext() - ); - } - - public static MutableAnnotationUsage makeNestedAnnotation( - Class annotationType, - XmlDocumentContext xmlDocumentContext) { - return makeNestedAnnotation( annotationType, null, xmlDocumentContext ); - } - - /** - * Make an AnnotationUsage. - * Used when applying XML in complete mode or when {@linkplain #getOrMakeAnnotation} - * needs to make. - */ - public static MutableAnnotationUsage makeAnnotation( - Class annotationType, - MutableAnnotationTarget target, - XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage created = makeNestedAnnotation( annotationType, target, xmlDocumentContext ); - target.addAnnotationUsage( created ); - return created; - } - - public static MutableAnnotationUsage makeAnnotation( - Class annotationType, - XmlDocumentContext xmlDocumentContext) { - return makeNestedAnnotation( annotationType, xmlDocumentContext ); - } /** * Find an existing annotation by name, or create one. @@ -199,7 +133,11 @@ public class XmlProcessingHelper { MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { if ( name == null ) { - return makeAnnotation( annotationType, target, xmlDocumentContext ); + return xmlDocumentContext + .getModelBuildingContext() + .getAnnotationDescriptorRegistry() + .getDescriptor( annotationType ) + .createUsage( null, xmlDocumentContext.getModelBuildingContext() ); } final AnnotationUsage existing = target.getNamedAnnotationUsage( annotationType, name, attributeToMatch ); @@ -221,7 +159,11 @@ public class XmlProcessingHelper { String nameAttributeName, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage created = makeNestedAnnotation( annotationType, target, xmlDocumentContext ); + final MutableAnnotationUsage created = xmlDocumentContext + .getModelBuildingContext() + .getAnnotationDescriptorRegistry() + .getDescriptor( annotationType ) + .createUsage( null, xmlDocumentContext.getModelBuildingContext() ); target.addAnnotationUsage( created ); created.setAttributeValue( nameAttributeName, name ); return created; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java index 56e901a070..bec4443253 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/AnyMappingAttributeProcessing.java @@ -19,6 +19,8 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingDiscriminatorImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbColumnImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; @@ -56,7 +58,10 @@ public class AnyMappingAttributeProcessing { declarer ); - final MutableAnnotationUsage anyAnn = XmlProcessingHelper.makeAnnotation( Any.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage anyAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ANY, + xmlDocumentContext.getModelBuildingContext() + ); CommonAttributeProcessing.applyAttributeBasics( jaxbHbmAnyMapping, memberDetails, anyAnn, accessType, xmlDocumentContext ); @@ -73,7 +78,10 @@ public class AnyMappingAttributeProcessing { MutableAnnotationUsage anyAnn, XmlDocumentContext xmlDocumentContext) { final JaxbAnyMappingDiscriminatorImpl jaxbDiscriminator = jaxbHbmAnyMapping.getDiscriminator(); - final MutableAnnotationUsage anyDiscriminatorAnn = XmlProcessingHelper.makeAnnotation( AnyDiscriminator.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage anyDiscriminatorAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ANY_DISCRIMINATOR, + xmlDocumentContext.getModelBuildingContext() + ); if ( jaxbDiscriminator == null ) { return; @@ -83,29 +91,39 @@ public class AnyMappingAttributeProcessing { XmlProcessingHelper.applyAttributeIfSpecified( "value", discriminatorType, anyDiscriminatorAnn ); final JaxbColumnImpl jaxbColumn = jaxbDiscriminator.getColumn(); - final MutableAnnotationUsage columnAnn = XmlProcessingHelper.makeAnnotation( Column.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.COLUMN, + xmlDocumentContext.getModelBuildingContext() + ); if ( jaxbColumn != null ) { ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, columnAnn, xmlDocumentContext ); } + final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); final List valueMappings = jaxbDiscriminator.getValueMappings(); if ( CollectionHelper.isNotEmpty( valueMappings ) ) { - final MutableAnnotationUsage valuesAnn = XmlProcessingHelper.makeAnnotation( AnyDiscriminatorValues.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage discriminatorValuesUsage = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ANY_DISCRIMINATOR_VALUES, + xmlDocumentContext.getModelBuildingContext() + ); final List> valueList = CollectionHelper.arrayList( valueMappings.size() ); - final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); - valuesAnn.setAttributeValue( "value", valueList ); - valueMappings.forEach( (valueMapping) -> { - final MutableAnnotationUsage valueAnn = XmlProcessingHelper.makeNestedAnnotation( AnyDiscriminatorValue.class, memberDetails, xmlDocumentContext ); - valueList.add( valueAnn ); + discriminatorValuesUsage.setAttributeValue( "value", valueList ); - valueAnn.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() ); + valueMappings.forEach( (valueMapping) -> { + final MutableAnnotationUsage discriminatorValueUsage = HibernateAnnotations.ANY_DISCRIMINATOR_VALUE.createUsage( + null, + xmlDocumentContext.getModelBuildingContext() + ); + valueList.add( discriminatorValueUsage ); + + discriminatorValueUsage.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() ); final String name = StringHelper.qualifyConditionally( xmlDocumentContext.getXmlDocument().getDefaults().getPackage(), valueMapping.getCorrespondingEntityName() ); final ClassDetails entityClassDetails = classDetailsRegistry.resolveClassDetails( name ); - valueAnn.setAttributeValue( "entity", entityClassDetails ); + discriminatorValueUsage.setAttributeValue( "entity", entityClassDetails ); } ); } } @@ -117,22 +135,31 @@ public class AnyMappingAttributeProcessing { XmlDocumentContext xmlDocumentContext) { final JaxbAnyMappingKeyImpl jaxbKey = jaxbHbmAnyMapping.getKey(); if ( StringHelper.isNotEmpty( jaxbKey.getType() ) ) { - final MutableAnnotationUsage keyTypeAnn = XmlProcessingHelper.makeAnnotation( AnyKeyType.class, memberDetails, xmlDocumentContext ); - keyTypeAnn.setAttributeValue( "value", jaxbKey.getType() ); + final MutableAnnotationUsage keyTypeUsage = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ANY_KEY_TYPE, + xmlDocumentContext.getModelBuildingContext() + ); + keyTypeUsage.setAttributeValue( "value", jaxbKey.getType() ); } if ( jaxbKey.getColumns().isEmpty() ) { - XmlProcessingHelper.makeAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); + memberDetails.applyAnnotationUsage( JpaAnnotations.JOIN_COLUMN, xmlDocumentContext.getModelBuildingContext() ); } else { - final MutableAnnotationUsage columnsAnn = XmlProcessingHelper.makeAnnotation( JoinColumns.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage joinColumnsUsage = memberDetails.applyAnnotationUsage( + JpaAnnotations.JOIN_COLUMNS, + xmlDocumentContext.getModelBuildingContext() + ); final ArrayList> columnAnnList = CollectionHelper.arrayList( jaxbKey.getColumns().size() ); - columnsAnn.setAttributeValue( "value", columnAnnList ); + joinColumnsUsage.setAttributeValue( "value", columnAnnList ); jaxbKey.getColumns().forEach( (jaxbColumn) -> { - final MutableAnnotationUsage columnAnn = XmlProcessingHelper.makeNestedAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); - columnAnnList.add( columnAnn ); + final MutableAnnotationUsage joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( + null, + xmlDocumentContext.getModelBuildingContext() + ); + columnAnnList.add( joinColumnUsage ); - ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, columnAnn, xmlDocumentContext ); + ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, joinColumnUsage, xmlDocumentContext ); } ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java index a5493cbcc7..8102c6ba85 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicAttributeProcessing.java @@ -8,6 +8,8 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.annotations.Formula; import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; @@ -40,16 +42,25 @@ public class BasicAttributeProcessing { declarer ); - final MutableAnnotationUsage basicAnn = XmlProcessingHelper.getOrMakeAnnotation( Basic.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage basicAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.BASIC, + xmlDocumentContext.getModelBuildingContext() + ); CommonAttributeProcessing.applyAttributeBasics( jaxbBasic, memberDetails, basicAnn, accessType, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbBasic.getFormula() ) ) { assert jaxbBasic.getColumn() == null; - final MutableAnnotationUsage formulaAnn = XmlProcessingHelper.getOrMakeAnnotation( Formula.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage formulaAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.FORMULA, + xmlDocumentContext.getModelBuildingContext() + ); formulaAnn.setAttributeValue( "value", jaxbBasic.getFormula() ); } else if ( jaxbBasic.getColumn() != null ) { - final MutableAnnotationUsage columnAnn = XmlProcessingHelper.getOrMakeAnnotation( Column.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.COLUMN, + xmlDocumentContext.getModelBuildingContext() + ); ColumnProcessing.applyColumnDetails( jaxbBasic.getColumn(), memberDetails, columnAnn, xmlDocumentContext ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java index 5915fa7e97..a16053af56 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/BasicIdAttributeProcessing.java @@ -7,16 +7,16 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import jakarta.persistence.AccessType; import jakarta.persistence.Basic; -import jakarta.persistence.Id; import static org.hibernate.internal.util.NullnessHelper.coalesce; @@ -37,8 +37,8 @@ public class BasicIdAttributeProcessing { declarer ); - final MutableAnnotationUsage idAnn = XmlProcessingHelper.makeAnnotation( Id.class, memberDetails, xmlDocumentContext ); - final MutableAnnotationUsage basicAnn = XmlProcessingHelper.makeAnnotation( Basic.class, memberDetails, xmlDocumentContext ); + memberDetails.applyAnnotationUsage( JpaAnnotations.ID, xmlDocumentContext.getModelBuildingContext() ); + final MutableAnnotationUsage basicAnn = memberDetails.applyAnnotationUsage( JpaAnnotations.BASIC, xmlDocumentContext.getModelBuildingContext() ); CommonAttributeProcessing.applyAttributeBasics( jaxbId, memberDetails, basicAnn, accessType, xmlDocumentContext ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java index 4080e4538f..aec7b1b87e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonAttributeProcessing.java @@ -19,6 +19,9 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbSingularAssociationAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbSingularFetchModeImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbStandardAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbTransientImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; +import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.models.spi.ClassDetails; @@ -29,9 +32,6 @@ import org.hibernate.models.spi.MutableMemberDetails; import jakarta.persistence.Access; import jakarta.persistence.AccessType; import jakarta.persistence.FetchType; -import jakarta.persistence.Transient; - -import static org.hibernate.internal.util.NullnessHelper.coalesce; /** * @author Steve Ebersole @@ -61,7 +61,10 @@ public class CommonAttributeProcessing { AccessType accessType, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage accessAnn = XmlProcessingHelper.makeAnnotation( Access.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage accessAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.ACCESS, + xmlDocumentContext.getModelBuildingContext() + ); accessAnn.setAttributeValue( "value", accessType ); } @@ -74,12 +77,16 @@ public class CommonAttributeProcessing { return; } + final MutableAnnotationUsage accessorAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ATTRIBUTE_ACCESSOR, + xmlDocumentContext.getModelBuildingContext() + ); + final ClassDetails strategyClassDetails = xmlDocumentContext .getModelBuildingContext() .getClassDetailsRegistry() .getClassDetails( attributeAccessor ); - final MutableAnnotationUsage accessAnn = XmlProcessingHelper.makeAnnotation( AttributeAccessor.class, memberDetails, xmlDocumentContext ); - XmlProcessingHelper.applyAttributeIfSpecified( "strategy", strategyClassDetails, accessAnn ); + XmlAnnotationHelper.applyOptionalAttribute( accessorAnn, "strategy", strategyClassDetails ); } public static void applyOptionality( @@ -100,7 +107,10 @@ public class CommonAttributeProcessing { MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { final boolean includeInOptimisticLock = jaxbAttribute.isOptimisticLock(); - final MutableAnnotationUsage optLockAnn = XmlProcessingHelper.makeAnnotation( OptimisticLock.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage optLockAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.OPTIMISTIC_LOCK, + xmlDocumentContext.getModelBuildingContext() + ); optLockAnn.setAttributeValue( "excluded", !includeInOptimisticLock ); } @@ -128,7 +138,10 @@ public class CommonAttributeProcessing { XmlDocumentContext xmlDocumentContext) { if ( jaxbFetchMode != null ) { final FetchMode fetchMode = FetchMode.valueOf( jaxbFetchMode.value() ); - final MutableAnnotationUsage fetchAnn = XmlProcessingHelper.makeAnnotation( Fetch.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage fetchAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.FETCH, + xmlDocumentContext.getModelBuildingContext() + ); fetchAnn.setAttributeValue( "value", fetchMode ); } } @@ -143,6 +156,6 @@ public class CommonAttributeProcessing { classAccessType, declarer ); - XmlProcessingHelper.makeAnnotation( Transient.class, memberDetails, xmlDocumentContext ); + memberDetails.applyAnnotationUsage( JpaAnnotations.TRANSIENT, xmlDocumentContext.getModelBuildingContext() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java index 20468447d6..7ded68eac7 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/CommonPluralAttributeProcessing.java @@ -6,7 +6,6 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import org.hibernate.annotations.Bag; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortNatural; @@ -16,6 +15,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbOrderColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAttribute; import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.ColumnProcessing; @@ -51,19 +51,23 @@ public class CommonPluralAttributeProcessing { final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry(); if ( jaxbPluralAttribute.getFetchMode() != null ) { - final MutableAnnotationUsage fetchAnn = XmlProcessingHelper.getOrMakeAnnotation( Fetch.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage fetchAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.FETCH, + buildingContext + ); fetchAnn.setAttributeValue( "value", jaxbPluralAttribute.getFetchMode() ); } if ( jaxbPluralAttribute.getClassification() != null ) { - final MutableAnnotationUsage collectionClassificationAnn = XmlProcessingHelper.getOrMakeAnnotation( - CollectionClassification.class, - memberDetails, - xmlDocumentContext - ); - collectionClassificationAnn.setAttributeValue( "value", jaxbPluralAttribute.getClassification() ); if ( jaxbPluralAttribute.getClassification() == LimitedCollectionClassification.BAG ) { - XmlProcessingHelper.getOrMakeAnnotation( Bag.class, memberDetails, xmlDocumentContext ); + memberDetails.applyAnnotationUsage( HibernateAnnotations.BAG, buildingContext ); + } + else { + final MutableAnnotationUsage collectionClassificationAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.COLLECTION_CLASSIFICATION, + buildingContext + ); + collectionClassificationAnn.setAttributeValue( "value", jaxbPluralAttribute.getClassification() ); } } @@ -75,10 +79,9 @@ public class CommonPluralAttributeProcessing { XmlAnnotationHelper.applyCollectionId( jaxbPluralAttribute.getCollectionId(), memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbPluralAttribute.getOrderBy() ) ) { - final MutableAnnotationUsage orderByAnn = XmlProcessingHelper.getOrMakeAnnotation( - OrderBy.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage orderByAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.ORDER_BY, + buildingContext ); orderByAnn.setAttributeValue( "value", jaxbPluralAttribute.getOrderBy() ); } @@ -86,51 +89,55 @@ public class CommonPluralAttributeProcessing { applyOrderColumn( jaxbPluralAttribute, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbPluralAttribute.getSort() ) ) { - final MutableAnnotationUsage sortAnn = XmlProcessingHelper.getOrMakeAnnotation( - SortComparator.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage sortAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.SORT_COMPARATOR, + buildingContext ); final ClassDetails comparatorClassDetails = classDetailsRegistry.resolveClassDetails( jaxbPluralAttribute.getSort() ); sortAnn.setAttributeValue( "value", comparatorClassDetails ); } if ( jaxbPluralAttribute.getSortNatural() != null ) { - XmlProcessingHelper.getOrMakeAnnotation( SortNatural.class, memberDetails, xmlDocumentContext ); + memberDetails.applyAnnotationUsage( HibernateAnnotations.SORT_NATURAL, buildingContext ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // map-key if ( jaxbPluralAttribute.getMapKey() != null ) { - final MutableAnnotationUsage mapKeyAnn = XmlProcessingHelper.getOrMakeAnnotation( MapKey.class, memberDetails, xmlDocumentContext ); - applyOr( - jaxbPluralAttribute.getMapKey(), - JaxbMapKeyImpl::getName, - "name", - mapKeyAnn, - buildingContext.getAnnotationDescriptorRegistry().getDescriptor( MapKey.class ) + final MutableAnnotationUsage mapKeyAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY, + buildingContext ); + if ( jaxbPluralAttribute.getMapKey() != null ) { + XmlAnnotationHelper.applyOptionalAttribute( mapKeyAnn, "name", jaxbPluralAttribute.getMapKey().getName() ); + } } if ( jaxbPluralAttribute.getMapKeyClass() != null ) { final String className = xmlDocumentContext.resolveClassName( jaxbPluralAttribute.getMapKeyClass().getClazz() ); final ClassDetails mapKeyClass = classDetailsRegistry.resolveClassDetails( className ); - XmlProcessingHelper.getOrMakeAnnotation( MapKeyClass.class, memberDetails, xmlDocumentContext ).setAttributeValue( "value", mapKeyClass ); + final MutableAnnotationUsage mapKeyClassAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY_CLASS, + buildingContext + ); + mapKeyClassAnn.setAttributeValue( "value", mapKeyClass ); } if ( jaxbPluralAttribute.getMapKeyTemporal() != null ) { - XmlProcessingHelper.getOrMakeAnnotation( MapKeyTemporal.class, memberDetails, xmlDocumentContext ).setAttributeValue( - "value", - jaxbPluralAttribute.getMapKeyTemporal() + final MutableAnnotationUsage mapKeyTemporalAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY_TEMPORAL, + buildingContext ); + mapKeyTemporalAnn.setAttributeValue( "value", jaxbPluralAttribute.getMapKeyTemporal() ); } if ( jaxbPluralAttribute.getMapKeyEnumerated() != null ) { - XmlProcessingHelper.getOrMakeAnnotation( MapKeyEnumerated.class, memberDetails, xmlDocumentContext ).setAttributeValue( - "value", - jaxbPluralAttribute.getMapKeyEnumerated() + final MutableAnnotationUsage mapKeyEnumeratedAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY_ENUMERATED, + buildingContext ); + mapKeyEnumeratedAnn.setAttributeValue( "value", jaxbPluralAttribute.getMapKeyEnumerated() ); } jaxbPluralAttribute.getMapKeyConverts().forEach( (jaxbConvert) -> { @@ -167,20 +174,16 @@ public class CommonPluralAttributeProcessing { return; } - final MutableAnnotationUsage orderColumnAnn = XmlProcessingHelper.getOrMakeAnnotation( - OrderColumn.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage orderColumnAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.ORDER_COLUMN, + xmlDocumentContext.getModelBuildingContext() ); - final AnnotationDescriptor orderColumnDescriptor = xmlDocumentContext.getModelBuildingContext() - .getAnnotationDescriptorRegistry() - .getDescriptor( OrderColumn.class ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::getName, "name", orderColumnAnn, orderColumnDescriptor ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::isNullable, "nullable", orderColumnAnn, orderColumnDescriptor ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::isInsertable, "insertable", orderColumnAnn, orderColumnDescriptor ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::isUpdatable, "updatable", orderColumnAnn, orderColumnDescriptor ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::getColumnDefinition, "columnDefinition", orderColumnAnn, orderColumnDescriptor ); - applyOr( jaxbOrderColumn, JaxbOrderColumnImpl::getOptions, "options", orderColumnAnn, orderColumnDescriptor ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "name", jaxbOrderColumn.getName() ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "nullable", jaxbOrderColumn.isNullable() ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "insertable", jaxbOrderColumn.isInsertable() ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "updatable", jaxbOrderColumn.isUpdatable() ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "columnDefinition", jaxbOrderColumn.getColumnDefinition() ); + XmlAnnotationHelper.applyOptionalAttribute( orderColumnAnn, "options", jaxbOrderColumn.getOptions() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java index a430649110..2ab373fec1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ElementCollectionAttributeProcessing.java @@ -101,10 +101,9 @@ public class ElementCollectionAttributeProcessing { return; } - final MutableAnnotationUsage collectionTableAnn = XmlProcessingHelper.getOrMakeAnnotation( - CollectionTable.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage collectionTableAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.COLLECTION_TABLE, + xmlDocumentContext.getModelBuildingContext() ); final AnnotationDescriptor collectionTableDescriptor = xmlDocumentContext.getModelBuildingContext() .getAnnotationDescriptorRegistry() diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java index 896a32434a..e283e88f2d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedAttributeProcessing.java @@ -8,6 +8,8 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; @@ -39,10 +41,16 @@ public class EmbeddedAttributeProcessing { declarer ); - final MutableAnnotationUsage embeddedAnn = XmlProcessingHelper.getOrMakeAnnotation( Embedded.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage embeddedAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.EMBEDDED, + xmlDocumentContext.getModelBuildingContext() + ); if ( StringHelper.isNotEmpty( jaxbEmbedded.getTarget() ) ) { - final MutableAnnotationUsage targetAnn = XmlProcessingHelper.getOrMakeAnnotation( Target.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); targetAnn.setAttributeValue( "value", determineTargetName( jaxbEmbedded.getTarget(), xmlDocumentContext ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java index 7008e521bb..b2605ba5c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/EmbeddedIdAttributeProcessing.java @@ -8,13 +8,15 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; -import org.hibernate.models.spi.MutableAnnotationUsage; import jakarta.persistence.AccessType; import jakarta.persistence.EmbeddedId; @@ -39,11 +41,17 @@ public class EmbeddedIdAttributeProcessing { classDetails ); - final MutableAnnotationUsage idAnn = XmlProcessingHelper.makeAnnotation( EmbeddedId.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage idAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.EMBEDDED_ID, + xmlDocumentContext.getModelBuildingContext() + ); CommonAttributeProcessing.applyAttributeBasics( jaxbEmbeddedId, memberDetails, idAnn, accessType, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbEmbeddedId.getTarget() ) ) { - final MutableAnnotationUsage targetAnn = XmlProcessingHelper.getOrMakeAnnotation( Target.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); targetAnn.setAttributeValue( "value", determineTargetName( jaxbEmbeddedId.getTarget(), xmlDocumentContext ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java index 45d18deba5..8c0700920a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToManyAttributeProcessing.java @@ -7,20 +7,19 @@ package org.hibernate.boot.models.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToManyImpl; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; -import org.hibernate.models.spi.AnnotationDescriptor; -import org.hibernate.models.spi.MutableAnnotationUsage; import jakarta.persistence.AccessType; import jakarta.persistence.ManyToMany; -import static org.hibernate.boot.models.xml.internal.XmlProcessingHelper.getOrMakeAnnotation; import static org.hibernate.internal.util.NullnessHelper.coalesce; /** @@ -74,18 +73,15 @@ public class ManyToManyAttributeProcessing { JaxbManyToManyImpl jaxbManyToMany, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage manyToManyAnn = getOrMakeAnnotation( - ManyToMany.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage manyToManyAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MANY_TO_MANY, + xmlDocumentContext.getModelBuildingContext() ); - final AnnotationDescriptor manyToManyDescriptor = xmlDocumentContext - .getModelBuildingContext() - .getAnnotationDescriptorRegistry() - .getDescriptor( ManyToMany.class ); - XmlAnnotationHelper.applyOr( jaxbManyToMany, JaxbManyToManyImpl::getFetch, "fetch", manyToManyAnn, manyToManyDescriptor ); - XmlAnnotationHelper.applyOr( jaxbManyToMany, JaxbManyToManyImpl::getMappedBy, "mappedBy", manyToManyAnn, manyToManyDescriptor ); + if ( jaxbManyToMany != null ) { + XmlAnnotationHelper.applyOptionalAttribute( manyToManyAnn, "fetch", jaxbManyToMany.getFetch() ); + XmlAnnotationHelper.applyOptionalAttribute( manyToManyAnn, "mappedBy", jaxbManyToMany.getMappedBy() ); + } return manyToManyAnn; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java index 6d53159280..cad0ccc636 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/ManyToOneAttributeProcessing.java @@ -6,15 +6,13 @@ */ package org.hibernate.boot.models.xml.internal.attr; -import java.util.EnumSet; -import java.util.List; - import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; import org.hibernate.boot.internal.Target; import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOneImpl; +import org.hibernate.boot.models.HibernateAnnotations; import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; @@ -22,7 +20,6 @@ import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; @@ -74,13 +71,13 @@ public class ManyToOneAttributeProcessing { MutableMemberDetails memberDetails, JaxbManyToOneImpl jaxbManyToOne, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage manyToOneUsage = XmlProcessingHelper.getOrMakeAnnotation( ManyToOne.class, memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyOptionalAttribute( - manyToOneUsage, - "fetch", - jaxbManyToOne.getFetch() + final MutableAnnotationUsage manyToOneUsage = memberDetails.applyAnnotationUsage( + JpaAnnotations.MANY_TO_ONE, + xmlDocumentContext.getModelBuildingContext() ); + XmlAnnotationHelper.applyOptionalAttribute( manyToOneUsage, "fetch", jaxbManyToOne.getFetch() ); + if ( jaxbManyToOne.isId() == Boolean.TRUE ) { memberDetails.applyAnnotationUsage( JpaAnnotations.ID, xmlDocumentContext.getModelBuildingContext() ); } @@ -106,7 +103,10 @@ public class ManyToOneAttributeProcessing { return; } - final MutableAnnotationUsage notFoundAnn = XmlProcessingHelper.makeAnnotation( NotFound.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage notFoundAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.NOT_FOUND, + xmlDocumentContext.getModelBuildingContext() + ); notFoundAnn.setAttributeValue( "action", notFoundAction ); } @@ -121,7 +121,10 @@ public class ManyToOneAttributeProcessing { return; } - final MutableAnnotationUsage notFoundAnn = XmlProcessingHelper.makeAnnotation( OnDelete.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage notFoundAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ON_DELETE, + xmlDocumentContext.getModelBuildingContext() + ); notFoundAnn.setAttributeValue( "action", action ); } @@ -136,13 +139,10 @@ public class ManyToOneAttributeProcessing { return; } - final MutableAnnotationUsage targetAnn = XmlProcessingHelper.makeAnnotation( Target.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage targetAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.TARGET, + xmlDocumentContext.getModelBuildingContext() + ); targetAnn.setAttributeValue( "value", determineTargetName( targetEntityName, xmlDocumentContext ) ); } - - private static > List asList(EnumSet enums) { - final List list = CollectionHelper.arrayList( enums.size() ); - list.addAll( enums ); - return list; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java index 872df5c330..47cec8d26b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/attr/OneToManyAttributeProcessing.java @@ -10,12 +10,13 @@ import org.hibernate.annotations.NotFound; import org.hibernate.annotations.NotFoundAction; import org.hibernate.annotations.OnDelete; import org.hibernate.boot.jaxb.mapping.spi.JaxbOneToManyImpl; +import org.hibernate.boot.models.HibernateAnnotations; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.internal.db.TableProcessing; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.StringHelper; -import org.hibernate.models.spi.AnnotationDescriptor; import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableMemberDetails; @@ -77,12 +78,20 @@ public class OneToManyAttributeProcessing { } ); if ( jaxbOneToMany.getOnDelete() != null ) { - XmlProcessingHelper.getOrMakeAnnotation( OnDelete.class, memberDetails, xmlDocumentContext ).setAttributeValue( "action", jaxbOneToMany.getOnDelete() ); + final MutableAnnotationUsage onDeleteAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.ON_DELETE, + xmlDocumentContext.getModelBuildingContext() + ); + onDeleteAnn.setAttributeValue( "action", jaxbOneToMany.getOnDelete() ); } if ( jaxbOneToMany.getNotFound() != null ) { if ( jaxbOneToMany.getNotFound() != NotFoundAction.EXCEPTION ) { - XmlProcessingHelper.getOrMakeAnnotation( NotFound.class, memberDetails, xmlDocumentContext ).setAttributeValue( "action", jaxbOneToMany.getNotFound() ); + final MutableAnnotationUsage notFoundAnn = memberDetails.applyAnnotationUsage( + HibernateAnnotations.NOT_FOUND, + xmlDocumentContext.getModelBuildingContext() + ); + notFoundAnn.setAttributeValue( "action", jaxbOneToMany.getNotFound() ); } } @@ -93,15 +102,16 @@ public class OneToManyAttributeProcessing { JaxbOneToManyImpl jaxbOneToMany, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage oneToManyAnn = XmlProcessingHelper.getOrMakeAnnotation( OneToMany.class, memberDetails, xmlDocumentContext ); - final AnnotationDescriptor oneToManyDescriptor = xmlDocumentContext - .getModelBuildingContext() - .getAnnotationDescriptorRegistry() - .getDescriptor( OneToMany.class ); + final MutableAnnotationUsage oneToManyAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.ONE_TO_MANY, + xmlDocumentContext.getModelBuildingContext() + ); - XmlAnnotationHelper.applyOr( jaxbOneToMany, JaxbOneToManyImpl::getFetch, "fetch", oneToManyAnn, oneToManyDescriptor ); - XmlAnnotationHelper.applyOr( jaxbOneToMany, JaxbOneToManyImpl::getMappedBy, "mappedBy", oneToManyAnn, oneToManyDescriptor ); - XmlAnnotationHelper.applyOr( jaxbOneToMany, JaxbOneToManyImpl::isOrphanRemoval, "orphanRemoval", oneToManyAnn, oneToManyDescriptor ); + if ( jaxbOneToMany != null ) { + XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "fetch", jaxbOneToMany.getFetch() ); + XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "mappedBy", jaxbOneToMany.getMappedBy() ); + XmlAnnotationHelper.applyOptionalAttribute( oneToManyAnn, "orphanRemoval", jaxbOneToMany.isOrphanRemoval() ); + } return oneToManyAnn; } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java index 1804963e2c..ff0b021eef 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/ColumnProcessing.java @@ -19,12 +19,12 @@ import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnSizable; import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnStandard; import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnUniqueable; import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCommentable; +import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.internal.AnnotationUsageHelper; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.models.spi.AnnotationTarget; -import org.hibernate.models.spi.MutableAnnotationTarget; import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableMemberDetails; @@ -210,8 +210,10 @@ public class ColumnProcessing { return; } - final MutableAnnotationUsage columnAnn = XmlProcessingHelper.getOrMakeAnnotation( MapKeyColumn.class, memberDetails, xmlDocumentContext ); - + final MutableAnnotationUsage columnAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.MAP_KEY_COLUMN, + xmlDocumentContext.getModelBuildingContext() + ); applyColumnDetails( jaxbMapKeyColumn, memberDetails, columnAnn, xmlDocumentContext ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java index 15798efd79..730ce6161a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/JoinColumnProcessing.java @@ -23,7 +23,6 @@ import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.AnnotationUsage; -import org.hibernate.models.spi.MutableAnnotationTarget; import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableMemberDetails; @@ -213,10 +212,9 @@ public class JoinColumnProcessing { XmlAnnotationHelper.applyJoinColumn( jaxbJoinColumns.get( 0 ), memberDetails, xmlDocumentContext ); } else { - final MutableAnnotationUsage columnsAnn = XmlProcessingHelper.makeAnnotation( - JoinColumns.class, - memberDetails, - xmlDocumentContext + final MutableAnnotationUsage columnsAnn = memberDetails.applyAnnotationUsage( + JpaAnnotations.JOIN_COLUMNS, + xmlDocumentContext.getModelBuildingContext() ); columnsAnn.setAttributeValue( "value", createJoinColumns( jaxbJoinColumns, memberDetails, xmlDocumentContext ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java index fbdc42265b..6b33ea745c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/db/TableProcessing.java @@ -12,7 +12,6 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinColumnImpl; import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTableImpl; import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; -import org.hibernate.boot.models.xml.internal.XmlProcessingHelper; import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; @@ -41,23 +40,6 @@ public class TableProcessing { return joinTableUsage; } - public static MutableAnnotationUsage createNestedJoinTable( - JaxbJoinTableImpl jaxbJoinTable, - AnnotationTarget annotationTarget, - XmlDocumentContext xmlDocumentContext) { - if ( jaxbJoinTable == null ) { - return null; - } - - final MutableAnnotationUsage joinTableAnn = XmlProcessingHelper.makeNestedAnnotation( - JoinTable.class, - annotationTarget, - xmlDocumentContext - ); - applyJoinTable( jaxbJoinTable, joinTableAnn, annotationTarget, xmlDocumentContext ); - return joinTableAnn; - } - private static void applyJoinTable( JaxbJoinTableImpl jaxbJoinTable, MutableAnnotationUsage joinTableUsage,