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) {
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 );
return builder.build();
}
private static IdentifierGeneratorDefinition buildSequenceGeneratorDefinition(String name) {
final Builder builder = new Builder();
final MutableAnnotationUsage<SequenceGenerator> sequenceGeneratorUsage = JpaAnnotations.SEQUENCE_GENERATOR.createUsage(
null,
null
);
final MutableAnnotationUsage<SequenceGenerator> sequenceGeneratorUsage = JpaAnnotations.SEQUENCE_GENERATOR.createUsage( null );
applyStringAttributeIfSpecified( "name", name, sequenceGeneratorUsage );
GenerationStrategyInterpreter.STRATEGY_INTERPRETER.interpretSequenceGenerator( sequenceGeneratorUsage, builder );
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.ClassDetails;
import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType;
import org.hibernate.usertype.internal.OffsetTimeCompositeUserType;
@ -485,37 +486,26 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
AnnotationUsage<Column> column,
MetadataBuildingContext context) {
final AnnotationUsage<TimeZoneColumn> timeZoneColumn = element.getAnnotationUsage( TimeZoneColumn.class );
return JpaAnnotations.COLUMN.createUsage(
element,
(created) -> {
final String columnName = timeZoneColumn != null
? timeZoneColumn.getString( "name" )
: column.getString( "name" ) + "_tz";
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", columnName, created );
AnnotationUsageHelper.applyAttributeIfSpecified(
"nullable",
column.getBoolean( "nullable" ),
created
);
final MutableAnnotationUsage<Column> created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
final String columnName = timeZoneColumn != null
? timeZoneColumn.getString( "name" )
: column.getString( "name" ) + "_tz";
created.setAttributeValue( "name", columnName );
final AnnotationUsage<?> source = timeZoneColumn != null
? timeZoneColumn
: column;
AnnotationUsageHelper.applyStringAttributeIfSpecified( "table", source.getAttributeValue( "table" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "nullable", column.getBoolean( "nullable" ), created );
if ( timeZoneColumn != null ) {
AnnotationUsageHelper
.applyStringAttributeIfSpecified(
"columnDefinition",
timeZoneColumn.getAttributeValue( "columnDefinition" ),
created
);
}
},
context.getMetadataCollector().getSourceModelBuildingContext()
);
final AnnotationUsage<?> source = timeZoneColumn != null
? timeZoneColumn
: column;
AnnotationUsageHelper.applyAttributeIfSpecified( "table", source.getString( "table" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "insertable", source.getAttributeValue( "insertable" ), created );
AnnotationUsageHelper.applyAttributeIfSpecified( "updatable", source.getAttributeValue( "updatable" ), created );
if ( timeZoneColumn != null ) {
AnnotationUsageHelper.applyStringAttributeIfSpecified( "columnDefinition", timeZoneColumn.getAttributeValue( "columnDefinition" ), created );
}
return created;
}
private static AnnotationUsage<Column> createTemporalColumn(
@ -561,15 +551,11 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
)
);
return JpaAnnotations.COLUMN.createUsage(
element,
(created) -> {
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), created );
created.setAttributeValue( "precision", precision );
created.setAttributeValue( "secondPrecision", secondPrecision );
},
context.getMetadataCollector().getSourceModelBuildingContext()
);
final MutableAnnotationUsage<Column> usage = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
AnnotationUsageHelper.applyStringAttributeIfSpecified( "name", implicitName.getText(), usage );
usage.setAttributeValue( "precision", precision );
usage.setAttributeValue( "secondPrecision", secondPrecision );
return usage;
}
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.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.spi.MetadataBuildingContext;
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.MemberDetails;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.SourceModelBuildingContext;
import jakarta.persistence.CheckConstraint;
@ -315,39 +315,33 @@ class ColumnsBuilder {
AnnotationUsage<PrimaryKeyJoinColumn> pkJoinColumnAnn,
MemberDetails property) {
final SourceModelBuildingContext hibernateModelsContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext();
final AnnotationDescriptorRegistry descriptorRegistry = hibernateModelsContext.getAnnotationDescriptorRegistry();
final AnnotationDescriptor<JoinColumn> joinColumnDescriptor = descriptorRegistry.getDescriptor( JoinColumn.class );
return joinColumnDescriptor.createUsage(
property,
(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
final MutableAnnotationUsage<JoinColumn> usage = JpaAnnotations.JOIN_COLUMN.createUsage( hibernateModelsContext );
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
);
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.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jpa.event.internal.CallbackDefinitionResolver;
import org.hibernate.jpa.event.spi.CallbackType;
import org.hibernate.mapping.BasicValue;
@ -124,7 +124,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.IdClass;
import jakarta.persistence.Index;
import jakarta.persistence.Inheritance;
import jakarta.persistence.JoinColumn;
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.BinderHelper.getOverrideAnnotation;
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.overrideMatchesDialect;
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.EmbeddableBinder.fillEmbeddable;
@ -1789,16 +1788,9 @@ public class EntityBinder {
}
private static AnnotationUsage<Cache> buildCacheMock(ClassDetails classDetails, MetadataBuildingContext context) {
final MutableAnnotationUsage<Cache> cacheUsage = HibernateAnnotations.CACHE.createUsage(
classDetails,
context.getMetadataCollector().getSourceModelBuildingContext()
);
final MutableAnnotationUsage<Cache> cacheUsage = HibernateAnnotations.CACHE.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() );
applyAttributeIfSpecified( "region", classDetails.getName(), cacheUsage );
applyAttributeIfSpecified(
"usage",
determineCacheConcurrencyStrategy( context ),
cacheUsage
);
applyAttributeIfSpecified( "usage", determineCacheConcurrencyStrategy( context ), cacheUsage );
return cacheUsage;
}

View File

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

View File

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

View File

@ -693,7 +693,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
}
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) {
@ -855,7 +855,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
}
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 );
sqlResultSetMappingRegistrations.put(
@ -906,7 +906,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
entityResultAnnotation.setAttributeValue( "fields", fieldResults );
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 );
// both name and column are required
fieldResultAnnotation.setAttributeValue( "name", jaxbFieldResult.getName() );

