HHH-18000 : Remove XmlProcessingHelper methods for creating AnnotationUsage instances

This commit is contained in:
Steve Ebersole 2024-04-23 17:36:24 -05:00
parent ecb8f6afc6
commit b1ec34f660
15 changed files with 412 additions and 608 deletions

View File

@ -155,6 +155,8 @@ public interface HibernateAnnotations {
AnnotationDescriptor<SqlFragmentAlias> SQL_FRAGMENT_ALIAS = createOrmDescriptor( SqlFragmentAlias.class );
AnnotationDescriptor<SQLInserts> SQL_INSERTS = createOrmDescriptor( SQLInserts.class );
AnnotationDescriptor<SQLInsert> SQL_INSERT = createOrmDescriptor( SQLInsert.class, SQL_INSERTS );
AnnotationDescriptor<SQLRestriction> SQL_RESTRICTION = createOrmDescriptor( SQLRestriction.class, SQL_INSERTS );
AnnotationDescriptor<SQLJoinTableRestriction> SQL_RESTRICTION_JOIN_TABLE = createOrmDescriptor( SQLJoinTableRestriction.class, SQL_INSERTS );
AnnotationDescriptor<SQLUpdates> SQL_UPDATES = createOrmDescriptor( SQLUpdates.class );
AnnotationDescriptor<SQLUpdate> SQL_UPDATE = createOrmDescriptor( SQLUpdate.class, SQL_UPDATES );
AnnotationDescriptor<Struct> STRUCT = createOrmDescriptor( Struct.class );
@ -162,6 +164,7 @@ public interface HibernateAnnotations {
AnnotationDescriptor<Synchronize> SYNCHRONIZE = createOrmDescriptor( Synchronize.class );
AnnotationDescriptor<Tables> TABLES = createOrmDescriptor( Tables.class );
AnnotationDescriptor<Table> TABLE = createOrmDescriptor( Table.class, TABLES );
AnnotationDescriptor<TenantId> TENANT_ID = createOrmDescriptor( TenantId.class );
AnnotationDescriptor<TimeZoneColumn> TZ_COLUMN = createOrmDescriptor( TimeZoneColumn.class );
AnnotationDescriptor<TimeZoneStorage> TZ_STORAGE = createOrmDescriptor( TimeZoneStorage.class );
AnnotationDescriptor<Type> TYPE = createOrmDescriptor( Type.class );

View File

@ -19,6 +19,7 @@
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CheckConstraint;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ColumnResult;
@ -114,6 +115,7 @@ public interface JpaAnnotations {
AnnotationDescriptor<AttributeOverride> ATTRIBUTE_OVERRIDE = createOrmDescriptor( AttributeOverride.class, ATTRIBUTE_OVERRIDES );
AnnotationDescriptor<Basic> BASIC = createOrmDescriptor( Basic.class );
AnnotationDescriptor<Cacheable> CACHEABLE = createOrmDescriptor( Cacheable.class );
AnnotationDescriptor<CheckConstraint> CHECK_CONSTRAINT = createOrmDescriptor(CheckConstraint.class );
AnnotationDescriptor<CollectionTable> COLLECTION_TABLE = createOrmDescriptor( CollectionTable.class );
AnnotationDescriptor<Column> COLUMN = createOrmDescriptor( Column.class );
AnnotationDescriptor<ColumnResult> COLUMN_RESULT = createOrmDescriptor( ColumnResult.class );

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.boot.models.xml.internal;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAnyMappingImpl;
@ -17,8 +16,6 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbBasicImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollectionImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbEmbeddedImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbForeignKeyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTableImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToManyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbManyToOneImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbNaturalId;
@ -37,21 +34,11 @@
import org.hibernate.boot.models.xml.internal.attr.OneToManyAttributeProcessing;
import org.hibernate.boot.models.xml.internal.attr.OneToOneAttributeProcessing;
import org.hibernate.boot.models.xml.internal.attr.PluralAnyMappingAttributeProcessing;
import org.hibernate.boot.models.xml.internal.db.ColumnProcessing;
import org.hibernate.boot.models.xml.internal.db.ForeignKeyProcessing;
import org.hibernate.boot.models.xml.internal.db.JoinColumnProcessing;
import org.hibernate.boot.models.xml.internal.db.TableProcessing;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableClassDetails;
import org.hibernate.models.spi.MutableMemberDetails;
import jakarta.persistence.AccessType;
import jakarta.persistence.AssociationOverride;
import jakarta.persistence.AssociationOverrides;
import jakarta.persistence.AttributeOverride;
import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.Column;
/**
* Helper for handling persistent attributes defined in mapping XML in metadata-complete mode
@ -243,84 +230,22 @@ public static void processAttributeOverrides(
List<JaxbAttributeOverrideImpl> attributeOverrides,
MutableClassDetails mutableClassDetails,
XmlDocumentContext xmlDocumentContext) {
final List<MutableAnnotationUsage<AttributeOverride>> attributeOverrideList = new ArrayList<>( attributeOverrides.size() );
for ( JaxbAttributeOverrideImpl attributeOverride : attributeOverrides ) {
final MutableAnnotationUsage<AttributeOverride> attributeOverrideAnn = XmlProcessingHelper.makeNestedAnnotation(
AttributeOverride.class,
mutableClassDetails,
xmlDocumentContext
);
attributeOverrideList.add( attributeOverrideAnn );
final MutableAnnotationUsage<Column> attributeOverrideColumnAnn = XmlProcessingHelper.makeNestedAnnotation(
Column.class,
mutableClassDetails,
xmlDocumentContext
);
ColumnProcessing.applyColumnDetails( attributeOverride.getColumn(), attributeOverrideColumnAnn, xmlDocumentContext );
attributeOverrideAnn.setAttributeValue( "name", attributeOverride.getName() );
attributeOverrideAnn.setAttributeValue( "column", attributeOverrideColumnAnn );
}
final MutableAnnotationUsage<AttributeOverrides> attributeOverridesAnn = XmlProcessingHelper.getOrMakeAnnotation(
AttributeOverrides.class,
XmlAnnotationHelper.applyAttributeOverrides(
attributeOverrides,
mutableClassDetails,
null,
xmlDocumentContext
);
attributeOverridesAnn.setAttributeValue( "value", attributeOverrideList );
}
public static void processAssociationOverrides(
List<JaxbAssociationOverrideImpl> associationOverrides,
MutableClassDetails mutableClassDetails,
XmlDocumentContext xmlDocumentContext) {
final List<MutableAnnotationUsage<AssociationOverride>> associationOverrideList = new ArrayList<>( associationOverrides.size() );
for ( JaxbAssociationOverrideImpl associationOverride : associationOverrides ) {
final MutableAnnotationUsage<AssociationOverride> attributeOverrideAnn = XmlProcessingHelper.makeNestedAnnotation(
AssociationOverride.class,
mutableClassDetails,
xmlDocumentContext
);
associationOverrideList.add( attributeOverrideAnn );
attributeOverrideAnn.setAttributeValue( "name", associationOverride.getName() );
attributeOverrideAnn.setAttributeValue(
"joinColumns",
JoinColumnProcessing.createJoinColumns(
associationOverride.getJoinColumns(),
mutableClassDetails,
xmlDocumentContext
)
);
final JaxbForeignKeyImpl foreignKeys = associationOverride.getForeignKeys();
if ( foreignKeys != null ) {
attributeOverrideAnn.setAttributeValue(
"foreignKey",
ForeignKeyProcessing.createNestedForeignKeyAnnotation(
foreignKeys,
mutableClassDetails,
xmlDocumentContext
)
);
}
final JaxbJoinTableImpl joinTable = associationOverride.getJoinTable();
if ( joinTable != null ) {
attributeOverrideAnn.setAttributeValue(
"joinTable",
TableProcessing.createNestedJoinTable(
joinTable,
mutableClassDetails,
xmlDocumentContext
)
);
}
}
final MutableAnnotationUsage<AssociationOverrides> associationOverridesAnn = XmlProcessingHelper.getOrMakeAnnotation(
AssociationOverrides.class,
XmlAnnotationHelper.applyAssociationOverrides(
associationOverrides,
mutableClassDetails,
xmlDocumentContext
);
associationOverridesAnn.setAttributeValue( "value", associationOverrideList );
}
}

View File

@ -10,13 +10,9 @@
import java.util.List;
import java.util.function.Supplier;
import org.hibernate.annotations.AttributeAccessor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.TenantId;
import org.hibernate.boot.internal.Abstract;
import org.hibernate.boot.internal.Extends;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainer;
import org.hibernate.boot.jaxb.mapping.spi.JaxbAttributesContainerImpl;
@ -55,16 +51,15 @@
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableClassDetails;
import org.hibernate.models.spi.MutableMemberDetails;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.hibernate.models.spi.TypeDetails;
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import static org.hibernate.internal.util.NullnessHelper.coalesce;
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
@ -473,7 +468,12 @@ private static void adjustDynamicTypeMember(
MutableMemberDetails memberDetails,
JaxbPersistentAttribute jaxbAttribute,
XmlDocumentContext xmlDocumentContext) {
XmlAnnotationHelper.applyAttributeAccessor( BuiltInPropertyAccessStrategies.MAP.getExternalName(), memberDetails, xmlDocumentContext );
final MutableAnnotationUsage<AttributeAccessor> annotationUsage = memberDetails.applyAnnotationUsage(
HibernateAnnotations.ATTRIBUTE_ACCESSOR,
xmlDocumentContext.getModelBuildingContext()
);
// todo (7.0) : this is the old String-based, deprecated form
annotationUsage.setAttributeValue( "value", BuiltInPropertyAccessStrategies.MAP.getExternalName() );
}
private static void processEntityMetadata(
@ -489,7 +489,7 @@ private static void processEntityMetadata(
applyCaching( jaxbEntity, classDetails, xmlDocumentContext );
if ( jaxbEntity.isAbstract() != null ) {
XmlProcessingHelper.makeAnnotation( Abstract.class, classDetails, xmlDocumentContext );
classDetails.applyAnnotationUsage( HibernateAnnotations.ABSTRACT, xmlDocumentContext.getModelBuildingContext() );
}
if ( isNotEmpty( jaxbEntity.getExtends() ) ) {
@ -541,17 +541,13 @@ private static void processEntityMetadata(
QueryProcessing.applyNamedNativeQueries( jaxbEntity, classDetails, jaxbRoot, xmlDocumentContext );
QueryProcessing.applyNamedProcedureQueries( jaxbEntity, classDetails, xmlDocumentContext );
jaxbEntity.getFilters().forEach( jaxbFilter -> XmlAnnotationHelper.applyFilter(
jaxbFilter,
classDetails,
xmlDocumentContext
) );
XmlAnnotationHelper.applyFilters( jaxbEntity.getFilters(), classDetails, xmlDocumentContext );
XmlAnnotationHelper.applySqlRestriction( jaxbEntity.getSqlRestriction(), classDetails, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlInsert(), classDetails, SQLInsert.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlUpdate(), classDetails, SQLUpdate.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlDelete(), classDetails, SQLDelete.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlInsert(), classDetails, HibernateAnnotations.SQL_INSERT, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlUpdate(), classDetails, HibernateAnnotations.SQL_UPDATE, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbEntity.getSqlDelete(), classDetails, HibernateAnnotations.SQL_DELETE, xmlDocumentContext );
processEntityOrMappedSuperclass( jaxbEntity, classDetails, xmlDocumentContext );
@ -584,7 +580,7 @@ private static void applyAccessAnnotation(
AccessType accessType,
MutableClassDetails target,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<Access> annotationUsage = XmlProcessingHelper.makeAnnotation( Access.class, target, xmlDocumentContext );
final MutableAnnotationUsage<Access> annotationUsage = target.applyAnnotationUsage( JpaAnnotations.ACCESS, xmlDocumentContext.getModelBuildingContext() );
annotationUsage.setAttributeValue( "value", accessType );
target.addAnnotationUsage( annotationUsage );
}
@ -636,11 +632,7 @@ private static void applyTenantId(
coalesce( jaxbTenantId.getAccess(), classAccessType ),
classDetails
);
XmlProcessingHelper.getOrMakeAnnotation(
TenantId.class,
memberDetails,
xmlDocumentContext
);
memberDetails.applyAnnotationUsage( HibernateAnnotations.TENANT_ID, xmlDocumentContext.getModelBuildingContext() );
BasicAttributeProcessing.processBasicAttribute(
jaxbTenantId,
classDetails,
@ -806,18 +798,20 @@ private static void processMappedSuperclassMetadata(
JaxbMappedSuperclassImpl jaxbMappedSuperclass,
MutableClassDetails classDetails,
XmlDocumentContext xmlDocumentContext) {
XmlProcessingHelper.getOrMakeAnnotation( MappedSuperclass.class, classDetails, xmlDocumentContext );
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
classDetails.applyAnnotationUsage( JpaAnnotations.MAPPED_SUPERCLASS, modelBuildingContext );
final AccessType classAccessType = coalesce(
jaxbMappedSuperclass.getAccess(),
xmlDocumentContext.getEffectiveDefaults().getDefaultPropertyAccessType()
);
if ( classAccessType != null ) {
classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation(
classAccessType,
classDetails,
xmlDocumentContext
) );
final MutableAnnotationUsage<Access> accessUsage = classDetails.applyAnnotationUsage(
JpaAnnotations.ACCESS,
modelBuildingContext
);
accessUsage.setAttributeValue( "value", classAccessType );
}
final JaxbAttributesContainerImpl attributes = jaxbMappedSuperclass.getAttributes();
@ -922,14 +916,16 @@ private static void processEmbeddableMetadata(
AccessType classAccessType,
AttributeProcessor.MemberAdjuster memberAdjuster,
XmlDocumentContext xmlDocumentContext) {
XmlProcessingHelper.getOrMakeAnnotation( Embeddable.class, classDetails, xmlDocumentContext );
classDetails.applyAnnotationUsage( JpaAnnotations.EMBEDDABLE, xmlDocumentContext.getModelBuildingContext() );
if ( classAccessType != null ) {
classDetails.addAnnotationUsage( XmlAnnotationHelper.createAccessAnnotation(
classAccessType,
classDetails,
xmlDocumentContext
) );
final MutableAnnotationUsage<Access> accessUsage = classDetails.applyAnnotationUsage(
JpaAnnotations.ACCESS,
xmlDocumentContext.getModelBuildingContext()
);
accessUsage.setAttributeValue( "value", classAccessType );
}
if ( jaxbEmbeddable.getAttributes() != null ) {
AttributeProcessor.processAttributes(
jaxbEmbeddable.getAttributes(),
@ -952,7 +948,7 @@ public static void processOverrideEmbeddable(List<XmlProcessingResult.OverrideTu
.getClassDetailsRegistry()
.resolveClassDetails( className );
XmlProcessingHelper.getOrMakeAnnotation( Embeddable.class, classDetails, xmlDocumentContext );
classDetails.applyAnnotationUsage( JpaAnnotations.EMBEDDABLE, xmlDocumentContext.getModelBuildingContext() );
if ( jaxbEmbeddable.getAttributes() != null ) {
AttributeProcessor.processAttributes(

View File

@ -8,10 +8,6 @@
import org.hibernate.annotations.Bag;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural;
import org.hibernate.boot.internal.CollectionClassification;
@ -19,6 +15,7 @@
import org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbOrderColumnImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbPluralAttribute;
import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.internal.db.ColumnProcessing;
@ -153,16 +150,12 @@ public static void applyPluralAttributeStructure(
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// filters and custom sql
jaxbPluralAttribute.getFilters().forEach( (jaxbFilter) -> {
XmlAnnotationHelper.applyFilter( jaxbFilter, memberDetails, xmlDocumentContext );
} );
XmlAnnotationHelper.applyFilters( jaxbPluralAttribute.getFilters(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applySqlRestriction( jaxbPluralAttribute.getSqlRestriction(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlInsert(), memberDetails, SQLInsert.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlUpdate(), memberDetails, SQLUpdate.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDelete(), memberDetails, SQLDelete.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDeleteAll(), memberDetails, SQLDeleteAll.class, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlInsert(), memberDetails, HibernateAnnotations.SQL_INSERT, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlUpdate(), memberDetails, HibernateAnnotations.SQL_UPDATE, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDelete(), memberDetails, HibernateAnnotations.SQL_DELETE, xmlDocumentContext );
XmlAnnotationHelper.applyCustomSql( jaxbPluralAttribute.getSqlDeleteAll(), memberDetails, HibernateAnnotations.SQL_DELETE_ALL, xmlDocumentContext );
}
private static void applyOrderColumn(

View File

@ -65,9 +65,7 @@ public static MutableMemberDetails processManyToManyAttribute(
XmlAnnotationHelper.applySqlJoinTableRestriction( jaxbManyToMany.getSqlJoinTableRestriction(), memberDetails, xmlDocumentContext );
jaxbManyToMany.getJoinTableFilters().forEach( (jaxbFilter) -> {
XmlAnnotationHelper.applyJoinTableFilter( jaxbFilter, memberDetails, xmlDocumentContext );
} );
XmlAnnotationHelper.applyJoinTableFilters( jaxbManyToMany.getJoinTableFilters(), memberDetails, xmlDocumentContext );
return memberDetails;
}

View File

@ -66,10 +66,8 @@ public static MutableMemberDetails processOneToManyAttribute(
TableProcessing.transformJoinTable( jaxbOneToMany.getJoinTable(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applySqlJoinTableRestriction( jaxbOneToMany.getSqlJoinTableRestriction(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyJoinTableFilters( jaxbOneToMany.getJoinTableFilters(), memberDetails, xmlDocumentContext );
jaxbOneToMany.getJoinTableFilters().forEach( (jaxbFilter) -> {
XmlAnnotationHelper.applyJoinTableFilter( jaxbFilter, memberDetails, xmlDocumentContext );
} );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// other properties

View File

@ -20,6 +20,7 @@
import org.hibernate.models.spi.MutableMemberDetails;
import jakarta.persistence.AccessType;
import jakarta.persistence.MapsId;
import jakarta.persistence.OneToOne;
import static org.hibernate.boot.models.xml.internal.XmlAnnotationHelper.applyCascading;
@ -67,11 +68,11 @@ public static MutableMemberDetails processOneToOneAttribute(
}
if ( StringHelper.isNotEmpty( jaxbOneToOne.getMapsId() ) ) {
memberDetails.applyAnnotationUsage(
final MutableAnnotationUsage<MapsId> mapsIdAnn = memberDetails.applyAnnotationUsage(
JpaAnnotations.MAPS_ID,
(usage) -> usage.setAttributeValue( "value", jaxbOneToOne.getMapsId() ),
xmlDocumentContext.getModelBuildingContext()
);
mapsIdAnn.setAttributeValue( "value", jaxbOneToOne.getMapsId() );
}
return memberDetails;
@ -81,24 +82,20 @@ private static MutableAnnotationUsage<OneToOne> applyOneToOne(
MutableMemberDetails memberDetails,
JaxbOneToOneImpl jaxbOneToOne,
XmlDocumentContext xmlDocumentContext) {
return memberDetails.applyAnnotationUsage(
JpaAnnotations.ONE_TO_ONE,
(usage) -> {
if ( jaxbOneToOne.getFetch() != null ) {
usage.setAttributeValue( "fetch", jaxbOneToOne.getFetch() );
}
if ( jaxbOneToOne.isOptional() != null ) {
usage.setAttributeValue( "optional", jaxbOneToOne.isOptional() );
}
if ( StringHelper.isNotEmpty( jaxbOneToOne.getMappedBy() ) ) {
usage.setAttributeValue( "mappedBy", jaxbOneToOne.getMappedBy() );
}
if ( jaxbOneToOne.isOrphanRemoval() != null ) {
usage.setAttributeValue( "orphanRemoval", jaxbOneToOne.isOrphanRemoval() );
}
},
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<OneToOne> usage = memberDetails.applyAnnotationUsage( JpaAnnotations.ONE_TO_ONE, xmlDocumentContext.getModelBuildingContext() );
if ( jaxbOneToOne.getFetch() != null ) {
usage.setAttributeValue( "fetch", jaxbOneToOne.getFetch() );
}
if ( jaxbOneToOne.isOptional() != null ) {
usage.setAttributeValue( "optional", jaxbOneToOne.isOptional() );
}
if ( StringHelper.isNotEmpty( jaxbOneToOne.getMappedBy() ) ) {
usage.setAttributeValue( "mappedBy", jaxbOneToOne.getMappedBy() );
}
if ( jaxbOneToOne.isOrphanRemoval() != null ) {
usage.setAttributeValue( "orphanRemoval", jaxbOneToOne.isOrphanRemoval() );
}
return usage;
}
@SuppressWarnings("unused")

View File

@ -72,7 +72,7 @@ public static <A extends Annotation> void applyColumnDetails(
applyColumnDefinition( jaxbColumn, columnAnn, xmlDocumentContext );
applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext );
applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, columnAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, null, columnAnn, xmlDocumentContext );
if ( jaxbColumn instanceof JaxbColumnSizable sizable ) {
applyColumnSizing( sizable, columnAnn, xmlDocumentContext );
@ -94,7 +94,7 @@ public static <A extends Annotation> void applyColumnDetails(
applyColumnSizing( jaxbColumn, columnAnn, xmlDocumentContext );
applyColumnUniqueness( jaxbColumn, columnAnn, xmlDocumentContext );
applyColumnComment( jaxbColumn, columnAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, columnAnn, xmlDocumentContext );
XmlAnnotationHelper.applyCheckConstraints( jaxbColumn, null, columnAnn, xmlDocumentContext );
}
public static <A extends Annotation> void applyColumnDetails(

View File

@ -11,7 +11,6 @@
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableMemberDetails;
@ -40,16 +39,29 @@ public static MutableAnnotationUsage<ForeignKey> createForeignKeyAnnotation(
if ( jaxbForeignKey == null ) {
return null;
}
return memberDetails.applyAnnotationUsage(
final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = memberDetails.applyAnnotationUsage(
JpaAnnotations.FOREIGN_KEY,
(foreignKeyUsage) -> {
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() );
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "value", jaxbForeignKey.getConstraintMode() );
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "foreignKeyDefinition", jaxbForeignKey.getForeignKeyDefinition() );
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "options", jaxbForeignKey.getOptions() );
},
xmlDocumentContext.getModelBuildingContext()
);
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() );
XmlAnnotationHelper.applyOptionalAttribute(
foreignKeyUsage,
"value",
jaxbForeignKey.getConstraintMode()
);
XmlAnnotationHelper.applyOptionalAttribute(
foreignKeyUsage,
"foreignKeyDefinition",
jaxbForeignKey.getForeignKeyDefinition()
);
XmlAnnotationHelper.applyOptionalAttribute(
foreignKeyUsage,
"options",
jaxbForeignKey.getOptions()
);
return foreignKeyUsage;
}
public static MutableAnnotationUsage<ForeignKey> createNestedForeignKeyAnnotation(
@ -59,7 +71,7 @@ public static MutableAnnotationUsage<ForeignKey> createNestedForeignKeyAnnotatio
assert jaxbForeignKey != null;
final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage(
annotationTarget,
null,
xmlDocumentContext.getModelBuildingContext()
);

View File

@ -153,7 +153,7 @@ public static List<AnnotationUsage<JoinColumn>> transformJoinColumnList(
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
jaxbJoinColumns.forEach( jaxbJoinColumn -> {
final MutableAnnotationUsage<JoinColumn> joinColumnAnn = JpaAnnotations.JOIN_COLUMN.createUsage(
annotationTarget,
null,
xmlDocumentContext.getModelBuildingContext()
);
transferJoinColumn( jaxbJoinColumn, joinColumnAnn, null, xmlDocumentContext );

View File

@ -16,10 +16,9 @@
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.MutableAnnotationTarget;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableMemberDetails;
import jakarta.persistence.AssociationOverride;
import jakarta.persistence.JoinTable;
/**
@ -28,17 +27,17 @@
public class TableProcessing {
public static MutableAnnotationUsage<JoinTable> transformJoinTable(
JaxbJoinTableImpl jaxbJoinTable,
MutableMemberDetails memberDetails,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
if ( jaxbJoinTable == null ) {
return null;
}
final MutableAnnotationUsage<JoinTable> joinTableUsage = memberDetails.applyAnnotationUsage(
final MutableAnnotationUsage<JoinTable> joinTableUsage = target.applyAnnotationUsage(
JpaAnnotations.JOIN_TABLE,
xmlDocumentContext.getModelBuildingContext()
);
applyJoinTable( jaxbJoinTable, joinTableUsage, memberDetails, xmlDocumentContext );
applyJoinTable( jaxbJoinTable, joinTableUsage, target, xmlDocumentContext );
return joinTableUsage;
}

View File

@ -214,8 +214,8 @@ public void testMapKeyEnumerated() {
public void testSingleMapKeyAttributeOverride() {
final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm10.xml" );
assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue();
final AnnotationUsage<AttributeOverride> attributeOverrideUsage = memberDetails.getAnnotationUsage( AttributeOverride.class );
assertThat( attributeOverrideUsage.getString( "name" ) ).isEqualTo( "key.field1" );
@ -440,8 +440,8 @@ public void testSingleAttributeOverride() {
final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm21.xml" );
assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverride.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AttributeOverrides.class ) ).isTrue();
final AnnotationUsage<AttributeOverride> overrideUsage = memberDetails.getAnnotationUsage( AttributeOverride.class );
assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "value.field1" );
@ -527,8 +527,8 @@ public void testSingleAssociationOverride() {
final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm24.xml" );
assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AssociationOverride.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( AssociationOverrides.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AssociationOverride.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( AssociationOverrides.class ) ).isTrue();
final AnnotationUsage<AssociationOverride> overrideUsage = memberDetails.getAnnotationUsage( AssociationOverride.class );
assertThat( overrideUsage.getString( "name" ) ).isEqualTo( "association1" );

View File

@ -22,6 +22,7 @@
import org.hibernate.models.internal.jdk.JdkClassDetails;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableMemberDetails;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
@ -328,11 +329,11 @@ private static void contributeEntity5Details(
modelBuildingContext
);
jdkClassDetails.applyAnnotationUsage(
final MutableAnnotationUsage<Entity> entityUsage = jdkClassDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
(entityUsage) -> entityUsage.setAttributeValue( "name", "___Entity5___" ),
modelBuildingContext
);
entityUsage.setAttributeValue( "name", "___Entity5___" );
final MutableMemberDetails idField = (MutableMemberDetails) jdkClassDetails.findFieldByName( "id" );
idField.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );
@ -368,11 +369,11 @@ private void contributeEntity6Details(
assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );
final DynamicClassDetails classDetails = new DynamicClassDetails( "Entity6", modelBuildingContext );
classDetails.applyAnnotationUsage(
final MutableAnnotationUsage<Entity> entityUsage = classDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
(config) -> config.setAttributeValue( "name", "Entity6" ),
modelBuildingContext
);
entityUsage.setAttributeValue( "name", "Entity6" );
classDetails.applyAttribute(
"id",
classDetailsRegistry.resolveClassDetails( Integer.class.getName() ),