Skip to content

Commit

Permalink
HHH-17993 Metamodel processing on bootstrap: avoid retrying same meta…
Browse files Browse the repository at this point in the history
…model class name multiple times
  • Loading branch information
Sanne committed Apr 22, 2024
1 parent 08127f2 commit 8f277d4
Showing 1 changed file with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ public void wrapUp() {
LOG.trace( "Wrapping up metadata context..." );
}

boolean staticMetamodelScanEnabled =
final boolean staticMetamodelScanEnabled =
this.jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED;
final Set<String> processedMetamodelClasses = new HashSet<>();

//we need to process types from superclasses to subclasses
for ( Object mapping : orderedMappings ) {
Expand Down Expand Up @@ -336,7 +337,7 @@ public void wrapUp() {
( (AttributeContainer<?>) jpaMapping ).getInFlightAccess().finishUp();

if ( staticMetamodelScanEnabled ) {
populateStaticMetamodel( jpaMapping );
populateStaticMetamodel( jpaMapping, processedMetamodelClasses );
}
}
finally {
Expand Down Expand Up @@ -380,7 +381,7 @@ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
( (AttributeContainer<?>) jpaType ).getInFlightAccess().finishUp();

if ( staticMetamodelScanEnabled ) {
populateStaticMetamodel( jpaType );
populateStaticMetamodel( jpaType, processedMetamodelClasses );
}
}
finally {
Expand Down Expand Up @@ -420,7 +421,7 @@ else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
embeddables.put( embeddable.getJavaType(), embeddable );

if ( staticMetamodelScanEnabled ) {
populateStaticMetamodel( embeddable );
populateStaticMetamodel( embeddable, processedMetamodelClasses );
}
}
}
Expand Down Expand Up @@ -648,43 +649,39 @@ private MappedSuperclass getMappedSuperclass(MappedSuperclass mappedSuperclass)
return attributes;
}

private <X> void populateStaticMetamodel(ManagedDomainType<X> managedType) {
private <X> void populateStaticMetamodel(ManagedDomainType<X> managedType, Set<String> processedMetamodelClassName) {
final Class<X> managedTypeClass = managedType.getJavaType();
if ( managedTypeClass == null ) {
// should indicate MAP entity mode, skip...
return;
}
final String metamodelClassName = managedTypeClass.getName() + '_';
try {
final Class<?> metamodelClass = classLoaderService.classForName( metamodelClassName );
// we found the class; so populate it...
registerAttributes( metamodelClass, managedType );
if ( processedMetamodelClassName.add( metamodelClassName ) ) {
try {
injectField( metamodelClass, "class_", managedType, false );
final Class<?> metamodelClass = classLoaderService.classForName( metamodelClassName );
// we found the class; so populate it...
registerAttributes( metamodelClass, managedType );
try {
injectField( metamodelClass, "class_", managedType, false );
}
catch ( NoSuchFieldException e ) {
// ignore
}
}
catch (NoSuchFieldException e) {
// ignore
catch ( ClassLoadingException ignore ) {
// nothing to do...
}
}
catch (ClassLoadingException ignore) {
// nothing to do...
}

// todo : this does not account for @MappedSuperclass, mainly because this is not being tracked in our
// internal metamodel as populated from the annotations properly
ManagedDomainType<? super X> superType = managedType.getSuperType();
if ( superType != null ) {
populateStaticMetamodel( superType );
// todo : this does not account for @MappedSuperclass, mainly because this is not being tracked in our
// internal metamodel as populated from the annotations properly
ManagedDomainType<? super X> superType = managedType.getSuperType();
if ( superType != null ) {
populateStaticMetamodel( superType, processedMetamodelClassName );
}
}
}

private final Set<Class<?>> processedMetamodelClasses = new HashSet<>();

private <X> void registerAttributes(Class<?> metamodelClass, ManagedDomainType<X> managedType) {
if ( !processedMetamodelClasses.add( metamodelClass ) ) {
return;
}

// push the attributes on to the metamodel class...
for ( Attribute<X, ?> attribute : managedType.getDeclaredAttributes() ) {
registerAttribute( metamodelClass, attribute );
Expand Down

0 comments on commit 8f277d4

Please sign in to comment.