Skip to content

Commit 263ca85

Browse files
committed
introduce constants for java.lang.Object and java.lang.Record
This is probably not much less expensive at runtime, since the JIT should be able to inline Object.class.getName(), but at least we save the JIT a bit of work.
1 parent b31dc71 commit 263ca85

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
import static org.hibernate.boot.model.internal.PropertyBinder.processElementAnnotations;
7373
import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder;
7474
import static org.hibernate.boot.BootLogging.BOOT_LOGGER;
75+
import static org.hibernate.internal.util.ReflectHelper.OBJECT_CLASS_NAME;
76+
import static org.hibernate.internal.util.ReflectHelper.RECORD_CLASS_NAME;
7577
import static org.hibernate.internal.util.StringHelper.isBlank;
7678
import static org.hibernate.internal.util.StringHelper.qualify;
7779
import static org.hibernate.internal.util.StringHelper.unqualify;
@@ -825,8 +827,8 @@ else if ( superClass.hasDirectAnnotationUsage( MappedSuperclass.class ) ) {
825827
}
826828
else if ( isIdClass ) {
827829
final String superClassName = superClass.getName();
828-
return !superClassName.equals( Object.class.getName() )
829-
&& !superClassName.equals( "java.lang.Record" );
830+
return !superClassName.equals( OBJECT_CLASS_NAME )
831+
&& !superClassName.equals( RECORD_CLASS_NAME );
830832
}
831833
else {
832834
return false;
@@ -842,9 +844,8 @@ private static List<PropertyData> collectBaseClassElements(
842844
final List<PropertyData> baseClassElements = new ArrayList<>();
843845
// iterate from base returned class up hierarchy to handle cases where the @Id attributes
844846
// might be spread across the subclasses and super classes.
845-
final String objectClassName = Object.class.getName();
846847
TypeDetails baseReturnedClassOrElement = baseInferredData.getClassOrElementType();
847-
while ( !objectClassName.equals( baseReturnedClassOrElement.getName() ) ) {
848+
while ( !OBJECT_CLASS_NAME.equals( baseReturnedClassOrElement.getName() ) ) {
848849
final var rawClass = baseReturnedClassOrElement.determineRawClass();
849850
final var container = new PropertyContainer( rawClass, entityAtStake, propertyAccessor );
850851
addElementsOfClass( baseClassElements, container, context, 0 );

hibernate-core/src/main/java/org/hibernate/boot/model/internal/InheritanceState.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static jakarta.persistence.InheritanceType.TABLE_PER_CLASS;
3434
import static org.hibernate.boot.model.internal.PropertyBinder.addElementsOfClass;
3535
import static org.hibernate.boot.model.internal.PropertyBinder.hasIdAnnotation;
36+
import static org.hibernate.internal.util.ReflectHelper.OBJECT_CLASS_NAME;
3637

3738
/**
3839
* Some extra data to the inheritance position of a class.
@@ -101,7 +102,7 @@ public static InheritanceState getInheritanceStateOfSuperEntity(
101102
return currentState;
102103
}
103104
}
104-
while ( candidate != null && !Object.class.getName().equals( candidate.getName() ) );
105+
while ( candidate != null && !OBJECT_CLASS_NAME.equals( candidate.getName() ) );
105106
return null;
106107
}
107108

@@ -116,7 +117,7 @@ public static InheritanceState getSuperclassInheritanceState(
116117
return currentState;
117118
}
118119
}
119-
while ( superclass != null && !Object.class.getName().equals( superclass.getName() ) );
120+
while ( superclass != null && !OBJECT_CLASS_NAME.equals( superclass.getName() ) );
120121
return null;
121122
}
122123

@@ -250,7 +251,7 @@ private ElementsToProcess getElementsToProcess() {
250251

251252
private AccessType determineDefaultAccessType() {
252253
for ( ClassDetails candidate = classDetails; candidate != null; candidate = candidate.getSuperClass() ) {
253-
if ( ( candidate.getSuperClass() == null || Object.class.getName().equals( candidate.getSuperClass().getName() ) )
254+
if ( ( candidate.getSuperClass() == null || OBJECT_CLASS_NAME.equals( candidate.getSuperClass().getName() ) )
254255
&& ( candidate.hasDirectAnnotationUsage( Entity.class ) || candidate.hasDirectAnnotationUsage( MappedSuperclass.class ) )
255256
&& candidate.hasDirectAnnotationUsage( Access.class ) ) {
256257
return AccessType.getAccessStrategy( candidate.getDirectAnnotationUsage( Access.class ).value() );
@@ -260,7 +261,7 @@ private AccessType determineDefaultAccessType() {
260261
// FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations,
261262
// but without an explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type?
262263
for ( ClassDetails candidate = classDetails;
263-
candidate != null && !Object.class.getName().equals( candidate.getName() );
264+
candidate != null && !OBJECT_CLASS_NAME.equals( candidate.getName() );
264265
candidate = candidate.getSuperClass() ) {
265266
if ( candidate.hasDirectAnnotationUsage( Entity.class )
266267
|| candidate.hasDirectAnnotationUsage( MappedSuperclass.class ) ) {
@@ -295,7 +296,7 @@ private void getMappedSuperclassesTillNextEntityOrdered() {
295296
superclassState = inheritanceStatePerClass.get( superClass );
296297
}
297298
while ( superClass != null
298-
&& !Object.class.getName().equals( superClass.getClassName() )
299+
&& !OBJECT_CLASS_NAME.equals( superClass.getClassName() )
299300
&& superclassState == null );
300301
currentClassInHierarchy = superClass;
301302
}

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.hibernate.boot.model.internal.AnnotationBinder.bindFetchProfilesForPackage;
3232
import static org.hibernate.boot.model.internal.AnnotationBinder.buildInheritanceStates;
3333
import static org.hibernate.boot.model.process.spi.MetadataBuildingProcess.processManagedResources;
34+
import static org.hibernate.internal.util.ReflectHelper.OBJECT_CLASS_NAME;
3435

3536
/**
3637
* @author Steve Ebersole
@@ -219,7 +220,7 @@ else if ( clazz.hasDirectAnnotationUsage( MappedSuperclass.class ) ) {
219220
copy.add( clazz );
220221
ClassDetails superClass = clazz.getSuperClass();
221222
while ( superClass != null
222-
&& !Object.class.getName().equals( superClass.getName() )
223+
&& !OBJECT_CLASS_NAME.equals( superClass.getName() )
223224
&& !copy.contains( superClass ) ) {
224225
if ( superClass.hasDirectAnnotationUsage( Entity.class )
225226
|| superClass.hasDirectAnnotationUsage( MappedSuperclass.class ) ) {
@@ -232,7 +233,7 @@ else if ( clazz.hasDirectAnnotationUsage( MappedSuperclass.class ) ) {
232233
}
233234

234235
private void orderHierarchy(List<ClassDetails> copy, List<ClassDetails> newList, LinkedHashSet<ClassDetails> original, ClassDetails clazz) {
235-
if ( clazz != null && !Object.class.getName().equals( clazz.getName() ) ) {
236+
if ( clazz != null && !OBJECT_CLASS_NAME.equals( clazz.getName() ) ) {
236237
//process superclass first
237238
orderHierarchy( copy, newList, original, clazz.getSuperClass() );
238239
if ( original.contains( clazz ) ) {

hibernate-core/src/main/java/org/hibernate/boot/models/xml/internal/DynamicModelHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.util.SortedSet;
5757

5858
import static org.hibernate.internal.util.NullnessHelper.nullif;
59+
import static org.hibernate.internal.util.ReflectHelper.OBJECT_CLASS_NAME;
5960
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
6061
import static org.hibernate.models.internal.ModifierUtils.DYNAMIC_ATTRIBUTE_MODIFIERS;
6162

@@ -432,7 +433,7 @@ private static TypeDetails makeCollectionType(
432433
case MAP -> {
433434
collectionClassDetails = mapType( jaxbPluralAttribute, classDetailsRegistry );
434435
// for now, just use wildcard for the key
435-
final ClassDetails objectClassDetails = classDetailsRegistry.resolveClassDetails( Object.class.getName() );
436+
final ClassDetails objectClassDetails = classDetailsRegistry.resolveClassDetails( OBJECT_CLASS_NAME );
436437
typeParams = List.of(
437438
new WildcardTypeDetailsImpl( new ClassTypeDetailsImpl( objectClassDetails, TypeDetails.Kind.CLASS ), true ),
438439
elementType
@@ -711,7 +712,7 @@ private static TypeDetails determineAttributeJavaTypeDetails(
711712
// Logically this is Object, which is what we return here for now.
712713
// todo : might be nice to allow specifying a "common interface"
713714
final ModelsContext modelsContext = xmlDocumentContext.getBootstrapContext().getModelsContext();
714-
final ClassDetails objectClassDetails = modelsContext.getClassDetailsRegistry().resolveClassDetails( Object.class.getName() );
715+
final ClassDetails objectClassDetails = modelsContext.getClassDetailsRegistry().resolveClassDetails( OBJECT_CLASS_NAME );
715716
return new ClassTypeDetailsImpl( objectClassDetails, TypeDetails.Kind.CLASS );
716717
}
717718

0 commit comments

Comments
 (0)