HHH-18000 : Remove XmlProcessingHelper methods for creating AnnotationUsage instances

This commit is contained in:
Steve Ebersole 2024-04-26 13:31:27 -05:00
parent f3624c712e
commit 23b461a109
22 changed files with 220 additions and 418 deletions

View File

@ -151,17 +151,15 @@ public class IdentifierGeneratorDefinition implements Serializable {
private static IdentifierGeneratorDefinition buildTableGeneratorDefinition(String name) { private static IdentifierGeneratorDefinition buildTableGeneratorDefinition(String name) {
final Builder builder = new Builder(); final Builder builder = new Builder();
final MutableAnnotationUsage<TableGenerator> tableGeneratorUsage = TABLE_GENERATOR.createUsage( null, null ); final MutableAnnotationUsage<TableGenerator> tableGeneratorUsage = TABLE_GENERATOR.createUsage( null );
tableGeneratorUsage.setAttributeValue( "name", name );
GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretTableGenerator( tableGeneratorUsage, builder ); GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretTableGenerator( tableGeneratorUsage, builder );
return builder.build(); return builder.build();
} }
private static IdentifierGeneratorDefinition buildSequenceGeneratorDefinition(String name) { private static IdentifierGeneratorDefinition buildSequenceGeneratorDefinition(String name) {
final Builder builder = new Builder(); final Builder builder = new Builder();
final MutableAnnotationUsage<SequenceGenerator> sequenceGeneratorUsage = JpaAnnotations.SEQUENCE_GENERATOR.createUsage( final MutableAnnotationUsage<SequenceGenerator> sequenceGeneratorUsage = JpaAnnotations.SEQUENCE_GENERATOR.createUsage( null );
null,
null
);
applyStringAttributeIfSpecified( "name", name, sequenceGeneratorUsage ); applyStringAttributeIfSpecified( "name", name, sequenceGeneratorUsage );
GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretSequenceGenerator( sequenceGeneratorUsage, builder ); GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretSequenceGenerator( sequenceGeneratorUsage, builder );
return builder.build(); return builder.build();

View File

@ -31,6 +31,7 @@ import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType; import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType;
import org.hibernate.usertype.internal.OffsetTimeCompositeUserType; import org.hibernate.usertype.internal.OffsetTimeCompositeUserType;
@ -485,37 +486,26 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
AnnotationUsage<Column> column, AnnotationUsage<Column> column,
MetadataBuildingContext context) { MetadataBuildingContext context) {
final AnnotationUsage<TimeZoneColumn> timeZoneColumn = element.getAnnotationUsage( TimeZoneColumn.class ); final AnnotationUsage<TimeZoneColumn> timeZoneColumn = element.getAnnotationUsage( TimeZoneColumn.class );
return JpaAnnotations.COLUMN.createUsage( final MutableAnnotationUsage<Column> created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
element, final String columnName = timeZoneColumn != null
(created) -> { ? timeZoneColumn.getString( "name" )
final String columnName = timeZoneColumn != null : column.getString( "name" ) + "_tz";
? timeZoneColumn.getString( "name" ) created.setAttributeValue( "name", columnName );
: column.getString( "name" ) + "_tz";
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", columnName, created );
AnnotationUsageHelper.applyAttributeIfSpecified(
"nullable",
column.getBoolean( "nullable" ),
created
);
final AnnotationUsage<?> source = timeZoneColumn != null AnnotationUsageHelper.applyAttributeIfSpecified( "nullable", column.getBoolean( "nullable" ), created );
? timeZoneColumn
: column;
AnnotationUsageHelper.applyStringAttributeIfSpecified( "table", source.getAttributeValue( "table" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created );
if ( timeZoneColumn != null ) { final AnnotationUsage<?> source = timeZoneColumn != null
AnnotationUsageHelper ? timeZoneColumn
.applyStringAttributeIfSpecified( : column;
"columnDefinition", AnnotationUsageHelper.applyAttributeIfSpecified( "table", source.getString( "table" ), created );
timeZoneColumn.getAttributeValue( "columnDefinition" ), AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created );
created AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created );
);
} if ( timeZoneColumn != null ) {
}, AnnotationUsageHelper.applyStringAttributeIfSpecified( "columnDefinition", timeZoneColumn.getAttributeValue( "columnDefinition" ), created );
context.getMetadataCollector().getSourceModelBuildingContext() }
);
return created;
} }
private static AnnotationUsage<Column> createTemporalColumn( private static AnnotationUsage<Column> createTemporalColumn(
@ -561,15 +551,11 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
) )
); );
return JpaAnnotations.COLUMN.createUsage( final MutableAnnotationUsage<Column> usage = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
element, AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), usage );
(created) -> { usage.setAttributeValue( "precision", precision );
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), created ); usage.setAttributeValue( "secondPrecision", secondPrecision );
created.setAttributeValue( "precision", precision ); return usage;
created.setAttributeValue( "secondPrecision", secondPrecision );
},
context.getMetadataCollector().getSourceModelBuildingContext()
);
} }
private static Map<String, AnnotationUsage<ColumnTransformer>> buildColumnTransformerOverride(AnnotationTarget element) { private static Map<String, AnnotationUsage<ColumnTransformer>> buildColumnTransformerOverride(AnnotationTarget element) {

View File

@ -17,12 +17,12 @@ import org.hibernate.annotations.FractionalSeconds;
import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas; import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.JoinFormula;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.PropertyData; import org.hibernate.boot.spi.PropertyData;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.SourceModelBuildingContext;
import jakarta.persistence.CheckConstraint; import jakarta.persistence.CheckConstraint;
@ -315,39 +315,33 @@ class ColumnsBuilder {
AnnotationUsage<PrimaryKeyJoinColumn> pkJoinColumnAnn, AnnotationUsage<PrimaryKeyJoinColumn> pkJoinColumnAnn,
MemberDetails property) { MemberDetails property) {
final SourceModelBuildingContext hibernateModelsContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); final SourceModelBuildingContext hibernateModelsContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext();
final AnnotationDescriptorRegistry descriptorRegistry = hibernateModelsContext.getAnnotationDescriptorRegistry(); final MutableAnnotationUsage<JoinColumn> usage = JpaAnnotations.JOIN_COLUMN.createUsage( hibernateModelsContext );
final AnnotationDescriptor<JoinColumn> joinColumnDescriptor = descriptorRegistry.getDescriptor( JoinColumn.class ); applyAttributeIfSpecified(
return joinColumnDescriptor.createUsage( "name",
property, pkJoinColumnAnn.getAttributeValue( "name" ),
(usage) -> { usage
applyAttributeIfSpecified(
"name",
pkJoinColumnAnn.getAttributeValue( "name" ),
usage
);
applyAttributeIfSpecified(
"referencedColumnName",
pkJoinColumnAnn.getAttributeValue( "referencedColumnName" ),
usage
);
applyAttributeIfSpecified(
"columnDefinition",
pkJoinColumnAnn.getAttributeValue( "columnDefinition" ),
usage
);
applyAttributeIfSpecified(
"options",
pkJoinColumnAnn.getAttributeValue( "options" ),
usage
);
applyAttributeIfSpecified(
"foreignKey",
pkJoinColumnAnn.getAttributeValue( "foreignKey" ),
usage
);
},
hibernateModelsContext
); );
applyAttributeIfSpecified(
"referencedColumnName",
pkJoinColumnAnn.getAttributeValue( "referencedColumnName" ),
usage
);
applyAttributeIfSpecified(
"columnDefinition",
pkJoinColumnAnn.getAttributeValue( "columnDefinition" ),
usage
);
applyAttributeIfSpecified(
"options",
pkJoinColumnAnn.getAttributeValue( "options" ),
usage
);
applyAttributeIfSpecified(
"foreignKey",
pkJoinColumnAnn.getAttributeValue( "foreignKey" ),
usage
);
return usage;
} }
/** /**

View File

@ -81,8 +81,8 @@ import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jpa.event.internal.CallbackDefinitionResolver; import org.hibernate.jpa.event.internal.CallbackDefinitionResolver;
import org.hibernate.jpa.event.spi.CallbackType; import org.hibernate.jpa.event.spi.CallbackType;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
@ -124,7 +124,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey; import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.IdClass; import jakarta.persistence.IdClass;
import jakarta.persistence.Index;
import jakarta.persistence.Inheritance; import jakarta.persistence.Inheritance;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable; import jakarta.persistence.JoinTable;
@ -148,8 +147,8 @@ import static org.hibernate.boot.model.internal.BinderHelper.getMappedSuperclass
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
import static org.hibernate.boot.model.internal.BinderHelper.getOverrideAnnotation; import static org.hibernate.boot.model.internal.BinderHelper.getOverrideAnnotation;
import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation; import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation;
import static org.hibernate.boot.model.internal.BinderHelper.overrideMatchesDialect;
import static org.hibernate.boot.model.internal.BinderHelper.noConstraint; import static org.hibernate.boot.model.internal.BinderHelper.noConstraint;
import static org.hibernate.boot.model.internal.BinderHelper.overrideMatchesDialect;
import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap; import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap;
import static org.hibernate.boot.model.internal.BinderHelper.toAliasTableMap; import static org.hibernate.boot.model.internal.BinderHelper.toAliasTableMap;
import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable; import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable;
@ -1789,16 +1788,9 @@ public class EntityBinder {
} }
private static AnnotationUsage<Cache> buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) { private static AnnotationUsage<Cache> buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) {
final MutableAnnotationUsage<Cache> cacheUsage = HibernateAnnotations.CACHE.createUsage( final MutableAnnotationUsage<Cache> cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
classDetails,
context.getMetadataCollector().getSourceModelBuildingContext()
);
applyAttributeIfSpecified( "region", classDetails.getName(), cacheUsage ); applyAttributeIfSpecified( "region", classDetails.getName(), cacheUsage );
applyAttributeIfSpecified( applyAttributeIfSpecified( "usage", determineCacheConcurrencyStrategy( context ), cacheUsage );
"usage",
determineCacheConcurrencyStrategy( context ),
cacheUsage
);
return cacheUsage; return cacheUsage;
} }

View File

@ -43,10 +43,7 @@ public class MapKeyJoinColumnDelegator implements JoinColumn {
AnnotationUsage<MapKeyJoinColumn> mapKeyJoinColumn, AnnotationUsage<MapKeyJoinColumn> mapKeyJoinColumn,
MemberDetails attributeMember, MemberDetails attributeMember,
MetadataBuildingContext context) { MetadataBuildingContext context) {
final MutableAnnotationUsage<JoinColumn> joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( final MutableAnnotationUsage<JoinColumn> joinColumn = JpaAnnotations.JOIN_COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
attributeMember,
context.getMetadataCollector().getSourceModelBuildingContext()
);
applyStringAttributeIfSpecified( applyStringAttributeIfSpecified(
"name", "name",

View File

@ -276,17 +276,15 @@ public abstract class QueryBinder {
final SourceModelBuildingContext sourceModelBuildingContext = context.getMetadataCollector() final SourceModelBuildingContext sourceModelBuildingContext = context.getMetadataCollector()
.getSourceModelBuildingContext(); .getSourceModelBuildingContext();
final MutableAnnotationUsage<NamedStoredProcedureQuery> nameStoredProcedureQueryAnn = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( final MutableAnnotationUsage<NamedStoredProcedureQuery> nameStoredProcedureQueryAnn =
null, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( sourceModelBuildingContext );
sourceModelBuildingContext
);
nameStoredProcedureQueryAnn.setAttributeValue( "name", builder.getName() ); nameStoredProcedureQueryAnn.setAttributeValue( "name", builder.getName() );
nameStoredProcedureQueryAnn.setAttributeValue( "procedureName", jdbcCall.callableName ); nameStoredProcedureQueryAnn.setAttributeValue( "procedureName", jdbcCall.callableName );
final List<AnnotationUsage<StoredProcedureParameter>> storedProcedureParameters = new ArrayList<>(); final List<AnnotationUsage<StoredProcedureParameter>> storedProcedureParameters = new ArrayList<>();
for ( String parameterName : jdbcCall.parameters ) { for ( String parameterName : jdbcCall.parameters ) {
final MutableAnnotationUsage<StoredProcedureParameter> storedProcedureParameterAnn = JpaAnnotations.STORED_PROCEDURE_PARAMETER final MutableAnnotationUsage<StoredProcedureParameter> storedProcedureParameterAnn =
.createUsage( null, sourceModelBuildingContext ); JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext );
storedProcedureParameterAnn.setAttributeValue( "name", parameterName ); storedProcedureParameterAnn.setAttributeValue( "name", parameterName );
storedProcedureParameterAnn.setAttributeValue( "mode", ParameterMode.IN ); storedProcedureParameterAnn.setAttributeValue( "mode", ParameterMode.IN );
final String typeName = builder.getParameterTypes().get( parameterName ); final String typeName = builder.getParameterTypes().get( parameterName );
@ -323,10 +321,7 @@ public abstract class QueryBinder {
final List<AnnotationUsage<QueryHint>> queryHints = new ArrayList<>(); final List<AnnotationUsage<QueryHint>> queryHints = new ArrayList<>();
if ( builder.getQuerySpaces() != null ) { if ( builder.getQuerySpaces() != null ) {
final MutableAnnotationUsage<QueryHint> queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( final MutableAnnotationUsage<QueryHint> queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext );
null,
sourceModelBuildingContext
);
queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_NATIVE_SPACES ); queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_NATIVE_SPACES );
queryHintAnn.setAttributeValue( "value", String.join( " ", builder.getQuerySpaces() ) ); queryHintAnn.setAttributeValue( "value", String.join( " ", builder.getQuerySpaces() ) );
queryHints.add( queryHintAnn ); queryHints.add( queryHintAnn );
@ -334,10 +329,7 @@ public abstract class QueryBinder {
if ( jdbcCall.resultParameter ) { if ( jdbcCall.resultParameter ) {
// Mark native queries that have a result parameter as callable functions // Mark native queries that have a result parameter as callable functions
final MutableAnnotationUsage<QueryHint> queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( final MutableAnnotationUsage<QueryHint> queryHintAnn = JpaAnnotations.QUERY_HINT.createUsage( sourceModelBuildingContext );
null,
sourceModelBuildingContext
);
queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_CALLABLE_FUNCTION ); queryHintAnn.setAttributeValue( "name", HibernateHints.HINT_CALLABLE_FUNCTION );
queryHintAnn.setAttributeValue( "value", "true" ); queryHintAnn.setAttributeValue( "value", "true" );
queryHints.add( queryHintAnn ); queryHints.add( queryHintAnn );

View File

@ -693,7 +693,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
} }
private <A extends Annotation> MutableAnnotationUsage<A> makeAnnotation(AnnotationDescriptor<A> annotationDescriptor) { private <A extends Annotation> MutableAnnotationUsage<A> makeAnnotation(AnnotationDescriptor<A> annotationDescriptor) {
return annotationDescriptor.createUsage( null, sourceModelContext ); return annotationDescriptor.createUsage( sourceModelContext );
} }
public void collectSequenceGenerator(AnnotationUsage<SequenceGenerator> usage) { public void collectSequenceGenerator(AnnotationUsage<SequenceGenerator> usage) {
@ -855,7 +855,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
} }
jaxbSqlResultSetMappings.forEach( (jaxbMapping) -> { jaxbSqlResultSetMappings.forEach( (jaxbMapping) -> {
final MutableAnnotationUsage<SqlResultSetMapping> mappingAnnotation = JpaAnnotations.SQL_RESULT_SET_MAPPING.createUsage( null, null ); final MutableAnnotationUsage<SqlResultSetMapping> mappingAnnotation = JpaAnnotations.SQL_RESULT_SET_MAPPING.createUsage( sourceModelContext );
applyStringAttributeIfSpecified( "name", jaxbMapping.getName(), mappingAnnotation ); applyStringAttributeIfSpecified( "name", jaxbMapping.getName(), mappingAnnotation );
sqlResultSetMappingRegistrations.put( sqlResultSetMappingRegistrations.put(
@ -906,7 +906,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
entityResultAnnotation.setAttributeValue( "fields", fieldResults ); entityResultAnnotation.setAttributeValue( "fields", fieldResults );
for ( JaxbFieldResultImpl jaxbFieldResult : jaxbEntityResult.getFieldResult() ) { for ( JaxbFieldResultImpl jaxbFieldResult : jaxbEntityResult.getFieldResult() ) {
final MutableAnnotationUsage<FieldResult> fieldResultAnnotation = JpaAnnotations.FIELD_RESULT.createUsage( null, sourceModelContext ); final MutableAnnotationUsage<FieldResult> fieldResultAnnotation = JpaAnnotations.FIELD_RESULT.createUsage( sourceModelContext );
fieldResults.add( fieldResultAnnotation ); fieldResults.add( fieldResultAnnotation );
// both name and column are required // both name and column are required
fieldResultAnnotation.setAttributeValue( "name", jaxbFieldResult.getName() ); fieldResultAnnotation.setAttributeValue( "name", jaxbFieldResult.getName() );

View File

@ -140,10 +140,7 @@ public class JpaEventListener {
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
prePersistMethod.set( methodDetails ); prePersistMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
JpaAnnotations.PRE_PERSIST.createUsage( JpaAnnotations.PRE_PERSIST.createUsage( modelsContext )
methodDetails,
modelsContext
)
); );
} }
else if ( jaxbMapping.getPostPersist() != null else if ( jaxbMapping.getPostPersist() != null
@ -151,10 +148,7 @@ public class JpaEventListener {
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
postPersistMethod.set( methodDetails ); postPersistMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
JpaAnnotations.POST_PERSIST.createUsage( JpaAnnotations.POST_PERSIST.createUsage( modelsContext )
methodDetails,
modelsContext
)
); );
} }
else if ( jaxbMapping.getPreRemove() != null else if ( jaxbMapping.getPreRemove() != null
@ -162,10 +156,7 @@ public class JpaEventListener {
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
preRemoveMethod.set( methodDetails ); preRemoveMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
JpaAnnotations.PRE_REMOVE.createUsage( JpaAnnotations.PRE_REMOVE.createUsage( modelsContext )
methodDetails,
modelsContext
)
); );
} }
else if ( jaxbMapping.getPostRemove() != null else if ( jaxbMapping.getPostRemove() != null
@ -173,10 +164,7 @@ public class JpaEventListener {
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
postRemoveMethod.set( methodDetails ); postRemoveMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
JpaAnnotations.POST_REMOVE.createUsage( JpaAnnotations.POST_REMOVE.createUsage( modelsContext )
methodDetails,
modelsContext
)
); );
} }
else if ( jaxbMapping.getPreUpdate() != null else if ( jaxbMapping.getPreUpdate() != null
@ -184,33 +172,20 @@ public class JpaEventListener {
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
preUpdateMethod.set( methodDetails ); preUpdateMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
JpaAnnotations.PRE_UPDATE.createUsage( JpaAnnotations.PRE_UPDATE.createUsage( modelsContext )
methodDetails,
modelsContext
)
); );
} }
else if ( jaxbMapping.getPostUpdate() != null else if ( jaxbMapping.getPostUpdate() != null
&& methodDetails.getName().equals( jaxbMapping.getPostUpdate().getMethodName() ) && methodDetails.getName().equals( jaxbMapping.getPostUpdate().getMethodName() )
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
postUpdateMethod.set( methodDetails ); postUpdateMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( JpaAnnotations.POST_UPDATE.createUsage( modelsContext ) );
JpaAnnotations.POST_UPDATE.createUsage(
methodDetails,
modelsContext
)
);
} }
else if ( jaxbMapping.getPostLoad() != null else if ( jaxbMapping.getPostLoad() != null
&& methodDetails.getName().equals( jaxbMapping.getPostLoad().getMethodName() ) && methodDetails.getName().equals( jaxbMapping.getPostLoad().getMethodName() )
&& matchesSignature( consumerType, methodDetails ) ) { && matchesSignature( consumerType, methodDetails ) ) {
postLoadMethod.set( methodDetails ); postLoadMethod.set( methodDetails );
( (MutableMemberDetails) methodDetails ).addAnnotationUsage( ( (MutableMemberDetails) methodDetails ).addAnnotationUsage( JpaAnnotations.POST_LOAD.createUsage( modelsContext ) );
JpaAnnotations.POST_LOAD.createUsage(
methodDetails,
modelsContext
)
);
} }
} ); } );

View File

@ -9,10 +9,7 @@ package org.hibernate.boot.models.internal;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext;
public class AnnotationUsageHelper { public class AnnotationUsageHelper {
@ -30,30 +27,4 @@ public class AnnotationUsageHelper {
XmlAnnotationHelper.applyOptionalAttribute( annotationUsage, attributeName, value ); XmlAnnotationHelper.applyOptionalAttribute( annotationUsage, attributeName, value );
} }
public static <A extends Annotation> MutableAnnotationUsage<A> getOrCreateUsage(
Class<A> annotationType,
AnnotationTarget target,
SourceModelBuildingContext modelBuildingContext) {
final MutableAnnotationUsage<A> existing = (MutableAnnotationUsage<A>) target.getAnnotationUsage( annotationType );
if ( existing != null ) {
return existing;
}
final AnnotationDescriptor<A> descriptor = modelBuildingContext
.getAnnotationDescriptorRegistry()
.getDescriptor( annotationType );
return descriptor.createUsage( target, modelBuildingContext );
}
public static <A extends Annotation> MutableAnnotationUsage<A> getOrCreateUsage(
AnnotationDescriptor<A> annotationDescriptor,
AnnotationTarget target,
SourceModelBuildingContext modelBuildingContext) {
final MutableAnnotationUsage<A> existing = (MutableAnnotationUsage<A>) target.getAnnotationUsage( annotationDescriptor );
if ( existing != null ) {
return existing;
}
return annotationDescriptor.createUsage( target, modelBuildingContext );
}
} }

View File

@ -48,11 +48,11 @@ public class EntityGraphProcessing {
} }
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
final MutableAnnotationUsage<NamedEntityGraphs> entityGraphsUsage = JpaAnnotations.NAMED_ENTITY_GRAPHS.createUsage( final MutableAnnotationUsage<NamedEntityGraphs> entityGraphsUsage = classDetails.replaceAnnotationUsage(
classDetails, JpaAnnotations.NAMED_ENTITY_GRAPH,
JpaAnnotations.NAMED_ENTITY_GRAPHS,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( entityGraphsUsage );
final ArrayList<Object> entityGraphList = arrayList( jaxbEntityGraphs.size() ); final ArrayList<Object> entityGraphList = arrayList( jaxbEntityGraphs.size() );
entityGraphsUsage.setAttributeValue( "value", entityGraphList ); entityGraphsUsage.setAttributeValue( "value", entityGraphList );
@ -68,10 +68,7 @@ public class EntityGraphProcessing {
ClassDetails classDetails, ClassDetails classDetails,
SourceModelBuildingContext modelBuildingContext, SourceModelBuildingContext modelBuildingContext,
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<NamedEntityGraph> graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage( final MutableAnnotationUsage<NamedEntityGraph> graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
applyStringAttributeIfSpecified( "name", jaxbEntityGraph.getName(), graphUsage ); applyStringAttributeIfSpecified( "name", jaxbEntityGraph.getName(), graphUsage );
applyAttributeIfSpecified( "includeAllAttributes", jaxbEntityGraph.isIncludeAllAttributes(), graphUsage ); applyAttributeIfSpecified( "includeAllAttributes", jaxbEntityGraph.isIncludeAllAttributes(), graphUsage );
@ -118,10 +115,7 @@ public class EntityGraphProcessing {
final ArrayList<MutableAnnotationUsage<NamedAttributeNode>> attributeNodeList = arrayList( jaxbAttributeNodes.size() ); final ArrayList<MutableAnnotationUsage<NamedAttributeNode>> attributeNodeList = arrayList( jaxbAttributeNodes.size() );
for ( JaxbNamedAttributeNodeImpl jaxbAttributeNode : jaxbAttributeNodes ) { for ( JaxbNamedAttributeNodeImpl jaxbAttributeNode : jaxbAttributeNodes ) {
final MutableAnnotationUsage<NamedAttributeNode> namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage( final MutableAnnotationUsage<NamedAttributeNode> namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
attributeNodeList.add( namedAttributeNodeAnn ); attributeNodeList.add( namedAttributeNodeAnn );
namedAttributeNodeAnn.setAttributeValue( "value", jaxbAttributeNode.getName() ); namedAttributeNodeAnn.setAttributeValue( "value", jaxbAttributeNode.getName() );
@ -141,10 +135,7 @@ public class EntityGraphProcessing {
final List<MutableAnnotationUsage<NamedSubgraph>> subgraphAnnotations = arrayList( jaxbSubgraphs.size() ); final List<MutableAnnotationUsage<NamedSubgraph>> subgraphAnnotations = arrayList( jaxbSubgraphs.size() );
for ( JaxbNamedSubgraphImpl jaxbSubgraph : jaxbSubgraphs ) { for ( JaxbNamedSubgraphImpl jaxbSubgraph : jaxbSubgraphs ) {
final MutableAnnotationUsage<NamedSubgraph> namedSubGraphUsage = JpaAnnotations.NAMED_SUB_GRAPH.createUsage( final MutableAnnotationUsage<NamedSubgraph> namedSubGraphUsage = JpaAnnotations.NAMED_SUB_GRAPH.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
subgraphAnnotations.add( namedSubGraphUsage ); subgraphAnnotations.add( namedSubGraphUsage );
namedSubGraphUsage.setAttributeValue( "name", jaxbSubgraph.getName() ); namedSubGraphUsage.setAttributeValue( "name", jaxbSubgraph.getName() );

View File

@ -493,10 +493,7 @@ public class ManagedTypeProcessor {
} }
if ( isNotEmpty( jaxbEntity.getExtends() ) ) { if ( isNotEmpty( jaxbEntity.getExtends() ) ) {
final MutableAnnotationUsage<Extends> extendsAnn = HibernateAnnotations.EXTENDS.createUsage( final MutableAnnotationUsage<Extends> extendsAnn = HibernateAnnotations.EXTENDS.createUsage( xmlDocumentContext.getModelBuildingContext() );
classDetails,
xmlDocumentContext.getModelBuildingContext()
);
extendsAnn.setAttributeValue( "superType", jaxbEntity.getExtends() ); extendsAnn.setAttributeValue( "superType", jaxbEntity.getExtends() );
} }
@ -590,8 +587,8 @@ public class ManagedTypeProcessor {
MutableClassDetails classDetails, MutableClassDetails classDetails,
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
if ( jaxbEntity.isCacheable() == Boolean.TRUE ) { if ( jaxbEntity.isCacheable() == Boolean.TRUE ) {
final MutableAnnotationUsage<Cacheable> cacheableUsage = JpaAnnotations.CACHEABLE.createUsage( final MutableAnnotationUsage<Cacheable> cacheableUsage = classDetails.applyAnnotationUsage(
classDetails, JpaAnnotations.CACHEABLE,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
classDetails.addAnnotationUsage( cacheableUsage ); classDetails.addAnnotationUsage( cacheableUsage );
@ -599,8 +596,8 @@ public class ManagedTypeProcessor {
final JaxbCachingImpl jaxbCaching = jaxbEntity.getCaching(); final JaxbCachingImpl jaxbCaching = jaxbEntity.getCaching();
if ( jaxbCaching != null ) { if ( jaxbCaching != null ) {
final MutableAnnotationUsage<Cache> cacheableUsage = HibernateAnnotations.CACHE.createUsage( final MutableAnnotationUsage<Cache> cacheableUsage = classDetails.applyAnnotationUsage(
classDetails, HibernateAnnotations.CACHE,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
classDetails.addAnnotationUsage( cacheableUsage ); classDetails.addAnnotationUsage( cacheableUsage );

View File

@ -77,9 +77,9 @@ public class QueryProcessing {
if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) { if ( CollectionHelper.isNotEmpty( jaxbNamedQuery.getHints() ) ) {
// treat this as a Jakarta Persistence named-query // treat this as a Jakarta Persistence named-query
if ( namedJpqlQueryList == null ) { if ( namedJpqlQueryList == null ) {
final MutableAnnotationUsage<jakarta.persistence.NamedQueries> namedJpqlQueriesUsage = AnnotationUsageHelper.getOrCreateUsage( final MutableAnnotationUsage<jakarta.persistence.NamedQueries> namedJpqlQueriesUsage = classDetails.replaceAnnotationUsage(
JpaAnnotations.NAMED_QUERY,
JpaAnnotations.NAMED_QUERIES, JpaAnnotations.NAMED_QUERIES,
classDetails,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( namedJpqlQueriesUsage ); classDetails.addAnnotationUsage( namedJpqlQueriesUsage );
@ -92,9 +92,9 @@ public class QueryProcessing {
else { else {
// treat this as a named HQL query // treat this as a named HQL query
if ( namedHqlQueryList == null ) { if ( namedHqlQueryList == null ) {
final MutableAnnotationUsage<NamedQueries> namedHqlQueriesUsage = AnnotationUsageHelper.getOrCreateUsage( final MutableAnnotationUsage<NamedQueries> namedHqlQueriesUsage = classDetails.replaceAnnotationUsage(
HibernateAnnotations.NAMED_QUERY,
HibernateAnnotations.NAMED_QUERIES, HibernateAnnotations.NAMED_QUERIES,
classDetails,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( namedHqlQueriesUsage ); classDetails.addAnnotationUsage( namedHqlQueriesUsage );
@ -112,10 +112,7 @@ public class QueryProcessing {
MutableClassDetails classDetails, MutableClassDetails classDetails,
List<MutableAnnotationUsage<NamedQuery>> namedQueryList, List<MutableAnnotationUsage<NamedQuery>> namedQueryList,
SourceModelBuildingContext modelBuildingContext) { SourceModelBuildingContext modelBuildingContext) {
final MutableAnnotationUsage<NamedQuery> namedQueryUsage = HibernateAnnotations.NAMED_QUERY.createUsage( final MutableAnnotationUsage<NamedQuery> namedQueryUsage = HibernateAnnotations.NAMED_QUERY.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
namedQueryList.add( namedQueryUsage ); namedQueryList.add( namedQueryUsage );
namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() );
@ -151,10 +148,7 @@ public class QueryProcessing {
ClassDetails classDetails, ClassDetails classDetails,
List<MutableAnnotationUsage<jakarta.persistence.NamedQuery>> namedQueryList, List<MutableAnnotationUsage<jakarta.persistence.NamedQuery>> namedQueryList,
SourceModelBuildingContext modelBuildingContext) { SourceModelBuildingContext modelBuildingContext) {
final MutableAnnotationUsage<jakarta.persistence.NamedQuery> namedQueryUsage = JpaAnnotations.NAMED_QUERY.createUsage( final MutableAnnotationUsage<jakarta.persistence.NamedQuery> namedQueryUsage = JpaAnnotations.NAMED_QUERY.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
namedQueryList.add( namedQueryUsage ); namedQueryList.add( namedQueryUsage );
namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() );
@ -173,10 +167,7 @@ public class QueryProcessing {
namedQueryUsage.setAttributeValue( "hints", hints ); namedQueryUsage.setAttributeValue( "hints", hints );
for ( JaxbQueryHint jaxbHint : jaxbNamedQuery.getHints() ) { for ( JaxbQueryHint jaxbHint : jaxbNamedQuery.getHints() ) {
final MutableAnnotationUsage<QueryHint> queryHintUsage = JpaAnnotations.QUERY_HINT.createUsage( final MutableAnnotationUsage<QueryHint> queryHintUsage = JpaAnnotations.QUERY_HINT.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
queryHintUsage.setAttributeValue( "name", jaxbHint.getName() ); queryHintUsage.setAttributeValue( "name", jaxbHint.getName() );
queryHintUsage.setAttributeValue( "value", jaxbHint.getValue() ); queryHintUsage.setAttributeValue( "value", jaxbHint.getValue() );
} }
@ -203,9 +194,9 @@ public class QueryProcessing {
if ( needsJpaNativeQuery( jaxbNamedQuery ) ) { if ( needsJpaNativeQuery( jaxbNamedQuery ) ) {
// @jakarta.persistence.NamedNativeQuery // @jakarta.persistence.NamedNativeQuery
if ( namedJpaQueryList == null ) { if ( namedJpaQueryList == null ) {
final MutableAnnotationUsage<jakarta.persistence.NamedNativeQueries> namedQueriesUsage = AnnotationUsageHelper.getOrCreateUsage( final MutableAnnotationUsage<jakarta.persistence.NamedNativeQueries> namedQueriesUsage = classDetails.replaceAnnotationUsage(
JpaAnnotations.NAMED_NATIVE_QUERY,
JpaAnnotations.NAMED_NATIVE_QUERIES, JpaAnnotations.NAMED_NATIVE_QUERIES,
classDetails,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( namedQueriesUsage ); classDetails.addAnnotationUsage( namedQueriesUsage );
@ -219,9 +210,9 @@ public class QueryProcessing {
else { else {
// @org.hibernate.annotations.NamedNativeQuery // @org.hibernate.annotations.NamedNativeQuery
if ( namedHibernateQueryList == null ) { if ( namedHibernateQueryList == null ) {
final MutableAnnotationUsage<NamedNativeQueries> namedQueriesUsage = AnnotationUsageHelper.getOrCreateUsage( final MutableAnnotationUsage<NamedNativeQueries> namedQueriesUsage = classDetails.replaceAnnotationUsage(
HibernateAnnotations.NAMED_NATIVE_QUERY,
HibernateAnnotations.NAMED_NATIVE_QUERIES, HibernateAnnotations.NAMED_NATIVE_QUERIES,
classDetails,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( namedQueriesUsage ); classDetails.addAnnotationUsage( namedQueriesUsage );
@ -248,10 +239,7 @@ public class QueryProcessing {
List<MutableAnnotationUsage<jakarta.persistence.NamedNativeQuery>> namedQueryUsageList, List<MutableAnnotationUsage<jakarta.persistence.NamedNativeQuery>> namedQueryUsageList,
SourceModelBuildingContext modelBuildingContext, SourceModelBuildingContext modelBuildingContext,
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<jakarta.persistence.NamedNativeQuery> namedQueryUsage = JpaAnnotations.NAMED_NATIVE_QUERY.createUsage( final MutableAnnotationUsage<jakarta.persistence.NamedNativeQuery> namedQueryUsage = JpaAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
namedQueryUsageList.add( namedQueryUsage ); namedQueryUsageList.add( namedQueryUsage );
namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() );
@ -345,10 +333,7 @@ public class QueryProcessing {
final ArrayList<MutableAnnotationUsage<ColumnResult>> columnResultList = CollectionHelper.arrayList( jaxbColumnResultList.size() ); final ArrayList<MutableAnnotationUsage<ColumnResult>> columnResultList = CollectionHelper.arrayList( jaxbColumnResultList.size() );
for ( JaxbColumnResultImpl jaxbColumnResult : jaxbColumnResultList ) { for ( JaxbColumnResultImpl jaxbColumnResult : jaxbColumnResultList ) {
final MutableAnnotationUsage<ColumnResult> columnResultUsage = JpaAnnotations.COLUMN_RESULT.createUsage( final MutableAnnotationUsage<ColumnResult> columnResultUsage = JpaAnnotations.COLUMN_RESULT.createUsage( modelBuildingContext );
annotationTarget,
modelBuildingContext
);
columnResultList.add( columnResultUsage ); columnResultList.add( columnResultUsage );
columnResultUsage.setAttributeValue( "name", jaxbColumnResult.getName() ); columnResultUsage.setAttributeValue( "name", jaxbColumnResult.getName() );
if ( isNotEmpty( jaxbColumnResult.getClazz() ) ) { if ( isNotEmpty( jaxbColumnResult.getClazz() ) ) {
@ -367,10 +352,7 @@ public class QueryProcessing {
final ArrayList<MutableAnnotationUsage<ConstructorResult>> constructorResultList = CollectionHelper.arrayList( jaxbConstructorResultList.size() ); final ArrayList<MutableAnnotationUsage<ConstructorResult>> constructorResultList = CollectionHelper.arrayList( jaxbConstructorResultList.size() );
for ( JaxbConstructorResultImpl jaxbConstructorResult : jaxbConstructorResultList ) { for ( JaxbConstructorResultImpl jaxbConstructorResult : jaxbConstructorResultList ) {
final MutableAnnotationUsage<ConstructorResult> constructorResultUsage = JpaAnnotations.CONSTRUCTOR_RESULT.createUsage( final MutableAnnotationUsage<ConstructorResult> constructorResultUsage = JpaAnnotations.CONSTRUCTOR_RESULT.createUsage( modelBuildingContext );
annotationTarget,
modelBuildingContext
);
constructorResultList.add( constructorResultUsage ); constructorResultList.add( constructorResultUsage );
constructorResultUsage.setAttributeValue( "targetClass", xmlDocumentContext.resolveJavaType( jaxbConstructorResult.getTargetClass() ) ); constructorResultUsage.setAttributeValue( "targetClass", xmlDocumentContext.resolveJavaType( jaxbConstructorResult.getTargetClass() ) );
@ -397,10 +379,7 @@ public class QueryProcessing {
final ArrayList<MutableAnnotationUsage<EntityResult>> entityResultList = CollectionHelper.arrayList( jaxbEntityResults.size() ); final ArrayList<MutableAnnotationUsage<EntityResult>> entityResultList = CollectionHelper.arrayList( jaxbEntityResults.size() );
for ( JaxbEntityResultImpl jaxbEntityResult : jaxbEntityResults ) { for ( JaxbEntityResultImpl jaxbEntityResult : jaxbEntityResults ) {
final MutableAnnotationUsage<EntityResult> entityResultUsage = JpaAnnotations.ENTITY_RESULT.createUsage( final MutableAnnotationUsage<EntityResult> entityResultUsage = JpaAnnotations.ENTITY_RESULT.createUsage( modelBuildingContext );
annotationTarget,
modelBuildingContext
);
entityResultList.add( entityResultUsage ); entityResultList.add( entityResultUsage );
entityResultUsage.setAttributeValue( "entityClass", xmlDocumentContext.resolveJavaType( jaxbEntityResult.getEntityClass() ) ); entityResultUsage.setAttributeValue( "entityClass", xmlDocumentContext.resolveJavaType( jaxbEntityResult.getEntityClass() ) );
@ -430,10 +409,7 @@ public class QueryProcessing {
final ArrayList<MutableAnnotationUsage<FieldResult>> fieldResultList = CollectionHelper.arrayList( jaxbFieldResults.size() ); final ArrayList<MutableAnnotationUsage<FieldResult>> fieldResultList = CollectionHelper.arrayList( jaxbFieldResults.size() );
for ( JaxbFieldResultImpl jaxbFieldResult : jaxbFieldResults ) { for ( JaxbFieldResultImpl jaxbFieldResult : jaxbFieldResults ) {
final MutableAnnotationUsage<FieldResult> fieldResultUsage = JpaAnnotations.FIELD_RESULT.createUsage( final MutableAnnotationUsage<FieldResult> fieldResultUsage = JpaAnnotations.FIELD_RESULT.createUsage( modelBuildingContext );
annotationTarget,
modelBuildingContext
);
fieldResultList.add( fieldResultUsage ); fieldResultList.add( fieldResultUsage );
fieldResultUsage.setAttributeValue( "name", jaxbFieldResult.getName() ); fieldResultUsage.setAttributeValue( "name", jaxbFieldResult.getName() );
@ -449,10 +425,7 @@ public class QueryProcessing {
List<MutableAnnotationUsage<NamedNativeQuery>> namedQueryUsageList, List<MutableAnnotationUsage<NamedNativeQuery>> namedQueryUsageList,
SourceModelBuildingContext modelBuildingContext, SourceModelBuildingContext modelBuildingContext,
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<NamedNativeQuery> namedQueryUsage = HibernateAnnotations.NAMED_NATIVE_QUERY.createUsage( final MutableAnnotationUsage<NamedNativeQuery> namedQueryUsage = HibernateAnnotations.NAMED_NATIVE_QUERY.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
namedQueryUsageList.add( namedQueryUsage ); namedQueryUsageList.add( namedQueryUsage );
namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() ); namedQueryUsage.setAttributeValue( "name", jaxbNamedQuery.getName() );
@ -471,19 +444,16 @@ public class QueryProcessing {
} }
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
final MutableAnnotationUsage<NamedStoredProcedureQueries> namedQueriesUsage = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERIES.createUsage( final MutableAnnotationUsage<NamedStoredProcedureQueries> namedQueriesUsage = classDetails.replaceAnnotationUsage(
classDetails, JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY,
JpaAnnotations.NAMED_STORED_PROCEDURE_QUERIES,
modelBuildingContext modelBuildingContext
); );
classDetails.addAnnotationUsage( namedQueriesUsage ); final List<AnnotationUsage<NamedStoredProcedureQuery>> namedQueryList = CollectionHelper.arrayList( jaxbEntity.getNamedStoredProcedureQueries().size() );
final ArrayList<AnnotationUsage<NamedStoredProcedureQuery>> namedQueryList = CollectionHelper.arrayList( jaxbEntity.getNamedStoredProcedureQueries().size() );
namedQueriesUsage.setAttributeValue( "value", namedQueryList ); namedQueriesUsage.setAttributeValue( "value", namedQueryList );
for ( JaxbNamedStoredProcedureQueryImpl jaxbQuery : jaxbEntity.getNamedStoredProcedureQueries() ) { for ( JaxbNamedStoredProcedureQueryImpl jaxbQuery : jaxbEntity.getNamedStoredProcedureQueries() ) {
final MutableAnnotationUsage<NamedStoredProcedureQuery> namedQueryUsage = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( final MutableAnnotationUsage<NamedStoredProcedureQuery> namedQueryUsage = JpaAnnotations.NAMED_STORED_PROCEDURE_QUERY.createUsage( modelBuildingContext );
classDetails,
modelBuildingContext
);
namedQueryList.add( namedQueryUsage ); namedQueryList.add( namedQueryUsage );
namedQueryUsage.setAttributeValue( "name", jaxbQuery.getName() ); namedQueryUsage.setAttributeValue( "name", jaxbQuery.getName() );
@ -511,10 +481,7 @@ public class QueryProcessing {
queryUsage.setAttributeValue( "parameters", parameterList ); queryUsage.setAttributeValue( "parameters", parameterList );
for ( JaxbStoredProcedureParameterImpl jaxbParameter : jaxbQuery.getProcedureParameters() ) { for ( JaxbStoredProcedureParameterImpl jaxbParameter : jaxbQuery.getProcedureParameters() ) {
final MutableAnnotationUsage<StoredProcedureParameter> parameterUsage = JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( final MutableAnnotationUsage<StoredProcedureParameter> parameterUsage = JpaAnnotations.STORED_PROCEDURE_PARAMETER.createUsage( sourceModelBuildingContext );
classDetails,
sourceModelBuildingContext
);
parameterList.add( parameterUsage ); parameterList.add( parameterUsage );
applyStringAttributeIfSpecified( "name", jaxbParameter.getName(), parameterUsage ); applyStringAttributeIfSpecified( "name", jaxbParameter.getName(), parameterUsage );

View File

@ -107,6 +107,7 @@ import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.CheckConstraint; import jakarta.persistence.CheckConstraint;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Convert; import jakarta.persistence.Convert;
import jakarta.persistence.Converts;
import jakarta.persistence.DiscriminatorColumn; import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -256,10 +257,8 @@ public class XmlAnnotationHelper {
List<AnnotationUsage<Parameter>> parameterAnnList = new ArrayList<>( jaxbParameters.size() ); List<AnnotationUsage<Parameter>> parameterAnnList = new ArrayList<>( jaxbParameters.size() );
jaxbParameters.forEach( (jaxbParam) -> { jaxbParameters.forEach( (jaxbParam) -> {
final MutableAnnotationUsage<Parameter> parameterUsage = HibernateAnnotations.PARAMETER.createUsage( final MutableAnnotationUsage<Parameter> parameterUsage =
null, HibernateAnnotations.PARAMETER.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
parameterAnnList.add( parameterUsage ); parameterAnnList.add( parameterUsage );
parameterUsage.setAttributeValue( "name", jaxbParam.getName() ); parameterUsage.setAttributeValue( "name", jaxbParam.getName() );
parameterUsage.setAttributeValue( "value", jaxbParam.getValue() ); parameterUsage.setAttributeValue( "value", jaxbParam.getValue() );
@ -371,10 +370,8 @@ public class XmlAnnotationHelper {
annotationUsage.setAttributeValue( "uniqueConstraints", uniqueConstraintUsages ); annotationUsage.setAttributeValue( "uniqueConstraints", uniqueConstraintUsages );
jaxbUniqueConstraints.forEach( (jaxbUniqueConstraint) -> { jaxbUniqueConstraints.forEach( (jaxbUniqueConstraint) -> {
final MutableAnnotationUsage<UniqueConstraint> ucUsage = JpaAnnotations.UNIQUE_CONSTRAINT.createUsage( final MutableAnnotationUsage<UniqueConstraint> ucUsage =
null, JpaAnnotations.UNIQUE_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "name", jaxbUniqueConstraint.getName() ); XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "name", jaxbUniqueConstraint.getName() );
XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "options", jaxbUniqueConstraint.getOptions() ); XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "options", jaxbUniqueConstraint.getOptions() );
ucUsage.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() ); ucUsage.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() );
@ -393,10 +390,8 @@ public class XmlAnnotationHelper {
final List<AnnotationUsage<Index>> indexes = new ArrayList<>( jaxbIndexes.size() ); final List<AnnotationUsage<Index>> indexes = new ArrayList<>( jaxbIndexes.size() );
jaxbIndexes.forEach( jaxbIndex -> { jaxbIndexes.forEach( jaxbIndex -> {
final MutableAnnotationUsage<Index> indexAnn = JpaAnnotations.INDEX.createUsage( final MutableAnnotationUsage<Index> indexAnn =
null, JpaAnnotations.INDEX.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, JpaAnnotations.INDEX ); applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, JpaAnnotations.INDEX );
applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", indexAnn, JpaAnnotations.INDEX ); applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", indexAnn, JpaAnnotations.INDEX );
applyOr( jaxbIndex, JaxbIndexImpl::isUnique, "unique", indexAnn, JpaAnnotations.INDEX ); applyOr( jaxbIndex, JaxbIndexImpl::isUnique, "unique", indexAnn, JpaAnnotations.INDEX );
@ -414,7 +409,7 @@ public class XmlAnnotationHelper {
if ( jaxbCheckable!= null && CollectionHelper.isNotEmpty( jaxbCheckable.getCheckConstraints() ) ) { if ( jaxbCheckable!= null && CollectionHelper.isNotEmpty( jaxbCheckable.getCheckConstraints() ) ) {
final List<AnnotationUsage<CheckConstraint>> checks = new ArrayList<>( jaxbCheckable.getCheckConstraints().size() ); final List<AnnotationUsage<CheckConstraint>> checks = new ArrayList<>( jaxbCheckable.getCheckConstraints().size() );
for ( JaxbCheckConstraintImpl jaxbCheck : jaxbCheckable.getCheckConstraints() ) { for ( JaxbCheckConstraintImpl jaxbCheck : jaxbCheckable.getCheckConstraints() ) {
final MutableAnnotationUsage<CheckConstraint> checkAnn = JpaAnnotations.CHECK_CONSTRAINT.createUsage( null, xmlDocumentContext.getModelBuildingContext() ); final MutableAnnotationUsage<CheckConstraint> checkAnn = JpaAnnotations.CHECK_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() );
checkAnn.setAttributeValue( "constraint", jaxbCheck.getConstraint() ); checkAnn.setAttributeValue( "constraint", jaxbCheck.getConstraint() );
applyOptionalAttribute( checkAnn, "name", jaxbCheck.getName() ); applyOptionalAttribute( checkAnn, "name", jaxbCheck.getName() );
applyOptionalAttribute( checkAnn, "options", jaxbCheck.getOptions() ); applyOptionalAttribute( checkAnn, "options", jaxbCheck.getOptions() );
@ -622,18 +617,12 @@ public class XmlAnnotationHelper {
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext(); final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
final MutableAnnotationUsage<AttributeOverride> overrideUsage = JpaAnnotations.ATTRIBUTE_OVERRIDE.createUsage( final MutableAnnotationUsage<AttributeOverride> overrideUsage = JpaAnnotations.ATTRIBUTE_OVERRIDE.createUsage( modelBuildingContext );
target,
modelBuildingContext
);
final String name = StringHelper.qualifyConditionally( namePrefix, jaxbOverride.getName() ); final String name = StringHelper.qualifyConditionally( namePrefix, jaxbOverride.getName() );
overrideUsage.setAttributeValue( "name", name ); overrideUsage.setAttributeValue( "name", name );
final MutableAnnotationUsage<Column> columnAnn = JpaAnnotations.COLUMN.createUsage( final MutableAnnotationUsage<Column> columnAnn = JpaAnnotations.COLUMN.createUsage( modelBuildingContext );
target,
modelBuildingContext
);
overrideUsage.setAttributeValue( "column", columnAnn ); overrideUsage.setAttributeValue( "column", columnAnn );
ColumnProcessing.applyColumnDetails( jaxbOverride.getColumn(), target, columnAnn, xmlDocumentContext ); ColumnProcessing.applyColumnDetails( jaxbOverride.getColumn(), target, columnAnn, xmlDocumentContext );
@ -656,11 +645,11 @@ public class XmlAnnotationHelper {
return; return;
} }
final MutableAnnotationUsage<AttributeOverrides> overridesUsage = target.applyAnnotationUsage( final MutableAnnotationUsage<AttributeOverrides> overridesUsage = target.replaceAnnotationUsage(
JpaAnnotations.ATTRIBUTE_OVERRIDE,
JpaAnnotations.ATTRIBUTE_OVERRIDES, JpaAnnotations.ATTRIBUTE_OVERRIDES,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
final ArrayList<MutableAnnotationUsage<AttributeOverride>> overrideUsages = arrayList( jaxbOverrides.size() ); final ArrayList<MutableAnnotationUsage<AttributeOverride>> overrideUsages = arrayList( jaxbOverrides.size() );
overridesUsage.setAttributeValue( "value", overrideUsages ); overridesUsage.setAttributeValue( "value", overrideUsages );
@ -682,7 +671,8 @@ public class XmlAnnotationHelper {
return; return;
} }
final MutableAnnotationUsage<AssociationOverrides> overridesUsage = target.applyAnnotationUsage( final MutableAnnotationUsage<AssociationOverrides> overridesUsage = target.replaceAnnotationUsage(
JpaAnnotations.ASSOCIATION_OVERRIDE,
JpaAnnotations.ASSOCIATION_OVERRIDES, JpaAnnotations.ASSOCIATION_OVERRIDES,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
@ -690,10 +680,8 @@ public class XmlAnnotationHelper {
overridesUsage.setAttributeValue( "value", overrideUsages ); overridesUsage.setAttributeValue( "value", overrideUsages );
jaxbOverrides.forEach( (jaxbOverride) -> { jaxbOverrides.forEach( (jaxbOverride) -> {
final MutableAnnotationUsage<AssociationOverride> overrideUsage = JpaAnnotations.ASSOCIATION_OVERRIDE.createUsage( final MutableAnnotationUsage<AssociationOverride> overrideUsage =
target, JpaAnnotations.ASSOCIATION_OVERRIDE.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
transferAssociationOverride( jaxbOverride, overrideUsage, target, xmlDocumentContext ); transferAssociationOverride( jaxbOverride, overrideUsage, target, xmlDocumentContext );
overrideUsages.add( overrideUsage ); overrideUsages.add( overrideUsage );
} ); } );
@ -728,6 +716,42 @@ public class XmlAnnotationHelper {
} }
public static void applyConverts(
List<JaxbConvertImpl> jaxbConverts,
String namePrefix,
MutableMemberDetails memberDetails,
XmlDocumentContext xmlDocumentContext) {
if ( CollectionHelper.isEmpty( jaxbConverts ) ) {
return;
}
final MutableAnnotationUsage<Converts> convertsUsage = memberDetails.replaceAnnotationUsage(
JpaAnnotations.CONVERT,
JpaAnnotations.CONVERTS,
xmlDocumentContext.getModelBuildingContext()
);
final ArrayList<MutableAnnotationUsage<Convert>> convertUsages = arrayList( jaxbConverts.size() );
convertsUsage.setAttributeValue( "value", convertUsages );
for ( JaxbConvertImpl jaxbConvert : jaxbConverts ) {
final MutableAnnotationUsage<Convert> convertUsage = JpaAnnotations.CONVERT.createUsage( xmlDocumentContext.getModelBuildingContext() );
convertUsages.add( convertUsage );
final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry();
final ClassDetails converter;
if ( StringHelper.isNotEmpty( jaxbConvert.getConverter() ) ) {
converter = classDetailsRegistry.resolveClassDetails( jaxbConvert.getConverter() );
convertUsage.setAttributeValue( "converter", converter );
}
XmlProcessingHelper.applyAttributeIfSpecified(
"attributeName",
prefixIfNotAlready( jaxbConvert.getAttributeName(), namePrefix ),
convertUsage
);
XmlProcessingHelper.applyAttributeIfSpecified( "disableConversion", jaxbConvert.isDisableConversion(), convertUsage );
}
}
public static void applyConvert( public static void applyConvert(
JaxbConvertImpl jaxbConvert, JaxbConvertImpl jaxbConvert,
@ -1025,20 +1049,17 @@ public class XmlAnnotationHelper {
} }
// replaces existing // replaces existing
final MutableAnnotationUsage<?> containerUsage = filterAnnotationDescriptor.getRepeatableContainer().createUsage( final MutableAnnotationUsage<?> containerUsage = target.replaceAnnotationUsage(
target, filterAnnotationDescriptor,
filterAnnotationDescriptor.getRepeatableContainer(),
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
target.addAnnotationUsage( containerUsage );
final ArrayList<Object> filterUsages = arrayList( filters.size() ); final ArrayList<Object> filterUsages = arrayList( filters.size() );
containerUsage.setAttributeValue( "value", filterUsages ); containerUsage.setAttributeValue( "value", filterUsages );
filters.forEach( (jaxbFilter) -> { filters.forEach( (jaxbFilter) -> {
final MutableAnnotationUsage<F> filterUsage = filterAnnotationDescriptor.createUsage( final MutableAnnotationUsage<F> filterUsage = filterAnnotationDescriptor.createUsage( xmlDocumentContext.getModelBuildingContext() );
null,
xmlDocumentContext.getModelBuildingContext()
);
filterUsages.add( filterUsage ); filterUsages.add( filterUsage );
filterUsage.setAttributeValue( "name", jaxbFilter.getName() ); filterUsage.setAttributeValue( "name", jaxbFilter.getName() );
@ -1058,10 +1079,8 @@ public class XmlAnnotationHelper {
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
final List<AnnotationUsage<SqlFragmentAlias>> sqlFragmentAliases = new ArrayList<>( aliases.size() ); final List<AnnotationUsage<SqlFragmentAlias>> sqlFragmentAliases = new ArrayList<>( aliases.size() );
for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) { for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) {
final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn = HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn =
null, HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
aliasAnn.setAttributeValue( "alias", alias.getAlias() ); aliasAnn.setAttributeValue( "alias", alias.getAlias() );
XmlProcessingHelper.applyAttributeIfSpecified( "table", alias.getTable(), aliasAnn ); XmlProcessingHelper.applyAttributeIfSpecified( "table", alias.getTable(), aliasAnn );

View File

@ -13,13 +13,9 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl;
import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType; import org.hibernate.boot.jaxb.mapping.spi.JaxbManagedType;
import org.hibernate.boot.models.MemberResolutionException; import org.hibernate.boot.models.MemberResolutionException;
import org.hibernate.boot.models.internal.AnnotationUsageHelper; import org.hibernate.boot.models.internal.AnnotationUsageHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.FieldDetails; import org.hibernate.models.spi.FieldDetails;
import org.hibernate.models.spi.MethodDetails; import org.hibernate.models.spi.MethodDetails;
import org.hibernate.models.spi.MutableAnnotationTarget;
import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableClassDetails; import org.hibernate.models.spi.MutableClassDetails;
import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.models.spi.MutableMemberDetails;
@ -111,52 +107,6 @@ public class XmlProcessingHelper {
} }
/**
* Find an existing annotation by name, or create one.
* Used when applying XML in override mode.
*/
public static <A extends Annotation> MutableAnnotationUsage<A> getOrMakeNamedAnnotation(
AnnotationDescriptor<A> annotationDescriptor,
String name,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
return getOrMakeNamedAnnotation( annotationDescriptor, name, "name", target, xmlDocumentContext );
}
/**
* Find an existing annotation by name, or create one.
* Used when applying XML in override mode.
*/
public static <A extends Annotation> MutableAnnotationUsage<A> getOrMakeNamedAnnotation(
AnnotationDescriptor<A> annotationDescriptor,
String name,
String attributeToMatch,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
if ( name == null ) {
return annotationDescriptor.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
}
final AnnotationUsage<A> existing = target.getNamedAnnotationUsage( annotationDescriptor, name, attributeToMatch );
if ( existing != null ) {
return (MutableAnnotationUsage<A>) existing;
}
return makeNamedAnnotation( annotationDescriptor, name, attributeToMatch, target, xmlDocumentContext );
}
private static <A extends Annotation> MutableAnnotationUsage<A> makeNamedAnnotation(
AnnotationDescriptor<A> annotationDescriptor,
String name,
String nameAttributeName,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<A> created = annotationDescriptor.createUsage( null, xmlDocumentContext.getModelBuildingContext() );
target.addAnnotationUsage( created );
created.setAttributeValue( nameAttributeName, name );
return created;
}
public static <A extends Annotation> void applyAttributeIfSpecified( public static <A extends Annotation> void applyAttributeIfSpecified(
String attributeName, String attributeName,
String value, String value,

View File

@ -102,7 +102,8 @@ public class AnyMappingAttributeProcessing {
final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry(); final ClassDetailsRegistry classDetailsRegistry = xmlDocumentContext.getModelBuildingContext().getClassDetailsRegistry();
final List<JaxbAnyDiscriminatorValueMappingImpl> valueMappings = jaxbDiscriminator.getValueMappings(); final List<JaxbAnyDiscriminatorValueMappingImpl> valueMappings = jaxbDiscriminator.getValueMappings();
if ( CollectionHelper.isNotEmpty( valueMappings ) ) { if ( CollectionHelper.isNotEmpty( valueMappings ) ) {
final MutableAnnotationUsage<AnyDiscriminatorValues> discriminatorValuesUsage = memberDetails.applyAnnotationUsage( final MutableAnnotationUsage<AnyDiscriminatorValues> discriminatorValuesUsage = memberDetails.replaceAnnotationUsage(
HibernateAnnotations.ANY_DISCRIMINATOR_VALUE,
HibernateAnnotations.ANY_DISCRIMINATOR_VALUES, HibernateAnnotations.ANY_DISCRIMINATOR_VALUES,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
@ -110,10 +111,8 @@ public class AnyMappingAttributeProcessing {
discriminatorValuesUsage.setAttributeValue( "value", valueList ); discriminatorValuesUsage.setAttributeValue( "value", valueList );
valueMappings.forEach( (valueMapping) -> { valueMappings.forEach( (valueMapping) -> {
final MutableAnnotationUsage<AnyDiscriminatorValue> discriminatorValueUsage = HibernateAnnotations.ANY_DISCRIMINATOR_VALUE.createUsage( final MutableAnnotationUsage<AnyDiscriminatorValue> discriminatorValueUsage =
null, HibernateAnnotations.ANY_DISCRIMINATOR_VALUE.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
valueList.add( discriminatorValueUsage ); valueList.add( discriminatorValueUsage );
discriminatorValueUsage.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() ); discriminatorValueUsage.setAttributeValue( "discriminator", valueMapping.getDiscriminatorValue() );
@ -153,10 +152,8 @@ public class AnyMappingAttributeProcessing {
final ArrayList<MutableAnnotationUsage<JoinColumn>> columnAnnList = CollectionHelper.arrayList( jaxbKey.getColumns().size() ); final ArrayList<MutableAnnotationUsage<JoinColumn>> columnAnnList = CollectionHelper.arrayList( jaxbKey.getColumns().size() );
joinColumnsUsage.setAttributeValue( "value", columnAnnList ); joinColumnsUsage.setAttributeValue( "value", columnAnnList );
jaxbKey.getColumns().forEach( (jaxbColumn) -> { jaxbKey.getColumns().forEach( (jaxbColumn) -> {
final MutableAnnotationUsage<JoinColumn> joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( final MutableAnnotationUsage<JoinColumn> joinColumnUsage =
null, JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
columnAnnList.add( joinColumnUsage ); columnAnnList.add( joinColumnUsage );
ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, joinColumnUsage, xmlDocumentContext ); ColumnProcessing.applyColumnDetails( jaxbColumn, memberDetails, joinColumnUsage, xmlDocumentContext );

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.boot.models.xml.internal.attr; package org.hibernate.boot.models.xml.internal.attr;
import java.util.List;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortComparator;
import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.SortNatural;
@ -30,6 +32,8 @@ import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableMemberDetails; import org.hibernate.models.spi.MutableMemberDetails;
import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.SourceModelBuildingContext;
import jakarta.persistence.Convert;
import jakarta.persistence.Converts;
import jakarta.persistence.MapKey; import jakarta.persistence.MapKey;
import jakarta.persistence.MapKeyClass; import jakarta.persistence.MapKeyClass;
import jakarta.persistence.MapKeyEnumerated; import jakarta.persistence.MapKeyEnumerated;

View File

@ -64,6 +64,15 @@ public class ElementCollectionAttributeProcessing {
targetUsage.setAttributeValue( "value", xmlDocumentContext.resolveClassName( targetClass ) ); targetUsage.setAttributeValue( "value", xmlDocumentContext.resolveClassName( targetClass ) );
} }
// NOTE: it is important that this happens before the `CommonPluralAttributeProcessing#applyPluralAttributeStructure`
// call below
XmlAnnotationHelper.applyConverts(
jaxbElementCollection.getConverts(),
null,
memberDetails,
xmlDocumentContext
);
CommonAttributeProcessing.applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionUsage, accessType, xmlDocumentContext ); CommonAttributeProcessing.applyAttributeBasics( jaxbElementCollection, memberDetails, elementCollectionUsage, accessType, xmlDocumentContext );
CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbElementCollection, memberDetails, xmlDocumentContext ); CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbElementCollection, memberDetails, xmlDocumentContext );
@ -81,11 +90,6 @@ public class ElementCollectionAttributeProcessing {
XmlAnnotationHelper.applyTemporal( jaxbElementCollection.getTemporal(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyTemporal( jaxbElementCollection.getTemporal(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyBasicTypeComposition( jaxbElementCollection, memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyBasicTypeComposition( jaxbElementCollection, memberDetails, xmlDocumentContext );
jaxbElementCollection.getConverts().forEach( (jaxbConvert) -> XmlAnnotationHelper.applyConvert(
jaxbConvert,
memberDetails,
xmlDocumentContext
) );
XmlAnnotationHelper.applyAttributeOverrides( jaxbElementCollection, memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyAttributeOverrides( jaxbElementCollection, memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyAssociationOverrides( jaxbElementCollection.getAssociationOverrides(), memberDetails, xmlDocumentContext ); XmlAnnotationHelper.applyAssociationOverrides( jaxbElementCollection.getAssociationOverrides(), memberDetails, xmlDocumentContext );

View File

@ -70,10 +70,7 @@ public class ForeignKeyProcessing {
XmlDocumentContext xmlDocumentContext) { XmlDocumentContext xmlDocumentContext) {
assert jaxbForeignKey != null; assert jaxbForeignKey != null;
final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( xmlDocumentContext.getModelBuildingContext() );
null,
xmlDocumentContext.getModelBuildingContext()
);
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() ); XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() );
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "value", jaxbForeignKey.getConstraintMode() ); XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "value", jaxbForeignKey.getConstraintMode() );

View File

@ -18,10 +18,8 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumnImpl;
import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnJoined; import org.hibernate.boot.jaxb.mapping.spi.db.JaxbColumnJoined;
import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper; import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext; import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.AnnotationUsage; import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.MutableAnnotationUsage; import org.hibernate.models.spi.MutableAnnotationUsage;
@ -55,29 +53,19 @@ public class JoinColumnProcessing {
return; return;
} }
if ( jaxbJoinColumns.size() == 1 ) { final MutableAnnotationUsage<MapKeyJoinColumns> joinColumnsUsage = memberDetails.replaceAnnotationUsage(
final MutableAnnotationUsage<MapKeyJoinColumn> joinColumnUsage = memberDetails.applyAnnotationUsage( JpaAnnotations.MAP_KEY_JOIN_COLUMN,
JpaAnnotations.MAP_KEY_JOIN_COLUMN, JpaAnnotations.MAP_KEY_JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
transferJoinColumn( jaxbJoinColumns.get( 0 ), joinColumnUsage, memberDetails, xmlDocumentContext ); final ArrayList<MutableAnnotationUsage<MapKeyJoinColumn>> joinColumnUsages = CollectionHelper.arrayList( jaxbJoinColumns.size() );
} joinColumnsUsage.setAttributeValue( "value", joinColumnUsages );
else { jaxbJoinColumns.forEach( (jaxbJoinColumn) -> {
final MutableAnnotationUsage<MapKeyJoinColumns> joinColumnsUsage = memberDetails.applyAnnotationUsage( final MutableAnnotationUsage<MapKeyJoinColumn> joinColumnUsage =
JpaAnnotations.MAP_KEY_JOIN_COLUMNS, JpaAnnotations.MAP_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext() joinColumnUsages.add( joinColumnUsage );
); transferJoinColumn( jaxbJoinColumn, joinColumnUsage, memberDetails, xmlDocumentContext );
final ArrayList<MutableAnnotationUsage<MapKeyJoinColumn>> joinColumnUsages = CollectionHelper.arrayList( jaxbJoinColumns.size() ); } );
joinColumnsUsage.setAttributeValue( "value", joinColumnUsages );
jaxbJoinColumns.forEach( (jaxbJoinColumn) -> {
final MutableAnnotationUsage<MapKeyJoinColumn> joinColumnUsage = JpaAnnotations.MAP_KEY_JOIN_COLUMN.createUsage(
memberDetails,
xmlDocumentContext.getModelBuildingContext()
);
joinColumnUsages.add( joinColumnUsage );
transferJoinColumn( jaxbJoinColumn, joinColumnUsage, memberDetails, xmlDocumentContext );
} );
}
} }
/** /**
@ -93,7 +81,8 @@ public class JoinColumnProcessing {
return; return;
} }
final MutableAnnotationUsage<PrimaryKeyJoinColumns> columnsUsage = memberDetails.applyAnnotationUsage( final MutableAnnotationUsage<PrimaryKeyJoinColumns> columnsUsage = memberDetails.replaceAnnotationUsage(
JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN,
JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );
@ -101,10 +90,8 @@ public class JoinColumnProcessing {
columnsUsage.setAttributeValue( "value", columnUsages ); columnsUsage.setAttributeValue( "value", columnUsages );
jaxbJoinColumns.forEach( (jaxbJoinColumn) -> { jaxbJoinColumns.forEach( (jaxbJoinColumn) -> {
final MutableAnnotationUsage<PrimaryKeyJoinColumn> columnUsage = JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( final MutableAnnotationUsage<PrimaryKeyJoinColumn> columnUsage =
memberDetails, JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
columnUsages.add( columnUsage ); columnUsages.add( columnUsage );
transferJoinColumn( transferJoinColumn(
@ -152,31 +139,14 @@ public class JoinColumnProcessing {
} }
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() ); final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
jaxbJoinColumns.forEach( jaxbJoinColumn -> { jaxbJoinColumns.forEach( jaxbJoinColumn -> {
final MutableAnnotationUsage<JoinColumn> joinColumnAnn = JpaAnnotations.JOIN_COLUMN.createUsage( final MutableAnnotationUsage<JoinColumn> joinColumnAnn =
null, JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
xmlDocumentContext.getModelBuildingContext()
);
transferJoinColumn( jaxbJoinColumn, joinColumnAnn, null, xmlDocumentContext ); transferJoinColumn( jaxbJoinColumn, joinColumnAnn, null, xmlDocumentContext );
joinColumns.add( joinColumnAnn ); joinColumns.add( joinColumnAnn );
} ); } );
return joinColumns; return joinColumns;
} }
public static <A extends Annotation> MutableAnnotationUsage<A> createJoinColumnAnnotation(
JaxbColumnJoined jaxbJoinColumn,
MutableMemberDetails memberDetails,
AnnotationDescriptor<A> annotationDescriptor,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<A> joinColumnAnn = XmlProcessingHelper.getOrMakeNamedAnnotation(
annotationDescriptor,
jaxbJoinColumn.getName(),
memberDetails,
xmlDocumentContext
);
transferJoinColumn( jaxbJoinColumn, joinColumnAnn, memberDetails, xmlDocumentContext );
return joinColumnAnn;
}
public static List<AnnotationUsage<JoinColumn>> createJoinColumns( public static List<AnnotationUsage<JoinColumn>> createJoinColumns(
List<JaxbJoinColumnImpl> jaxbJoinColumns, List<JaxbJoinColumnImpl> jaxbJoinColumns,
AnnotationTarget annotationTarget, AnnotationTarget annotationTarget,
@ -186,10 +156,7 @@ public class JoinColumnProcessing {
} }
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() ); final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
jaxbJoinColumns.forEach( jaxbJoinColumn -> { jaxbJoinColumns.forEach( jaxbJoinColumn -> {
final MutableAnnotationUsage<JoinColumn> joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( final MutableAnnotationUsage<JoinColumn> joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
annotationTarget,
xmlDocumentContext.getModelBuildingContext()
);
transferJoinColumn( transferJoinColumn(
jaxbJoinColumn, jaxbJoinColumn,
joinColumnUsage, joinColumnUsage,
@ -209,7 +176,8 @@ public class JoinColumnProcessing {
return; return;
} }
final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.applyAnnotationUsage( final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.replaceAnnotationUsage(
JpaAnnotations.JOIN_COLUMN,
JpaAnnotations.JOIN_COLUMNS, JpaAnnotations.JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext() xmlDocumentContext.getModelBuildingContext()
); );

View File

@ -311,8 +311,8 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm14.xml" ); final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm14.xml" );
assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue(); assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isTrue(); assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse(); assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse(); assertThat( memberDetails.hasAnnotationUsage( MapKey.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse(); assertThat( memberDetails.hasAnnotationUsage( MapKeyClass.class ) ).isFalse();

View File

@ -19,6 +19,7 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.models.internal.dynamic.DynamicClassDetails; import org.hibernate.models.internal.dynamic.DynamicClassDetails;
import org.hibernate.models.internal.dynamic.DynamicFieldDetails;
import org.hibernate.models.internal.jdk.JdkClassDetails; import org.hibernate.models.internal.jdk.JdkClassDetails;
import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry; import org.hibernate.models.spi.ClassDetailsRegistry;
@ -374,22 +375,24 @@ public class AdditionalMappingContributorTests {
modelBuildingContext modelBuildingContext
); );
entityUsage.setAttributeValue( "name", "Entity6" ); entityUsage.setAttributeValue( "name", "Entity6" );
classDetails.applyAttribute(
final DynamicFieldDetails idMember = classDetails.applyAttribute(
"id", "id",
classDetailsRegistry.resolveClassDetails( Integer.class.getName() ), classDetailsRegistry.resolveClassDetails( Integer.class.getName() ),
false, false,
false, false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ),
modelBuildingContext modelBuildingContext
); );
classDetails.applyAttribute( idMember.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );
final DynamicFieldDetails nameMember = classDetails.applyAttribute(
"name", "name",
classDetailsRegistry.resolveClassDetails( String.class.getName() ), classDetailsRegistry.resolveClassDetails( String.class.getName() ),
false, false,
false, false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext ),
modelBuildingContext modelBuildingContext
); );
nameMember.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext );
return classDetails; return classDetails;
} }

View File

@ -70,7 +70,7 @@ dependencyResolutionManagement {
def byteBuddyVersion = version "byteBuddy", "1.14.18" def byteBuddyVersion = version "byteBuddy", "1.14.18"
def classmateVersion = version "classmate", "1.5.1" def classmateVersion = version "classmate", "1.5.1"
def geolatteVersion = version "geolatte", "1.9.1" def geolatteVersion = version "geolatte", "1.9.1"
def hibernateModelsVersion = version "hibernateModels", "0.7.9" def hibernateModelsVersion = version "hibernateModels", "0.8.3"
def jandexVersion = version "jandex", "3.2.0" def jandexVersion = version "jandex", "3.2.0"
def hcannVersion = version "hcann", "7.0.1.Final" def hcannVersion = version "hcann", "7.0.1.Final"
def jacksonVersion = version "jackson", "2.17.0" def jacksonVersion = version "jackson", "2.17.0"