Skip to content

Commit 0d58a24

Browse files
committed
HHH-18410 Hoist some state to AbstractAttributeMapping to avoid megamorphic call sites
1 parent e4bc19b commit 0d58a24

File tree

4 files changed

+49
-60
lines changed

4 files changed

+49
-60
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractAttributeMapping.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
package org.hibernate.metamodel.mapping.internal;
88

99
import org.hibernate.metamodel.mapping.AttributeMapping;
10+
import org.hibernate.metamodel.mapping.AttributeMetadata;
1011
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
1112
import org.hibernate.metamodel.mapping.ManagedMappingType;
1213
import org.hibernate.metamodel.mapping.MappingType;
14+
import org.hibernate.property.access.spi.PropertyAccess;
1315
import org.hibernate.type.descriptor.java.JavaType;
1416

1517
/**
@@ -18,20 +20,39 @@
1820
public abstract class AbstractAttributeMapping implements AttributeMapping {
1921
private final String name;
2022
private final int fetchableIndex;
23+
private final int stateArrayPosition;
2124

2225
private final ManagedMappingType declaringType;
26+
private final AttributeMetadata attributeMetadata;
27+
private final PropertyAccess propertyAccess;
2328

24-
public AbstractAttributeMapping(String name, int fetchableIndex, ManagedMappingType declaringType) {
29+
public AbstractAttributeMapping(
30+
String name,
31+
int fetchableIndex,
32+
ManagedMappingType declaringType,
33+
AttributeMetadata attributeMetadata,
34+
int stateArrayPosition,
35+
PropertyAccess propertyAccess) {
2536
this.name = name;
2637
this.fetchableIndex = fetchableIndex;
2738
this.declaringType = declaringType;
39+
this.attributeMetadata = attributeMetadata;
40+
this.stateArrayPosition = stateArrayPosition;
41+
this.propertyAccess = propertyAccess;
2842
}
2943

3044
/**
3145
* For Hibernate Reactive
3246
*/
3347
protected AbstractAttributeMapping(AbstractAttributeMapping original) {
34-
this( original.name, original.fetchableIndex, original.declaringType );
48+
this(
49+
original.name,
50+
original.fetchableIndex,
51+
original.declaringType,
52+
original.attributeMetadata,
53+
original.stateArrayPosition,
54+
original.propertyAccess
55+
);
3556
}
3657

3758
@Override
@@ -44,6 +65,21 @@ public String getAttributeName() {
4465
return name;
4566
}
4667

68+
@Override
69+
public AttributeMetadata getAttributeMetadata() {
70+
return attributeMetadata;
71+
}
72+
73+
@Override
74+
public int getStateArrayPosition() {
75+
return stateArrayPosition;
76+
}
77+
78+
@Override
79+
public PropertyAccess getPropertyAccess() {
80+
return propertyAccess;
81+
}
82+
4783
@Override
4884
public int getFetchableKey() {
4985
return fetchableIndex;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractSingularAttributeMapping.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public abstract class AbstractSingularAttributeMapping
2626
extends AbstractStateArrayContributorMapping
2727
implements SingularAttributeMapping {
2828

29-
private final PropertyAccess propertyAccess;
30-
3129
public AbstractSingularAttributeMapping(
3230
String name,
3331
int stateArrayPosition,
@@ -36,8 +34,7 @@ public AbstractSingularAttributeMapping(
3634
FetchOptions mappedFetchOptions,
3735
ManagedMappingType declaringType,
3836
PropertyAccess propertyAccess) {
39-
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType );
40-
this.propertyAccess = propertyAccess;
37+
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
4138
}
4239

4340
public AbstractSingularAttributeMapping(
@@ -49,21 +46,14 @@ public AbstractSingularAttributeMapping(
4946
FetchStyle fetchStyle,
5047
ManagedMappingType declaringType,
5148
PropertyAccess propertyAccess) {
52-
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType );
53-
this.propertyAccess = propertyAccess;
49+
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType, propertyAccess );
5450
}
5551

5652
/**
5753
* For Hibernate Reactive
5854
*/
5955
protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping original ) {
6056
super( original );
61-
this.propertyAccess = original.propertyAccess;
62-
}
63-
64-
@Override
65-
public PropertyAccess getPropertyAccess() {
66-
return propertyAccess;
6757
}
6858

6959
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractStateArrayContributorMapping.java

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hibernate.engine.FetchTiming;
1111
import org.hibernate.metamodel.mapping.AttributeMetadata;
1212
import org.hibernate.metamodel.mapping.ManagedMappingType;
13+
import org.hibernate.property.access.spi.PropertyAccess;
1314
import org.hibernate.sql.results.graph.FetchOptions;
1415

