From fdc65cd2350a9e7b772782e9eaee53c0c1dad149 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Sat, 18 Nov 2023 19:59:08 -0600 Subject: [PATCH] #78 - Implement AnyMappingAttributeProcessing --- settings.gradle | 2 +- .../hibernate/boot/internal/AnyKeyType.java | 2 +- .../internal/binders/EntityTypeBinder.java | 2 +- .../DomainModelCategorizationCollector.java | 7 +- .../internal/GlobalRegistrationsImpl.java | 20 +- .../orm/categorize/spi/JpaEventListener.java | 5 +- .../spi/ManagedResourcesProcessor.java | 7 +- .../xml/internal/AttributeProcessor.java | 2 +- .../xml/internal/ManagedTypeProcessor.java | 63 ++-- .../xml/internal/XmlAnnotationHelper.java | 345 +++++++----------- .../xml/internal/XmlProcessingHelper.java | 46 ++- .../attr/AnyMappingAttributeProcessing.java | 52 ++- .../attr/BasicAttributeProcessing.java | 40 +- .../attr/BasicIdAttributeProcessing.java | 23 +- .../attr/CommonAttributeProcessing.java | 115 +++++- .../xml/internal/attr/CommonProcessing.java | 88 ----- .../ElementCollectionAttributeProcessing.java | 53 +-- .../attr/EmbeddedAttributeProcessing.java | 12 +- .../attr/EmbeddedIdAttributeProcessing.java | 11 +- .../attr/ManyToOneAttributeProcessing.java | 33 +- .../xml/internal/db/ColumnProcessing.java | 229 ++++++++++++ .../orm/xml/XmlProcessingSmokeTests.java | 6 +- .../models/orm/xml/attr/AnyTests.java | 15 + .../models/orm/xml/attr/ManyToOneTests.java | 4 +- .../xml/globals/JpaEventListenerTests.java | 3 +- .../resources/mappings/attr/any/simple.xml | 2 +- 26 files changed, 728 insertions(+), 459 deletions(-) delete mode 100644 src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonProcessing.java create mode 100644 src/main/java/org/hibernate/models/orm/categorize/xml/internal/db/ColumnProcessing.java diff --git a/settings.gradle b/settings.gradle index 105af76..95fe47a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -38,7 +38,7 @@ dependencyResolutionManagement { def hcannVersion = version "hcann", "6.0.6.Final" library( "hcann", "org.hibernate.common", "hibernate-commons-annotations" ).versionRef( hcannVersion ) - def hibernateModelsVersion = version "hibernateModels", "0.5.1" + def hibernateModelsVersion = version "hibernateModels", "0.5.3" library( "hibernateModels", "org.hibernate.models", "hibernate-models" ).versionRef( hibernateModelsVersion ) def hibernateOrmVersion = version "hibernateOrm", "7.0.0-SNAPSHOT" diff --git a/src/main/java/org/hibernate/boot/internal/AnyKeyType.java b/src/main/java/org/hibernate/boot/internal/AnyKeyType.java index 4e738c3..cdd51d5 100644 --- a/src/main/java/org/hibernate/boot/internal/AnyKeyType.java +++ b/src/main/java/org/hibernate/boot/internal/AnyKeyType.java @@ -19,5 +19,5 @@ @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface AnyKeyType { - String type(); + String value(); } diff --git a/src/main/java/org/hibernate/models/orm/bind/internal/binders/EntityTypeBinder.java b/src/main/java/org/hibernate/models/orm/bind/internal/binders/EntityTypeBinder.java index 716812e..f02346c 100644 --- a/src/main/java/org/hibernate/models/orm/bind/internal/binders/EntityTypeBinder.java +++ b/src/main/java/org/hibernate/models/orm/bind/internal/binders/EntityTypeBinder.java @@ -512,7 +512,7 @@ private static void applyColumnName( final SoftDeleteType strategy = softDeleteConfig.getEnum( "strategy" ); final String logicalColumnName = coalesce( strategy.getDefaultColumnName(), - softDeleteConfig.getString( softDeleteConfig.getString( "columnName" ) ) + softDeleteConfig.getString( "columnName" ) ); final Identifier physicalColumnName = namingStrategy.toPhysicalColumnName( database.toIdentifier( logicalColumnName ), diff --git a/src/main/java/org/hibernate/models/orm/categorize/internal/DomainModelCategorizationCollector.java b/src/main/java/org/hibernate/models/orm/categorize/internal/DomainModelCategorizationCollector.java index 76b75d0..943b5c0 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/internal/DomainModelCategorizationCollector.java +++ b/src/main/java/org/hibernate/models/orm/categorize/internal/DomainModelCategorizationCollector.java @@ -41,9 +41,12 @@ public class DomainModelCategorizationCollector { private final Map embeddables = new HashMap<>(); private final GlobalRegistrationsImpl globalRegistrations; - public DomainModelCategorizationCollector(boolean areIdGeneratorsGlobal, ClassDetailsRegistry classDetailsRegistry) { + public DomainModelCategorizationCollector( + boolean areIdGeneratorsGlobal, + ClassDetailsRegistry classDetailsRegistry, + AnnotationDescriptorRegistry descriptorRegistry) { this.areIdGeneratorsGlobal = areIdGeneratorsGlobal; - this.globalRegistrations = new GlobalRegistrationsImpl( classDetailsRegistry ); + this.globalRegistrations = new GlobalRegistrationsImpl( classDetailsRegistry, descriptorRegistry ); } public Set getRootEntities() { diff --git a/src/main/java/org/hibernate/models/orm/categorize/internal/GlobalRegistrationsImpl.java b/src/main/java/org/hibernate/models/orm/categorize/internal/GlobalRegistrationsImpl.java index af8b346..30c7d5f 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/internal/GlobalRegistrationsImpl.java +++ b/src/main/java/org/hibernate/models/orm/categorize/internal/GlobalRegistrationsImpl.java @@ -35,6 +35,7 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.CollectionClassification; +import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.dynamic.DynamicAnnotationUsage; import org.hibernate.models.orm.categorize.spi.CollectionTypeRegistration; import org.hibernate.models.orm.categorize.spi.CompositeUserTypeRegistration; @@ -51,6 +52,8 @@ import org.hibernate.models.orm.categorize.spi.TableGeneratorRegistration; import org.hibernate.models.orm.categorize.spi.UserTypeRegistration; import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; +import org.hibernate.models.spi.AnnotationDescriptor; +import org.hibernate.models.spi.AnnotationDescriptorRegistry; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.ClassDetails; @@ -77,6 +80,7 @@ */ public class GlobalRegistrationsImpl implements GlobalRegistrations { private final ClassDetailsRegistry classDetailsRegistry; + private final AnnotationDescriptorRegistry descriptorRegistry; private List jpaEventListeners; private List converterRegistrations; @@ -93,11 +97,12 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations { private Map genericGeneratorRegistrations; public GlobalRegistrationsImpl(SourceModelContext sourceModelContext) { - this( sourceModelContext.getClassDetailsRegistry() ); + this( sourceModelContext.getClassDetailsRegistry(), sourceModelContext.getAnnotationDescriptorRegistry() ); } - public GlobalRegistrationsImpl(ClassDetailsRegistry classDetailsRegistry) { + public GlobalRegistrationsImpl(ClassDetailsRegistry classDetailsRegistry, AnnotationDescriptorRegistry descriptorRegistry) { this.classDetailsRegistry = classDetailsRegistry; + this.descriptorRegistry = descriptorRegistry; } @Override @@ -528,7 +533,7 @@ public void collectSequenceGenerators(List sequenceGe } sequenceGenerators.forEach( (generator) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( SequenceGenerator.class ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( SequenceGenerator.class ); annotationUsage.setAttributeValue( "name", generator.getName() ); annotationUsage.setAttributeValue( "sequenceName", generator.getSequenceName() ); annotationUsage.setAttributeValue( "catalog", generator.getCatalog() ); @@ -540,6 +545,11 @@ public void collectSequenceGenerators(List sequenceGe } ); } + private MutableAnnotationUsage makeAnnotation(Class annotationType) { + final AnnotationDescriptor descriptor = descriptorRegistry.getDescriptor( annotationType ); + return new DynamicAnnotationUsage<>( descriptor ); + } + public void collectSequenceGenerator(AnnotationUsage usage) { collectSequenceGenerator( new SequenceGeneratorRegistration( usage.getAttributeValue( "name" ), usage ) ); } @@ -562,7 +572,7 @@ public void collectTableGenerators(List tableGenerators) } tableGenerators.forEach( (generator) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( TableGenerator.class ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( TableGenerator.class ); annotationUsage.setAttributeValue( "name", generator.getName() ); annotationUsage.setAttributeValue( "table", generator.getTable() ); annotationUsage.setAttributeValue( "catalog", generator.getCatalog() ); @@ -599,7 +609,7 @@ private void collectGenericGenerators(List genericGe } genericGenerators.forEach( (generator) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( GenericGenerator.class ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( GenericGenerator.class ); annotationUsage.setAttributeValue( "name", generator.getName() ); annotationUsage.setAttributeValue( "strategy", generator.getClazz() ); diff --git a/src/main/java/org/hibernate/models/orm/categorize/spi/JpaEventListener.java b/src/main/java/org/hibernate/models/orm/categorize/spi/JpaEventListener.java index 1ad0d67..e65f603 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/spi/JpaEventListener.java +++ b/src/main/java/org/hibernate/models/orm/categorize/spi/JpaEventListener.java @@ -10,6 +10,7 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaultsImpl; import org.hibernate.internal.util.MutableObject; import org.hibernate.models.ModelsException; +import org.hibernate.models.internal.jdk.VoidClassDetails; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MethodDetails; @@ -261,13 +262,13 @@ public static boolean matchesSignature(JpaEventListenerStyle callbackType, Metho if ( callbackType == JpaEventListenerStyle.CALLBACK ) { // should have no arguments. and technically (spec) have a void return return methodDetails.getArgumentTypes().isEmpty() - && methodDetails.getReturnType() == null; + && methodDetails.getReturnType() == VoidClassDetails.VOID_CLASS_DETAILS; } else { assert callbackType == JpaEventListenerStyle.LISTENER; // should have 1 argument. and technically (spec) have a void return return methodDetails.getArgumentTypes().size() == 1 - && methodDetails.getReturnType() == null; + && methodDetails.getReturnType() == VoidClassDetails.VOID_CLASS_DETAILS; } } diff --git a/src/main/java/org/hibernate/models/orm/categorize/spi/ManagedResourcesProcessor.java b/src/main/java/org/hibernate/models/orm/categorize/spi/ManagedResourcesProcessor.java index 7af24c5..8e6f564 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/spi/ManagedResourcesProcessor.java +++ b/src/main/java/org/hibernate/models/orm/categorize/spi/ManagedResourcesProcessor.java @@ -119,9 +119,11 @@ public static CategorizedDomainModel processManagedResources( // JPA id generator global-ity thing final boolean areIdGeneratorsGlobal = true; final ClassDetailsRegistry mutableClassDetailsRegistry = sourceModelBuildingContext.getClassDetailsRegistry(); + final AnnotationDescriptorRegistry descriptorRegistry = sourceModelBuildingContext.getAnnotationDescriptorRegistry(); final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector( areIdGeneratorsGlobal, - mutableClassDetailsRegistry + mutableClassDetailsRegistry, + descriptorRegistry ); final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, modelCategorizationCollector, sourceModelBuildingContext ); @@ -153,8 +155,7 @@ public static CategorizedDomainModel processManagedResources( final ClassDetailsRegistry classDetailsRegistryImmutable = mutableClassDetailsRegistry .makeImmutableCopy(); - final AnnotationDescriptorRegistry annotationDescriptorRegistryImmutable = sourceModelBuildingContext - .getAnnotationDescriptorRegistry() + final AnnotationDescriptorRegistry annotationDescriptorRegistryImmutable = descriptorRegistry .makeImmutableCopy(); // Collect the entity hierarchies based on the set of `rootEntities` diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java index edb7092..f315d95 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/AttributeProcessor.java @@ -59,7 +59,7 @@ public static void processNaturalId( return; } - XmlAnnotationHelper.applyNaturalIdCache( jaxbNaturalId, mutableClassDetails ); + XmlAnnotationHelper.applyNaturalIdCache( jaxbNaturalId, mutableClassDetails, xmlDocumentContext ); processBaseAttributes( jaxbNaturalId, mutableClassDetails, classAccessType, memberAdjuster, xmlDocumentContext ); } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java index a7aece4..737bc84 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/ManagedTypeProcessor.java @@ -6,6 +6,7 @@ */ package org.hibernate.models.orm.categorize.xml.internal; +import java.lang.reflect.Modifier; import java.util.Collection; import java.util.List; import java.util.Map; @@ -36,13 +37,14 @@ import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.ModelsException; +import org.hibernate.models.internal.ModelsClassLogging; import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableClassDetails; import org.hibernate.models.internal.MutableMemberDetails; -import org.hibernate.models.internal.SourceModelLogging; import org.hibernate.models.internal.dynamic.DynamicClassDetails; import org.hibernate.models.internal.dynamic.MapModeFieldDetails; import org.hibernate.models.orm.categorize.spi.JpaEventListenerStyle; +import org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing; import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; import org.hibernate.models.orm.categorize.xml.spi.XmlProcessingResult; import org.hibernate.models.spi.ClassDetails; @@ -65,6 +67,7 @@ * @author Steve Ebersole */ public class ManagedTypeProcessor { + private static final int MEMBER_MODIFIERS = buildMemberModifiers(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Entity @@ -144,6 +147,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbId.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -156,6 +160,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( embeddedId.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -171,6 +176,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbBasic.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -184,6 +190,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbEmbedded.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -194,6 +201,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbManyToOne.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -204,6 +212,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbAnyMapping.getName(), attributeJavaType, + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -216,6 +225,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbBasic.getName(), determineDynamicAttributeJavaType( jaxbBasic, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -225,6 +235,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbEmbedded.getName(), determineDynamicAttributeJavaType( jaxbEmbedded, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -234,6 +245,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbOneToOne.getName(), determineDynamicAttributeJavaType( jaxbOneToOne, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -243,6 +255,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbManyToOne.getName(), determineDynamicAttributeJavaType( jaxbManyToOne, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -252,6 +265,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbAnyMapping.getName(), determineDynamicAttributeJavaType( jaxbAnyMapping, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -261,6 +275,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbElementCollection.getName(), determineDynamicAttributeJavaType( jaxbElementCollection, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -270,6 +285,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbOneToMany.getName(), determineDynamicAttributeJavaType( jaxbOneToMany, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -279,6 +295,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbManyToMany.getName(), determineDynamicAttributeJavaType( jaxbManyToMany, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -288,6 +305,7 @@ private static void prepareDynamicClass( final MapModeFieldDetails member = new MapModeFieldDetails( jaxbPluralAnyMapping.getName(), determineDynamicAttributeJavaType( jaxbPluralAnyMapping, xmlDocumentContext ), + MEMBER_MODIFIERS, xmlDocumentContext.getModelBuildingContext() ); classDetails.addField( member ); @@ -366,11 +384,7 @@ private static void adjustDynamicTypeMember( MutableMemberDetails memberDetails, JaxbPersistentAttribute jaxbAttribute, XmlDocumentContext xmlDocumentContext) { - XmlAnnotationHelper.applyAttributeAccessor( - BuiltInPropertyAccessStrategies.MAP.getExternalName(), - memberDetails, - xmlDocumentContext - ); + XmlAnnotationHelper.applyAttributeAccessor( BuiltInPropertyAccessStrategies.MAP.getExternalName(), memberDetails, xmlDocumentContext ); } private static void processEntityMetadata( @@ -380,18 +394,19 @@ private static void processEntityMetadata( AttributeProcessor.MemberAdjuster memberAdjuster, JaxbEntityMappingsImpl jaxbRoot, XmlDocumentContext xmlDocumentContext) { - XmlAnnotationHelper.applyEntity( jaxbEntity, classDetails ); - XmlAnnotationHelper.applyInheritance( jaxbEntity, classDetails ); - classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails ) ); + XmlAnnotationHelper.applyEntity( jaxbEntity, classDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyInheritance( jaxbEntity, classDetails, xmlDocumentContext ); + classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails, xmlDocumentContext ) ); if ( jaxbEntity.isAbstract() != null ) { - XmlProcessingHelper.makeAnnotation( Abstract.class, classDetails ); + XmlProcessingHelper.makeAnnotation( Abstract.class, classDetails, xmlDocumentContext ); } if ( StringHelper.isNotEmpty( jaxbEntity.getExtends() ) ) { final MutableAnnotationUsage extendsAnn = XmlProcessingHelper.makeAnnotation( Extends.class, - classDetails + classDetails, + xmlDocumentContext ); extendsAnn.setAttributeValue( "superType", jaxbEntity.getExtends() ); } @@ -429,11 +444,11 @@ private static void processEntityMetadata( xmlDocumentContext ) ); - XmlAnnotationHelper.applySqlRestriction( jaxbEntity.getSqlRestriction(), classDetails ); + XmlAnnotationHelper.applySqlRestriction( jaxbEntity.getSqlRestriction(), classDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlInsert(), classDetails, SQLInsert.class ); - XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlUpdate(), classDetails, SQLUpdate.class ); - XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlDelete(), classDetails, SQLDelete.class ); + XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlInsert(), classDetails, SQLInsert.class, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlUpdate(), classDetails, SQLUpdate.class, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlDelete(), classDetails, SQLDelete.class, xmlDocumentContext ); processEntityOrMappedSuperclass( jaxbEntity, classDetails, xmlDocumentContext ); @@ -447,8 +462,8 @@ private static void adjustNonDynamicTypeMember( MutableMemberDetails memberDetails, JaxbPersistentAttribute jaxbAttribute, XmlDocumentContext xmlDocumentContext) { - XmlAnnotationHelper.applyAttributeAccessor( - jaxbAttribute.getAttributeAccessor(), + CommonAttributeProcessing.applyAttributeAccessor( + jaxbAttribute, memberDetails, xmlDocumentContext ); @@ -514,7 +529,7 @@ else if ( jaxbEmbeddedId != null ) { memberAdjuster.adjust( memberDetails, jaxbEmbeddedId, xmlDocumentContext ); } else { - SourceModelLogging.SOURCE_MODEL_LOGGER.debugf( + ModelsClassLogging.MODELS_CLASS_LOGGER.debugf( "Identifiable type [%s] contained no nor ", classDetails.getName() ); @@ -548,13 +563,13 @@ private static void processMappedSuperclassMetadata( JaxbMappedSuperclassImpl jaxbMappedSuperclass, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.getOrMakeAnnotation( MappedSuperclass.class, classDetails ); + XmlProcessingHelper.getOrMakeAnnotation( MappedSuperclass.class, classDetails, xmlDocumentContext ); final AccessType classAccessType = coalesce( jaxbMappedSuperclass.getAccess(), xmlDocumentContext.getPersistenceUnitMetadata().getAccessType() ); - classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails ) ); + classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails, xmlDocumentContext ) ); final JaxbAttributesContainer attributes = jaxbMappedSuperclass.getAttributes(); AttributeProcessor.processAttributes( attributes, classDetails, classAccessType, xmlDocumentContext ); @@ -649,8 +664,8 @@ private static void processEmbeddableMetadata( AccessType classAccessType, AttributeProcessor.MemberAdjuster memberAdjuster, XmlDocumentContext xmlDocumentContext) { - XmlProcessingHelper.getOrMakeAnnotation( Embeddable.class, classDetails ); - classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails ) ); + XmlProcessingHelper.getOrMakeAnnotation( Embeddable.class, classDetails, xmlDocumentContext ); + classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation( classAccessType, classDetails, xmlDocumentContext ) ); AttributeProcessor.processAttributes( jaxbEmbeddable.getAttributes(), @@ -681,4 +696,8 @@ public static void processOverrideEmbeddable(List entityUsage = getOrMakeAnnotation( Entity.class, classDetails ); + MutableClassDetails classDetails, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage entityUsage = getOrMakeAnnotation( Entity.class, classDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbEntity.getName() ) ) { entityUsage.setAttributeValue( "name", jaxbEntity.getName() ); } } - public static void applyBasic(JaxbIdImpl jaxbId, MutableMemberDetails memberDetails) { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( Basic.class, memberDetails ); - memberDetails.addAnnotationUsage( annotationUsage ); - annotationUsage.setAttributeValue( "fetch", EAGER ); - annotationUsage.setAttributeValue( "optional", false ); - } - - public static void applyBasic( - JaxbBasicImpl jaxbBasic, - MutableMemberDetails memberDetails) { - final MutableAnnotationUsage basicAnn = getOrMakeAnnotation( Basic.class, memberDetails ); - if ( jaxbBasic.getFetch() != null ) { - basicAnn.setAttributeValue( "fetch", jaxbBasic.getFetch() ); - } - if ( jaxbBasic.isOptional() != null ) { - basicAnn.setAttributeValue( "optional", jaxbBasic.isOptional() ); - } - } - - public static void applyAccess( - AccessType accessType, - MutableMemberDetails memberDetails) { - final DynamicAnnotationUsage annotationUsage = createAccessAnnotation( - accessType, - memberDetails - ); - memberDetails.addAnnotationUsage( annotationUsage ); - } - - public static DynamicAnnotationUsage createAccessAnnotation( + public static MutableAnnotationUsage createAccessAnnotation( AccessType accessType, - MutableAnnotationTarget target) { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( - Access.class, - target - ); + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage annotationUsage = makeAnnotation( Access.class, target, xmlDocumentContext ); annotationUsage.setAttributeValue( "value", accessType ); return annotationUsage; } @@ -195,7 +161,7 @@ public static void applyAttributeAccessor( String attributeAccessor, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final DynamicAnnotationUsage accessorAnn = new DynamicAnnotationUsage<>( AttributeAccessor.class, memberDetails ); + final MutableAnnotationUsage accessorAnn = makeAnnotation( AttributeAccessor.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( accessorAnn ); // todo : this is the old, deprecated form accessorAnn.setAttributeValue( "value", attributeAccessor ); @@ -203,12 +169,13 @@ public static void applyAttributeAccessor( public static void applyColumn( JaxbColumnImpl jaxbColumn, - MutableMemberDetails memberDetails) { + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { if ( jaxbColumn == null ) { return; } - createColumnAnnotation( jaxbColumn, memberDetails ); + createColumnAnnotation( jaxbColumn, memberDetails, xmlDocumentContext ); } public static MutableAnnotationUsage applyJoinColumn( @@ -226,7 +193,7 @@ public static MutableAnnotationUsage createJoinColumnAnnotation( JaxbJoinColumnImpl jaxbJoinColumn, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final MutableAnnotationUsage joinColumnAnn = getOrMakeAnnotation( JoinColumn.class, memberDetails ); + final MutableAnnotationUsage joinColumnAnn = getOrMakeAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); final AnnotationDescriptor joinColumnDescriptor = xmlDocumentContext .getModelBuildingContext() .getAnnotationDescriptorRegistry() @@ -239,8 +206,8 @@ public static MutableAnnotationUsage createJoinColumnAnnotation( applyOr( jaxbJoinColumn, JaxbJoinColumnImpl::getComment, "comment", joinColumnAnn, joinColumnDescriptor ); applyOr( jaxbJoinColumn, JaxbJoinColumnImpl::getColumnDefinition, "columnDefinition", joinColumnAnn, joinColumnDescriptor ); - final JaxbForeignKeyImpl jaxbForeignKey = jaxbJoinColumn.getForeignKeys(); - final MutableAnnotationUsage foreignKeyAnn = getOrMakeAnnotation( ForeignKey.class, memberDetails ); + final JaxbForeignKeyImpl jaxbForeignKey = jaxbJoinColumn.getForeignKey(); + final MutableAnnotationUsage foreignKeyAnn = getOrMakeAnnotation( ForeignKey.class, memberDetails, xmlDocumentContext ); final AnnotationDescriptor foreignKeyDescriptor = xmlDocumentContext .getModelBuildingContext() .getAnnotationDescriptorRegistry() @@ -257,7 +224,7 @@ public static MutableAnnotationUsage createJoinColumnAnnotation( joinColumnAnn.setAttributeValue( "check", constraints ); for ( int i = 0; i < jaxbJoinColumn.getCheckConstraints().size(); i++ ) { final JaxbCheckConstraintImpl jaxbCheckConstraint = jaxbJoinColumn.getCheckConstraints().get( i ); - final MutableAnnotationUsage checkConstraintAnn = getOrMakeAnnotation( CheckConstraint.class, memberDetails ); + final MutableAnnotationUsage checkConstraintAnn = getOrMakeAnnotation( CheckConstraint.class, memberDetails, xmlDocumentContext ); final AnnotationDescriptor checkConstraintDescriptor = xmlDocumentContext .getModelBuildingContext() .getAnnotationDescriptorRegistry() @@ -270,7 +237,7 @@ public static MutableAnnotationUsage createJoinColumnAnnotation( } } else { - final MutableAnnotationUsage checkConstraintAnn = getOrMakeAnnotation( CheckConstraint.class, memberDetails ); + final MutableAnnotationUsage checkConstraintAnn = getOrMakeAnnotation( CheckConstraint.class, memberDetails, xmlDocumentContext ); joinColumnAnn.setAttributeValue( "check", List.of( checkConstraintAnn ) ); } @@ -311,97 +278,14 @@ public static void applyOr( } private static MutableAnnotationUsage createColumnAnnotation( - JaxbColumnImpl jaxbColumn, - MutableAnnotationTarget target) { - final MutableAnnotationUsage columnAnn = getOrMakeAnnotation( Column.class, target ); - - populateColumn( jaxbColumn, target, columnAnn ); - - return columnAnn; - } - - public static void populateColumn( JaxbColumnImpl jaxbColumn, MutableAnnotationTarget target, - MutableAnnotationUsage columnAnn) { - if ( jaxbColumn != null ) { - if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { - columnAnn.setAttributeValue( "name", jaxbColumn.getName() ); - } - - if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { - columnAnn.setAttributeValue( "table", jaxbColumn.getTable() ); - } - - if ( jaxbColumn.isUnique() != null ) { - columnAnn.setAttributeValue( "unique", jaxbColumn.isUnique() ); - } - - if ( jaxbColumn.isNullable() != null ) { - columnAnn.setAttributeValue( "nullable", jaxbColumn.isNullable() ); - } - - if ( jaxbColumn.isInsertable() != null ) { - columnAnn.setAttributeValue( "insertable", jaxbColumn.isInsertable() ); - } - - if ( jaxbColumn.isUpdatable() != null ) { - columnAnn.setAttributeValue( "updatable", jaxbColumn.isUpdatable() ); - } - - if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { - columnAnn.setAttributeValue( "columnDefinition", jaxbColumn.getColumnDefinition() ); - } - - if ( jaxbColumn.getLength() != null ) { - columnAnn.setAttributeValue( "length", jaxbColumn.getLength() ); - } - - if ( jaxbColumn.getPrecision() != null ) { - columnAnn.setAttributeValue( "precision", jaxbColumn.getPrecision() ); - } - - if ( jaxbColumn.getScale() != null ) { - columnAnn.setAttributeValue( "scale", jaxbColumn.getScale() ); - } - - if ( jaxbColumn.getComment() != null ) { - columnAnn.setAttributeValue( "comment", jaxbColumn.getComment() ); - } - - if ( jaxbColumn.getOptions() != null ) { - columnAnn.setAttributeValue( "options", jaxbColumn.getOptions() ); - } - - if ( CollectionHelper.isNotEmpty( jaxbColumn.getCheckConstraints() ) ) { - final List> checks = new ArrayList<>( jaxbColumn.getCheckConstraints().size() ); - for ( int i = 0; i < jaxbColumn.getCheckConstraints().size(); i++ ) { - final JaxbCheckConstraintImpl jaxbCheck = jaxbColumn.getCheckConstraints().get( i ); - final MutableAnnotationUsage checkAnn = getOrMakeAnnotation( Check.class, target ); - checkAnn.setAttributeValue( "name", jaxbCheck.getName() ); - checkAnn.setAttributeValue( "constraints", jaxbCheck.getConstraint() ); - checks.add( checkAnn ); - } - columnAnn.setAttributeValue( "check", checks ); - } - } - } - - public static void applyFormula(String formula, MutableMemberDetails memberDetails) { - if ( StringHelper.isEmpty( formula ) ) { - return; - } + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage columnAnn = getOrMakeAnnotation( Column.class, target, xmlDocumentContext ); - final AnnotationUsage annotationUsage = createFormulaAnnotation( formula, memberDetails ); - memberDetails.addAnnotationUsage( annotationUsage ); - } + ColumnProcessing.applyColumnDetails( jaxbColumn, target, columnAnn, xmlDocumentContext ); - private static AnnotationUsage createFormulaAnnotation( - String formula, - AnnotationTarget target) { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( Formula.class, target ); - annotationUsage.setAttributeValue( "value", formula ); - return annotationUsage; + return columnAnn; } public static void applyUserType( @@ -412,24 +296,25 @@ public static void applyUserType( return; } - final DynamicAnnotationUsage typeAnn = new DynamicAnnotationUsage<>( Type.class, memberDetails ); + final MutableAnnotationUsage typeAnn = makeAnnotation( Type.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( typeAnn ); final ClassDetails userTypeImpl = resolveJavaType( jaxbType.getValue(), xmlDocumentContext ); typeAnn.setAttributeValue( "value", userTypeImpl ); - typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails ) ); + typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails, xmlDocumentContext ) ); } public static List> collectParameters( List jaxbParameters, - AnnotationTarget target) { + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbParameters ) ) { return emptyList(); } List> parameterAnnList = new ArrayList<>( jaxbParameters.size() ); jaxbParameters.forEach( (jaxbParam) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( Parameter.class, target ); + final MutableAnnotationUsage annotationUsage = makeNestedAnnotation( Parameter.class, target, xmlDocumentContext ); parameterAnnList.add( annotationUsage ); annotationUsage.setAttributeValue( "name", jaxbParam.getName() ); annotationUsage.setAttributeValue( "value", jaxbParam.getValue() ); @@ -445,12 +330,12 @@ public static void applyCollectionUserType( return; } - final DynamicAnnotationUsage typeAnn = new DynamicAnnotationUsage<>( CollectionType.class, memberDetails ); + final MutableAnnotationUsage typeAnn = makeAnnotation( CollectionType.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( typeAnn ); final ClassDetails userTypeImpl = resolveJavaType( jaxbType.getType(), xmlDocumentContext ); typeAnn.setAttributeValue( "type", userTypeImpl ); - typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails ) ); + typeAnn.setAttributeValue( "parameters", collectParameters( jaxbType.getParameters(), memberDetails, xmlDocumentContext ) ); } public static void applyTargetClass( @@ -458,55 +343,53 @@ public static void applyTargetClass( MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { final ClassDetails classDetails = resolveJavaType( name, xmlDocumentContext ); - final MutableAnnotationUsage targetAnn = makeAnnotation( Target.class, memberDetails ); + final MutableAnnotationUsage targetAnn = makeAnnotation( Target.class, memberDetails, xmlDocumentContext ); targetAnn.setAttributeValue( "value", classDetails ); } public static void applyTemporal( TemporalType temporalType, - MutableMemberDetails memberDetails) { + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { if ( temporalType == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( Temporal.class, memberDetails ); - memberDetails.addAnnotationUsage( annotationUsage ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( Temporal.class, memberDetails, xmlDocumentContext ); annotationUsage.setAttributeValue( "value", temporalType ); } - public static void applyLob(JaxbLobImpl jaxbLob, MutableMemberDetails memberDetails) { + public static void applyLob(JaxbLobImpl jaxbLob, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { if ( jaxbLob == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( Lob.class, memberDetails ); - memberDetails.addAnnotationUsage( annotationUsage ); + makeAnnotation( Lob.class, memberDetails, xmlDocumentContext ); } - public static void applyEnumerated(EnumType enumType, MutableMemberDetails memberDetails) { + public static void applyEnumerated(EnumType enumType, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { if ( enumType == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( Enumerated.class, - memberDetails + memberDetails, + xmlDocumentContext ); - memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "value", enumType ); } - public static void applyNationalized(JaxbNationalizedImpl jaxbNationalized, MutableMemberDetails memberDetails) { + public static void applyNationalized( + JaxbNationalizedImpl jaxbNationalized, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { if ( jaxbNationalized == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( - Nationalized.class, - memberDetails - ); - memberDetails.addAnnotationUsage( annotationUsage ); + makeAnnotation( Nationalized.class, memberDetails, xmlDocumentContext ); } public static void applyGeneratedValue( @@ -517,7 +400,7 @@ public static void applyGeneratedValue( return; } - final DynamicAnnotationUsage generatedValueAnn = new DynamicAnnotationUsage<>( GeneratedValue.class, memberDetails ); + final MutableAnnotationUsage generatedValueAnn = makeAnnotation( GeneratedValue.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( generatedValueAnn ); generatedValueAnn.setAttributeValue( "strategy", jaxbGeneratedValue.getStrategy() ); generatedValueAnn.setAttributeValue( "generator", jaxbGeneratedValue.getGenerator() ); @@ -531,10 +414,11 @@ public static void applySequenceGenerator( return; } - final MutableAnnotationUsage sequenceAnn = XmlProcessingHelper.getOrMakeNamedAnnotation( + final MutableAnnotationUsage sequenceAnn = getOrMakeNamedAnnotation( SequenceGenerator.class, jaxbGenerator.getName(), - memberDetails + memberDetails, + xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbGenerator.getSequenceName() ) ) { @@ -555,7 +439,7 @@ public static void applyTableGenerator( return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( TableGenerator.class, memberDetails ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( TableGenerator.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "name", jaxbGenerator.getName() ); annotationUsage.setAttributeValue( "table", jaxbGenerator.getTable() ); @@ -578,40 +462,44 @@ public static void applyUuidGenerator( return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( UuidGenerator.class, memberDetails ); + final MutableAnnotationUsage annotationUsage = makeAnnotation( UuidGenerator.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "style", jaxbGenerator.getStyle() ); } public static void applyAttributeOverrides( List jaxbOverrides, - MutableMemberDetails memberDetails) { + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbOverrides ) ) { return; } jaxbOverrides.forEach( (jaxbOverride) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( AttributeOverride.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "name", jaxbOverride.getName() ); - annotationUsage.setAttributeValue( "column", createColumnAnnotation( jaxbOverride.getColumn(), memberDetails ) ); + annotationUsage.setAttributeValue( "column", createColumnAnnotation( jaxbOverride.getColumn(), memberDetails, xmlDocumentContext ) ); } ); } public static void applyAssociationOverrides( List jaxbOverrides, - MutableMemberDetails memberDetails) { + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { if ( CollectionHelper.isEmpty( jaxbOverrides ) ) { return; } jaxbOverrides.forEach( (jaxbOverride) -> { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( AssociationOverride.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "name", jaxbOverride.getName() ); @@ -623,10 +511,12 @@ public static void applyAssociationOverrides( public static void applyOptimisticLockInclusion( boolean inclusion, - MutableMemberDetails memberDetails) { - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage annotationUsage = makeAnnotation( OptimisticLock.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "exclude", !inclusion ); @@ -640,9 +530,10 @@ public static void applyConvert( return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( Convert.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); @@ -657,7 +548,7 @@ public static void applyTable( JaxbTableImpl jaxbTable, MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { - final DynamicAnnotationUsage tableAnn = new DynamicAnnotationUsage<>( Table.class, target ); + final MutableAnnotationUsage
tableAnn = makeAnnotation( Table.class, target, xmlDocumentContext ); target.addAnnotationUsage( tableAnn ); applyTableAttributes( tableAnn, jaxbTable, xmlDocumentContext ); @@ -674,7 +565,7 @@ public static void applyTableOverride( return; } - final MutableAnnotationUsage
tableAnn = getOrMakeAnnotation( Table.class, target ); + final MutableAnnotationUsage
tableAnn = getOrMakeAnnotation( Table.class, target, xmlDocumentContext ); applyTableAttributes( tableAnn, jaxbTable, xmlDocumentContext ); @@ -723,13 +614,14 @@ private static void applyAttributeIfSpecified( public static void applyNaturalId( JaxbNaturalId jaxbNaturalId, MutableMemberDetails backingMember, - SourceModelBuildingContext sourceModelBuildingContext) { + XmlDocumentContext xmlDocumentContext) { if ( jaxbNaturalId == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( NaturalId.class, - backingMember + backingMember, + xmlDocumentContext ); backingMember.addAnnotationUsage( annotationUsage ); annotationUsage.setAttributeValue( "mutable", jaxbNaturalId.isMutable() ); @@ -737,14 +629,16 @@ public static void applyNaturalId( public static void applyNaturalIdCache( JaxbNaturalId jaxbNaturalId, - MutableClassDetails classDetails) { + MutableClassDetails classDetails, + XmlDocumentContext xmlDocumentContext) { if ( jaxbNaturalId == null || jaxbNaturalId.getCaching() == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( NaturalIdCache.class, - classDetails + classDetails, + xmlDocumentContext ); classDetails.addAnnotationUsage( annotationUsage ); @@ -759,9 +653,10 @@ public static void applyId( if ( jaxbId == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( Id.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); } @@ -773,23 +668,26 @@ public static void applyEmbeddedId( if ( jaxbEmbeddedId == null ) { return; } - final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + final MutableAnnotationUsage annotationUsage = makeAnnotation( EmbeddedId.class, - memberDetails + memberDetails, + xmlDocumentContext ); memberDetails.addAnnotationUsage( annotationUsage ); } static void applyInheritance( JaxbEntity jaxbEntity, - MutableClassDetails classDetails) { + MutableClassDetails classDetails, + XmlDocumentContext xmlDocumentContext) { if ( jaxbEntity.getInheritance() == null ) { return; } final MutableAnnotationUsage inheritanceAnn = getOrMakeAnnotation( Inheritance.class, - classDetails + classDetails, + xmlDocumentContext ); inheritanceAnn.setAttributeValue( "strategy", jaxbEntity.getInheritance().getStrategy() ); } @@ -898,7 +796,7 @@ public static void applyJavaTypeDescriptor( String descriptorClassName, MutableMemberDetails memberDetails, XmlDocumentContext xmlDocumentContext) { - final DynamicAnnotationUsage typeAnn = new DynamicAnnotationUsage<>( JavaType.class, memberDetails ); + final MutableAnnotationUsage typeAnn = makeAnnotation( JavaType.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( typeAnn ); final ClassDetails descriptorClass = xmlDocumentContext @@ -917,7 +815,7 @@ private static void applyJdbcTypeDescriptor( .getModelBuildingContext() .getClassDetailsRegistry() .resolveClassDetails( descriptorClassName ); - final MutableAnnotationUsage jdbcTypeAnn = makeAnnotation( JdbcType.class, memberDetails ); + final MutableAnnotationUsage jdbcTypeAnn = makeAnnotation( JdbcType.class, memberDetails, xmlDocumentContext ); jdbcTypeAnn.setAttributeValue( "value", descriptorClassDetails ); } @@ -930,7 +828,7 @@ public static void applyJdbcTypeCode( return; } - final DynamicAnnotationUsage typeCodeAnn = new DynamicAnnotationUsage<>( JdbcTypeCode.class, memberDetails ); + final MutableAnnotationUsage typeCodeAnn = makeAnnotation( JdbcTypeCode.class, memberDetails, xmlDocumentContext ); memberDetails.addAnnotationUsage( typeCodeAnn ); typeCodeAnn.setAttributeValue( "value", jdbcTypeCode ); } @@ -956,10 +854,11 @@ private static void applyFilter( XmlDocumentContext xmlDocumentContext) { // Since @Filter and @FilterJoinTable have exactly the same attributes, // we can use the same method with parametrized annotation class - final MutableAnnotationUsage filterAnn = XmlProcessingHelper.getOrMakeNamedAnnotation( + final MutableAnnotationUsage filterAnn = getOrMakeNamedAnnotation( filterAnnotationClass, jaxbFilter.getName(), - target + target, + xmlDocumentContext ); applyAttributeIfSpecified( filterAnn, "condition", jaxbFilter.getCondition() ); @@ -967,16 +866,17 @@ private static void applyFilter( final List aliases = jaxbFilter.getAliases(); if ( !CollectionHelper.isEmpty( aliases ) ) { - filterAnn.setAttributeValue( "aliases", getSqlFragmentAliases( aliases, xmlDocumentContext ) ); + filterAnn.setAttributeValue( "aliases", getSqlFragmentAliases( aliases, target, xmlDocumentContext ) ); } } private static List> getSqlFragmentAliases( List aliases, + MutableAnnotationTarget target, XmlDocumentContext xmlDocumentContext) { final List> sqlFragmentAliases = new ArrayList<>( aliases.size() ); for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) { - final MutableAnnotationUsage aliasAnn = new DynamicAnnotationUsage<>( SqlFragmentAlias.class ); + final MutableAnnotationUsage aliasAnn = makeNestedAnnotation( SqlFragmentAlias.class, target, xmlDocumentContext ); aliasAnn.setAttributeValue( "alias", alias.getAlias() ); applyAttributeIfSpecified( aliasAnn, "table", alias.getTable() ); if ( StringHelper.isNotEmpty( alias.getEntity() ) ) { @@ -992,23 +892,25 @@ private static List> getSqlFragmentAliases( public static void applySqlRestriction( String sqlRestriction, - MutableAnnotationTarget target) { - applySqlRestriction( sqlRestriction, target, SQLRestriction.class ); + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + applySqlRestriction( sqlRestriction, target, SQLRestriction.class, xmlDocumentContext ); } public static void applySqlJoinTableRestriction( String sqlJoinTableRestriction, MutableAnnotationTarget target, - SourceModelBuildingContext buildingContext) { - applySqlRestriction( sqlJoinTableRestriction, target, SQLJoinTableRestriction.class ); + XmlDocumentContext xmlDocumentContext) { + applySqlRestriction( sqlJoinTableRestriction, target, SQLJoinTableRestriction.class, xmlDocumentContext ); } private static void applySqlRestriction( String sqlRestriction, MutableAnnotationTarget target, - Class annotationType) { + Class annotationType, + XmlDocumentContext xmlDocumentContext) { if ( StringHelper.isNotEmpty( sqlRestriction ) ) { - final MutableAnnotationUsage annotation = getOrMakeAnnotation( annotationType, target ); + final MutableAnnotationUsage annotation = getOrMakeAnnotation( annotationType, target, xmlDocumentContext ); annotation.setAttributeValue( "value", sqlRestriction ); } } @@ -1016,9 +918,10 @@ private static void applySqlRestriction( public static void applyCustomSql( JaxbCustomSqlImpl jaxbCustomSql, MutableAnnotationTarget target, - Class annotationType) { + Class annotationType, + XmlDocumentContext xmlDocumentContext) { if ( jaxbCustomSql != null ) { - final MutableAnnotationUsage annotation = getOrMakeAnnotation( annotationType, target ); + final MutableAnnotationUsage annotation = getOrMakeAnnotation( annotationType, target, xmlDocumentContext ); annotation.setAttributeValue( "sql", jaxbCustomSql.getValue() ); annotation.setAttributeValue( "callable", jaxbCustomSql.isCallable() ); applyAttributeIfSpecified( annotation, "table", jaxbCustomSql.getTable() ); @@ -1046,7 +949,7 @@ static void applyIdClass( MutableClassDetails target, XmlDocumentContext xmlDocumentContext) { if ( jaxbIdClass != null ) { - getOrMakeAnnotation( IdClass.class, target ).setAttributeValue( + getOrMakeAnnotation( IdClass.class, target, xmlDocumentContext ).setAttributeValue( "value", xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry().resolveClassDetails( jaxbIdClass.getClazz() ) ); @@ -1059,7 +962,8 @@ static void applyEntityListener( XmlDocumentContext xmlDocumentContext) { final MutableAnnotationUsage entityListeners = getOrMakeAnnotation( EntityListeners.class, - classDetails + classDetails, + xmlDocumentContext ); final MutableClassDetails entityListenerClass = (MutableClassDetails) xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry() .resolveClassDetails( jaxbEntityListener.getClazz() ); @@ -1083,20 +987,21 @@ static void applyLifecycleCallbacks( JpaEventListenerStyle callbackType, MutableClassDetails classDetails, XmlDocumentContext xmlDocumentContext) { - applyLifecycleCallback( lifecycleCallbackContainer.getPrePersist(), callbackType, PrePersist.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPostPersist(), callbackType, PostPersist.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPreRemove(), callbackType, PreRemove.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPostRemove(), callbackType, PostRemove.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPreUpdate(), callbackType, PreUpdate.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPostUpdate(), callbackType, PostUpdate.class, classDetails ); - applyLifecycleCallback( lifecycleCallbackContainer.getPostLoad(), callbackType, PostLoad.class, classDetails ); + applyLifecycleCallback( lifecycleCallbackContainer.getPrePersist(), callbackType, PrePersist.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPostPersist(), callbackType, PostPersist.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPreRemove(), callbackType, PreRemove.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPostRemove(), callbackType, PostRemove.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPreUpdate(), callbackType, PreUpdate.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPostUpdate(), callbackType, PostUpdate.class, classDetails, xmlDocumentContext ); + applyLifecycleCallback( lifecycleCallbackContainer.getPostLoad(), callbackType, PostLoad.class, classDetails, xmlDocumentContext ); } private static void applyLifecycleCallback( JaxbLifecycleCallback lifecycleCallback, JpaEventListenerStyle callbackType, Class lifecycleAnnotation, - MutableClassDetails classDetails) { + MutableClassDetails classDetails, + XmlDocumentContext xmlDocumentContext) { if ( lifecycleCallback != null ) { final MethodDetails methodDetails = getCallbackMethodDetails( lifecycleCallback.getMethodName(), @@ -1110,7 +1015,7 @@ private static void applyLifecycleCallback( classDetails.getName() ) ); } - makeAnnotation( lifecycleAnnotation, (MutableMemberDetails) methodDetails ); + makeAnnotation( lifecycleAnnotation, (MutableMemberDetails) methodDetails, xmlDocumentContext ); } } @@ -1131,7 +1036,7 @@ static void applyRowId( MutableClassDetails target, XmlDocumentContext xmlDocumentContext) { if ( rowId != null ) { - final MutableAnnotationUsage rowIdAnn = getOrMakeAnnotation( RowId.class, target ); + final MutableAnnotationUsage rowIdAnn = getOrMakeAnnotation( RowId.class, target, xmlDocumentContext ); applyAttributeIfSpecified( rowIdAnn, "value", rowId ); } } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlProcessingHelper.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlProcessingHelper.java index 2b95e99..003250b 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlProcessingHelper.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/XmlProcessingHelper.java @@ -121,22 +121,30 @@ else if ( methodDetails.getName().startsWith( "is" ) ) { */ public static MutableAnnotationUsage getOrMakeAnnotation( Class annotationType, - MutableAnnotationTarget target) { + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { final AnnotationUsage existing = target.getAnnotationUsage( annotationType ); if ( existing != null ) { return (MutableAnnotationUsage) existing; } - return makeAnnotation( annotationType, target ); + return makeAnnotation( annotationType, target, xmlDocumentContext ); } /** - * Make an AnnotationUsage. - * Used when applying XML in complete mode or when {@linkplain #getOrMakeAnnotation} - * needs to make. + * 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 makeAnnotation(Class annotationType) { - return new DynamicAnnotationUsage<>( annotationType ); + public static MutableAnnotationUsage makeNestedAnnotation( + Class annotationType, + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + return new DynamicAnnotationUsage<>( + xmlDocumentContext.getModelBuildingContext() + .getAnnotationDescriptorRegistry() + .getDescriptor( annotationType ), + target + ); } /** @@ -146,8 +154,9 @@ public static MutableAnnotationUsage makeAnnotation(Cl */ public static MutableAnnotationUsage makeAnnotation( Class annotationType, - MutableAnnotationTarget target) { - final DynamicAnnotationUsage created = new DynamicAnnotationUsage<>( annotationType, target ); + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage created = makeNestedAnnotation( annotationType, target, xmlDocumentContext ); target.addAnnotationUsage( created ); return created; } @@ -159,8 +168,9 @@ public static MutableAnnotationUsage makeAnnotation( public static MutableAnnotationUsage getOrMakeNamedAnnotation( Class annotationType, String name, - MutableAnnotationTarget target) { - return getOrMakeNamedAnnotation( annotationType, name, "name", target ); + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + return getOrMakeNamedAnnotation( annotationType, name, "name", target, xmlDocumentContext ); } /** @@ -171,9 +181,10 @@ public static MutableAnnotationUsage getOrMakeNamedAnn Class annotationType, String name, String attributeToMatch, - MutableAnnotationTarget target) { + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { if ( name == null ) { - return makeAnnotation( annotationType, target ); + return makeAnnotation( annotationType, target, xmlDocumentContext ); } final AnnotationUsage existing = target.getNamedAnnotationUsage( annotationType, name, attributeToMatch ); @@ -181,7 +192,7 @@ public static MutableAnnotationUsage getOrMakeNamedAnn return (MutableAnnotationUsage) existing; } - return makeNamedAnnotation( annotationType, name, attributeToMatch, target ); + return makeNamedAnnotation( annotationType, name, attributeToMatch, target, xmlDocumentContext ); } /** @@ -189,12 +200,13 @@ public static MutableAnnotationUsage getOrMakeNamedAnn * Used when applying XML in complete mode or when {@linkplain #getOrMakeNamedAnnotation} * needs to make. */ - public static DynamicAnnotationUsage makeNamedAnnotation( + public static MutableAnnotationUsage makeNamedAnnotation( Class annotationType, String name, String nameAttributeName, - MutableAnnotationTarget target) { - final DynamicAnnotationUsage created = new DynamicAnnotationUsage<>( annotationType, target ); + MutableAnnotationTarget target, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage created = makeNestedAnnotation( annotationType, target, xmlDocumentContext ); target.addAnnotationUsage( created ); created.setAttributeValue( nameAttributeName, name ); return created; diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/AnyMappingAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/AnyMappingAttributeProcessing.java index 543c050..ec5202b 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/AnyMappingAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/AnyMappingAttributeProcessing.java @@ -6,24 +6,26 @@ */ package org.hibernate.models.orm.categorize.xml.internal.attr; +import java.util.ArrayList; import java.util.List; -import java.util.Locale; import org.hibernate.annotations.Any; import org.hibernate.annotations.AnyDiscriminator; import org.hibernate.annotations.AnyDiscriminatorValue; import org.hibernate.annotations.AnyDiscriminatorValues; +import org.hibernate.boot.internal.AnyKeyType; import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyDiscriminatorValueMappingImpl; 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.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableClassDetails; import org.hibernate.models.internal.MutableMemberDetails; -import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; import org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper; +import org.hibernate.models.orm.categorize.xml.internal.db.ColumnProcessing; import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetailsRegistry; @@ -31,9 +33,12 @@ import jakarta.persistence.AccessType; import jakarta.persistence.Column; import jakarta.persistence.DiscriminatorType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import static org.hibernate.internal.util.NullnessHelper.coalesce; import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeNestedAnnotation; /** * @author Steve Ebersole @@ -52,11 +57,9 @@ public static MutableMemberDetails processAnyMappingAttribute( declarer ); - final MutableAnnotationUsage anyAnn = makeAnnotation( Any.class, memberDetails ); + final MutableAnnotationUsage anyAnn = makeAnnotation( Any.class, memberDetails, xmlDocumentContext ); - CommonProcessing.applyFetching( memberDetails, jaxbHbmAnyMapping, anyAnn ); - CommonProcessing.applyAttributeAccessor( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); - CommonProcessing.applyOptimisticLock( memberDetails, jaxbHbmAnyMapping, anyAnn ); + CommonAttributeProcessing.applyAttributeBasics( jaxbHbmAnyMapping, memberDetails, anyAnn, accessType, xmlDocumentContext ); applyDiscriminator( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); applyKey( memberDetails, jaxbHbmAnyMapping, anyAnn, xmlDocumentContext ); @@ -70,33 +73,29 @@ private static void applyDiscriminator( MutableAnnotationUsage anyAnn, XmlDocumentContext xmlDocumentContext) { final JaxbAnyMappingDiscriminatorImpl jaxbDiscriminator = jaxbHbmAnyMapping.getDiscriminator(); - final MutableAnnotationUsage anyDiscriminatorAnn = makeAnnotation( AnyDiscriminator.class, memberDetails ); + final MutableAnnotationUsage anyDiscriminatorAnn = makeAnnotation( AnyDiscriminator.class, memberDetails, xmlDocumentContext ); if ( jaxbDiscriminator == null ) { return; } - final String discriminatorTypeName = jaxbDiscriminator.getType(); - if ( StringHelper.isNotEmpty( discriminatorTypeName ) ) { - final String normalizedName = discriminatorTypeName.toUpperCase( Locale.ROOT ); - final DiscriminatorType discriminatorType = DiscriminatorType.valueOf( normalizedName ); - anyDiscriminatorAnn.setAttributeValue( "value", discriminatorType ); - } + final DiscriminatorType discriminatorType = jaxbDiscriminator.getType(); + anyDiscriminatorAnn.setAttributeValue( "value", discriminatorType ); final JaxbColumnImpl jaxbColumn = jaxbDiscriminator.getColumn(); - final MutableAnnotationUsage columnAnn = makeAnnotation( Column.class, memberDetails ); + final MutableAnnotationUsage columnAnn = makeAnnotation( Column.class, memberDetails, xmlDocumentContext ); if ( jaxbColumn != null ) { - XmlAnnotationHelper.populateColumn( jaxbColumn, memberDetails, columnAnn ); + ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, columnAnn, xmlDocumentContext ); } final List valueMappings = jaxbDiscriminator.getValueMappings(); if ( CollectionHelper.isNotEmpty( valueMappings ) ) { - final MutableAnnotationUsage valuesAnn = makeAnnotation( AnyDiscriminatorValues.class, memberDetails ); + final MutableAnnotationUsage valuesAnn = makeAnnotation( AnyDiscriminatorValues.class, memberDetails, xmlDocumentContext ); final List> valueList = CollectionHelper.arrayList( valueMappings.size() ); final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); valuesAnn.setAttributeValue( "value", valueList ); valueMappings.forEach( (valueMapping) -> { - final MutableAnnotationUsage valueAnn = makeAnnotation( AnyDiscriminatorValue.class ); + final MutableAnnotationUsage valueAnn = makeNestedAnnotation( AnyDiscriminatorValue.class, memberDetails, xmlDocumentContext ); valueList.add( valueAnn ); valueAnn.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() ); @@ -116,7 +115,26 @@ private static void applyKey( JaxbAnyMappingImpl jaxbHbmAnyMapping, MutableAnnotationUsage anyAnn, XmlDocumentContext xmlDocumentContext) { + final JaxbAnyMappingKeyImpl jaxbKey = jaxbHbmAnyMapping.getKey(); + if ( StringHelper.isNotEmpty( jaxbKey.getType() ) ) { + final MutableAnnotationUsage keyTypeAnn = makeAnnotation( AnyKeyType.class, memberDetails, xmlDocumentContext ); + keyTypeAnn.setAttributeValue( "value", jaxbKey.getType() ); + } + if ( jaxbKey.getColumns().isEmpty() ) { + makeAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); + } + else { + final MutableAnnotationUsage columnsAnn = makeAnnotation( JoinColumns.class, memberDetails, xmlDocumentContext ); + final ArrayList> columnAnnList = CollectionHelper.arrayList( jaxbKey.getColumns().size() ); + columnsAnn.setAttributeValue( "value", columnAnnList ); + jaxbKey.getColumns().forEach( (jaxbColumn) -> { + final MutableAnnotationUsage columnAnn = makeNestedAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); + columnAnnList.add( columnAnn ); + + ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, columnAnn, xmlDocumentContext ); + } ); + } } } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicAttributeProcessing.java index 64f0c33..70fe78a 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicAttributeProcessing.java @@ -6,17 +6,24 @@ */ package org.hibernate.models.orm.categorize.xml.internal.attr; +import org.hibernate.annotations.Formula; import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl; +import org.hibernate.internal.util.StringHelper; +import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableClassDetails; import org.hibernate.models.internal.MutableMemberDetails; import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; import org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper; +import org.hibernate.models.orm.categorize.xml.internal.db.ColumnProcessing; import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; import jakarta.persistence.AccessType; +import jakarta.persistence.Basic; +import jakarta.persistence.Column; import static org.hibernate.internal.util.NullnessHelper.coalesce; -import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.processCommonAttributeAnnotations; +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.getOrMakeAnnotation; +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; /** * @author Steve Ebersole @@ -35,24 +42,29 @@ public static MutableMemberDetails processBasicAttribute( declarer ); - XmlAnnotationHelper.applyBasic( jaxbBasic, memberDetails ); + final MutableAnnotationUsage basicAnn = getOrMakeAnnotation( Basic.class, memberDetails, xmlDocumentContext ); + CommonAttributeProcessing.applyAttributeBasics( jaxbBasic, memberDetails, basicAnn, accessType, xmlDocumentContext ); - processCommonAttributeAnnotations( jaxbBasic, memberDetails, accessType ); - // only semi-common - XmlAnnotationHelper.applyOptimisticLockInclusion( jaxbBasic.isOptimisticLock(), memberDetails ); - - XmlAnnotationHelper.applyColumn( jaxbBasic.getColumn(), memberDetails ); - XmlAnnotationHelper.applyFormula( jaxbBasic.getFormula(), memberDetails ); - - // todo : value generation + if ( StringHelper.isNotEmpty( jaxbBasic.getFormula() ) ) { + assert jaxbBasic.getColumn() == null; + final MutableAnnotationUsage formulaAnn = getOrMakeAnnotation( Formula.class, memberDetails, xmlDocumentContext ); + formulaAnn.setAttributeValue( "value", jaxbBasic.getFormula() ); + } + else { + final MutableAnnotationUsage columnAnn = getOrMakeAnnotation( Column.class, memberDetails, xmlDocumentContext ); + ColumnProcessing.applyColumnDetails( jaxbBasic.getColumn(), memberDetails, columnAnn, xmlDocumentContext ); + } XmlAnnotationHelper.applyConvert( jaxbBasic.getConvert(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyBasicTypeComposition( jaxbBasic, memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyTemporal( jaxbBasic.getTemporal(), memberDetails ); - XmlAnnotationHelper.applyLob( jaxbBasic.getLob(), memberDetails ); - XmlAnnotationHelper.applyEnumerated( jaxbBasic.getEnumerated(), memberDetails ); - XmlAnnotationHelper.applyNationalized( jaxbBasic.getNationalized(), memberDetails ); + XmlAnnotationHelper.applyTemporal( jaxbBasic.getTemporal(), memberDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyLob( jaxbBasic.getLob(), memberDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyEnumerated( jaxbBasic.getEnumerated(), memberDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyNationalized( jaxbBasic.getNationalized(), memberDetails, xmlDocumentContext ); + + // todo : value generation + // todo : ... return memberDetails; } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicIdAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicIdAttributeProcessing.java index e7eebab..e982581 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicIdAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/BasicIdAttributeProcessing.java @@ -7,6 +7,7 @@ package org.hibernate.models.orm.categorize.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbIdImpl; +import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableClassDetails; import org.hibernate.models.internal.MutableMemberDetails; import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; @@ -14,9 +15,12 @@ import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; import jakarta.persistence.AccessType; +import jakarta.persistence.Basic; +import jakarta.persistence.Id; import static org.hibernate.internal.util.NullnessHelper.coalesce; -import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.processCommonAttributeAnnotations; +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; +import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; /** * @author Steve Ebersole @@ -34,23 +38,22 @@ public static MutableMemberDetails processBasicIdAttribute( accessType, declarer ); - XmlAnnotationHelper.applyId( jaxbId, memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyBasic( jaxbId, memberDetails ); - processCommonAttributeAnnotations( - jaxbId, - memberDetails, - accessType - ); - XmlAnnotationHelper.applyColumn( jaxbId.getColumn(), memberDetails ); + final MutableAnnotationUsage idAnn = makeAnnotation( Id.class, memberDetails, xmlDocumentContext ); + final MutableAnnotationUsage basicAnn = makeAnnotation( Basic.class, memberDetails, xmlDocumentContext ); + + applyAttributeBasics( jaxbId, memberDetails, basicAnn, accessType, xmlDocumentContext ); + + XmlAnnotationHelper.applyColumn( jaxbId.getColumn(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyBasicTypeComposition( jaxbId, memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyTemporal( jaxbId.getTemporal(), memberDetails ); + XmlAnnotationHelper.applyTemporal( jaxbId.getTemporal(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyGeneratedValue( jaxbId.getGeneratedValue(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applySequenceGenerator( jaxbId.getSequenceGenerator(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyTableGenerator( jaxbId.getTableGenerator(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyUuidGenerator( jaxbId.getUuidGenerator(), memberDetails, xmlDocumentContext ); // todo : unsaved-value? + // todo : ... return memberDetails; } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonAttributeProcessing.java index ee7dcfd..93672ef 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonAttributeProcessing.java @@ -6,23 +6,128 @@ */ package org.hibernate.models.orm.categorize.xml.internal.attr; +import java.lang.annotation.Annotation; + +import org.hibernate.annotations.AttributeAccessor; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.OptimisticLock; +import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl; +import org.hibernate.boot.jaxb.mapping.spi.JaxbLockableAttribute; import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistentAttribute; +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.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableMemberDetails; -import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; +import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.ClassDetails; +import jakarta.persistence.Access; import jakarta.persistence.AccessType; +import jakarta.persistence.FetchType; + +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; /** * @author Steve Ebersole */ public class CommonAttributeProcessing { - public static void processCommonAttributeAnnotations( + public static void applyAttributeBasics( JaxbPersistentAttribute jaxbAttribute, MutableMemberDetails memberDetails, - AccessType accessType) { - XmlAnnotationHelper.applyAccess( accessType, memberDetails ); + MutableAnnotationUsage attributeAnn, + AccessType accessType, + XmlDocumentContext xmlDocumentContext) { + applyAccess( accessType, memberDetails, xmlDocumentContext ); + applyAttributeAccessor( jaxbAttribute, memberDetails, xmlDocumentContext ); + + if ( jaxbAttribute instanceof JaxbStandardAttribute jaxbStandardAttribute ) { + applyFetching( jaxbStandardAttribute, memberDetails, attributeAnn, xmlDocumentContext ); + applyOptionality( jaxbStandardAttribute, memberDetails, attributeAnn, xmlDocumentContext ); + } + + if ( jaxbAttribute instanceof JaxbLockableAttribute jaxbLockableAttribute ) { + applyOptimisticLock( jaxbLockableAttribute, memberDetails, xmlDocumentContext ); + } + } + + public static void applyAccess( + AccessType accessType, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + final MutableAnnotationUsage accessAnn = makeAnnotation( Access.class, memberDetails, xmlDocumentContext ); + accessAnn.setAttributeValue( "value", accessType ); + } + + public static void applyAttributeAccessor( + JaxbPersistentAttribute jaxbAttribute, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + final String attributeAccessor = jaxbAttribute.getAttributeAccessor(); + if ( attributeAccessor == null ) { + return; + } + + final ClassDetails strategyClassDetails = xmlDocumentContext + .getModelBuildingContext() + .getClassDetailsRegistry() + .getClassDetails( attributeAccessor ); + final MutableAnnotationUsage accessAnn = makeAnnotation( AttributeAccessor.class, memberDetails, xmlDocumentContext ); + accessAnn.setAttributeValue( "strategy", strategyClassDetails ); + } - // todo : optimistic-lock + public static void applyOptionality( + JaxbStandardAttribute jaxbAttribute, + MutableMemberDetails memberDetails, + MutableAnnotationUsage attributeAnn, + XmlDocumentContext xmlDocumentContext) { + // todo : fix this in jpa32 + if ( jaxbAttribute.isOptional() == null ) { + return; + } + + attributeAnn.setAttributeValue( "optional", jaxbAttribute.isOptional() ); + } + + public static void applyOptimisticLock( + JaxbLockableAttribute jaxbAttribute, + MutableMemberDetails memberDetails, + XmlDocumentContext xmlDocumentContext) { + final boolean includeInOptimisticLock = jaxbAttribute.isOptimisticLock(); + final MutableAnnotationUsage optLockAnn = makeAnnotation( OptimisticLock.class, memberDetails, xmlDocumentContext ); + optLockAnn.setAttributeValue( "excluded", !includeInOptimisticLock ); + } + + public static void applyFetching( + JaxbStandardAttribute jaxbAttribute, + MutableMemberDetails memberDetails, + MutableAnnotationUsage attributeAnn, + XmlDocumentContext xmlDocumentContext) { + final FetchType fetchType = jaxbAttribute.getFetch(); + if ( fetchType != null ) { + attributeAnn.setAttributeValue( "fetch", fetchType ); + } + + if ( jaxbAttribute instanceof JaxbSingularAssociationAttribute jaxbSingularAttribute ) { + final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbSingularAttribute.getFetchMode(); + applyFetchMode( memberDetails, jaxbFetchMode, xmlDocumentContext ); + } + else if ( jaxbAttribute instanceof JaxbAnyMappingImpl jaxbAnyAttribute ) { + final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbAnyAttribute.getFetchMode(); + applyFetchMode( memberDetails, jaxbFetchMode, xmlDocumentContext ); + } + } + + private static void applyFetchMode( + MutableMemberDetails memberDetails, + JaxbSingularFetchModeImpl jaxbFetchMode, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbFetchMode != null ) { + final FetchMode fetchMode = FetchMode.valueOf( jaxbFetchMode.value() ); + final MutableAnnotationUsage fetchAnn = makeAnnotation( Fetch.class, memberDetails, xmlDocumentContext ); + fetchAnn.setAttributeValue( "value", fetchMode ); + } } } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonProcessing.java deleted file mode 100644 index b170344..0000000 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/CommonProcessing.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.categorize.xml.internal.attr; - -import java.lang.annotation.Annotation; - -import org.hibernate.annotations.AttributeAccessor; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; -import org.hibernate.annotations.OptimisticLock; -import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl; -import org.hibernate.boot.jaxb.mapping.spi.JaxbLockableAttribute; -import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistentAttribute; -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.models.internal.MutableAnnotationUsage; -import org.hibernate.models.internal.MutableMemberDetails; -import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; -import org.hibernate.models.spi.ClassDetails; -import org.hibernate.models.spi.SourceModelBuildingContext; - -import jakarta.persistence.FetchType; - -import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; - -/** - * @author Steve Ebersole - */ -public class CommonProcessing { - public static void applyOptimisticLock( - MutableMemberDetails memberDetails, - JaxbLockableAttribute jaxbAttribute, - MutableAnnotationUsage attributeAnn) { - final boolean includeInOptimisticLock = jaxbAttribute.isOptimisticLock(); - final MutableAnnotationUsage optLockAnn = makeAnnotation( OptimisticLock.class, memberDetails ); - optLockAnn.setAttributeValue( "excluded", !includeInOptimisticLock ); - } - - public static void applyAttributeAccessor( - MutableMemberDetails memberDetails, - JaxbPersistentAttribute jaxbAttribute, - MutableAnnotationUsage attributeAnn, - XmlDocumentContext xmlDocumentContext) { - final String attributeAccessor = jaxbAttribute.getAttributeAccessor(); - if ( attributeAccessor == null ) { - return; - } - - final ClassDetails strategyClassDetails = xmlDocumentContext - .getModelBuildingContext() - .getClassDetailsRegistry() - .getClassDetails( attributeAccessor ); - final MutableAnnotationUsage accessAnn = makeAnnotation( AttributeAccessor.class, memberDetails ); - accessAnn.setAttributeValue( "strategy", strategyClassDetails ); - } - - public static void applyFetching( - MutableMemberDetails memberDetails, - JaxbStandardAttribute jaxbAttribute, - MutableAnnotationUsage attributeAnn) { - final FetchType fetchType = jaxbAttribute.getFetch(); - if ( fetchType != null ) { - attributeAnn.setAttributeValue( "fetch", fetchType ); - } - - if ( jaxbAttribute instanceof JaxbSingularAssociationAttribute jaxbSingularAttribute ) { - final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbSingularAttribute.getFetchMode(); - applyFetchMode( memberDetails, jaxbFetchMode ); - } - else if ( jaxbAttribute instanceof JaxbAnyMappingImpl jaxbAnyAttribute ) { - final JaxbSingularFetchModeImpl jaxbFetchMode = jaxbAnyAttribute.getFetchMode(); - applyFetchMode( memberDetails, jaxbFetchMode ); - } - } - - private static void applyFetchMode(MutableMemberDetails memberDetails, JaxbSingularFetchModeImpl jaxbFetchMode) { - if ( jaxbFetchMode != null ) { - final FetchMode fetchMode = FetchMode.valueOf( jaxbFetchMode.value() ); - final MutableAnnotationUsage fetchAnn = makeAnnotation( Fetch.class, memberDetails ); - fetchAnn.setAttributeValue( "value", fetchMode ); - } - } -} diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ElementCollectionAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ElementCollectionAttributeProcessing.java index 7c9a5ec..0170d40 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ElementCollectionAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ElementCollectionAttributeProcessing.java @@ -45,7 +45,7 @@ import static org.hibernate.internal.util.NullnessHelper.coalesce; import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.getOrMakeAnnotation; import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.setIf; -import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.processCommonAttributeAnnotations; +import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; /** * @author Steve Ebersole @@ -69,15 +69,16 @@ public static MutableMemberDetails processElementCollectionAttribute( final MutableAnnotationUsage elementCollectionAnn = XmlProcessingHelper.getOrMakeAnnotation( ElementCollection.class, - memberDetails + memberDetails, + xmlDocumentContext ); setIf( jaxbElementCollection.getTargetClass(), "targetClass", elementCollectionAnn ); setIf( jaxbElementCollection.getFetch(), "fetch", elementCollectionAnn ); - processCommonAttributeAnnotations( jaxbElementCollection, memberDetails, accessType ); + applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionAnn, accessType, xmlDocumentContext ); if ( jaxbElementCollection.getFetchMode() != null ) { - final MutableAnnotationUsage fetchAnn = getOrMakeAnnotation( Fetch.class, memberDetails ); + final MutableAnnotationUsage fetchAnn = getOrMakeAnnotation( Fetch.class, memberDetails, xmlDocumentContext ); fetchAnn.setAttributeValue( "value", jaxbElementCollection.getFetchMode() ); } @@ -85,13 +86,15 @@ public static MutableMemberDetails processElementCollectionAttribute( if ( jaxbCollectionId != null ) { final MutableAnnotationUsage collectionIdAnn = XmlProcessingHelper.getOrMakeAnnotation( CollectionId.class, - memberDetails + memberDetails, + xmlDocumentContext ); final JaxbColumnImpl jaxbColumn = jaxbCollectionId.getColumn(); final MutableAnnotationUsage columnAnn = XmlProcessingHelper.getOrMakeAnnotation( Column.class, - memberDetails + memberDetails, + xmlDocumentContext ); collectionIdAnn.setAttributeValue( "column", columnAnn ); setIf( jaxbColumn.getName(), "name", columnAnn ); @@ -113,11 +116,12 @@ public static MutableMemberDetails processElementCollectionAttribute( if ( jaxbElementCollection.getClassification() != null ) { final MutableAnnotationUsage collectionClassificationAnn = getOrMakeAnnotation( CollectionClassification.class, - memberDetails + memberDetails, + xmlDocumentContext ); setIf( jaxbElementCollection.getClassification(), "value", collectionClassificationAnn ); if ( jaxbElementCollection.getClassification() == LimitedCollectionClassification.BAG ) { - getOrMakeAnnotation( Bag.class, memberDetails ); + getOrMakeAnnotation( Bag.class, memberDetails, xmlDocumentContext ); } } @@ -126,20 +130,22 @@ public static MutableMemberDetails processElementCollectionAttribute( if ( StringHelper.isNotEmpty( jaxbElementCollection.getSort() ) ) { final MutableAnnotationUsage sortAnn = getOrMakeAnnotation( SortComparator.class, - memberDetails + memberDetails, + xmlDocumentContext ); final ClassDetails comparatorClassDetails = classDetailsRegistry.resolveClassDetails( jaxbElementCollection.getSort() ); sortAnn.setAttributeValue( "value", comparatorClassDetails ); } if ( jaxbElementCollection.getSortNatural() != null ) { - getOrMakeAnnotation( SortNatural.class, memberDetails ); + getOrMakeAnnotation( SortNatural.class, memberDetails, xmlDocumentContext ); } if ( StringHelper.isNotEmpty( jaxbElementCollection.getOrderBy() ) ) { final MutableAnnotationUsage orderByAnn = getOrMakeAnnotation( OrderBy.class, - memberDetails + memberDetails, + xmlDocumentContext ); orderByAnn.setAttributeValue( "value", jaxbElementCollection.getOrderBy() ); } @@ -147,7 +153,8 @@ public static MutableMemberDetails processElementCollectionAttribute( if ( jaxbElementCollection.getOrderColumn() != null ) { final MutableAnnotationUsage orderByAnn = getOrMakeAnnotation( OrderColumn.class, - memberDetails + memberDetails, + xmlDocumentContext ); setIf( jaxbElementCollection.getOrderColumn().getName(), "name", orderByAnn ); setIf( jaxbElementCollection.getOrderColumn().isNullable(), "nullable", orderByAnn ); @@ -162,30 +169,32 @@ public static MutableMemberDetails processElementCollectionAttribute( if ( jaxbElementCollection.getEnumerated() != null ) { final MutableAnnotationUsage enumeratedAnn = getOrMakeAnnotation( Enumerated.class, - memberDetails + memberDetails, + xmlDocumentContext ); enumeratedAnn.setAttributeValue( "value", jaxbElementCollection.getEnumerated() ); } if ( jaxbElementCollection.getLob() != null ) { - getOrMakeAnnotation( Lob.class, memberDetails ); + getOrMakeAnnotation( Lob.class, memberDetails, xmlDocumentContext ); } if ( jaxbElementCollection.getNationalized() != null ) { - getOrMakeAnnotation( Nationalized.class, memberDetails ); + getOrMakeAnnotation( Nationalized.class, memberDetails, xmlDocumentContext ); } if ( jaxbElementCollection.getTemporal() != null ) { final MutableAnnotationUsage temporalAnn = getOrMakeAnnotation( Temporal.class, - memberDetails + memberDetails, + xmlDocumentContext ); temporalAnn.setAttributeValue( "value", jaxbElementCollection.getTemporal() ); } XmlAnnotationHelper.applyBasicTypeComposition( jaxbElementCollection, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbElementCollection.getTargetClass() ) ) { - final MutableAnnotationUsage targetAnn = getOrMakeAnnotation( Target.class, memberDetails ); + final MutableAnnotationUsage targetAnn = getOrMakeAnnotation( Target.class, memberDetails, xmlDocumentContext ); targetAnn.setAttributeValue( "value", jaxbElementCollection.getTargetClass() ); } @@ -199,12 +208,12 @@ public static MutableMemberDetails processElementCollectionAttribute( xmlDocumentContext ) ); - XmlAnnotationHelper.applySqlRestriction( jaxbElementCollection.getSqlRestriction(), memberDetails ); + XmlAnnotationHelper.applySqlRestriction( jaxbElementCollection.getSqlRestriction(), memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlInsert(), memberDetails, SQLInsert.class ); - XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlUpdate(), memberDetails, SQLUpdate.class ); - XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDelete(), memberDetails, SQLDelete.class ); - XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDeleteAll(), memberDetails, SQLDeleteAll.class ); + XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlInsert(), memberDetails, SQLInsert.class, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlUpdate(), memberDetails, SQLUpdate.class, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDelete(), memberDetails, SQLDelete.class, xmlDocumentContext ); + XmlAnnotationHelper.applyCustomSql( jaxbElementCollection.getSqlDeleteAll(), memberDetails, SQLDeleteAll.class, xmlDocumentContext ); // todo : attribute-override // todo : association-override diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedAttributeProcessing.java index 0f91b1e..7156aaf 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedAttributeProcessing.java @@ -21,7 +21,7 @@ import static org.hibernate.internal.util.NullnessHelper.coalesce; import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.getOrMakeAnnotation; -import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.processCommonAttributeAnnotations; +import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; /** * @author Steve Ebersole @@ -39,16 +39,16 @@ public static MutableMemberDetails processEmbeddedAttribute( declarer ); - XmlProcessingHelper.getOrMakeAnnotation( Embedded.class, memberDetails ); + final MutableAnnotationUsage embeddedAnn = getOrMakeAnnotation( Embedded.class, memberDetails, xmlDocumentContext ); if ( StringHelper.isNotEmpty( jaxbEmbedded.getTarget() ) ) { - final MutableAnnotationUsage targetAnn = getOrMakeAnnotation( Target.class, memberDetails ); + final MutableAnnotationUsage targetAnn = getOrMakeAnnotation( Target.class, memberDetails, xmlDocumentContext ); targetAnn.setAttributeValue( "value", jaxbEmbedded.getTarget() ); } - processCommonAttributeAnnotations( jaxbEmbedded, memberDetails, accessType ); - XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbedded.getAttributeOverrides(), memberDetails ); - XmlAnnotationHelper.applyAssociationOverrides( jaxbEmbedded.getAssociationOverrides(), memberDetails ); + applyAttributeBasics( jaxbEmbedded, memberDetails, embeddedAnn, accessType, xmlDocumentContext ); + XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbedded.getAttributeOverrides(), memberDetails, xmlDocumentContext ); + XmlAnnotationHelper.applyAssociationOverrides( jaxbEmbedded.getAssociationOverrides(), memberDetails, xmlDocumentContext ); return memberDetails; } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedIdAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedIdAttributeProcessing.java index f4dfb9c..4334e8b 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedIdAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/EmbeddedIdAttributeProcessing.java @@ -7,6 +7,7 @@ package org.hibernate.models.orm.categorize.xml.internal.attr; import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedIdImpl; +import org.hibernate.models.internal.MutableAnnotationUsage; import org.hibernate.models.internal.MutableClassDetails; import org.hibernate.models.internal.MutableMemberDetails; import org.hibernate.models.orm.categorize.xml.internal.XmlAnnotationHelper; @@ -14,9 +15,11 @@ import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; import jakarta.persistence.AccessType; +import jakarta.persistence.EmbeddedId; import static org.hibernate.internal.util.NullnessHelper.coalesce; -import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.processCommonAttributeAnnotations; +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.makeAnnotation; +import static org.hibernate.models.orm.categorize.xml.internal.attr.CommonAttributeProcessing.applyAttributeBasics; /** * @author Steve Ebersole @@ -35,10 +38,10 @@ public static MutableMemberDetails processEmbeddedIdAttribute( classDetails ); - processCommonAttributeAnnotations( jaxbEmbeddedId, memberDetails, accessType ); + final MutableAnnotationUsage idAnn = makeAnnotation( EmbeddedId.class, memberDetails, xmlDocumentContext ); + applyAttributeBasics( jaxbEmbeddedId, memberDetails, idAnn, accessType, xmlDocumentContext ); - XmlAnnotationHelper.applyEmbeddedId( jaxbEmbeddedId, memberDetails, xmlDocumentContext ); - XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbeddedId.getAttributeOverrides(), memberDetails ); + XmlAnnotationHelper.applyAttributeOverrides( jaxbEmbeddedId.getAttributeOverrides(), memberDetails, xmlDocumentContext ); return memberDetails; } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ManyToOneAttributeProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ManyToOneAttributeProcessing.java index 9188b05..9d81dec 100644 --- a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ManyToOneAttributeProcessing.java +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/attr/ManyToOneAttributeProcessing.java @@ -31,6 +31,7 @@ import jakarta.persistence.AccessType; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import jakarta.persistence.ManyToOne; import static org.hibernate.internal.util.NullnessHelper.coalesce; @@ -60,9 +61,8 @@ public static MutableMemberDetails processManyToOneAttribute( xmlDocumentContext ); - CommonProcessing.applyFetching( memberDetails, jaxbManyToOne, manyToOneAnn ); - CommonProcessing.applyOptimisticLock( memberDetails, jaxbManyToOne, manyToOneAnn ); - CommonProcessing.applyAttributeAccessor( memberDetails, jaxbManyToOne, manyToOneAnn, xmlDocumentContext ); + CommonAttributeProcessing.applyAttributeBasics( jaxbManyToOne, memberDetails, manyToOneAnn, accessType, xmlDocumentContext ); + applyJoinColumns( memberDetails, jaxbManyToOne, manyToOneAnn, xmlDocumentContext ); applyNotFound( memberDetails, jaxbManyToOne, manyToOneAnn, xmlDocumentContext ); applyOnDelete( memberDetails, jaxbManyToOne, manyToOneAnn, xmlDocumentContext ); @@ -78,7 +78,7 @@ private static MutableAnnotationUsage applyManyToOne( XmlDocumentContext xmlDocumentContext) { // todo : apply the @ManyToOne annotation - final MutableAnnotationUsage manyToOneAnn = getOrMakeAnnotation( ManyToOne.class, memberDetails ); + final MutableAnnotationUsage manyToOneAnn = getOrMakeAnnotation( ManyToOne.class, memberDetails, xmlDocumentContext ); final AnnotationDescriptor manyToOneDescriptor = xmlDocumentContext .getModelBuildingContext() .getAnnotationDescriptorRegistry() @@ -100,9 +100,17 @@ private static void applyJoinColumns( JaxbManyToOneImpl jaxbManyToOne, MutableAnnotationUsage manyToOneAnn, XmlDocumentContext xmlDocumentContext) { - if ( CollectionHelper.isNotEmpty( jaxbManyToOne.getJoinColumns() ) ) { - final List> joinColumns = new ArrayList<>( jaxbManyToOne.getJoinColumns().size() ); - manyToOneAnn.setAttributeValue( "joinColumns", joinColumns ); + if ( CollectionHelper.isEmpty( jaxbManyToOne.getJoinColumns() ) ) { + makeAnnotation( JoinColumn.class, memberDetails, xmlDocumentContext ); + } + else { + final MutableAnnotationUsage columnsAnn = makeAnnotation( + JoinColumns.class, + memberDetails, + xmlDocumentContext + ); + final List> columnList = new ArrayList<>( jaxbManyToOne.getJoinColumns().size() ); + columnsAnn.setAttributeValue( "value", columnList ); for ( int i = 0; i < jaxbManyToOne.getJoinColumns().size(); i++ ) { final JaxbJoinColumnImpl jaxbJoinColumn = jaxbManyToOne.getJoinColumns().get( i ); final MutableAnnotationUsage joinColumnAnn = XmlAnnotationHelper.applyJoinColumn( @@ -110,12 +118,9 @@ private static void applyJoinColumns( memberDetails, xmlDocumentContext ); - joinColumns.add( joinColumnAnn ); + columnList.add( joinColumnAnn ); } } - else { - manyToOneAnn.setAttributeValue( "joinColumns", List.of( makeAnnotation( JoinColumn.class, memberDetails ) ) ); - } } private static void applyNotFound( @@ -128,7 +133,7 @@ private static void applyNotFound( return; } - final MutableAnnotationUsage notFoundAnn = makeAnnotation( NotFound.class, memberDetails ); + final MutableAnnotationUsage notFoundAnn = makeAnnotation( NotFound.class, memberDetails, xmlDocumentContext ); notFoundAnn.setAttributeValue( "action", notFoundAction ); } @@ -143,7 +148,7 @@ private static void applyOnDelete( return; } - final MutableAnnotationUsage notFoundAnn = makeAnnotation( OnDelete.class, memberDetails ); + final MutableAnnotationUsage notFoundAnn = makeAnnotation( OnDelete.class, memberDetails, xmlDocumentContext ); notFoundAnn.setAttributeValue( "action", action ); } @@ -158,7 +163,7 @@ private static void applyTarget( return; } - final MutableAnnotationUsage targetAnn = makeAnnotation( Target.class, memberDetails ); + final MutableAnnotationUsage targetAnn = makeAnnotation( Target.class, memberDetails, xmlDocumentContext ); targetAnn.setAttributeValue( "value", targetEntityName ); } diff --git a/src/main/java/org/hibernate/models/orm/categorize/xml/internal/db/ColumnProcessing.java b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/db/ColumnProcessing.java new file mode 100644 index 0000000..e4e6120 --- /dev/null +++ b/src/main/java/org/hibernate/models/orm/categorize/xml/internal/db/ColumnProcessing.java @@ -0,0 +1,229 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright: Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.models.orm.categorize.xml.internal.db; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.annotations.Check; +import org.hibernate.boot.jaxb.mapping.spi.JaxbCheckConstraintImpl; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbCheckable; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumn; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnCommon; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnDefinable; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnMutable; +import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnNullable; +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.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.models.internal.MutableAnnotationTarget; +import org.hibernate.models.internal.MutableAnnotationUsage; +import org.hibernate.models.orm.categorize.xml.spi.XmlDocumentContext; +import org.hibernate.models.spi.AnnotationUsage; + +import static org.hibernate.models.orm.categorize.xml.internal.XmlProcessingHelper.getOrMakeAnnotation; + +/** + * @author Steve Ebersole + */ +public class ColumnProcessing { + + public static void applyColumnDetails( + JaxbColumnCommon jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn == null ) { + return; + } + + applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnNullness( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnMutability( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnDefinition( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnUniqueness( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnComment( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnChecks( jaxbColumn, target, columnAnn, xmlDocumentContext ); + + if ( jaxbColumn instanceof JaxbColumnSizable sizable ) { + applyColumnSizing( sizable, target, columnAnn, xmlDocumentContext ); + } + + } + + public static void applyColumnDetails( + JaxbColumnStandard jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn == null ) { + return; + } + + applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnNullness( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnMutability( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnDefinition( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnSizing( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnUniqueness( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnComment( jaxbColumn, target, columnAnn, xmlDocumentContext ); + applyColumnChecks( jaxbColumn, target, columnAnn, xmlDocumentContext ); + } + + public static void applyColumnDetails( + JaxbColumn jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn == null ) { + return; + } + + applyColumnBasics( jaxbColumn, target, columnAnn, xmlDocumentContext ); + + if ( jaxbColumn instanceof JaxbColumnNullable nullable ) { + applyColumnNullness( nullable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbColumnMutable mutable ) { + applyColumnMutability( mutable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbColumnDefinable definable ) { + applyColumnDefinition( definable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbColumnSizable sizable ) { + applyColumnSizing( sizable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbColumnUniqueable uniqueable ) { + applyColumnUniqueness( uniqueable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbCommentable commentable ) { + applyColumnComment( commentable, target, columnAnn, xmlDocumentContext ); + } + + if ( jaxbColumn instanceof JaxbCheckable checkable ) { + applyColumnChecks( checkable, target, columnAnn, xmlDocumentContext ); + } + } + + private static void applyColumnBasics( + JaxbColumn jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getName() ) ) { + columnAnn.setAttributeValue( "name", jaxbColumn.getName() ); + } + + if ( StringHelper.isNotEmpty( jaxbColumn.getTable() ) ) { + columnAnn.setAttributeValue( "table", jaxbColumn.getTable() ); + } + } + + private static void applyColumnNullness( + JaxbColumnNullable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn.isNullable() != null ) { + columnAnn.setAttributeValue( "unique", jaxbColumn.isNullable() ); + } + } + + private static void applyColumnMutability( + JaxbColumnMutable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn.isInsertable() != null ) { + columnAnn.setAttributeValue( "insertable", jaxbColumn.isInsertable() ); + } + + if ( jaxbColumn.isUpdatable() != null ) { + columnAnn.setAttributeValue( "updatable", jaxbColumn.isUpdatable() ); + } + } + + private static void applyColumnSizing( + JaxbColumnSizable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + + if ( jaxbColumn.getLength() != null ) { + columnAnn.setAttributeValue( "length", jaxbColumn.getLength() ); + } + + if ( jaxbColumn.getPrecision() != null ) { + columnAnn.setAttributeValue( "precision", jaxbColumn.getPrecision() ); + } + + if ( jaxbColumn.getScale() != null ) { + columnAnn.setAttributeValue( "scale", jaxbColumn.getScale() ); + } + } + + private static void applyColumnUniqueness( + JaxbColumnUniqueable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( jaxbColumn.isUnique() != null ) { + columnAnn.setAttributeValue( "unique", jaxbColumn.isUnique() ); + } + } + + private static void applyColumnDefinition( + JaxbColumnDefinable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getColumnDefinition() ) ) { + columnAnn.setAttributeValue( "columnDefinition", jaxbColumn.getColumnDefinition() ); + } + + if ( jaxbColumn.getOptions() != null ) { + columnAnn.setAttributeValue( "options", jaxbColumn.getOptions() ); + } + } + + private static void applyColumnComment( + JaxbCommentable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( StringHelper.isNotEmpty( jaxbColumn.getComment() ) ) { + columnAnn.setAttributeValue( "comment", jaxbColumn.getComment() ); + } + } + + private static void applyColumnChecks( + JaxbCheckable jaxbColumn, + MutableAnnotationTarget target, + MutableAnnotationUsage columnAnn, + XmlDocumentContext xmlDocumentContext) { + if ( CollectionHelper.isNotEmpty( jaxbColumn.getCheckConstraints() ) ) { + final List> checks = new ArrayList<>( jaxbColumn.getCheckConstraints().size() ); + for ( int i = 0; i < jaxbColumn.getCheckConstraints().size(); i++ ) { + final JaxbCheckConstraintImpl jaxbCheck = jaxbColumn.getCheckConstraints().get( i ); + final MutableAnnotationUsage checkAnn = getOrMakeAnnotation( Check.class, target, xmlDocumentContext ); + checkAnn.setAttributeValue( "name", jaxbCheck.getName() ); + checkAnn.setAttributeValue( "constraints", jaxbCheck.getConstraint() ); + checks.add( checkAnn ); + } + columnAnn.setAttributeValue( "check", checks ); + } + } +} diff --git a/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java b/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java index eaf5874..878a92d 100644 --- a/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java +++ b/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java @@ -124,7 +124,11 @@ void testSimpleGlobalXmlProcessing() { final JaxbEntityMappingsImpl xmlMapping = loadMapping( "mappings/globals.xml", SIMPLE_CLASS_LOADING ); collectedXmlResources.addDocument( xmlMapping ); - final DomainModelCategorizationCollector collector = new DomainModelCategorizationCollector( false, buildingContext.getClassDetailsRegistry() ); + final DomainModelCategorizationCollector collector = new DomainModelCategorizationCollector( + false, + buildingContext.getClassDetailsRegistry(), + buildingContext.getAnnotationDescriptorRegistry() + ); collectedXmlResources.getDocuments().forEach( collector::apply ); final GlobalRegistrationsImpl globalRegistrations = collector.getGlobalRegistrations(); diff --git a/src/test/java/org/hibernate/models/orm/xml/attr/AnyTests.java b/src/test/java/org/hibernate/models/orm/xml/attr/AnyTests.java index 5458061..13678e0 100644 --- a/src/test/java/org/hibernate/models/orm/xml/attr/AnyTests.java +++ b/src/test/java/org/hibernate/models/orm/xml/attr/AnyTests.java @@ -7,10 +7,12 @@ package org.hibernate.models.orm.xml.attr; import java.util.List; +import java.util.stream.Collectors; import org.hibernate.annotations.Any; import org.hibernate.annotations.AnyDiscriminator; import org.hibernate.annotations.AnyDiscriminatorValue; +import org.hibernate.boot.internal.AnyKeyType; import org.hibernate.boot.internal.BootstrapContextImpl; import org.hibernate.boot.internal.MetadataBuilderImpl; import org.hibernate.boot.model.process.spi.ManagedResources; @@ -28,6 +30,7 @@ import jakarta.persistence.DiscriminatorType; import jakarta.persistence.Entity; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; import jakarta.persistence.Table; import static org.assertj.core.api.Assertions.assertThat; @@ -76,6 +79,18 @@ void testSimpleAnyAttribute(ServiceRegistryScope scope) { final List> discriminatorMappings = associationField.getRepeatedAnnotationUsages( AnyDiscriminatorValue.class ); assertThat( discriminatorMappings ).hasSize( 2 ); + final List mappedEntityNames = discriminatorMappings.stream() + .map( (valueAnn) -> valueAnn.getClassDetails( "entity" ).getName() ) + .collect( Collectors.toList() ); + assertThat( mappedEntityNames ).containsExactly( Entity1.class.getName(), Entity2.class.getName() ); + + final AnnotationUsage keyTypeAnn = associationField.getAnnotationUsage( AnyKeyType.class ); + assertThat( keyTypeAnn ).isNotNull(); + assertThat( keyTypeAnn.getString( "value" ) ).isEqualTo( "integer" ); + + final AnnotationUsage keyColumn = associationField.getAnnotationUsage( JoinColumn.class ); + assertThat( keyColumn ).isNotNull(); + assertThat( keyColumn.getString( "name" ) ).isEqualTo( "association_fk" ); } @Entity(name="Entity1") diff --git a/src/test/java/org/hibernate/models/orm/xml/attr/ManyToOneTests.java b/src/test/java/org/hibernate/models/orm/xml/attr/ManyToOneTests.java index 8e1eeee..f97964b 100644 --- a/src/test/java/org/hibernate/models/orm/xml/attr/ManyToOneTests.java +++ b/src/test/java/org/hibernate/models/orm/xml/attr/ManyToOneTests.java @@ -35,6 +35,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinColumns; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; @@ -75,7 +76,8 @@ void testSimpleManyToOne(ServiceRegistryScope scope) { assertThat( joinColumnAnn ).isNotNull(); assertThat( joinColumnAnn.getString( "name" ) ).isEqualTo( "parent_fk" ); - assertThat( manyToOneAnn.getList( "joinColumns" ) ).isNotEmpty(); + assertThat( parentField.getAnnotationUsage( JoinColumns.class ) ).isNotNull(); + assertThat( parentField.getAnnotationUsage( JoinColumns.class ).getList( "value" ) ).hasSize( 1 ); final AnnotationUsage notFoundAnn = parentField.getAnnotationUsage( NotFound.class ); assertThat( notFoundAnn ).isNotNull(); diff --git a/src/test/java/org/hibernate/models/orm/xml/globals/JpaEventListenerTests.java b/src/test/java/org/hibernate/models/orm/xml/globals/JpaEventListenerTests.java index cb6da25..b4f58d5 100644 --- a/src/test/java/org/hibernate/models/orm/xml/globals/JpaEventListenerTests.java +++ b/src/test/java/org/hibernate/models/orm/xml/globals/JpaEventListenerTests.java @@ -13,6 +13,7 @@ import org.hibernate.boot.model.process.spi.ManagedResources; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.models.internal.jdk.VoidClassDetails; import org.hibernate.models.orm.process.ManagedResourcesImpl; import org.hibernate.models.orm.categorize.spi.CategorizedDomainModel; import org.hibernate.models.orm.categorize.spi.JpaEventListener; @@ -49,7 +50,7 @@ void testGlobalRegistration() { final JpaEventListener registration = registrations.get( 0 ); final MethodDetails postPersistMethod = registration.getPostPersistMethod(); assertThat( postPersistMethod ).isNotNull(); - assertThat( postPersistMethod.getReturnType() ).isNull(); + assertThat( postPersistMethod.getReturnType() ).isEqualTo( VoidClassDetails.VOID_CLASS_DETAILS ); assertThat( postPersistMethod.getArgumentTypes() ).hasSize( 1 ); } } diff --git a/src/test/resources/mappings/attr/any/simple.xml b/src/test/resources/mappings/attr/any/simple.xml index dd24abd..731e7d0 100644 --- a/src/test/resources/mappings/attr/any/simple.xml +++ b/src/test/resources/mappings/attr/any/simple.xml @@ -15,7 +15,7 @@ - integer + INTEGER AnyTests$Entity1 AnyTests$Entity2