From 5c004f1f702e88405356d936275159c8c3c9848c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 20 Oct 2023 13:42:28 -0500 Subject: [PATCH] #42 - Replace org.hibernate.models.orm.internal.*Registration refs with AnnotationUsage refs https://github.com/sebersole/hibernate-models2/issues/42 --- .../internal/CollectionTypeRegistration.java | 42 --- .../CompositeUserTypeRegistration.java | 30 -- .../orm/internal/ConversionRegistration.java | 168 ---------- .../EmbeddableInstantiatorRegistration.java | 32 -- .../internal/EntityListenerRegistration.java | 6 + .../orm/internal/FilterDefRegistration.java | 42 --- ...ions.java => GlobalRegistrationsImpl.java} | 304 ++++++++++-------- .../orm/internal/JavaTypeRegistration.java | 32 -- .../orm/internal/JdbcTypeRegistration.java | 32 -- .../orm/internal/ProcessResultCollector.java | 25 +- .../orm/internal/ProcessResultImpl.java | 105 +----- .../orm/internal/UserTypeRegistration.java | 30 -- .../models/orm/spi/GlobalRegistrations.java | 53 +++ .../models/orm/spi/ProcessResult.java | 37 +-- .../xml/internal/XmlManagedTypeHelper.java | 11 +- .../orm/process/SimpleProcessorTests.java | 20 +- .../orm/xml/XmlProcessingSmokeTests.java | 28 +- 17 files changed, 273 insertions(+), 724 deletions(-) delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CollectionTypeRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CompositeUserTypeRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EmbeddableInstantiatorRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/FilterDefRegistration.java rename hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/{GlobalRegistrations.java => GlobalRegistrationsImpl.java} (59%) delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java delete mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java create mode 100644 hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CollectionTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CollectionTypeRegistration.java deleted file mode 100644 index 9bed8a2..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CollectionTypeRegistration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import java.util.Map; - -import org.hibernate.metamodel.CollectionClassification; -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @author Steve Ebersole - */ -public class CollectionTypeRegistration { - private final CollectionClassification classification; - private final ClassDetails userTypeClass; - private final Map parameterMap; - - public CollectionTypeRegistration( - CollectionClassification classification, - ClassDetails userTypeClass, - Map parameterMap) { - this.classification = classification; - this.userTypeClass = userTypeClass; - this.parameterMap = parameterMap; - } - - public CollectionClassification getClassification() { - return classification; - } - - public ClassDetails getUserTypeClass() { - return userTypeClass; - } - - public Map getParameterMap() { - return parameterMap; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CompositeUserTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CompositeUserTypeRegistration.java deleted file mode 100644 index 16dfcc9..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/CompositeUserTypeRegistration.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @author Steve Ebersole - */ -public class CompositeUserTypeRegistration { - private final ClassDetails embeddableClass; - private final ClassDetails userTypeClass; - - public CompositeUserTypeRegistration(ClassDetails embeddableClass, ClassDetails userTypeClass) { - this.embeddableClass = embeddableClass; - this.userTypeClass = userTypeClass; - } - - public ClassDetails getEmbeddableClass() { - return embeddableClass; - } - - public ClassDetails getUserTypeClass() { - return userTypeClass; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java deleted file mode 100644 index bbbefd0..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ConversionRegistration.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ - -package org.hibernate.models.orm.internal; - -import java.util.List; -import java.util.Objects; - -import org.hibernate.boot.internal.ClassmateContext; -import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorBypassedImpl; -import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorStandardImpl; -import org.hibernate.boot.model.convert.internal.ConverterHelper; -import org.hibernate.boot.model.convert.spi.AutoApplicableConverterDescriptor; -import org.hibernate.boot.model.convert.spi.ConverterDescriptor; -import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext; -import org.hibernate.boot.model.convert.spi.RegisteredConversion; -import org.hibernate.models.Copied; -import org.hibernate.models.source.spi.ClassDetails; -import org.hibernate.resource.beans.spi.ManagedBean; -import org.hibernate.type.descriptor.converter.internal.JpaAttributeConverterImpl; -import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; -import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; -import org.hibernate.type.spi.TypeConfiguration; - -import com.fasterxml.classmate.ResolvedType; -import jakarta.persistence.AttributeConverter; - -/** - * A registered conversion. - * - * @see org.hibernate.annotations.ConverterRegistration - * - * @author Steve Ebersole - */ -@Copied(RegisteredConversion.class) -public class ConversionRegistration { - private final ClassDetails explicitDomainType; - private final ClassDetails converterType; - private final boolean autoApply; - - public ConversionRegistration(ClassDetails explicitDomainType, ClassDetails converterType, boolean autoApply) { - assert converterType != null; - - this.explicitDomainType = explicitDomainType; - this.converterType = converterType; - this.autoApply = autoApply; - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - ConversionRegistration that = (ConversionRegistration) o; - return autoApply == that.autoApply - && Objects.equals( explicitDomainType, that.explicitDomainType ) - && converterType.equals( that.converterType ); - } - - @Override - public int hashCode() { - return Objects.hash( explicitDomainType, converterType ); - } - - public ClassDetails getExplicitDomainType() { - return explicitDomainType; - } - - public ClassDetails getConverterType() { - return converterType; - } - - public boolean isAutoApply() { - return autoApply; - } - - public ConverterDescriptor makeConverterDescriptor(ClassmateContext classmateContext) { - final Class explicitDomainType = this.explicitDomainType.toJavaClass(); - final Class> converterType = this.converterType.toJavaClass(); - - final List resolvedParamTypes = ConverterHelper.resolveConverterClassParamTypes( - converterType, - classmateContext - ); - final ResolvedType relationalType = resolvedParamTypes.get( 1 ); - final ResolvedType domainTypeToMatch; - if ( !void.class.equals( explicitDomainType ) ) { - domainTypeToMatch = classmateContext.getTypeResolver().resolve( explicitDomainType ); - } - else { - domainTypeToMatch = resolvedParamTypes.get( 0 ); - } - - return new ConverterDescriptorImpl( converterType, domainTypeToMatch, relationalType, autoApply ); - } - - private static class ConverterDescriptorImpl implements ConverterDescriptor { - private final Class> converterType; - private final ResolvedType domainTypeToMatch; - private final ResolvedType relationalType; - private final boolean autoApply; - - private final AutoApplicableConverterDescriptor autoApplyDescriptor; - - public ConverterDescriptorImpl( - Class> converterType, - ResolvedType domainTypeToMatch, - ResolvedType relationalType, - boolean autoApply) { - this.converterType = converterType; - this.domainTypeToMatch = domainTypeToMatch; - this.relationalType = relationalType; - this.autoApply = autoApply; - - this.autoApplyDescriptor = autoApply - ? new AutoApplicableConverterDescriptorStandardImpl( this ) - : AutoApplicableConverterDescriptorBypassedImpl.INSTANCE; - } - - @Override - public Class> getAttributeConverterClass() { - return converterType; - } - - @Override - public ResolvedType getDomainValueResolvedType() { - return domainTypeToMatch; - } - - @Override - public ResolvedType getRelationalValueResolvedType() { - return relationalType; - } - - @Override - public AutoApplicableConverterDescriptor getAutoApplyDescriptor() { - return autoApplyDescriptor; - } - - @SuppressWarnings("unchecked") - @Override - public JpaAttributeConverter createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { - final ManagedBean> converterBean = context - .getManagedBeanRegistry() - .getBean( converterType ); - - final TypeConfiguration typeConfiguration = context.getTypeConfiguration(); - final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry(); - javaTypeRegistry.resolveDescriptor( domainTypeToMatch.getErasedType() ); - - //noinspection rawtypes - return new JpaAttributeConverterImpl( - converterBean, - javaTypeRegistry.getDescriptor( converterBean.getBeanClass() ), - javaTypeRegistry.resolveDescriptor( domainTypeToMatch.getErasedType() ), - javaTypeRegistry.resolveDescriptor( relationalType.getErasedType() ) - ); - } - } - -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EmbeddableInstantiatorRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EmbeddableInstantiatorRegistration.java deleted file mode 100644 index b7386de..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EmbeddableInstantiatorRegistration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @see org.hibernate.annotations.EmbeddableInstantiatorRegistration - * - * @author Steve Ebersole - */ -public class EmbeddableInstantiatorRegistration { - private final ClassDetails embeddableClass; - private final ClassDetails instantiator; - - public EmbeddableInstantiatorRegistration(ClassDetails embeddableClass, ClassDetails instantiator) { - this.embeddableClass = embeddableClass; - this.instantiator = instantiator; - } - - public ClassDetails getEmbeddableClass() { - return embeddableClass; - } - - public ClassDetails getInstantiator() { - return instantiator; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java index ff0b7ed..d2e4d54 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/EntityListenerRegistration.java @@ -14,6 +14,12 @@ import org.hibernate.models.source.spi.MethodDetails; /** + * Represents an entity listener defined in XML. + * + * @apiNote Simply using {@code AnnotationUsage} is not enough here + * + * @see jakarta.persistence.EntityListeners + * * @author Steve Ebersole */ public class EntityListenerRegistration { diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/FilterDefRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/FilterDefRegistration.java deleted file mode 100644 index 06aa818..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/FilterDefRegistration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import java.util.Map; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * Global registration of a filter definition - * - * @author Marco Belladelli - */ -public class FilterDefRegistration { - private final String name; - - private final String defaultCondition; - - private final Map parameters; - - public FilterDefRegistration(String name, String defaultCondition, Map parameters) { - this.name = name; - this.defaultCondition = defaultCondition; - this.parameters = parameters; - } - - public String getName() { - return name; - } - - public String getDefaultCondition() { - return defaultCondition; - } - - public Map getParameters() { - return parameters; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java similarity index 59% rename from hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java rename to hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java index d1c6e6c..21d3ff8 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrations.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/GlobalRegistrationsImpl.java @@ -6,7 +6,6 @@ */ package org.hibernate.models.orm.internal; -import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -14,10 +13,17 @@ import java.util.Map; import org.hibernate.AnnotationException; +import org.hibernate.annotations.CollectionTypeRegistration; +import org.hibernate.annotations.CompositeTypeRegistration; +import org.hibernate.annotations.ConverterRegistration; +import org.hibernate.annotations.EmbeddableInstantiatorRegistration; import org.hibernate.annotations.FilterDef; import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.JavaTypeRegistration; +import org.hibernate.annotations.JdbcTypeRegistration; import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.TypeRegistration; import org.hibernate.boot.jaxb.mapping.JaxbCollectionUserTypeRegistration; import org.hibernate.boot.jaxb.mapping.JaxbCompositeUserTypeRegistration; import org.hibernate.boot.jaxb.mapping.JaxbConfigurationParameter; @@ -33,8 +39,9 @@ import org.hibernate.boot.jaxb.mapping.JaxbTableGenerator; import org.hibernate.boot.jaxb.mapping.JaxbUserTypeRegistration; import org.hibernate.internal.util.collections.CollectionHelper; -import org.hibernate.metamodel.CollectionClassification; import org.hibernate.models.internal.StringHelper; +import org.hibernate.models.orm.spi.GlobalRegistrations; +import org.hibernate.models.source.internal.MutableClassDetails; import org.hibernate.models.source.internal.dynamic.DynamicAnnotationUsage; import org.hibernate.models.source.spi.AnnotationDescriptorRegistry; import org.hibernate.models.source.spi.AnnotationTarget; @@ -43,6 +50,7 @@ import org.hibernate.models.source.spi.ClassDetailsRegistry; import org.hibernate.models.source.spi.SourceModelBuildingContext; +import jakarta.persistence.Converter; import jakarta.persistence.SequenceGenerator; import jakarta.persistence.TableGenerator; @@ -60,20 +68,24 @@ /** * @author Steve Ebersole */ -public class GlobalRegistrations { +public class GlobalRegistrationsImpl implements GlobalRegistrations { private final ClassDetailsRegistry classDetailsRegistry; private final AnnotationDescriptorRegistry annotationDescriptorRegistry; private List entityListenerRegistrations; - private List autoAppliedConverters; - private List converterRegistrations; - private List javaTypeRegistrations; - private List jdbcTypeRegistrations; - private List userTypeRegistrations; - private List compositeUserTypeRegistrations; - private List collectionTypeRegistrations; - private List embeddableInstantiatorRegistrations; - private Map filterDefRegistrations; + + private List> autoAppliedConverters; + private List> converterRegistrations; + + private List> javaTypeRegistrations; + private List> jdbcTypeRegistrations; + private List> userTypeRegistrations; + private List> compositeUserTypeRegistrations; + private List> collectionTypeRegistrations; + + private List> embeddableInstantiatorRegistrations; + + private Map> filterDefRegistrations; private Map sequenceGeneratorRegistrations; private Map tableGeneratorRegistrations; @@ -83,11 +95,11 @@ public class GlobalRegistrations { private Map hibernateNamedHqlQueries; private Map hibernateNamedNativeQueries; - public GlobalRegistrations(SourceModelBuildingContext sourceModelBuildingContext) { + public GlobalRegistrationsImpl(SourceModelBuildingContext sourceModelBuildingContext) { this( sourceModelBuildingContext.getClassDetailsRegistry(), sourceModelBuildingContext.getAnnotationDescriptorRegistry() ); } - public GlobalRegistrations(ClassDetailsRegistry classDetailsRegistry, AnnotationDescriptorRegistry annotationDescriptorRegistry) { + public GlobalRegistrationsImpl(ClassDetailsRegistry classDetailsRegistry, AnnotationDescriptorRegistry annotationDescriptorRegistry) { this.classDetailsRegistry = classDetailsRegistry; this.annotationDescriptorRegistry = annotationDescriptorRegistry; } @@ -96,50 +108,62 @@ public List getEntityListenerRegistrations() { return entityListenerRegistrations; } - public List getConverterRegistrations() { + public List> getConverterRegistrations() { return converterRegistrations == null ? emptyList() : converterRegistrations; } - public List getAutoAppliedConverters() { + public List> getAutoAppliedConverters() { return autoAppliedConverters == null ? emptyList() : autoAppliedConverters; } - public List getJavaTypeRegistrations() { + public List> getJavaTypeRegistrations() { return javaTypeRegistrations == null ? emptyList() : javaTypeRegistrations; } - public List getJdbcTypeRegistrations() { + public List> getJdbcTypeRegistrations() { return jdbcTypeRegistrations == null ? emptyList() : jdbcTypeRegistrations; } - public List getUserTypeRegistrations() { + public List> getUserTypeRegistrations() { return userTypeRegistrations == null ? emptyList() : userTypeRegistrations; } - public List getCompositeUserTypeRegistrations() { + public List> getCompositeUserTypeRegistrations() { return compositeUserTypeRegistrations == null ? emptyList() : compositeUserTypeRegistrations; } - public List getCollectionTypeRegistrations() { + public List> getCollectionTypeRegistrations() { return collectionTypeRegistrations == null ? emptyList() : collectionTypeRegistrations; } - public List getEmbeddableInstantiatorRegistrations() { + public List> getEmbeddableInstantiatorRegistrations() { return embeddableInstantiatorRegistrations == null ? emptyList() : embeddableInstantiatorRegistrations; } - public Map getFilterDefRegistrations() { + public Map> getFilterDefRegistrations() { return filterDefRegistrations == null ? emptyMap() : filterDefRegistrations; } + @Override + public Map getJpaNamedQueries() { + throw new UnsupportedOperationException( "Not yet implemented" ); + } + + @Override + public Map getHibernateNamedHqlQueries() { + throw new UnsupportedOperationException( "Not yet implemented" ); + } + + @Override + public Map getHibernateNamedNativeQueries() { + throw new UnsupportedOperationException( "Not yet implemented" ); + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // JavaTypeRegistration public void collectJavaTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( JAVA_TYPE_REG, (usage) -> collectJavaTypeRegistration( - usage.getAttributeValue( "javaType" ), - usage.getAttributeValue( "descriptorClass" ) - ) ); + annotationTarget.forEachAnnotationUsage( JAVA_TYPE_REG, this::collectJavaTypeRegistration ); } public void collectJavaTypeRegistrations(List registrations) { @@ -147,17 +171,22 @@ public void collectJavaTypeRegistrations(List registra return; } - registrations.forEach( (reg) -> collectJavaTypeRegistration( - classDetailsRegistry.resolveClassDetails( reg.getClazz() ), - classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ) - ) ); + registrations.forEach( (reg) -> { + final ClassDetails descriptorClass = classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ); + final ClassDetails domainTypeClass = classDetailsRegistry.resolveClassDetails( reg.getClazz() ); + + final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( JavaTypeRegistration.class ); + annotationUsage.setAttributeValue( "javaType", domainTypeClass ); + annotationUsage.setAttributeValue( "descriptorClass", descriptorClass ); + collectJavaTypeRegistration( annotationUsage ); + } ); } - public void collectJavaTypeRegistration(ClassDetails javaType, ClassDetails descriptor) { + public void collectJavaTypeRegistration(AnnotationUsage annotationUsage) { if ( javaTypeRegistrations == null ) { javaTypeRegistrations = new ArrayList<>(); } - javaTypeRegistrations.add( new JavaTypeRegistration( javaType, descriptor ) ); + javaTypeRegistrations.add( annotationUsage ); } @@ -165,10 +194,7 @@ public void collectJavaTypeRegistration(ClassDetails javaType, ClassDetails des // JdbcTypeRegistration public void collectJdbcTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( JDBC_TYPE_REG, (usage) -> collectJdbcTypeRegistration( - usage.getAttributeValue( "registrationCode" ), - usage.getAttributeValue( "value" ) - ) ); + annotationTarget.forEachAnnotationUsage( JDBC_TYPE_REG, this::collectJdbcTypeRegistration ); } public void collectJdbcTypeRegistrations(List registrations) { @@ -176,17 +202,20 @@ public void collectJdbcTypeRegistrations(List registra return; } - registrations.forEach( (reg) -> collectJdbcTypeRegistration( - reg.getCode(), - classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ) - ) ); + registrations.forEach( (reg) -> { + final ClassDetails descriptorClassDetails = classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ); + final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( JdbcTypeRegistration.class ); + annotationUsage.setAttributeValue( "registrationCode", reg.getCode() ); + annotationUsage.setAttributeValue( "value", descriptorClassDetails ); + collectJdbcTypeRegistration( annotationUsage ); + } ); } - public void collectJdbcTypeRegistration(Integer registrationCode, ClassDetails descriptor) { + public void collectJdbcTypeRegistration(AnnotationUsage annotationUsage) { if ( jdbcTypeRegistrations == null ) { jdbcTypeRegistrations = new ArrayList<>(); } - jdbcTypeRegistrations.add( new JdbcTypeRegistration( registrationCode, descriptor ) ); + jdbcTypeRegistrations.add( annotationUsage ); } @@ -194,12 +223,7 @@ public void collectJdbcTypeRegistration(Integer registrationCode, ClassDetails d // ConversionRegistration public void collectConverterRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( CONVERTER_REG, (usage) -> { - final ClassDetails domainType = usage.getAttributeValue( "domainType" ); - final ClassDetails converterType = usage.getAttributeValue( "converter" ); - final boolean autoApply = usage.getAttributeValue( "autoApply" ); - collectConverterRegistration( new ConversionRegistration( domainType, converterType, autoApply ) ); - } ); + annotationTarget.forEachAnnotationUsage( CONVERTER_REG, this::collectConverterRegistration ); } public void collectConverterRegistrations(List registrations) { @@ -208,6 +232,14 @@ public void collectConverterRegistrations(List regist } registrations.forEach( (registration) -> { + final MutableClassDetails converterType = (MutableClassDetails) classDetailsRegistry.resolveClassDetails( registration.getConverter() ); + final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( + ConverterRegistration.class, + converterType + ); + // technically does not need this, but... + converterType.addAnnotationUsage( annotationUsage ); + final ClassDetails explicitDomainType; final String explicitDomainTypeName = registration.getClazz(); if ( StringHelper.isNotEmpty( explicitDomainTypeName ) ) { @@ -216,13 +248,15 @@ public void collectConverterRegistrations(List regist else { explicitDomainType = null; } - final ClassDetails converterType = classDetailsRegistry.resolveClassDetails( registration.getConverter() ); - final boolean autoApply = registration.isAutoApply(); - collectConverterRegistration( new ConversionRegistration( explicitDomainType, converterType, autoApply ) ); + + annotationUsage.setAttributeValue( "converter", converterType ); + annotationUsage.setAttributeValue( "domainType", explicitDomainType ); + annotationUsage.setAttributeValue( "autoApply", registration.isAutoApply() ); + collectConverterRegistration( annotationUsage ); } ); } - public void collectConverterRegistration(ConversionRegistration conversion) { + public void collectConverterRegistration(AnnotationUsage conversion) { if ( converterRegistrations == null ) { converterRegistrations = new ArrayList<>(); } @@ -234,10 +268,7 @@ public void collectConverterRegistration(ConversionRegistration conversion) { // UserTypeRegistration public void collectUserTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( TYPE_REG, (usage) -> collectUserTypeRegistration( - usage.getAttributeValue( "basicClass" ), - usage.getAttributeValue( "userType" ) - ) ); + annotationTarget.forEachAnnotationUsage( TYPE_REG, this::collectUserTypeRegistration ); } public void collectUserTypeRegistrations(List registrations) { @@ -248,15 +279,19 @@ public void collectUserTypeRegistrations(List registra registrations.forEach( (reg) -> { final ClassDetails domainTypeDetails = classDetailsRegistry.resolveClassDetails( reg.getClazz() ); final ClassDetails descriptorDetails = classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ); - collectUserTypeRegistration( domainTypeDetails, descriptorDetails ); + + final DynamicAnnotationUsage annotationUsage = new DynamicAnnotationUsage<>( TypeRegistration.class ); + annotationUsage.setAttributeValue( "basicClass", domainTypeDetails ); + annotationUsage.setAttributeValue( "userType", descriptorDetails ); + collectUserTypeRegistration( annotationUsage ); } ); } - public void collectUserTypeRegistration(ClassDetails domainClass, ClassDetails userTypeClass) { + public void collectUserTypeRegistration(AnnotationUsage annotationUsage) { if ( userTypeRegistrations == null ) { userTypeRegistrations = new ArrayList<>(); } - userTypeRegistrations.add( new UserTypeRegistration( domainClass, userTypeClass ) ); + userTypeRegistrations.add( annotationUsage ); } @@ -264,10 +299,7 @@ public void collectUserTypeRegistration(ClassDetails domainClass, ClassDetails u // CompositeUserTypeRegistration public void collectCompositeUserTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( COMPOSITE_TYPE_REG, (usage) -> collectCompositeUserTypeRegistration( - usage.getAttributeValue( "embeddableClass" ), - usage.getAttributeValue( "userType" ) - ) ); + annotationTarget.forEachAnnotationUsage( COMPOSITE_TYPE_REG, this::collectCompositeUserTypeRegistration ); } public void collectCompositeUserTypeRegistrations(List registrations) { @@ -275,17 +307,22 @@ public void collectCompositeUserTypeRegistrations(List collectCompositeUserTypeRegistration( - classDetailsRegistry.resolveClassDetails( reg.getClazz() ), - classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ) - ) ); + registrations.forEach( (reg) -> { + final ClassDetails compositeType = classDetailsRegistry.resolveClassDetails( reg.getClazz() ); + final ClassDetails descriptorType = classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ); + + final DynamicAnnotationUsage usage = new DynamicAnnotationUsage<>( CompositeTypeRegistration.class ); + usage.setAttributeValue( "embeddableClass", compositeType ); + usage.setAttributeValue( "userType", descriptorType ); + collectCompositeUserTypeRegistration( usage ); + } ); } - public void collectCompositeUserTypeRegistration(ClassDetails domainClass, ClassDetails userTypeClass) { + public void collectCompositeUserTypeRegistration(AnnotationUsage annotationUsage) { if ( compositeUserTypeRegistrations == null ) { compositeUserTypeRegistrations = new ArrayList<>(); } - compositeUserTypeRegistrations.add( new CompositeUserTypeRegistration( domainClass, userTypeClass ) ); + compositeUserTypeRegistrations.add( annotationUsage ); } @@ -293,24 +330,7 @@ public void collectCompositeUserTypeRegistration(ClassDetails domainClass, Class // CollectionTypeRegistration public void collectCollectionTypeRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( COLLECTION_TYPE_REG, (usage) -> collectCollectionTypeRegistration( - usage.getAttributeValue( "classification" ), - usage.getAttributeValue( "type" ), - extractParameterMap( usage ) - ) ); - } - - private Map extractParameterMap(AnnotationUsage source) { - final List> parameters = source.getAttributeValue( "parameters" ); - - final Map result = new HashMap<>(); - for ( AnnotationUsage parameter : parameters ) { - result.put( - parameter.getAttributeValue( "name" ), - parameter.getAttributeValue( "value" ) - ); - } - return result; + annotationTarget.forEachAnnotationUsage( COLLECTION_TYPE_REG, this::collectCollectionTypeRegistration ); } public void collectCollectionTypeRegistrations(List registrations) { @@ -318,31 +338,40 @@ public void collectCollectionTypeRegistrations(List collectCollectionTypeRegistration( - reg.getClassification(), - classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ), - extractParameterMap( reg.getParameters() ) - ) ); + registrations.forEach( (reg) -> { + final ClassDetails typeDetails = classDetailsRegistry.resolveClassDetails( reg.getDescriptor() ); + + final DynamicAnnotationUsage typeRegistration = new DynamicAnnotationUsage<>( CollectionTypeRegistration.class ); + typeRegistration.setAttributeValue( "classification", reg.getClassification() ); + typeRegistration.setAttributeValue( "type", typeDetails ); + typeRegistration.setAttributeValue( "parameters", extractParameters( reg.getParameters() ) ); + + collectCollectionTypeRegistration( typeRegistration ); + } ); } - private Map extractParameterMap(List parameters) { + private List> extractParameters(List parameters) { if ( CollectionHelper.isEmpty( parameters ) ) { - return Collections.emptyMap(); + return Collections.emptyList(); } - final Map result = new HashMap<>(); - parameters.forEach( parameter -> result.put( parameter.getName(), parameter.getValue() ) ); + final List> result = new ArrayList<>(); + parameters.forEach( (parameter) -> result.add( makeParameter( parameter ) ) ); return result; } - public void collectCollectionTypeRegistration( - CollectionClassification classification, - ClassDetails userTypeClass, - Map parameters) { + private AnnotationUsage makeParameter(JaxbConfigurationParameter jaxbParameter) { + final DynamicAnnotationUsage parameter = new DynamicAnnotationUsage<>( Parameter.class ); + parameter.setAttributeValue( "name", jaxbParameter.getName() ); + parameter.setAttributeValue( "value", jaxbParameter.getValue() ); + return parameter; + } + + public void collectCollectionTypeRegistration(AnnotationUsage annotationUsage) { if ( collectionTypeRegistrations == null ) { collectionTypeRegistrations = new ArrayList<>(); } - collectionTypeRegistrations.add( new CollectionTypeRegistration( classification, userTypeClass, parameters ) ); + collectionTypeRegistrations.add( annotationUsage ); } @@ -350,10 +379,7 @@ public void collectCollectionTypeRegistration( // EmbeddableInstantiatorRegistration public void collectEmbeddableInstantiatorRegistrations(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( EMBEDDABLE_INSTANTIATOR_REG, (usage) -> collectEmbeddableInstantiatorRegistration( - usage.getAttributeValue( "embeddableClass" ), - usage.getAttributeValue( "instantiator" ) - ) ); + annotationTarget.forEachAnnotationUsage( EMBEDDABLE_INSTANTIATOR_REG, this::collectEmbeddableInstantiatorRegistration ); } public void collectEmbeddableInstantiatorRegistrations(List registrations) { @@ -361,17 +387,25 @@ public void collectEmbeddableInstantiatorRegistrations(List collectEmbeddableInstantiatorRegistration( - classDetailsRegistry.resolveClassDetails( reg.getEmbeddableClass() ), - classDetailsRegistry.resolveClassDetails( reg.getInstantiator() ) - ) ); + registrations.forEach( (reg) -> { + final ClassDetails embeddableClass = classDetailsRegistry.resolveClassDetails( reg.getEmbeddableClass() ); + final ClassDetails instantiatorClass = classDetailsRegistry.resolveClassDetails( reg.getInstantiator() ); + + final DynamicAnnotationUsage usage = new DynamicAnnotationUsage<>( + EmbeddableInstantiatorRegistration.class, + instantiatorClass + ); + usage.setAttributeValue( "embeddableClass", embeddableClass ); + usage.setAttributeValue( "instantiator", instantiatorClass ); + collectEmbeddableInstantiatorRegistration( usage ); + } ); } - public void collectEmbeddableInstantiatorRegistration(ClassDetails embeddableClass, ClassDetails instantiator) { + public void collectEmbeddableInstantiatorRegistration(AnnotationUsage usage) { if ( embeddableInstantiatorRegistrations == null ) { embeddableInstantiatorRegistrations = new ArrayList<>(); } - embeddableInstantiatorRegistrations.add( new EmbeddableInstantiatorRegistration( embeddableClass, instantiator ) ); + embeddableInstantiatorRegistrations.add( usage ); } @@ -379,20 +413,7 @@ public void collectEmbeddableInstantiatorRegistration(ClassDetails embeddableCla // Filter-defs public void collectFilterDefinitions(AnnotationTarget annotationTarget) { - annotationTarget.forEachAnnotationUsage( FILTER_DEF, (usage) -> collectFilterDefinition( - usage.getAttributeValue( "name" ), - usage.getAttributeValue( "defaultCondition" ), - extractFilterParameters( usage ) - ) ); - } - - private Map extractFilterParameters(AnnotationUsage source) { - final List> parameters = source.getAttributeValue( "parameters" ); - final Map result = new HashMap<>( parameters.size() ); - for ( AnnotationUsage parameter : parameters ) { - result.put( parameter.getAttributeValue( "name" ), parameter.getAttributeValue( "type" ) ); - } - return result; + annotationTarget.forEachAnnotationUsage( FILTER_DEF, this::collectFilterDefinition ); } public void collectFilterDefinitions(List filterDefinitions) { @@ -400,33 +421,42 @@ public void collectFilterDefinitions(List filterDefinitions) { return; } - filterDefinitions.forEach( (filterDefinition) -> collectFilterDefinition( - filterDefinition.getName(), - filterDefinition.getCondition(), - extractFilterParameters( filterDefinition ) - ) ); + filterDefinitions.forEach( (filterDefinition) -> { + final DynamicAnnotationUsage filterDef = new DynamicAnnotationUsage<>( FilterDef.class ); + filterDef.setAttributeValue( "name", filterDefinition.getName() ); + filterDef.setAttributeValue( "defaultCondition", filterDefinition.getCondition() ); + filterDef.setAttributeValue( "parameters", extractFilterParameters( filterDefinition ) ); + collectFilterDefinition( filterDefinition.getName(), filterDef ); + } ); } - private Map extractFilterParameters(JaxbFilterDef source) { + private List> extractFilterParameters(JaxbFilterDef source) { final List parameters = source.getFilterParam(); // todo : update the mapping.xsd to account for new @ParamDef definition // todo : handle simplified type names for XML, e.g. "String" instead of "java.lang.String" - final Map result = new HashMap<>( parameters.size() ); + final List> result = new ArrayList<>( parameters.size() ); for ( JaxbFilterDef.JaxbFilterParam parameter : parameters ) { - result.put( parameter.getName(), classDetailsRegistry.resolveClassDetails( parameter.getType() ) ); + final DynamicAnnotationUsage paramDef = new DynamicAnnotationUsage<>( ParamDef.class ); + paramDef.setAttributeValue( "name", parameter.getName() ); + paramDef.setAttributeValue( "type", classDetailsRegistry.resolveClassDetails( parameter.getType() ) ); + result.add( paramDef ); } return result; } - public void collectFilterDefinition(String name, String defaultCondition, Map parameters) { + public void collectFilterDefinition(AnnotationUsage filterDef) { + collectFilterDefinition( filterDef.getAttributeValue( "name" ), filterDef ); + } + + public void collectFilterDefinition(String name, AnnotationUsage filterDef) { if ( filterDefRegistrations == null ) { filterDefRegistrations = new HashMap<>(); } - if ( filterDefRegistrations.put( name, new FilterDefRegistration( name, defaultCondition, parameters ) ) != null ) { - throw new AnnotationException( "Multiple '@FilterDef' annotations define a filter named '" + name + "'" ); + if ( filterDefRegistrations.put( name, filterDef ) != null ) { + throw new AnnotationException( "Multiple `@FilterDef` annotations define with the same name '" + name + "'" ); } } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java deleted file mode 100644 index ee73d37..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JavaTypeRegistration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @see org.hibernate.annotations.JavaTypeRegistration - * - * @author Steve Ebersole - */ -public class JavaTypeRegistration { - private final ClassDetails domainType; - private final ClassDetails descriptor; - - public JavaTypeRegistration(ClassDetails domainType, ClassDetails descriptor) { - this.domainType = domainType; - this.descriptor = descriptor; - } - - public ClassDetails getDomainType() { - return domainType; - } - - public ClassDetails getDescriptor() { - return descriptor; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java deleted file mode 100644 index 0a5aab5..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/JdbcTypeRegistration.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @see org.hibernate.annotations.JdbcTypeRegistration - * - * @author Steve Ebersole - */ -public class JdbcTypeRegistration { - private final Integer code; - private final ClassDetails descriptor; - - public JdbcTypeRegistration(Integer code, ClassDetails descriptor) { - this.code = code; - this.descriptor = descriptor; - } - - public Integer getCode() { - return code; - } - - public ClassDetails getDescriptor() { - return descriptor; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java index 493b846..de6e5b3 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultCollector.java @@ -12,10 +12,9 @@ import org.hibernate.boot.jaxb.mapping.JaxbEntityMappings; import org.hibernate.boot.jaxb.mapping.JaxbPersistenceUnitDefaults; import org.hibernate.boot.jaxb.mapping.JaxbPersistenceUnitMetadata; -import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.orm.spi.EntityHierarchy; +import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.source.spi.ClassDetails; -import org.hibernate.models.source.spi.ClassDetailsRegistry; import org.hibernate.models.source.spi.PackageDetails; import org.hibernate.models.source.spi.SourceModelBuildingContext; @@ -29,15 +28,15 @@ * @author Steve Ebersole */ public class ProcessResultCollector { - private final GlobalRegistrations globalRegistrations; + private final GlobalRegistrationsImpl globalRegistrations; private final boolean areIdGeneratorsGlobal; public ProcessResultCollector(boolean areIdGeneratorsGlobal, SourceModelBuildingContext sourceModelBuildingContext) { - this.globalRegistrations = new GlobalRegistrations( sourceModelBuildingContext ); + this.globalRegistrations = new GlobalRegistrationsImpl( sourceModelBuildingContext ); this.areIdGeneratorsGlobal = areIdGeneratorsGlobal; } - public GlobalRegistrations getGlobalRegistrations() { + public GlobalRegistrationsImpl getGlobalRegistrations() { return globalRegistrations; } @@ -110,21 +109,7 @@ public void apply(PackageDetails packageDetails) { public ProcessResult createResult(Set entityHierarchies) { return new ProcessResultImpl( entityHierarchies, - getGlobalRegistrations().getJavaTypeRegistrations(), - getGlobalRegistrations().getJdbcTypeRegistrations(), - getGlobalRegistrations().getConverterRegistrations(), - getGlobalRegistrations().getAutoAppliedConverters(), - getGlobalRegistrations().getUserTypeRegistrations(), - getGlobalRegistrations().getCompositeUserTypeRegistrations(), - getGlobalRegistrations().getCollectionTypeRegistrations(), - getGlobalRegistrations().getEmbeddableInstantiatorRegistrations(), - getGlobalRegistrations().getFilterDefRegistrations(), -// jpaNamedQueries == null ? emptyMap() : jpaNamedQueries, -// hibernateNamedHqlQueries == null ? emptyMap() : hibernateNamedHqlQueries, -// hibernateNamedNativeQueries == null ? emptyMap() : hibernateNamedNativeQueries - emptyMap(), - emptyMap(), - emptyMap() + getGlobalRegistrations() ); } } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java index bbc892f..7d1831a 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/ProcessResultImpl.java @@ -6,60 +6,24 @@ */ package org.hibernate.models.orm.internal; -import java.util.List; -import java.util.Map; import java.util.Set; -import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.orm.spi.EntityHierarchy; -import org.hibernate.models.source.spi.ClassDetails; +import org.hibernate.models.orm.spi.GlobalRegistrations; +import org.hibernate.models.orm.spi.ProcessResult; /** * @author Steve Ebersole */ public class ProcessResultImpl implements ProcessResult { private final Set entityHierarchies; - - private final List javaTypeRegistrations; - private final List jdbcTypeRegistrations; - private final List converterRegistrations; - private final List autoAppliedConverters; - private final List userTypeRegistrations; - private final List compositeUserTypeRegistrations; - private final List collectionTypeRegistrations; - private final List embeddableInstantiatorRegistrations; - private final Map filterDefRegistrations; - private final Map jpaNamedQueries; - private final Map hibernateNamedHqlQueries; - private final Map hibernateNamedNativeQueries; + private final GlobalRegistrations globalRegistrations; public ProcessResultImpl( Set entityHierarchies, - List javaTypeRegistrations, - List jdbcTypeRegistrations, - List converterRegistrations, - List autoAppliedConverters, - List userTypeRegistrations, - List compositeUserTypeRegistrations, - List collectionTypeRegistrations, - List embeddableInstantiatorRegistrations, - Map filterDefRegistrations, - Map jpaNamedQueries, - Map hibernateNamedHqlQueries, - Map hibernateNamedNativeQueries) { + GlobalRegistrations globalRegistrations) { this.entityHierarchies = entityHierarchies; - this.javaTypeRegistrations = javaTypeRegistrations; - this.jdbcTypeRegistrations = jdbcTypeRegistrations; - this.converterRegistrations = converterRegistrations; - this.autoAppliedConverters = autoAppliedConverters; - this.userTypeRegistrations = userTypeRegistrations; - this.compositeUserTypeRegistrations = compositeUserTypeRegistrations; - this.collectionTypeRegistrations = collectionTypeRegistrations; - this.embeddableInstantiatorRegistrations = embeddableInstantiatorRegistrations; - this.filterDefRegistrations = filterDefRegistrations; - this.jpaNamedQueries = jpaNamedQueries; - this.hibernateNamedHqlQueries = hibernateNamedHqlQueries; - this.hibernateNamedNativeQueries = hibernateNamedNativeQueries; + this.globalRegistrations = globalRegistrations; } @Override @@ -68,62 +32,7 @@ public Set getEntityHierarchies() { } @Override - public List getJavaTypeRegistrations() { - return javaTypeRegistrations; - } - - @Override - public List getJdbcTypeRegistrations() { - return jdbcTypeRegistrations; - } - - @Override - public List getConverterRegistrations() { - return converterRegistrations; - } - - @Override - public List getAutoAppliedConverters() { - return autoAppliedConverters; - } - - @Override - public List getUserTypeRegistrations() { - return userTypeRegistrations; - } - - @Override - public List getCompositeUserTypeRegistrations() { - return compositeUserTypeRegistrations; - } - - @Override - public List getCollectionTypeRegistrations() { - return collectionTypeRegistrations; - } - - @Override - public List getEmbeddableInstantiatorRegistrations() { - return embeddableInstantiatorRegistrations; - } - - @Override - public Map getFilterDefRegistrations() { - return filterDefRegistrations; - } - - @Override - public Map getJpaNamedQueries() { - return jpaNamedQueries; - } - - @Override - public Map getHibernateNamedHqlQueries() { - return hibernateNamedHqlQueries; - } - - @Override - public Map getHibernateNamedNativeQueries() { - return hibernateNamedNativeQueries; + public GlobalRegistrations getGlobalRegistrations() { + return globalRegistrations; } } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java deleted file mode 100644 index 9f47d6f..0000000 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/internal/UserTypeRegistration.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * SPDX-License-Identifier: Apache-2.0 - * Copyright: Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.models.orm.internal; - -import org.hibernate.models.source.spi.ClassDetails; - -/** - * @author Steve Ebersole - */ -public class UserTypeRegistration { - private final ClassDetails domainClass; - private final ClassDetails userTypeClass; - - public UserTypeRegistration(ClassDetails domainClass, ClassDetails userTypeClass) { - this.domainClass = domainClass; - this.userTypeClass = userTypeClass; - } - - public ClassDetails getDomainClass() { - return domainClass; - } - - public ClassDetails getUserTypeClass() { - return userTypeClass; - } -} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java new file mode 100644 index 0000000..7994c7e --- /dev/null +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/GlobalRegistrations.java @@ -0,0 +1,53 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * SPDX-License-Identifier: Apache-2.0 + * Copyright: Red Hat Inc. and Hibernate Authors + */ +package org.hibernate.models.orm.spi; + +import java.util.List; +import java.util.Map; + +import org.hibernate.annotations.CollectionTypeRegistration; +import org.hibernate.annotations.CompositeTypeRegistration; +import org.hibernate.annotations.ConverterRegistration; +import org.hibernate.annotations.EmbeddableInstantiatorRegistration; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.JavaTypeRegistration; +import org.hibernate.annotations.JdbcTypeRegistration; +import org.hibernate.annotations.TypeRegistration; +import org.hibernate.models.orm.internal.NamedQueryRegistration; +import org.hibernate.models.source.spi.AnnotationUsage; + +import jakarta.persistence.Converter; + +/** + * @author Steve Ebersole + */ +public interface GlobalRegistrations { + + List> getConverterRegistrations(); + + List> getAutoAppliedConverters(); + + List> getJavaTypeRegistrations(); + + List> getJdbcTypeRegistrations(); + + List> getUserTypeRegistrations(); + + List> getCompositeUserTypeRegistrations(); + + List> getCollectionTypeRegistrations(); + + List> getEmbeddableInstantiatorRegistrations(); + + Map> getFilterDefRegistrations(); + + Map getJpaNamedQueries(); + + Map getHibernateNamedHqlQueries(); + + Map getHibernateNamedNativeQueries(); +} diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java index ce9ee9d..fc08111 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/spi/ProcessResult.java @@ -6,21 +6,8 @@ */ package org.hibernate.models.orm.spi; -import java.util.List; -import java.util.Map; import java.util.Set; -import org.hibernate.models.orm.internal.CollectionTypeRegistration; -import org.hibernate.models.orm.internal.CompositeUserTypeRegistration; -import org.hibernate.models.orm.internal.ConversionRegistration; -import org.hibernate.models.orm.internal.EmbeddableInstantiatorRegistration; -import org.hibernate.models.orm.internal.FilterDefRegistration; -import org.hibernate.models.orm.internal.JavaTypeRegistration; -import org.hibernate.models.orm.internal.JdbcTypeRegistration; -import org.hibernate.models.orm.internal.NamedQueryRegistration; -import org.hibernate.models.orm.internal.UserTypeRegistration; -import org.hibernate.models.source.spi.ClassDetails; - /** * The result of {@linkplain Processor#process processing} the domain model * @@ -29,27 +16,5 @@ public interface ProcessResult { Set getEntityHierarchies(); - List getJavaTypeRegistrations(); - - List getJdbcTypeRegistrations(); - - List getConverterRegistrations(); - - List getAutoAppliedConverters(); - - List getUserTypeRegistrations(); - - List getCompositeUserTypeRegistrations(); - - List getCollectionTypeRegistrations(); - - List getEmbeddableInstantiatorRegistrations(); - - Map getFilterDefRegistrations(); - - Map getJpaNamedQueries(); - - Map getHibernateNamedHqlQueries(); - - Map getHibernateNamedNativeQueries(); + GlobalRegistrations getGlobalRegistrations(); } diff --git a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/internal/XmlManagedTypeHelper.java b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/internal/XmlManagedTypeHelper.java index 7037dbd..eb72aed 100644 --- a/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/internal/XmlManagedTypeHelper.java +++ b/hibernate-models-orm/src/main/java/org/hibernate/models/orm/xml/internal/XmlManagedTypeHelper.java @@ -291,7 +291,9 @@ public static void applyMappedSuperclassOverrides( Map mappedSuperClasses, List> mappedSuperclassesOverrides, SourceModelBuildingContext sourceModelBuildingContext) { - throw new UnsupportedOperationException( " override support not yet implemented" ); + if ( CollectionHelper.isNotEmpty( mappedSuperclassesOverrides ) ) { + throw new UnsupportedOperationException( " override support not yet implemented" ); + } } public static void applyEntityOverrides( @@ -305,15 +307,18 @@ public static void applyEntityOverrides( final MutableClassDetails classDetails = (MutableClassDetails) sourceModelBuildingContext .getClassDetailsRegistry() .resolveClassDetails( className ); + + throw new UnsupportedOperationException( " override support not yet implemented" ); } ); - throw new UnsupportedOperationException( " override support not yet implemented" ); } public static void applyEmbeddableOverrides( Map embeddables, List> embeddableOverrides, SourceModelBuildingContext sourceModelBuildingContext) { - throw new UnsupportedOperationException( " override support not yet implemented" ); + if ( CollectionHelper.isNotEmpty( embeddableOverrides ) ) { + throw new UnsupportedOperationException( " override support not yet implemented" ); + } } } diff --git a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java index 8225c14..09e66d1 100644 --- a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java +++ b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/process/SimpleProcessorTests.java @@ -7,18 +7,20 @@ package org.hibernate.models.orm.process; import java.util.Iterator; +import java.util.List; import java.util.Map; -import org.hibernate.models.orm.internal.FilterDefRegistration; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.ParamDef; import org.hibernate.models.orm.internal.ManagedResourcesImpl; import org.hibernate.models.orm.spi.EntityHierarchy; import org.hibernate.models.orm.spi.EntityTypeMetadata; -import org.hibernate.models.orm.spi.IdentifiableTypeMetadata; import org.hibernate.models.orm.spi.ManagedResources; import org.hibernate.models.orm.spi.ProcessResult; import org.hibernate.models.orm.spi.Processor; import org.hibernate.models.source.SourceModelTestHelper; import org.hibernate.models.source.internal.SourceModelBuildingContextImpl; +import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; import org.hibernate.type.CharBooleanConverter; import org.hibernate.type.YesNoConverter; @@ -115,7 +117,7 @@ public boolean shouldIgnoreUnlistedClasses() { validateJoinedHierarchy( one ); } - validateFilterDefs( processResult.getFilterDefRegistrations() ); + validateFilterDefs( processResult.getGlobalRegistrations().getFilterDefRegistrations() ); } private void validatePersonHierarchy(EntityHierarchy hierarchy) { @@ -151,14 +153,14 @@ private void validateJoinedHierarchy(EntityHierarchy hierarchy) { assertThat( subMetadata.getNumberOfSubTypes() ).isEqualTo( 0 ); } - private void validateFilterDefs(Map filterDefRegistrations) { + private void validateFilterDefs(Map> filterDefRegistrations) { assertThat( filterDefRegistrations ).hasSize( 1 ); assertThat( filterDefRegistrations ).containsKey( "name_filter" ); - final FilterDefRegistration nameFilter = filterDefRegistrations.get( "name_filter" ); - assertThat( nameFilter.getDefaultCondition() ).isEqualTo( "name = :name" ); - final Map parameters = nameFilter.getParameters(); + final AnnotationUsage nameFilter = filterDefRegistrations.get( "name_filter" ); + assertThat( nameFilter.getAttributeValue( "defaultCondition" ) ).isEqualTo( "name = :name" ); + final List> parameters = nameFilter.getAttributeValue( "parameters" ); assertThat( parameters ).hasSize( 1 ); - assertThat( parameters ).containsKey( "name" ); - assertThat( parameters.get( "name" ).getName() ).isEqualTo( String.class.getName() ); + assertThat( parameters.get( 0 ).getAttributeValue( "name" ) ).isEqualTo( "name" ); + assertThat( parameters.get( 0 ).getAttributeValue( "type" ).getName() ).isEqualTo( String.class.getName() ); } } diff --git a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java index a267f92..ca3f19c 100644 --- a/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java +++ b/hibernate-models-orm/src/test/java/org/hibernate/models/orm/xml/XmlProcessingSmokeTests.java @@ -9,15 +9,17 @@ import java.util.List; import java.util.Map; +import org.hibernate.annotations.FilterDef; +import org.hibernate.annotations.ParamDef; import org.hibernate.boot.jaxb.mapping.JaxbEntityMappings; -import org.hibernate.models.orm.internal.FilterDefRegistration; -import org.hibernate.models.orm.internal.GlobalRegistrations; +import org.hibernate.models.orm.internal.GlobalRegistrationsImpl; import org.hibernate.models.orm.internal.ProcessResultCollector; import org.hibernate.models.orm.xml.internal.XmlDocumentImpl; import org.hibernate.models.orm.xml.spi.XmlResources; import org.hibernate.models.orm.xml.spi.PersistenceUnitMetadata; import org.hibernate.models.source.SourceModelTestHelper; import org.hibernate.models.source.internal.StringTypeDescriptor; +import org.hibernate.models.source.spi.AnnotationUsage; import org.hibernate.models.source.spi.ClassDetails; import org.hibernate.models.source.spi.SourceModelBuildingContext; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; @@ -121,34 +123,34 @@ void testSimpleGlobalXmlProcessing() { final ProcessResultCollector processResultCollector = new ProcessResultCollector( false, buildingContext ); collectedXmlResources.getDocuments().forEach( processResultCollector::apply ); - final GlobalRegistrations globalRegistrations = processResultCollector.getGlobalRegistrations(); + final GlobalRegistrationsImpl globalRegistrations = processResultCollector.getGlobalRegistrations(); assertThat( globalRegistrations.getJavaTypeRegistrations() ).hasSize( 1 ); - assertThat( globalRegistrations.getJavaTypeRegistrations().get(0).getDescriptor().getClassName() ) + assertThat( globalRegistrations.getJavaTypeRegistrations().get(0).getAttributeValue( "descriptorClass" ).getClassName() ) .isEqualTo( StringTypeDescriptor.class.getName() ); assertThat( globalRegistrations.getJdbcTypeRegistrations() ).hasSize( 1 ); - assertThat( globalRegistrations.getJdbcTypeRegistrations().get(0).getDescriptor().getClassName() ) + assertThat( globalRegistrations.getJdbcTypeRegistrations().get(0).getAttributeValue( "value" ).getClassName() ) .isEqualTo( ClobJdbcType.class.getName() ); assertThat( globalRegistrations.getUserTypeRegistrations() ).hasSize( 1 ); - assertThat( globalRegistrations.getUserTypeRegistrations().get(0).getUserTypeClass().getClassName() ) + assertThat( globalRegistrations.getUserTypeRegistrations().get(0).getAttributeValue( "userType" ).getClassName() ) .isEqualTo( MyUserType.class.getName() ); assertThat( globalRegistrations.getConverterRegistrations() ).hasSize( 1 ); - assertThat( globalRegistrations.getConverterRegistrations().get(0).getConverterType().getClassName() ) + assertThat( globalRegistrations.getConverterRegistrations().get(0).getAttributeValue( "converter" ).getClassName() ) .isEqualTo( org.hibernate.type.YesNoConverter.class.getName() ); validateFilterDefs( globalRegistrations.getFilterDefRegistrations() ); } - private void validateFilterDefs(Map filterDefRegistrations) { + private void validateFilterDefs(Map> filterDefRegistrations) { assertThat( filterDefRegistrations ).hasSize( 1 ); assertThat( filterDefRegistrations ).containsKey( "amount_filter" ); - final FilterDefRegistration filterDef = filterDefRegistrations.get( "amount_filter" ); - assertThat( filterDef.getDefaultCondition() ).isEqualTo( "amount = :amount" ); - final Map parameters = filterDef.getParameters(); + final AnnotationUsage filterDef = filterDefRegistrations.get( "amount_filter" ); + assertThat( filterDef.getAttributeValue( "defaultCondition" ) ).isEqualTo( "amount = :amount" ); + final List> parameters = filterDef.getAttributeValue( "parameters" ); assertThat( parameters ).hasSize( 1 ); - assertThat( parameters ).containsKey( "amount" ); - assertThat( parameters.get( "amount" ).getName() ).isEqualTo( Integer.class.getName() ); + assertThat( parameters.get(0).getAttributeValue( "name" ) ).isEqualTo( "amount" ); + assertThat( parameters.get(0).getAttributeValue( "type" ).getName() ).isEqualTo( Integer.class.getName() ); } }