HHH-18410 Hoist some state to AbstractAttributeMapping to avoid megamorphic call sites

This commit is contained in:
Christian Beikov 2024-07-23 18:29:19 +02:00
parent 73af6a0b75
commit 40a9b9d725
4 changed files with 49 additions and 60 deletions

View File

@ -7,9 +7,11 @@
package org.hibernate.metamodel.mapping.internal;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.type.descriptor.java.JavaType;
/**
@ -18,20 +20,39 @@ import org.hibernate.type.descriptor.java.JavaType;
public abstract class AbstractAttributeMapping implements AttributeMapping {
private final String name;
private final int fetchableIndex;
private final int stateArrayPosition;
private final ManagedMappingType declaringType;
private final AttributeMetadata attributeMetadata;
private final PropertyAccess propertyAccess;
public AbstractAttributeMapping(String name, int fetchableIndex, ManagedMappingType declaringType) {
public AbstractAttributeMapping(
String name,
int fetchableIndex,
ManagedMappingType declaringType,
AttributeMetadata attributeMetadata,
int stateArrayPosition,
PropertyAccess propertyAccess) {
this.name = name;
this.fetchableIndex = fetchableIndex;
this.declaringType = declaringType;
this.attributeMetadata = attributeMetadata;
this.stateArrayPosition = stateArrayPosition;
this.propertyAccess = propertyAccess;
}
/**
* For Hibernate Reactive
*/
protected AbstractAttributeMapping(AbstractAttributeMapping original) {
this( original.name, original.fetchableIndex, original.declaringType );
this(
original.name,
original.fetchableIndex,
original.declaringType,
original.attributeMetadata,
original.stateArrayPosition,
original.propertyAccess
);
}
@Override
@ -44,6 +65,21 @@ public abstract class AbstractAttributeMapping implements AttributeMapping {
return name;
}
@Override
public AttributeMetadata getAttributeMetadata() {
return attributeMetadata;
}
@Override
public int getStateArrayPosition() {
return stateArrayPosition;
}
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
}
@Override
public int getFetchableKey() {
return fetchableIndex;

View File

@ -22,8 +22,6 @@ public abstract class AbstractSingularAttributeMapping
extends AbstractStateArrayContributorMapping
implements SingularAttributeMapping {
private final PropertyAccess propertyAccess;
public AbstractSingularAttributeMapping(
String name,
int stateArrayPosition,
@ -32,8 +30,7 @@ public abstract class AbstractSingularAttributeMapping
FetchOptions mappedFetchOptions,
ManagedMappingType declaringType,
PropertyAccess propertyAccess) {
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType );
this.propertyAccess = propertyAccess;
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
}
public AbstractSingularAttributeMapping(
@ -45,8 +42,7 @@ public abstract class AbstractSingularAttributeMapping
FetchStyle fetchStyle,
ManagedMappingType declaringType,
PropertyAccess propertyAccess) {
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType );
this.propertyAccess = propertyAccess;
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
}
/**
@ -54,12 +50,6 @@ public abstract class AbstractSingularAttributeMapping
*/
protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping original ) {
super( original );
this.propertyAccess = original.propertyAccess;
}
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
}
@Override

View File

@ -10,6 +10,7 @@ import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.sql.results.graph.FetchOptions;
/**
@ -19,10 +20,8 @@ public abstract class AbstractStateArrayContributorMapping
extends AbstractAttributeMapping
implements FetchOptions {
private final AttributeMetadata attributeMetadata;
private final FetchTiming fetchTiming;
private final FetchStyle fetchStyle;
private final int stateArrayPosition;
public AbstractStateArrayContributorMapping(
String name,
@ -31,12 +30,11 @@ public abstract class AbstractStateArrayContributorMapping
FetchStyle fetchStyle,
int stateArrayPosition,
int fetchableIndex,
ManagedMappingType declaringType) {
super( name, fetchableIndex, declaringType );
this.attributeMetadata = attributeMetadata;
ManagedMappingType declaringType,
PropertyAccess propertyAccess) {
super( name, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
this.fetchTiming = fetchTiming;
this.fetchStyle = fetchStyle;
this.stateArrayPosition = stateArrayPosition;
}
public AbstractStateArrayContributorMapping(
@ -45,7 +43,8 @@ public abstract class AbstractStateArrayContributorMapping
FetchOptions mappedFetchOptions,
int stateArrayPosition,
int fetchableIndex,
ManagedMappingType declaringType) {
ManagedMappingType declaringType,
PropertyAccess propertyAccess) {
this(
name,
attributeMetadata,
@ -53,7 +52,8 @@ public abstract class AbstractStateArrayContributorMapping
mappedFetchOptions.getStyle(),
stateArrayPosition,
fetchableIndex,
declaringType
declaringType,
propertyAccess
);
}
@ -62,21 +62,8 @@ public abstract class AbstractStateArrayContributorMapping
*/
protected AbstractStateArrayContributorMapping(AbstractStateArrayContributorMapping original) {
super( original );
this.attributeMetadata = original.attributeMetadata;
this.fetchTiming = original.fetchTiming;
this.fetchStyle = original.fetchStyle;
this.stateArrayPosition = original.stateArrayPosition;
}
@Override
public int getStateArrayPosition() {
return stateArrayPosition;
}
@Override
public AttributeMetadata getAttributeMetadata() {
return attributeMetadata;
}
@Override

View File

@ -103,9 +103,6 @@ public class PluralAttributeMappingImpl
@SuppressWarnings("rawtypes")
private final CollectionMappingType collectionMappingType;
private final int stateArrayPosition;
private final PropertyAccess propertyAccess;
private final AttributeMetadata attributeMetadata;
private final String referencedPropertyName;
private final String mapKeyPropertyName;
@ -148,11 +145,8 @@ public class PluralAttributeMappingImpl
ManagedMappingType declaringType,
CollectionPersister collectionDescriptor,
MappingModelCreationProcess creationProcess) {
super( attributeName, fetchableIndex, declaringType );
this.propertyAccess = propertyAccess;
this.attributeMetadata = attributeMetadata;
super( attributeName, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
this.collectionMappingType = collectionMappingType;
this.stateArrayPosition = stateArrayPosition;
this.elementDescriptor = elementDescriptor;
this.indexDescriptor = indexDescriptor;
this.identifierDescriptor = identifierDescriptor;
@ -215,10 +209,7 @@ public class PluralAttributeMappingImpl
*/
protected PluralAttributeMappingImpl(PluralAttributeMappingImpl original) {
super( original );
this.propertyAccess = original.propertyAccess;
this.attributeMetadata = original.attributeMetadata;
this.collectionMappingType = original.collectionMappingType;
this.stateArrayPosition = original.stateArrayPosition;
this.elementDescriptor = original.elementDescriptor;
this.indexDescriptor = original.indexDescriptor;
this.identifierDescriptor = original.identifierDescriptor;
@ -381,21 +372,6 @@ public class PluralAttributeMappingImpl
return tableExpression.equals( separateCollectionTable );
}
@Override
public int getStateArrayPosition() {
return stateArrayPosition;
}
@Override
public AttributeMetadata getAttributeMetadata() {
return attributeMetadata;
}
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
}
@Override
public Generator getGenerator() {
// can never be a generated value