6
6
7
7
import java .lang .reflect .Method ;
8
8
import java .util .LinkedHashMap ;
9
+ import java .util .LinkedHashSet ;
9
10
import java .util .Locale ;
10
11
import java .util .Map ;
11
12
import java .util .Set ;
17
18
import org .hibernate .bytecode .spi .ReflectionOptimizer ;
18
19
import org .hibernate .internal .CoreLogging ;
19
20
import org .hibernate .internal .CoreMessageLogger ;
20
- import org .hibernate .mapping .Backref ;
21
21
import org .hibernate .mapping .Component ;
22
- import org .hibernate .mapping .IndexBackref ;
23
- import org .hibernate .mapping .KeyValue ;
24
22
import org .hibernate .mapping .PersistentClass ;
25
23
import org .hibernate .mapping .Property ;
26
24
import org .hibernate .mapping .Subclass ;
29
27
import org .hibernate .metamodel .spi .EntityRepresentationStrategy ;
30
28
import org .hibernate .metamodel .spi .RuntimeModelCreationContext ;
31
29
import org .hibernate .persister .entity .EntityPersister ;
32
- import org .hibernate .property .access .internal .PropertyAccessStrategyBackRefImpl ;
33
- import org .hibernate .property .access .internal .PropertyAccessStrategyIndexBackRefImpl ;
34
- import org .hibernate .property .access .spi .BuiltInPropertyAccessStrategies ;
35
30
import org .hibernate .property .access .spi .PropertyAccess ;
36
- import org .hibernate .property .access .spi .PropertyAccessStrategy ;
37
31
import org .hibernate .proxy .HibernateProxy ;
38
32
import org .hibernate .proxy .ProxyFactory ;
39
33
import org .hibernate .tuple .entity .EntityMetamodel ;
44
38
45
39
import static org .hibernate .engine .internal .ManagedTypeHelper .isPersistentAttributeInterceptableType ;
46
40
import static org .hibernate .internal .util .ReflectHelper .getMethod ;
47
- import static org .hibernate .internal .util . StringHelper . isNotEmpty ;
41
+ import static org .hibernate .metamodel . internal .PropertyAccessHelper . propertyAccessStrategy ;
48
42
import static org .hibernate .proxy .pojo .ProxyFactoryHelper .validateGetterSetterMethodProxyability ;
49
43
50
44
/**
@@ -88,33 +82,19 @@ public EntityRepresentationStrategyPojoStandard(
88
82
identifierPropertyName = null ;
89
83
identifierPropertyAccess = null ;
90
84
91
- final KeyValue bootDescriptorIdentifier = bootDescriptor .getIdentifier ();
92
-
93
- if ( bootDescriptorIdentifier instanceof Component descriptorIdentifierComponent ) {
85
+ if ( bootDescriptor .getIdentifier () instanceof Component descriptorIdentifierComponent ) {
94
86
final Component identifierMapper = bootDescriptor .getIdentifierMapper ();
95
- if ( identifierMapper != null ) {
96
- mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
97
- identifierMapper ,
98
- () -> ( ( CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType () )
99
- .getMappingModelPart ().getEmbeddableTypeDescriptor (),
100
- // we currently do not support custom instantiators for identifiers
101
- null ,
102
- null ,
103
- creationContext
104
- );
105
- }
106
- else {
107
- mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
108
- descriptorIdentifierComponent ,
109
- // TODO: something wrong here: bootDescriptor.getIdentifierMapper() was null!
110
- () -> ( ( CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType () )
111
- .getMappingModelPart ().getEmbeddableTypeDescriptor (),
112
- // we currently do not support custom instantiators for identifiers
113
- null ,
114
- null ,
115
- creationContext
116
- );
117
- }
87
+ mapsIdRepresentationStrategy = new EmbeddableRepresentationStrategyPojo (
88
+ identifierMapper == null ? descriptorIdentifierComponent : identifierMapper ,
89
+ () -> {
90
+ final var type = (CompositeTypeImplementor ) bootDescriptor .getIdentifierMapper ().getType ();
91
+ return type .getMappingModelPart ().getEmbeddableTypeDescriptor ();
92
+ },
93
+ // we currently do not support custom instantiators for identifiers
94
+ null ,
95
+ null ,
96
+ creationContext
97
+ );
118
98
}
119
99
else {
120
100
mapsIdRepresentationStrategy = null ;
@@ -146,36 +126,35 @@ public EntityRepresentationStrategyPojoStandard(
146
126
this .instantiator = determineInstantiator ( bootDescriptor , runtimeDescriptor .getEntityMetamodel () );
147
127
}
148
128
149
- @ SuppressWarnings ("removal" )
150
129
private ProxyFactory resolveProxyFactory (
151
130
PersistentClass bootDescriptor ,
152
131
EntityPersister entityPersister ,
153
- JavaType <?> proxyJtd ,
132
+ JavaType <?> proxyJavaType ,
154
133
BytecodeProvider bytecodeProvider ,
155
134
RuntimeModelCreationContext creationContext ) {
156
- final EntityMetamodel entityMetamodel = entityPersister .getEntityMetamodel ();
157
- final boolean enhancedForLazyLoading =
158
- entityPersister .getBytecodeEnhancementMetadata ()
159
- .isEnhancedForLazyLoading ();
160
-
161
135
// todo : `@ConcreteProxy` handling
162
- if ( enhancedForLazyLoading
136
+ if ( entityPersister . getBytecodeEnhancementMetadata (). isEnhancedForLazyLoading ()
163
137
&& bootDescriptor .getRootClass () == bootDescriptor
164
138
&& !bootDescriptor .hasSubclasses () ) {
165
- // the entity is bytecode enhanced for lazy loading and is not part of an inheritance hierarchy,
139
+ // the entity is bytecode enhanced for lazy loading
140
+ // and is not part of an inheritance hierarchy,
166
141
// so no need for a ProxyFactory
167
142
return null ;
168
143
}
169
-
170
- if ( proxyJtd != null && entityMetamodel .isLazy () ) {
171
- final ProxyFactory proxyFactory = createProxyFactory ( bootDescriptor , bytecodeProvider , creationContext );
172
- if ( proxyFactory == null ) {
173
- entityMetamodel .setLazy ( false );
144
+ else {
145
+ final EntityMetamodel entityMetamodel = entityPersister .getEntityMetamodel ();
146
+ if ( proxyJavaType != null && entityMetamodel .isLazy () ) {
147
+ final ProxyFactory proxyFactory =
148
+ createProxyFactory ( bootDescriptor , bytecodeProvider , creationContext );
149
+ if ( proxyFactory == null ) {
150
+ entityMetamodel .setLazy ( false );
151
+ }
152
+ return proxyFactory ;
153
+ }
154
+ else {
155
+ return null ;
174
156
}
175
- return proxyFactory ;
176
157
}
177
-
178
- return null ;
179
158
}
180
159
181
160
private Map <String , PropertyAccess > buildPropertyAccessMap (PersistentClass bootDescriptor ) {
@@ -209,7 +188,7 @@ private ProxyFactory createProxyFactory(
209
188
// that the most general @Proxy declared interface at the top of a class
210
189
// hierarchy will be used first when a HibernateProxy decides what it
211
190
// should implement.
212
- final Set <Class <?>> proxyInterfaces = new java . util . LinkedHashSet <>();
191
+ final Set <Class <?>> proxyInterfaces = new LinkedHashSet <>();
213
192
214
193
final Class <?> mappedClass = mappedJtd .getJavaTypeClass ();
215
194
final Class <?> proxyInterface = proxyJtd != null ? proxyJtd .getJavaTypeClass () : null ;
@@ -306,32 +285,8 @@ private ReflectionOptimizer resolveReflectionOptimizer(BytecodeProvider bytecode
306
285
}
307
286
308
287
private PropertyAccess makePropertyAccess (Property bootAttributeDescriptor ) {
309
- PropertyAccessStrategy strategy = bootAttributeDescriptor .getPropertyAccessStrategy ( mappedJtd .getJavaTypeClass () );
310
-
311
- if ( strategy == null ) {
312
- final String propertyAccessorName = bootAttributeDescriptor .getPropertyAccessorName ();
313
- if ( isNotEmpty ( propertyAccessorName ) ) {
314
- // handle explicitly specified attribute accessor
315
- strategy = strategySelector .resolveStrategy ( PropertyAccessStrategy .class , propertyAccessorName );
316
- }
317
- else {
318
- if ( bootAttributeDescriptor instanceof Backref backref ) {
319
- strategy = new PropertyAccessStrategyBackRefImpl ( backref .getCollectionRole (), backref
320
- .getEntityName () );
321
- }
322
- else if ( bootAttributeDescriptor instanceof IndexBackref indexBackref ) {
323
- strategy = new PropertyAccessStrategyIndexBackRefImpl (
324
- indexBackref .getCollectionRole (),
325
- indexBackref .getEntityName ()
326
- );
327
- }
328
- else {
329
- // for now...
330
- strategy = BuiltInPropertyAccessStrategies .MIXED .getStrategy ();
331
- }
332
- }
333
- }
334
-
288
+ final Class <?> mappedClass = mappedJtd .getJavaTypeClass ();
289
+ final var strategy = propertyAccessStrategy ( bootAttributeDescriptor , mappedClass , strategySelector );
335
290
if ( strategy == null ) {
336
291
throw new HibernateException (
337
292
String .format (
@@ -342,8 +297,7 @@ else if ( bootAttributeDescriptor instanceof IndexBackref indexBackref ) {
342
297
)
343
298
);
344
299
}
345
-
346
- return strategy .buildPropertyAccess ( mappedJtd .getJavaTypeClass (), bootAttributeDescriptor .getName (), true );
300
+ return strategy .buildPropertyAccess ( mappedClass , bootAttributeDescriptor .getName (), true );
347
301
}
348
302
349
303
@ Override
@@ -386,16 +340,17 @@ public PropertyAccess resolvePropertyAccess(Property bootAttributeDescriptor) {
386
340
if ( bootAttributeDescriptor .getName ().equals ( identifierPropertyName ) ) {
387
341
return identifierPropertyAccess ;
388
342
}
389
-
390
- final PropertyAccess propertyAccess = propertyAccessMap .get ( bootAttributeDescriptor .getName () );
391
- if ( propertyAccess != null ) {
392
- return propertyAccess ;
393
- }
394
-
395
- if ( mapsIdRepresentationStrategy != null ) {
396
- return mapsIdRepresentationStrategy .resolvePropertyAccess ( bootAttributeDescriptor );
343
+ else {
344
+ final PropertyAccess propertyAccess = propertyAccessMap .get ( bootAttributeDescriptor .getName () );
345
+ if ( propertyAccess != null ) {
346
+ return propertyAccess ;
347
+ }
348
+ else if ( mapsIdRepresentationStrategy != null ) {
349
+ return mapsIdRepresentationStrategy .resolvePropertyAccess ( bootAttributeDescriptor );
350
+ }
351
+ else {
352
+ return null ;
353
+ }
397
354
}
398
-
399
- return null ;
400
355
}
401
356
}
0 commit comments