View File

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

View File

@ -9,10 +9,7 @@ package org.hibernate.boot.models.internal;
import java.lang.annotation.Annotation;
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.SourceModelBuildingContext;
public class AnnotationUsageHelper {
@ -30,30 +27,4 @@ public class AnnotationUsageHelper {
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 MutableAnnotationUsage<NamedEntityGraphs> entityGraphsUsage = JpaAnnotations.NAMED_ENTITY_GRAPHS.createUsage(
classDetails,
final MutableAnnotationUsage<NamedEntityGraphs> entityGraphsUsage = classDetails.replaceAnnotationUsage(
JpaAnnotations.NAMED_ENTITY_GRAPH,
JpaAnnotations.NAMED_ENTITY_GRAPHS,
modelBuildingContext
);
classDetails.addAnnotationUsage( entityGraphsUsage );
final ArrayList<Object> entityGraphList = arrayList( jaxbEntityGraphs.size() );
entityGraphsUsage.setAttributeValue( "value", entityGraphList );
@ -68,10 +68,7 @@ public class EntityGraphProcessing {
ClassDetails classDetails,
SourceModelBuildingContext modelBuildingContext,
XmlDocumentContext xmlDocumentContext) {
final MutableAnnotationUsage<NamedEntityGraph> graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage(
classDetails,
modelBuildingContext
);
final MutableAnnotationUsage<NamedEntityGraph> graphUsage = JpaAnnotations.NAMED_ENTITY_GRAPH.createUsage( modelBuildingContext );
applyStringAttributeIfSpecified( "name", jaxbEntityGraph.getName(), graphUsage );
applyAttributeIfSpecified( "includeAllAttributes", jaxbEntityGraph.isIncludeAllAttributes(), graphUsage );
@ -118,10 +115,7 @@ public class EntityGraphProcessing {
final ArrayList<MutableAnnotationUsage<NamedAttributeNode>> attributeNodeList = arrayList( jaxbAttributeNodes.size() );
for ( JaxbNamedAttributeNodeImpl jaxbAttributeNode : jaxbAttributeNodes ) {
final MutableAnnotationUsage<NamedAttributeNode> namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage(
classDetails,
modelBuildingContext
);
final MutableAnnotationUsage<NamedAttributeNode> namedAttributeNodeAnn = NAMED_ATTRIBUTE_NODE.createUsage( modelBuildingContext );
attributeNodeList.add( namedAttributeNodeAnn );
namedAttributeNodeAnn.setAttributeValue( "value", jaxbAttributeNode.getName() );
@ -141,10 +135,7 @@ public class EntityGraphProcessing {
final List<MutableAnnotationUsage<NamedSubgraph>> subgraphAnnotations = arrayList( jaxbSubgraphs.size() );
for ( JaxbNamedSubgraphImpl jaxbSubgraph : jaxbSubgraphs ) {
final MutableAnnotationUsage<NamedSubgraph> namedSubGraphUsage = JpaAnnotations.NAMED_SUB_GRAPH.createUsage(
classDetails,
modelBuildingContext
);
final MutableAnnotationUsage<NamedSubgraph> namedSubGraphUsage = JpaAnnotations.NAMED_SUB_GRAPH.createUsage( modelBuildingContext );
subgraphAnnotations.add( namedSubGraphUsage );
namedSubGraphUsage.setAttributeValue( "name", jaxbSubgraph.getName() );

View File

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

View File

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

View File

@ -107,6 +107,7 @@ import jakarta.persistence.AttributeOverrides;
import jakarta.persistence.CheckConstraint;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Converts;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
@ -256,10 +257,8 @@ public class XmlAnnotationHelper {
List<AnnotationUsage<Parameter>> parameterAnnList = new ArrayList<>( jaxbParameters.size() );
jaxbParameters.forEach( (jaxbParam) -> {
final MutableAnnotationUsage<Parameter> parameterUsage = HibernateAnnotations.PARAMETER.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<Parameter> parameterUsage =
HibernateAnnotations.PARAMETER.createUsage( xmlDocumentContext.getModelBuildingContext() );
parameterAnnList.add( parameterUsage );
parameterUsage.setAttributeValue( "name", jaxbParam.getName() );
parameterUsage.setAttributeValue( "value", jaxbParam.getValue() );
@ -371,10 +370,8 @@ public class XmlAnnotationHelper {
annotationUsage.setAttributeValue( "uniqueConstraints", uniqueConstraintUsages );
jaxbUniqueConstraints.forEach( (jaxbUniqueConstraint) -> {
final MutableAnnotationUsage<UniqueConstraint> ucUsage = JpaAnnotations.UNIQUE_CONSTRAINT.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<UniqueConstraint> ucUsage =
JpaAnnotations.UNIQUE_CONSTRAINT.createUsage( xmlDocumentContext.getModelBuildingContext() );
XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "name", jaxbUniqueConstraint.getName() );
XmlAnnotationHelper.applyOptionalAttribute( ucUsage, "options", jaxbUniqueConstraint.getOptions() );
ucUsage.setAttributeValue( "columnNames", jaxbUniqueConstraint.getColumnName() );
@ -393,10 +390,8 @@ public class XmlAnnotationHelper {
final List<AnnotationUsage<Index>> indexes = new ArrayList<>( jaxbIndexes.size() );
jaxbIndexes.forEach( jaxbIndex -> {
final MutableAnnotationUsage<Index> indexAnn = JpaAnnotations.INDEX.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<Index> indexAnn =
JpaAnnotations.INDEX.createUsage( xmlDocumentContext.getModelBuildingContext() );
applyOr( jaxbIndex, JaxbIndexImpl::getName, "name", indexAnn, JpaAnnotations.INDEX );
applyOr( jaxbIndex, JaxbIndexImpl::getColumnList, "columnList", 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() ) ) {
final List<AnnotationUsage<CheckConstraint>> checks = new ArrayList<>( jaxbCheckable.getCheckConstraints().size() );
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() );
applyOptionalAttribute( checkAnn, "name", jaxbCheck.getName() );
applyOptionalAttribute( checkAnn, "options", jaxbCheck.getOptions() );
@ -622,18 +617,12 @@ public class XmlAnnotationHelper {
XmlDocumentContext xmlDocumentContext) {
final SourceModelBuildingContext modelBuildingContext = xmlDocumentContext.getModelBuildingContext();
final MutableAnnotationUsage<AttributeOverride> overrideUsage = JpaAnnotations.ATTRIBUTE_OVERRIDE.createUsage(
target,
modelBuildingContext
);
final MutableAnnotationUsage<AttributeOverride> overrideUsage = JpaAnnotations.ATTRIBUTE_OVERRIDE.createUsage( modelBuildingContext );
final String name = StringHelper.qualifyConditionally( namePrefix, jaxbOverride.getName() );
overrideUsage.setAttributeValue( "name", name );
final MutableAnnotationUsage<Column> columnAnn = JpaAnnotations.COLUMN.createUsage(
target,
modelBuildingContext
);
final MutableAnnotationUsage<Column> columnAnn = JpaAnnotations.COLUMN.createUsage( modelBuildingContext );
overrideUsage.setAttributeValue( "column", columnAnn );
ColumnProcessing.applyColumnDetails( jaxbOverride.getColumn(), target, columnAnn, xmlDocumentContext );
@ -656,11 +645,11 @@ public class XmlAnnotationHelper {
return;
}
final MutableAnnotationUsage<AttributeOverrides> overridesUsage = target.applyAnnotationUsage(
final MutableAnnotationUsage<AttributeOverrides> overridesUsage = target.replaceAnnotationUsage(
JpaAnnotations.ATTRIBUTE_OVERRIDE,
JpaAnnotations.ATTRIBUTE_OVERRIDES,
xmlDocumentContext.getModelBuildingContext()
);
final ArrayList<MutableAnnotationUsage<AttributeOverride>> overrideUsages = arrayList( jaxbOverrides.size() );
overridesUsage.setAttributeValue( "value", overrideUsages );
@ -682,7 +671,8 @@ public class XmlAnnotationHelper {
return;
}
final MutableAnnotationUsage<AssociationOverrides> overridesUsage = target.applyAnnotationUsage(
final MutableAnnotationUsage<AssociationOverrides> overridesUsage = target.replaceAnnotationUsage(
JpaAnnotations.ASSOCIATION_OVERRIDE,
JpaAnnotations.ASSOCIATION_OVERRIDES,
xmlDocumentContext.getModelBuildingContext()
);
@ -690,10 +680,8 @@ public class XmlAnnotationHelper {
overridesUsage.setAttributeValue( "value", overrideUsages );
jaxbOverrides.forEach( (jaxbOverride) -> {
final MutableAnnotationUsage<AssociationOverride> overrideUsage = JpaAnnotations.ASSOCIATION_OVERRIDE.createUsage(
target,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<AssociationOverride> overrideUsage =
JpaAnnotations.ASSOCIATION_OVERRIDE.createUsage( xmlDocumentContext.getModelBuildingContext() );
transferAssociationOverride( jaxbOverride, overrideUsage, target, xmlDocumentContext );
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(
JaxbConvertImpl jaxbConvert,
@ -1025,20 +1049,17 @@ public class XmlAnnotationHelper {
}
// replaces existing
final MutableAnnotationUsage<?> containerUsage = filterAnnotationDescriptor.getRepeatableContainer().createUsage(
target,
final MutableAnnotationUsage<?> containerUsage = target.replaceAnnotationUsage(
filterAnnotationDescriptor,
filterAnnotationDescriptor.getRepeatableContainer(),
xmlDocumentContext.getModelBuildingContext()
);
target.addAnnotationUsage( containerUsage );
final ArrayList<Object> filterUsages = arrayList( filters.size() );
containerUsage.setAttributeValue( "value", filterUsages );
filters.forEach( (jaxbFilter) -> {
final MutableAnnotationUsage<F> filterUsage = filterAnnotationDescriptor.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<F> filterUsage = filterAnnotationDescriptor.createUsage( xmlDocumentContext.getModelBuildingContext() );
filterUsages.add( filterUsage );
filterUsage.setAttributeValue( "name", jaxbFilter.getName() );
@ -1058,10 +1079,8 @@ public class XmlAnnotationHelper {
XmlDocumentContext xmlDocumentContext) {
final List<AnnotationUsage<SqlFragmentAlias>> sqlFragmentAliases = new ArrayList<>( aliases.size() );
for ( JaxbHbmFilterImpl.JaxbAliasesImpl alias : aliases ) {
final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn = HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<SqlFragmentAlias> aliasAnn =
HibernateAnnotations.SQL_FRAGMENT_ALIAS.createUsage( xmlDocumentContext.getModelBuildingContext() );
aliasAnn.setAttributeValue( "alias", alias.getAlias() );
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.models.MemberResolutionException;
import org.hibernate.boot.models.internal.AnnotationUsageHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.FieldDetails;
import org.hibernate.models.spi.MethodDetails;
import org.hibernate.models.spi.MutableAnnotationTarget;
import org.hibernate.models.spi.MutableAnnotationUsage;
import org.hibernate.models.spi.MutableClassDetails;
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(
String attributeName,
String value,

View File

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

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.boot.models.xml.internal.attr;
import java.util.List;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.SortComparator;
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.SourceModelBuildingContext;
import jakarta.persistence.Convert;
import jakarta.persistence.Converts;
import jakarta.persistence.MapKey;
import jakarta.persistence.MapKeyClass;
import jakarta.persistence.MapKeyEnumerated;

View File

@ -64,6 +64,15 @@ public class ElementCollectionAttributeProcessing {
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 );
CommonPluralAttributeProcessing.applyPluralAttributeStructure( jaxbElementCollection, memberDetails, xmlDocumentContext );
@ -81,11 +90,6 @@ public class ElementCollectionAttributeProcessing {
XmlAnnotationHelper.applyTemporal( jaxbElementCollection.getTemporal(), memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyBasicTypeComposition( jaxbElementCollection, memberDetails, xmlDocumentContext );
jaxbElementCollection.getConverts().forEach( (jaxbConvert) -> XmlAnnotationHelper.applyConvert(
jaxbConvert,
memberDetails,
xmlDocumentContext
) );
XmlAnnotationHelper.applyAttributeOverrides( jaxbElementCollection, memberDetails, xmlDocumentContext );
XmlAnnotationHelper.applyAssociationOverrides( jaxbElementCollection.getAssociationOverrides(), memberDetails, xmlDocumentContext );

View File

@ -70,10 +70,7 @@ public class ForeignKeyProcessing {
XmlDocumentContext xmlDocumentContext) {
assert jaxbForeignKey != null;
final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<ForeignKey> foreignKeyUsage = JpaAnnotations.FOREIGN_KEY.createUsage( xmlDocumentContext.getModelBuildingContext() );
XmlAnnotationHelper.applyOptionalAttribute( foreignKeyUsage, "name", jaxbForeignKey.getName() );
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.models.JpaAnnotations;
import org.hibernate.boot.models.xml.internal.XmlAnnotationHelper;
import org.hibernate.boot.models.xml.internal.XmlProcessingHelper;
import org.hibernate.boot.models.xml.spi.XmlDocumentContext;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AnnotationTarget;
import org.hibernate.models.spi.AnnotationUsage;
import org.hibernate.models.spi.MutableAnnotationUsage;
@ -55,29 +53,19 @@ public class JoinColumnProcessing {
return;
}
if ( jaxbJoinColumns.size() == 1 ) {
final MutableAnnotationUsage<MapKeyJoinColumn> joinColumnUsage = memberDetails.applyAnnotationUsage(
JpaAnnotations.MAP_KEY_JOIN_COLUMN,
xmlDocumentContext.getModelBuildingContext()
);
transferJoinColumn( jaxbJoinColumns.get( 0 ), joinColumnUsage, memberDetails, xmlDocumentContext );
}
else {
final MutableAnnotationUsage<MapKeyJoinColumns> joinColumnsUsage = memberDetails.applyAnnotationUsage(
JpaAnnotations.MAP_KEY_JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);
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 );
} );
}
final MutableAnnotationUsage<MapKeyJoinColumns> joinColumnsUsage = memberDetails.replaceAnnotationUsage(
JpaAnnotations.MAP_KEY_JOIN_COLUMN,
JpaAnnotations.MAP_KEY_JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);
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( xmlDocumentContext.getModelBuildingContext() );
joinColumnUsages.add( joinColumnUsage );
transferJoinColumn( jaxbJoinColumn, joinColumnUsage, memberDetails, xmlDocumentContext );
} );
}
/**
@ -93,7 +81,8 @@ public class JoinColumnProcessing {
return;
}
final MutableAnnotationUsage<PrimaryKeyJoinColumns> columnsUsage = memberDetails.applyAnnotationUsage(
final MutableAnnotationUsage<PrimaryKeyJoinColumns> columnsUsage = memberDetails.replaceAnnotationUsage(
JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN,
JpaAnnotations.PRIMARY_KEY_JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);
@ -101,10 +90,8 @@ public class JoinColumnProcessing {
columnsUsage.setAttributeValue( "value", columnUsages );
jaxbJoinColumns.forEach( (jaxbJoinColumn) -> {
final MutableAnnotationUsage<PrimaryKeyJoinColumn> columnUsage = JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage(
memberDetails,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<PrimaryKeyJoinColumn> columnUsage =
JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
columnUsages.add( columnUsage );
transferJoinColumn(
@ -152,31 +139,14 @@ public class JoinColumnProcessing {
}
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
jaxbJoinColumns.forEach( jaxbJoinColumn -> {
final MutableAnnotationUsage<JoinColumn> joinColumnAnn = JpaAnnotations.JOIN_COLUMN.createUsage(
null,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<JoinColumn> joinColumnAnn =
JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
transferJoinColumn( jaxbJoinColumn, joinColumnAnn, null, xmlDocumentContext );
joinColumns.add( joinColumnAnn );
} );
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(
List<JaxbJoinColumnImpl> jaxbJoinColumns,
AnnotationTarget annotationTarget,
@ -186,10 +156,7 @@ public class JoinColumnProcessing {
}
final List<AnnotationUsage<JoinColumn>> joinColumns = new ArrayList<>( jaxbJoinColumns.size() );
jaxbJoinColumns.forEach( jaxbJoinColumn -> {
final MutableAnnotationUsage<JoinColumn> joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage(
annotationTarget,
xmlDocumentContext.getModelBuildingContext()
);
final MutableAnnotationUsage<JoinColumn> joinColumnUsage = JpaAnnotations.JOIN_COLUMN.createUsage( xmlDocumentContext.getModelBuildingContext() );
transferJoinColumn(
jaxbJoinColumn,
joinColumnUsage,
@ -209,7 +176,8 @@ public class JoinColumnProcessing {
return;
}
final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.applyAnnotationUsage(
final MutableAnnotationUsage<JoinColumns> columnsAnn = memberDetails.replaceAnnotationUsage(
JpaAnnotations.JOIN_COLUMN,
JpaAnnotations.JOIN_COLUMNS,
xmlDocumentContext.getModelBuildingContext()
);

View File

@ -311,8 +311,8 @@ public class Ejb3XmlElementCollectionTest extends Ejb3XmlTestCase {
final MemberDetails memberDetails = getAttributeMember( Entity3.class, "field1", "element-collection.orm14.xml" );
assertThat( memberDetails.hasAnnotationUsage( ElementCollection.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumn.class ) ).isFalse();
assertThat( memberDetails.hasAnnotationUsage( MapKeyJoinColumns.class ) ).isTrue();
assertThat( memberDetails.hasAnnotationUsage( MapKey.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.mapping.PersistentClass;
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.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
@ -374,22 +375,24 @@ public class AdditionalMappingContributorTests {
modelBuildingContext
);
entityUsage.setAttributeValue( "name", "Entity6" );
classDetails.applyAttribute(
final DynamicFieldDetails idMember = classDetails.applyAttribute(
"id",
classDetailsRegistry.resolveClassDetails( Integer.class.getName() ),
false,
false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext ),
modelBuildingContext
);
classDetails.applyAttribute(
idMember.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );
final DynamicFieldDetails nameMember = classDetails.applyAttribute(
"name",
classDetailsRegistry.resolveClassDetails( String.class.getName() ),
false,
false,
(fieldDetails) -> fieldDetails.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext ),
modelBuildingContext
);
nameMember.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext );
return classDetails;
}

View File

@ -70,7 +70,7 @@ dependencyResolutionManagement {
def byteBuddyVersion = version "byteBuddy", "1.14.18"
def classmateVersion = version "classmate", "1.5.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 hcannVersion = version "hcann", "7.0.1.Final"
def jacksonVersion = version "jackson", "2.17.0"