Skip to content

Commit b8a6fc2

Browse files
committed
fix crazy and ancient use of .class.isAssignableFrom()
1 parent 78da903 commit b8a6fc2

File tree

3 files changed

+33
-36
lines changed

3 files changed

+33
-36
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ private static EmbeddableTypeImpl<?> dynamicEmbeddableType(MetadataContext conte
303303
private static DomainType<?> entityDomainType(ValueContext typeContext, MetadataContext context) {
304304
final var type = typeContext.getHibernateValue().getType();
305305
if ( type instanceof EntityType entityType ) {
306-
final var domainType =
307-
context.locateIdentifiableType( entityType.getAssociatedEntityName() );
306+
final var domainType = context.locateIdentifiableType( entityType.getAssociatedEntityName() );
308307
if ( domainType == null ) {
309308
// Due to the use of generics, it can happen that a mapped super class uses a type
310309
// for an attribute that is not a managed type. Since this case is not specifically mentioned

hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetamodelPopulationSetting.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import java.util.Locale;
88
import java.util.Map;
99

10-
import org.hibernate.cfg.AvailableSettings;
1110
import org.hibernate.internal.util.config.ConfigurationHelper;
1211

12+
import static org.hibernate.cfg.MappingSettings.STATIC_METAMODEL_POPULATION;
13+
1314
/**
1415
* Enumerated setting used to control whether Hibernate looks for and populates
1516
* JPA static metamodel models of application's domain model.
@@ -41,13 +42,14 @@ public static JpaStaticMetamodelPopulationSetting parse(String setting) {
4142
};
4243
}
4344

44-
public static JpaStaticMetamodelPopulationSetting determineJpaStaticMetaModelPopulationSetting(Map configurationValues) {
45+
public static JpaStaticMetamodelPopulationSetting determineJpaStaticMetaModelPopulationSetting(
46+
Map<String, Object> configurationValues) {
4547
return parse( determineSetting( configurationValues ) );
4648
}
4749

48-
private static String determineSetting(Map configurationValues) {
50+
private static String determineSetting(Map<String, Object> configurationValues) {
4951
return ConfigurationHelper.getString(
50-
AvailableSettings.STATIC_METAMODEL_POPULATION,
52+
STATIC_METAMODEL_POPULATION,
5153
configurationValues,
5254
"skipUnsupported"
5355
);

hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ public void registerEntityType(PersistentClass persistentClass, EntityTypeImpl<
190190
public void registerEmbeddableType(
191191
EmbeddableDomainType<?> embeddableType,
192192
Component bootDescriptor) {
193-
assert embeddableType.getJavaType() != null;
194-
assert ! Map.class.isAssignableFrom( embeddableType.getJavaType() );
195-
196-
embeddablesToProcess
197-
.computeIfAbsent( embeddableType.getJavaType(), k -> new ArrayList<>( 1 ) )
193+
final var javaType = embeddableType.getJavaType();
194+
assert javaType != null;
195+
assert !Map.class.isAssignableFrom( javaType );
196+
embeddablesToProcess.computeIfAbsent( javaType, k -> new ArrayList<>( 1 ) )
198197
.add( embeddableType );
199198
registerComponentByEmbeddable( embeddableType, bootDescriptor );
200199
}
@@ -254,9 +253,8 @@ public EntityDomainType<?> locateEntityType(Class<?> javaType) {
254253
*
255254
* @return The corresponding JPA {@link org.hibernate.type.EntityType}, or null.
256255
*/
257-
@SuppressWarnings("unchecked")
258-
public <E> IdentifiableDomainType<E> locateIdentifiableType(String entityName) {
259-
return (IdentifiableDomainType<E>) identifiableTypesByName.get( entityName );
256+
public IdentifiableDomainType<?> locateIdentifiableType(String entityName) {
257+
return identifiableTypesByName.get( entityName );
260258
}
261259

262260
public Map<String, IdentifiableDomainType<?>> getIdentifiableTypesByName() {
@@ -298,31 +296,30 @@ public void wrapUp() {
298296
}
299297

300298
final boolean staticMetamodelScanEnabled =
301-
this.jpaStaticMetaModelPopulationSetting != JpaStaticMetamodelPopulationSetting.DISABLED;
299+
jpaStaticMetaModelPopulationSetting != JpaStaticMetamodelPopulationSetting.DISABLED;
302300
final Set<String> processedMetamodelClasses = new HashSet<>();
303301

304302
//we need to process types from superclasses to subclasses
305303
for ( Object mapping : orderedMappings ) {
306-
if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
307-
final PersistentClass safeMapping = (PersistentClass) mapping;
304+
if ( mapping instanceof PersistentClass persistentClass ) {
308305
if ( log.isTraceEnabled() ) {
309-
log.trace( "Starting entity [" + safeMapping.getEntityName() + ']' );
306+
log.trace( "Starting entity [" + persistentClass.getEntityName() + ']' );
310307
}
311308
try {
312-
final EntityDomainType<?> jpaMapping = entityTypesByPersistentClass.get( safeMapping );
309+
final var jpaMapping = entityTypesByPersistentClass.get( persistentClass );
313310

314-
applyIdMetadata( safeMapping, jpaMapping );
315-
applyVersionAttribute( safeMapping, jpaMapping );
316-
applyGenericProperties( safeMapping, jpaMapping );
311+
applyIdMetadata( persistentClass, jpaMapping );
312+
applyVersionAttribute( persistentClass, jpaMapping );
313+
applyGenericProperties( persistentClass, jpaMapping );
317314

318-
for ( Property property : safeMapping.getDeclaredProperties() ) {
319-
if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
315+
for ( Property property : persistentClass.getDeclaredProperties() ) {
316+
if ( property.getValue() == persistentClass.getIdentifierMapper() ) {
320317
// property represents special handling for id-class mappings but we have already
321318
// accounted for the embedded property mappings in #applyIdMetadata &&
322319
// #buildIdClassAttributes
323320
continue;
324321
}
325-
if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
322+
if ( persistentClass.isVersioned() && property == persistentClass.getVersion() ) {
326323
// skip the version property, it was already handled previously.
327324
continue;
328325
}
@@ -337,30 +334,29 @@ public void wrapUp() {
337334
}
338335
finally {
339336
if ( log.isTraceEnabled() ) {
340-
log.trace( "Completed entity [" + safeMapping.getEntityName() + ']' );
337+
log.trace( "Completed entity [" + persistentClass.getEntityName() + ']' );
341338
}
342339
}
343340
}
344-
else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
345-
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
341+
else if ( mapping instanceof MappedSuperclass mappedSuperclass ) {
346342
if ( log.isTraceEnabled() ) {
347-
log.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']' );
343+
log.trace( "Starting mapped superclass [" + mappedSuperclass.getMappedClass().getName() + ']' );
348344
}
349345
try {
350-
final var jpaType = mappedSuperclassByMappedSuperclassMapping.get( safeMapping );
346+
final var jpaType = mappedSuperclassByMappedSuperclassMapping.get( mappedSuperclass );
351347

352-
applyIdMetadata( safeMapping, jpaType );
353-
applyVersionAttribute( safeMapping, jpaType );
348+
applyIdMetadata( mappedSuperclass, jpaType );
349+
applyVersionAttribute( mappedSuperclass, jpaType );
354350
// applyNaturalIdAttribute( safeMapping, jpaType );
355351

356-
for ( Property property : safeMapping.getDeclaredProperties() ) {
357-
if ( isIdentifierProperty( property, safeMapping ) ) {
352+
for ( Property property : mappedSuperclass.getDeclaredProperties() ) {
353+
if ( isIdentifierProperty( property, mappedSuperclass ) ) {
358354
// property represents special handling for id-class mappings but we have already
359355
// accounted for the embedded property mappings in #applyIdMetadata &&
360356
// #buildIdClassAttributes
361357
continue;
362358
}
363-
else if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
359+
else if ( mappedSuperclass.isVersioned() && property == mappedSuperclass.getVersion() ) {
364360
// skip the version property, it was already handled previously.
365361
continue;
366362
}
@@ -375,7 +371,7 @@ else if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) {
375371
}
376372
finally {
377373
if ( log.isTraceEnabled() ) {
378-
log.trace( "Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']' );
374+
log.trace( "Completed mapped superclass [" + mappedSuperclass.getMappedClass().getName() + ']' );
379375
}
380376
}
381377
}

0 commit comments

Comments
 (0)