1516
/**
@@ -19,10 +20,8 @@ public abstract class AbstractStateArrayContributorMapping
1920
extends AbstractAttributeMapping
2021
implements FetchOptions {
2122

22-
private final AttributeMetadata attributeMetadata;
2323
private final FetchTiming fetchTiming;
2424
private final FetchStyle fetchStyle;
25-
private final int stateArrayPosition;
2625

2726
public AbstractStateArrayContributorMapping(
2827
String name,
@@ -31,12 +30,11 @@ public AbstractStateArrayContributorMapping(
3130
FetchStyle fetchStyle,
3231
int stateArrayPosition,
3332
int fetchableIndex,
34-
ManagedMappingType declaringType) {
35-
super( name, fetchableIndex, declaringType );
36-
this.attributeMetadata = attributeMetadata;
33+
ManagedMappingType declaringType,
34+
PropertyAccess propertyAccess) {
35+
super( name, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
3736
this.fetchTiming = fetchTiming;
3837
this.fetchStyle = fetchStyle;
39-
this.stateArrayPosition = stateArrayPosition;
4038
}
4139

4240
public AbstractStateArrayContributorMapping(
@@ -45,15 +43,17 @@ public AbstractStateArrayContributorMapping(
4543
FetchOptions mappedFetchOptions,
4644
int stateArrayPosition,
4745
int fetchableIndex,
48-
ManagedMappingType declaringType) {
46+
ManagedMappingType declaringType,
47+
PropertyAccess propertyAccess) {
4948
this(
5049
name,
5150
attributeMetadata,
5251
mappedFetchOptions.getTiming(),
5352
mappedFetchOptions.getStyle(),
5453
stateArrayPosition,
5554
fetchableIndex,
56-
declaringType
55+
declaringType,
56+
propertyAccess
5757
);
5858
}
5959

@@ -62,21 +62,8 @@ public AbstractStateArrayContributorMapping(
6262
*/
6363
protected AbstractStateArrayContributorMapping(AbstractStateArrayContributorMapping original) {
6464
super( original );
65-
this.attributeMetadata = original.attributeMetadata;
6665
this.fetchTiming = original.fetchTiming;
6766
this.fetchStyle = original.fetchStyle;
68-
this.stateArrayPosition = original.stateArrayPosition;
69-
}
70-
71-
72-
@Override
73-
public int getStateArrayPosition() {
74-
return stateArrayPosition;
75-
}
76-
77-
@Override
78-
public AttributeMetadata getAttributeMetadata() {
79-
return attributeMetadata;
8067
}
8168

8269
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ public interface Aware {
9595

9696
@SuppressWarnings("rawtypes")
9797
private final CollectionMappingType collectionMappingType;
98-
private final int stateArrayPosition;
99-
private final PropertyAccess propertyAccess;
100-
private final AttributeMetadata attributeMetadata;
10198
private final String referencedPropertyName;
10299
private final String mapKeyPropertyName;
103100

@@ -137,11 +134,8 @@ public PluralAttributeMappingImpl(
137134
CascadeStyle cascadeStyle,
138135
ManagedMappingType declaringType,
139136
CollectionPersister collectionDescriptor) {
140-
super( attributeName, fetchableIndex, declaringType );
141-
this.propertyAccess = propertyAccess;
142-
this.attributeMetadata = attributeMetadata;
137+
super( attributeName, fetchableIndex, declaringType, attributeMetadata, stateArrayPosition, propertyAccess );
143138
this.collectionMappingType = collectionMappingType;
144-
this.stateArrayPosition = stateArrayPosition;
145139
this.elementDescriptor = elementDescriptor;
146140
this.indexDescriptor = indexDescriptor;
147141
this.identifierDescriptor = identifierDescriptor;
@@ -201,10 +195,7 @@ public String getIndexPropertyName() {
201195
*/
202196
protected PluralAttributeMappingImpl(PluralAttributeMappingImpl original) {
203197
super( original );
204-
this.propertyAccess = original.propertyAccess;
205-
this.attributeMetadata = original.attributeMetadata;
206198
this.collectionMappingType = original.collectionMappingType;
207-
this.stateArrayPosition = original.stateArrayPosition;
208199
this.elementDescriptor = original.elementDescriptor;
209200
this.indexDescriptor = original.indexDescriptor;
210201
this.identifierDescriptor = original.identifierDescriptor;
@@ -355,21 +346,6 @@ public boolean containsTableReference(String tableExpression) {
355346
return tableExpression.equals( separateCollectionTable );
356347
}
357348

358-
@Override
359-
public int getStateArrayPosition() {
360-
return stateArrayPosition;
361-
}
362-
363-
@Override
364-
public AttributeMetadata getAttributeMetadata() {
365-
return attributeMetadata;
366-
}
367-
368-
@Override
369-
public PropertyAccess getPropertyAccess() {
370-
return propertyAccess;
371-
}
372-
373349
@Override
374350
public Generator getGenerator() {
375351
// can never be a generated value

0 commit comments

Comments
 (0)