Skip to content

Commit d2d40c7

Browse files
committed
HHH-15853 Avoid re-computing AttributeMetadataAccess at runtime
1 parent 58f8d3d commit d2d40c7

File tree

6 files changed

+194
-348
lines changed

6 files changed

+194
-348
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/AttributeMetadataAccess.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*
1313
* @author Steve Ebersole
1414
*/
15-
@FunctionalInterface
1615
public interface AttributeMetadataAccess {
1716
/**
1817
* Resolve the details about the attribute

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

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import org.hibernate.mapping.Value;
3131
import org.hibernate.metamodel.UnsupportedMappingException;
3232
import org.hibernate.metamodel.mapping.AttributeMapping;
33-
import org.hibernate.metamodel.mapping.AttributeMetadata;
34-
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
3533
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
3634
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
3735
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
@@ -364,48 +362,14 @@ public Object assemble(Serializable cached, SharedSessionContract session) {
364362
mutabilityPlan = ImmutableMutabilityPlan.INSTANCE;
365363
}
366364

367-
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
368-
@Override
369-
public PropertyAccess getPropertyAccess() {
370-
return propertyAccess;
371-
}
372-
373-
@Override
374-
public MutabilityPlan<?> getMutabilityPlan() {
375-
return mutabilityPlan;
376-
}
377-
378-
@Override
379-
public boolean isNullable() {
380-
return nullable;
381-
}
382-
383-
@Override
384-
public boolean isInsertable() {
385-
return insertable;
386-
}
387-
388-
@Override
389-
public boolean isUpdatable() {
390-
return updateable;
391-
}
392-
393-
@Override
394-
public boolean isIncludedInDirtyChecking() {
395-
// todo (6.0) : do not believe this is correct
396-
return updateable;
397-
}
398-
399-
@Override
400-
public boolean isIncludedInOptimisticLocking() {
401-
return includeInOptimisticLocking;
402-
}
403-
404-
@Override
405-
public CascadeStyle getCascadeStyle() {
406-
return cascadeStyle;
407-
}
408-
};
365+
BasicAttributeMetadataAccess attributeMetadataAccess = new BasicAttributeMetadataAccess( propertyAccess,
366+
mutabilityPlan,
367+
nullable,
368+
insertable,
369+
updateable,
370+
includeInOptimisticLocking,
371+
cascadeStyle
372+
);
409373

410374
attributeMapping = new DiscriminatedAssociationAttributeMapping(
411375
navigableRole.append( bootPropertyDescriptor.getName() ),
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.metamodel.mapping.internal;
8+
9+
import org.hibernate.engine.spi.CascadeStyle;
10+
import org.hibernate.engine.spi.CascadeStyles;
11+
import org.hibernate.mapping.Property;
12+
import org.hibernate.mapping.Value;
13+
import org.hibernate.metamodel.mapping.AttributeMetadata;
14+
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
15+
import org.hibernate.metamodel.mapping.EntityMappingType;
16+
import org.hibernate.property.access.spi.PropertyAccess;
17+
import org.hibernate.type.descriptor.java.MutabilityPlan;
18+
19+
public final class BasicAttributeMetadataAccess implements AttributeMetadataAccess, AttributeMetadata {
20+
21+
private final PropertyAccess propertyAccess;
22+
private final MutabilityPlan<?> mutabilityPlan;
23+
private final boolean nullable;
24+
private final boolean insertable;
25+
private final boolean updateable;
26+
private final boolean includeInOptimisticLocking;
27+
private final CascadeStyle cascadeStyle;
28+
29+
public BasicAttributeMetadataAccess(
30+
PropertyAccess propertyAccess,
31+
MutabilityPlan mutabilityPlan,
32+
Property bootProperty,
33+
Value value
34+
) {
35+
this(
36+
propertyAccess,
37+
mutabilityPlan,
38+
value.isNullable(),
39+
bootProperty.isInsertable(),
40+
bootProperty.isUpdateable(),
41+
bootProperty.isOptimisticLocked()
42+
);
43+
}
44+
45+
public BasicAttributeMetadataAccess(
46+
PropertyAccess propertyAccess,
47+
MutabilityPlan mutabilityPlan,
48+
boolean nullable, boolean insertable, boolean updateable, boolean includeInOptimisticLocking) {
49+
this(
50+
propertyAccess,
51+
mutabilityPlan,
52+
nullable,
53+
insertable,
54+
updateable,
55+
includeInOptimisticLocking,
56+
CascadeStyles.NONE // default - but beware of comment on AttributeMetadata#getCascadeStyle having a TODO
57+
);
58+
}
59+
60+
public BasicAttributeMetadataAccess(
61+
PropertyAccess propertyAccess,
62+
MutabilityPlan mutabilityPlan,
63+
boolean nullable,
64+
boolean insertable,
65+
boolean updateable,
66+
boolean includeInOptimisticLocking,
67+
CascadeStyle cascadeStyle) {
68+
this.propertyAccess = propertyAccess;
69+
this.mutabilityPlan = mutabilityPlan;
70+
this.nullable = nullable;
71+
this.insertable = insertable;
72+
this.updateable = updateable;
73+
this.includeInOptimisticLocking = includeInOptimisticLocking;
74+
this.cascadeStyle = cascadeStyle;
75+
}
76+
77+
@Override
78+
public AttributeMetadata resolveAttributeMetadata(EntityMappingType entityMappingType) {
79+
return this;
80+
}
81+
82+
@Override
83+
public PropertyAccess getPropertyAccess() {
84+
return propertyAccess;
85+
}
86+
87+
@Override
88+
public MutabilityPlan getMutabilityPlan() {
89+
return mutabilityPlan;
90+
}
91+
92+
@Override
93+
public boolean isNullable() {
94+
return nullable;
95+
}
96+
97+
@Override
98+
public boolean isInsertable() {
99+
return insertable;
100+
}
101+
102+
@Override
103+
public boolean isUpdatable() {
104+
return updateable;
105+
}
106+
107+
@Override
108+
public boolean isIncludedInDirtyChecking() {
109+
// todo (6.0) : do not believe this is correct
110+
return updateable;
111+
}
112+
113+
@Override
114+
public boolean isIncludedInOptimisticLocking() {
115+
return includeInOptimisticLocking;
116+
}
117+
118+
@Override
119+
public CascadeStyle getCascadeStyle() {
120+
return cascadeStyle;
121+
}
122+
123+
}

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

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import org.hibernate.mapping.Selectable;
3535
import org.hibernate.mapping.Value;
3636
import org.hibernate.metamodel.mapping.AttributeMapping;
37-
import org.hibernate.metamodel.mapping.AttributeMetadata;
38-
import org.hibernate.metamodel.mapping.AttributeMetadataAccess;
3937
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
4038
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
4139
import org.hibernate.metamodel.mapping.EntityMappingType;
@@ -374,48 +372,15 @@ public Object assemble(Serializable cached, SharedSessionContract session) {
374372
mutabilityPlan = ImmutableMutabilityPlan.INSTANCE;
375373
}
376374

377-
final AttributeMetadataAccess attributeMetadataAccess = entityMappingType -> new AttributeMetadata() {
378-
@Override
379-
public PropertyAccess getPropertyAccess() {
380-
return propertyAccess;
381-
}
382-
383-
@Override
384-
public MutabilityPlan<?> getMutabilityPlan() {
385-
return mutabilityPlan;
386-
}
387-
388-
@Override
389-
public boolean isNullable() {
390-
return nullable;
391-
}
392-
393-
@Override
394-
public boolean isInsertable() {
395-
return insertable;
396-
}
397-
398-
@Override
399-
public boolean isUpdatable() {
400-
return updateable;
401-
}
402-
403-
@Override
404-
public boolean isIncludedInDirtyChecking() {
405-
// todo (6.0) : do not believe this is correct
406-
return updateable;
407-
}
408-
409-
@Override
410-
public boolean isIncludedInOptimisticLocking() {
411-
return includeInOptimisticLocking;
412-
}
413-
414-
@Override
415-
public CascadeStyle getCascadeStyle() {
416-
return cascadeStyle;
417-
}
418-
};
375+
BasicAttributeMetadataAccess attributeMetadataAccess = new BasicAttributeMetadataAccess(
376+
propertyAccess,
377+
mutabilityPlan,
378+
nullable,
379+
insertable,
380+
updateable,
381+
includeInOptimisticLocking,
382+
cascadeStyle
383+
);
419384

420385
attributeMapping = new DiscriminatedAssociationAttributeMapping(
421386
valueMapping.getNavigableRole().append( bootPropertyDescriptor.getName() ),

0 commit comments

Comments
 (0)