HHH-18520 Upgrade to hibernate-models 0.9.0 + HHH-18521 Leverage hibernate-models ModelsConfiguration

This commit is contained in:
Andrea Boriero 2024-08-28 13:48:24 +02:00 committed by Steve Ebersole
parent 6e2ed7f1a0
commit 3c1b5c7a1d
15 changed files with 165 additions and 262 deletions

View File

@ -28,6 +28,7 @@ dependencies {
api jakartaLibs.jta
implementation libs.hibernateModels
implementation libs.hibernateModelsJandex
implementation libs.jandex
implementation libs.classmate
implementation libs.byteBuddy
@ -65,6 +66,7 @@ dependencies {
}
testImplementation "joda-time:joda-time:2.3"
testImplementation dbLibs.h2
testImplementation libs.hibernateModelsJandex
testRuntimeOnly libs.byteBuddy
testRuntimeOnly testLibs.weld

View File

@ -105,8 +105,8 @@ import org.hibernate.mapping.Table;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.mapping.DiscriminatorType;
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ModelsConfiguration;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
@ -228,11 +228,13 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector,
private static SourceModelBuildingContext createModelBuildingContext(BootstrapContext bootstrapContext) {
final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
final ClassLoaderServiceLoading classLoading = new ClassLoaderServiceLoading( classLoaderService );
return new SourceModelBuildingContextImpl(
classLoading,
bootstrapContext.getJandexView(),
ModelsHelper::preFillRegistries
);
final ModelsConfiguration modelsConfiguration = new ModelsConfiguration();
modelsConfiguration.setClassLoading(classLoading);
// modelsConfiguration.setExplicitContextProvider( );
modelsConfiguration.configValue( "hibernate.models.jandex.index", bootstrapContext.getJandexView() );
modelsConfiguration.setRegistryPrimer( ModelsHelper::preFillRegistries );
return modelsConfiguration.bootstrap();
}
@Override

View File

@ -87,10 +87,8 @@ public class PropertyInferredData implements PropertyData {
if ( targetAnnotation != null ) {
final String targetName = targetAnnotation.value();
final SourceModelBuildingContext sourceModelBuildingContext = sourceModelContext;
final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry().resolveClassDetails(
targetName,
name -> new DynamicClassDetails( targetName, sourceModelBuildingContext )
);
final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry()
.resolveClassDetails( targetName );
return new ClassTypeDetailsImpl( classDetails, TypeDetails.Kind.CLASS );
}
@ -119,10 +117,8 @@ public class PropertyInferredData implements PropertyData {
final org.hibernate.boot.internal.Target annotationUsage = propertyMember.getDirectAnnotationUsage( org.hibernate.boot.internal.Target.class );
if ( annotationUsage != null ) {
final String targetName = annotationUsage.value();
final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry().resolveClassDetails(
targetName,
name -> new DynamicClassDetails( targetName, sourceModelBuildingContext )
);
final ClassDetails classDetails = sourceModelBuildingContext.getClassDetailsRegistry()
.resolveClassDetails( targetName );
return new ClassTypeDetailsImpl( classDetails, TypeDetails.Kind.CLASS );
}

View File

@ -72,7 +72,8 @@ import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.mapping.Table;
import org.hibernate.models.internal.jandex.JandexIndexerHelper;
import org.hibernate.models.internal.MutableClassDetailsRegistry;
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.ClassLoading;
@ -458,7 +459,7 @@ public class MetadataBuildingProcess {
xmlProcessingResult.apply( xmlPreProcessingResult.getPersistenceUnitMetadata() );
return new DomainModelSource(
classDetailsRegistry.makeImmutableCopy(),
classDetailsRegistry,
jandexIndex,
allKnownClassNames,
modelCategorizationCollector.getGlobalRegistrations(),
@ -516,40 +517,6 @@ public class MetadataBuildingProcess {
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
}
//
// public static void preFillRegistries(RegistryPrimer.Contributions contributions, SourceModelBuildingContext buildingContext) {
// OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation );
//
// final IndexView jandexIndex = buildingContext.getJandexIndex();
// if ( jandexIndex == null ) {
// return;
// }
//
// final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
// final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
//
// for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
// final String className = knownClass.name().toString();
//
// if ( knownClass.isAnnotation() ) {
// // it is always safe to load the annotation classes - we will never be enhancing them
// //noinspection rawtypes
// final Class annotationClass = buildingContext
// .getClassLoading()
// .classForName( className );
// //noinspection unchecked
// annotationDescriptorRegistry.resolveDescriptor(
// annotationClass,
// (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
// );
// }
//
// classDetailsRegistry.resolveClassDetails(
// className,
// (name) -> new JandexClassDetails( knownClass, buildingContext )
// );
// }
// }
private static void processAdditionalMappingContributions(
InFlightMetadataCollectorImpl metadataCollector,
@ -628,6 +595,7 @@ public class MetadataBuildingProcess {
additionalClassDetails.add( classDetails );
metadataCollector.getSourceModelBuildingContext()
.getClassDetailsRegistry()
.as( MutableClassDetailsRegistry.class )
.addClassDetails( classDetails.getName(), classDetails );
}

View File

@ -7,6 +7,12 @@
package org.hibernate.boot.models.categorize.internal;
import java.net.URL;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import java.util.Set;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.models.spi.ClassLoading;
@ -37,4 +43,9 @@ public class ClassLoaderServiceLoading implements ClassLoading {
public URL locateResource(String resourceName) {
return classLoaderService.locateResource( resourceName );
}
@Override
public <S> Collection<S> loadJavaServices(Class<S> serviceType) {
return classLoaderService.loadJavaServices( serviceType );
}
}

View File

@ -31,8 +31,8 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataBuildingOptions;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.internal.jandex.JandexIndexerHelper;
import org.hibernate.models.internal.BasicModelBuildingContextImpl;
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
@ -103,9 +103,8 @@ public class ManagedResourcesProcessor {
// At this point we know all managed class names across all sources.
// Resolve the Jandex Index and build the SourceModelBuildingContext.
final IndexView jandexIndex = resolveJandexIndex( allKnownClassNames, bootstrapContext.getJandexView(), classLoading );
final SourceModelBuildingContextImpl sourceModelBuildingContext = new SourceModelBuildingContextImpl(
final BasicModelBuildingContextImpl sourceModelBuildingContext = new BasicModelBuildingContextImpl(
classLoading,
jandexIndex,
ModelsHelper::preFillRegistries
);
@ -174,16 +173,11 @@ public class ManagedResourcesProcessor {
// OUTPUTS:
// - CategorizedDomainModel
final ClassDetailsRegistry classDetailsRegistryImmutable = classDetailsRegistry
.makeImmutableCopy();
final AnnotationDescriptorRegistry annotationDescriptorRegistryImmutable = descriptorRegistry
.makeImmutableCopy();
// Collect the entity hierarchies based on the set of `rootEntities`
final ModelCategorizationContextImpl mappingBuildingContext = new ModelCategorizationContextImpl(
classDetailsRegistryImmutable,
annotationDescriptorRegistryImmutable,
classDetailsRegistry,
descriptorRegistry,
globalRegistrations
);
@ -212,8 +206,8 @@ public class ManagedResourcesProcessor {
return modelCategorizationCollector.createResult(
entityHierarchies,
xmlPreProcessingResult.getPersistenceUnitMetadata(),
classDetailsRegistryImmutable,
annotationDescriptorRegistryImmutable
classDetailsRegistry,
descriptorRegistry
);
}

View File

@ -7,8 +7,8 @@
package org.hibernate.boot.models.internal;
import org.hibernate.annotations.TenantId;
import org.hibernate.models.internal.jandex.JandexClassDetails;
import org.hibernate.models.internal.jdk.JdkBuilders;
import org.hibernate.models.jandex.spi.JandexModelBuildingContext;
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.RegistryPrimer;
@ -26,34 +26,33 @@ public class ModelsHelper {
buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class );
final IndexView jandexIndex = buildingContext.getJandexIndex();
if ( jandexIndex == null ) {
return;
}
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
final String className = knownClass.name().toString();
if ( knownClass.isAnnotation() ) {
// it is always safe to load the annotation classes - we will never be enhancing them
//noinspection rawtypes
final Class annotationClass = buildingContext
.getClassLoading()
.classForName( className );
//noinspection unchecked
annotationDescriptorRegistry.resolveDescriptor(
annotationClass,
(t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
);
if ( buildingContext instanceof JandexModelBuildingContext ) {
final IndexView jandexIndex = buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex();
if ( jandexIndex == null ) {
return;
}
classDetailsRegistry.resolveClassDetails(
className,
(name) -> new JandexClassDetails( knownClass, buildingContext )
);
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
final String className = knownClass.name().toString();
if ( knownClass.isAnnotation() ) {
// it is always safe to load the annotation classes - we will never be enhancing them
//noinspection rawtypes
final Class annotationClass = buildingContext
.getClassLoading()
.classForName( className );
//noinspection unchecked
annotationDescriptorRegistry.resolveDescriptor(
annotationClass,
(t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
);
}
classDetailsRegistry.resolveClassDetails( className );
}
}
}
}

View File

@ -15,7 +15,6 @@ import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
import org.hibernate.boot.models.DialectOverrideAnnotations;
@ -23,13 +22,13 @@ import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.XmlAnnotations;
import org.hibernate.models.AnnotationAccessException;
import org.hibernate.models.jandex.spi.JandexModelBuildingContext;
import org.hibernate.models.jandex.spi.JandexValueExtractor;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.AttributeDescriptor;
import org.hibernate.models.spi.JandexValueExtractor;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
/**
* @author Steve Ebersole
@ -76,7 +75,8 @@ public class OrmAnnotationHelper {
}
public static <V> V extractJandexValue(AnnotationInstance jandexAnnotation, AttributeDescriptor<V> attributeDescriptor, SourceModelBuildingContext modelContext) {
final JandexValueExtractor<V> extractor = attributeDescriptor.getTypeDescriptor().createJandexValueExtractor( modelContext );
final JandexValueExtractor<V> extractor = modelContext.as( JandexModelBuildingContext.class )
.getJandexValueExtractor( attributeDescriptor.getTypeDescriptor() );
return extractor.extractValue( jandexAnnotation, attributeDescriptor, modelContext );
// final AnnotationValue value = jandexAnnotation.value( attributeDescriptor.getName() );
// return attributeDescriptor

View File

@ -44,9 +44,10 @@ import org.hibernate.models.ModelsException;
import org.hibernate.models.internal.ClassTypeDetailsImpl;
import org.hibernate.models.internal.ModelsClassLogging;
import org.hibernate.models.internal.ModifierUtils;
import org.hibernate.models.internal.RenderingCollectorImpl;
import org.hibernate.models.internal.dynamic.DynamicClassDetails;
import org.hibernate.models.internal.dynamic.DynamicFieldDetails;
import org.hibernate.models.rendering.internal.RenderingTargetCollectingImpl;
import org.hibernate.models.rendering.internal.SimpleRenderer;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.FieldDetails;
@ -99,17 +100,7 @@ public class ManagedTypeProcessor {
memberAdjuster = ManagedTypeProcessor::adjustDynamicTypeMember;
classAccessType = AccessType.FIELD;
classDetails = (MutableClassDetails) classDetailsRegistry.resolveClassDetails(
jaxbEntity.getName(),
(name) -> new DynamicClassDetails(
jaxbEntity.getName(),
null,
false,
null,
null,
xmlDocumentContext.getModelBuildingContext()
)
);
classDetails = (MutableClassDetails) classDetailsRegistry.resolveClassDetails( jaxbEntity.getName() );
prepareDynamicClass( classDetails, jaxbEntity, xmlDocumentContext );
}
@ -625,9 +616,10 @@ public class ManagedTypeProcessor {
return;
}
final RenderingCollectorImpl renderingCollector = new RenderingCollectorImpl();
classDetails.render( renderingCollector, xmlDocumentContext.getModelBuildingContext() );
XML_PROCESS_LOGGER.debugf( "Class annotations from XML for %s:\n%s", classDetails.getName(), renderingCollector.toString() );
final RenderingTargetCollectingImpl collectingTarget = new RenderingTargetCollectingImpl();
final SimpleRenderer renderer = new SimpleRenderer( collectingTarget );
renderer.renderClass( classDetails, xmlDocumentContext.getModelBuildingContext() );
XML_PROCESS_LOGGER.debugf( "Class annotations from XML for %s:\n%s", classDetails.getName(), renderer.toString() );
}
private static void applyAccessAnnotation(
@ -943,7 +935,7 @@ public class ManagedTypeProcessor {
}
// no class == dynamic...
classDetails = (MutableClassDetails) classDetailsRegistry
.resolveClassDetails( jaxbEmbeddable.getName(), DynamicClassDetails::new );
.resolveClassDetails( jaxbEmbeddable.getName() );
classAccessType = AccessType.FIELD;
memberAdjuster = ManagedTypeProcessor::adjustDynamicTypeMember;

View File

@ -137,10 +137,8 @@ public interface XmlDocumentContext {
// <embedded/>, <embedded-id/>
final String target = jaxbEmbeddedMapping.getTarget();
if ( isNotEmpty( target ) ) {
return (MutableClassDetails) getModelBuildingContext().getClassDetailsRegistry().resolveClassDetails(
target,
(name) -> new DynamicClassDetails( target, getModelBuildingContext() )
);
return (MutableClassDetails) getModelBuildingContext().getClassDetailsRegistry()
.resolveClassDetails( target );
}
// fall through to exception
}
@ -148,17 +146,8 @@ public interface XmlDocumentContext {
if ( jaxbPersistentAttribute instanceof JaxbAssociationAttribute jaxbAssociationAttribute ) {
final String target = jaxbAssociationAttribute.getTargetEntity();
if ( isNotEmpty( target ) ) {
return (MutableClassDetails) getModelBuildingContext().getClassDetailsRegistry().resolveClassDetails(
target,
(name) -> new DynamicClassDetails(
target,
null,
false,
null,
null,
getModelBuildingContext()
)
);
return (MutableClassDetails) getModelBuildingContext().getClassDetailsRegistry()
.resolveClassDetails( target );
}
// fall through to exception
}

View File

@ -20,7 +20,7 @@ import org.hibernate.boot.models.xml.spi.XmlProcessingResult;
import org.hibernate.boot.models.xml.spi.XmlProcessor;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.internal.BasicModelBuildingContextImpl;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.FieldDetails;
import org.hibernate.models.spi.MemberDetails;
@ -91,9 +91,8 @@ public abstract class Ejb3XmlTestCase extends BaseUnitTestCase {
persistenceUnitMetadata
);
final SourceModelBuildingContext modelBuildingContext = new SourceModelBuildingContextImpl(
final SourceModelBuildingContext modelBuildingContext = new BasicModelBuildingContextImpl(
SIMPLE_CLASS_LOADING,
null,
(contributions, inFlightContext) -> {
OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation );
}

View File

@ -52,17 +52,15 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.MappingSettings;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.models.internal.AnnotationDescriptorRegistryStandard;
import org.hibernate.models.internal.BaseLineJavaTypes;
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
import org.hibernate.models.internal.jandex.JandexBuilders;
import org.hibernate.models.internal.jandex.JandexIndexerHelper;
import org.hibernate.models.internal.BasicModelBuildingContextImpl;
import org.hibernate.models.internal.jdk.JdkBuilders;
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
import org.hibernate.models.jandex.internal.JandexModelBuildingContextImpl;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.ClassDetailsRegistry;
import org.hibernate.models.spi.ClassLoading;
import org.hibernate.models.spi.SourceModelBuildingContext;
import org.hibernate.service.ServiceRegistry;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.Index;
@ -87,49 +85,50 @@ public class SourceModelTestHelper {
return createBuildingContext( jandexIndex, modelClasses );
}
public static SourceModelBuildingContextImpl createBuildingContext(Index jandexIndex, Class<?>... modelClasses) {
public static SourceModelBuildingContext createBuildingContext(Index jandexIndex, Class<?>... modelClasses) {
return createBuildingContext( jandexIndex, SIMPLE_CLASS_LOADING, modelClasses );
}
public static SourceModelBuildingContextImpl createBuildingContext(
public static SourceModelBuildingContext createBuildingContext(
Index jandexIndex,
ClassLoading classLoadingAccess,
Class<?>... modelClasses) {
final SourceModelBuildingContextImpl buildingContext = new SourceModelBuildingContextImpl(
classLoadingAccess,
jandexIndex,
(contributions, buildingContext1) -> OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation )
);
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
final AnnotationDescriptorRegistryStandard annotationDescriptorRegistry = (AnnotationDescriptorRegistryStandard) buildingContext.getAnnotationDescriptorRegistry();
final SourceModelBuildingContext ctx;
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
// if ( knownClass.simpleName().endsWith( "package-info" ) ) {
// new PackageDetailsImpl( knownClass, buildingContext );
// continue;
// }
classDetailsRegistry.resolveClassDetails(
knownClass.name().toString(),
JandexBuilders.DEFAULT_BUILDER
if ( jandexIndex == null ) {
ctx = new BasicModelBuildingContextImpl(
classLoadingAccess,
(contributions, buildingContext1) -> OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation )
);
}
else {
ctx = new JandexModelBuildingContextImpl(
jandexIndex,
classLoadingAccess,
(contributions, buildingContext1) -> OrmAnnotationHelper.forEachOrmAnnotation( contributions::registerAnnotation )
);
if ( knownClass.isAnnotation() ) {
final Class<? extends Annotation> annotationClass = buildingContext
.getClassLoading()
.classForName( knownClass.name().toString() );
annotationDescriptorRegistry.resolveDescriptor( annotationClass, annotationType -> JdkBuilders.buildAnnotationDescriptor(
annotationType,
buildingContext
) );
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
ctx.getClassDetailsRegistry().resolveClassDetails( knownClass.name().toString() );
if ( knownClass.isAnnotation() ) {
final Class<? extends Annotation> annotationClass = classLoadingAccess.classForName( knownClass.name().toString() );
ctx.getAnnotationDescriptorRegistry().resolveDescriptor(
annotationClass,
annotationType -> JdkBuilders.buildAnnotationDescriptor(
annotationType,
ctx
)
);
}
}
}
for ( int i = 0; i < modelClasses.length; i++ ) {
classDetailsRegistry.resolveClassDetails( modelClasses[i].getName() );
ctx.getClassDetailsRegistry().resolveClassDetails( modelClasses[i].getName() );
}
return buildingContext;
return ctx;
}
public static Index buildJandexIndex(Class<?>... modelClasses) {
@ -275,11 +274,21 @@ public class SourceModelTestHelper {
? buildJandexIndex( classLoading, allKnownClassNames )
: null;
final SourceModelBuildingContextImpl sourceModelBuildingContext = new SourceModelBuildingContextImpl(
classLoading,
jandexIndex,
ModelsHelper::preFillRegistries
);
final SourceModelBuildingContext sourceModelBuildingContext;
if ( jandexIndex == null ) {
sourceModelBuildingContext = new BasicModelBuildingContextImpl(
classLoading,
ModelsHelper::preFillRegistries
);
}
else {
sourceModelBuildingContext = new JandexModelBuildingContextImpl(
jandexIndex,
classLoading,
ModelsHelper::preFillRegistries
);
}
final RootMappingDefaults rootMappingDefaults = new RootMappingDefaults(
metadataBuildingOptions.getMappingDefaults(),

View File

@ -7,7 +7,7 @@
package org.hibernate.orm.test.boot.models;
import org.hibernate.models.AnnotationAccessException;
import org.hibernate.models.internal.jandex.JandexClassDetails;
import org.hibernate.models.jandex.internal.JandexClassDetails;
import org.hibernate.models.spi.AnnotationDescriptor;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.FieldDetails;

View File

@ -11,20 +11,13 @@ import java.io.InputStream;
import java.util.List;
import org.hibernate.boot.ResourceStreamLocator;
import org.hibernate.boot.models.HibernateAnnotations;
import org.hibernate.boot.models.JpaAnnotations;
import org.hibernate.boot.models.annotations.internal.EntityJpaAnnotation;
import org.hibernate.boot.spi.AdditionalMappingContributions;
import org.hibernate.boot.spi.AdditionalMappingContributor;
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;
import org.hibernate.models.spi.MutableMemberDetails;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry.JavaService;
@ -43,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Steve Ebersole
*
* @implNote hibernate-envers is already a full testing of contributing a {@code hbm.xml}
* document; so we skip that here until if/when we transition it to use a better approach
*/
@ -105,13 +97,17 @@ public class AdditionalMappingContributorTests {
@DomainModel
@SessionFactory
@SuppressWarnings("JUnitMalformedDeclaration")
void verifyJdkClassDetailsContributions(DomainModelScope domainModelScope, SessionFactoryScope sessionFactoryScope) {
final PersistentClass entity4Binding = domainModelScope.getDomainModel().getEntityBinding( Entity4.class.getName() );
void verifyJdkClassDetailsContributions(
DomainModelScope domainModelScope,
SessionFactoryScope sessionFactoryScope) {
final PersistentClass entity4Binding = domainModelScope.getDomainModel()
.getEntityBinding( Entity4.class.getName() );
assertThat( entity4Binding ).isNotNull();
assertThat( entity4Binding.getIdentifierProperty() ).isNotNull();
assertThat( entity4Binding.getProperties() ).hasSize( 1 );
final PersistentClass entity5Binding = domainModelScope.getDomainModel().getEntityBinding( Entity5.class.getName() );
final PersistentClass entity5Binding = domainModelScope.getDomainModel()
.getEntityBinding( Entity5.class.getName() );
assertThat( entity5Binding ).isNotNull();
assertThat( entity5Binding.getIdentifierProperty() ).isNotNull();
assertThat( entity5Binding.getProperties() ).hasSize( 1 );
@ -137,7 +133,9 @@ public class AdditionalMappingContributorTests {
@DomainModel
@SessionFactory
@SuppressWarnings("JUnitMalformedDeclaration")
void verifyDynamicClassDetailsContributions(DomainModelScope domainModelScope, SessionFactoryScope sessionFactoryScope) {
void verifyDynamicClassDetailsContributions(
DomainModelScope domainModelScope,
SessionFactoryScope sessionFactoryScope) {
final PersistentClass entity6Binding = domainModelScope.getDomainModel().getEntityBinding( "Entity6" );
assertThat( entity6Binding ).isNotNull();
assertThat( entity6Binding.getIdentifierProperty() ).isNotNull();
@ -150,12 +148,12 @@ public class AdditionalMappingContributorTests {
} );
}
@Entity( name = "Entity1" )
@Table( name = "Entity1" )
@Entity(name = "Entity1")
@Table(name = "Entity1")
public static class Entity1 {
@Id
private Integer id;
@Basic
@Id
private Integer id;
@Basic
private String name;
@SuppressWarnings("unused")
@ -182,12 +180,12 @@ public class AdditionalMappingContributorTests {
}
@Entity( name = "Entity2" )
@Table( name = "Entity2" )
@Entity(name = "Entity2")
@Table(name = "Entity2")
public static class Entity2 {
@Id
private Integer id;
@Basic
@Id
private Integer id;
@Basic
private String name;
@SuppressWarnings("unused")
@ -213,12 +211,12 @@ public class AdditionalMappingContributorTests {
}
}
@Entity( name = "Entity3" )
@Table( name = "Entity3" )
@Entity(name = "Entity3")
@Table(name = "Entity3")
public static class Entity3 {
@Id
private Integer id;
@Basic
@Id
private Integer id;
@Basic
private String name;
@SuppressWarnings("unused")
@ -245,8 +243,8 @@ public class AdditionalMappingContributorTests {
}
@SuppressWarnings("unused")
@Entity(name="Entity4")
@Table(name="Entity4")
@Entity(name = "Entity4")
@Table(name = "Entity4")
public static class Entity4 {
@Id
private Integer id;
@ -277,7 +275,8 @@ public class AdditionalMappingContributorTests {
InFlightMetadataCollector metadata,
ResourceStreamLocator resourceStreamLocator,
MetadataBuildingContext buildingContext) {
try ( final InputStream stream = resourceStreamLocator.locateResourceStream( "mappings/intg/contributed-mapping.xml" ) ) {
try (final InputStream stream = resourceStreamLocator.locateResourceStream(
"mappings/intg/contributed-mapping.xml" )) {
contributions.contributeBinding( stream );
}
catch (IOException e) {
@ -297,50 +296,24 @@ public class AdditionalMappingContributorTests {
.getSourceModelBuildingContext()
.getClassDetailsRegistry();
contributeEntity4Details( contributions, buildingContext, classDetailsRegistry );
contributeEntity5Details( contributions, buildingContext, classDetailsRegistry );
contributeEntity4Details( contributions, classDetailsRegistry );
contributeEntity5Details( contributions, classDetailsRegistry );
}
private static void contributeEntity4Details(
AdditionalMappingContributions contributions,
MetadataBuildingContext buildingContext,
ClassDetailsRegistry classDetailsRegistry) {
final ClassDetails entity4Details = classDetailsRegistry.resolveClassDetails(
Entity4.class.getName(),
(name, modelBuildingContext) -> {
assertThat( name ).isEqualTo( Entity4.class.getName() );
assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );
return new JdkClassDetails( Entity4.class, modelBuildingContext );
}
Entity4.class.getName()
);
contributions.contributeManagedClass( entity4Details );
}
private static void contributeEntity5Details(
AdditionalMappingContributions contributions,
MetadataBuildingContext buildingContext,
ClassDetailsRegistry classDetailsRegistry) {
final ClassDetails entity5Details = classDetailsRegistry.resolveClassDetails(
Entity5.class.getName(),
(name, modelBuildingContext) -> {
assertThat( name ).isEqualTo( Entity5.class.getName() );
assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );
final JdkClassDetails jdkClassDetails = new JdkClassDetails(
Entity5.class,
modelBuildingContext
);
final EntityJpaAnnotation entityUsage = (EntityJpaAnnotation) jdkClassDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
modelBuildingContext
);
entityUsage.name( "___Entity5___" );
final MutableMemberDetails idField = (MutableMemberDetails) jdkClassDetails.findFieldByName( "id" );
idField.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );
return jdkClassDetails;
}
Entity5.class.getName()
);
contributions.contributeManagedClass( entity5Details );
}
@ -356,46 +329,14 @@ public class AdditionalMappingContributorTests {
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getMetadataCollector()
.getSourceModelBuildingContext()
.getClassDetailsRegistry();
contributeEntity6Details( contributions, buildingContext, classDetailsRegistry );
contributeEntity6Details( contributions, classDetailsRegistry );
}
private void contributeEntity6Details(
AdditionalMappingContributions contributions,
MetadataBuildingContext buildingContext,
ClassDetailsRegistry classDetailsRegistry) {
final ClassDetails entity6Details = classDetailsRegistry.resolveClassDetails(
"Entity6",
(name, modelBuildingContext) -> {
assertThat( name ).isEqualTo( "Entity6" );
assertThat( modelBuildingContext ).isSameAs( buildingContext.getMetadataCollector().getSourceModelBuildingContext() );
final DynamicClassDetails classDetails = new DynamicClassDetails( "Entity6", modelBuildingContext );
final EntityJpaAnnotation entityUsage = (EntityJpaAnnotation) classDetails.applyAnnotationUsage(
JpaAnnotations.ENTITY,
modelBuildingContext
);
entityUsage.name( "Entity6" );
final DynamicFieldDetails idMember = classDetails.applyAttribute(
"id",
classDetailsRegistry.resolveClassDetails( Integer.class.getName() ),
false,
false,
modelBuildingContext
);
idMember.applyAnnotationUsage( JpaAnnotations.ID, modelBuildingContext );
final DynamicFieldDetails nameMember = classDetails.applyAttribute(
"name",
classDetailsRegistry.resolveClassDetails( String.class.getName() ),
false,
false,
modelBuildingContext
);
nameMember.applyAnnotationUsage( HibernateAnnotations.NATIONALIZED, modelBuildingContext );
return classDetails;
}
"Entity6"
);
contributions.contributeManagedClass( entity6Details );
}

View File

@ -76,7 +76,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.8.6"
def hibernateModelsVersion = version "hibernateModels", "0.9.0"
def jandexVersion = version "jandex", "3.2.0"
def jacksonVersion = version "jackson", "2.17.0"
def jbossLoggingVersion = version "jbossLogging", "3.6.0.Final"
@ -107,6 +107,7 @@ dependencyResolutionManagement {
library( "loggingProcessor", "org.jboss.logging", "jboss-logging-processor" ).versionRef( jbossLoggingToolVersion )
library( "hibernateModels", "org.hibernate.models", "hibernate-models" ).versionRef( hibernateModelsVersion )
library( "hibernateModelsJandex", "org.hibernate.models", "hibernate-models-jandex" ).versionRef( hibernateModelsVersion )
library( "jandex", "io.smallrye", "jandex" ).versionRef( jandexVersion )
library( "classmate", "com.fasterxml", "classmate" ).versionRef( classmateVersion )