37
37
import org .springframework .data .mapping .PersistentEntity ;
38
38
import org .springframework .data .mapping .PersistentProperty ;
39
39
import org .springframework .data .mapping .PropertyPath ;
40
+ import org .springframework .data .mapping .model .DefaultPersistentPropertyAccessorFactory ;
40
41
import org .springframework .data .mapping .model .MappingException ;
41
42
import org .springframework .data .mapping .model .MutablePersistentEntity ;
42
43
import org .springframework .data .mapping .model .SimpleTypeHolder ;
54
55
* <p>
55
56
* The implementation uses a {@link ReentrantReadWriteLock} to make sure {@link PersistentEntity} are completely
56
57
* populated before accessing them from outside.
57
- *
58
+ *
58
59
* @param E the concrete {@link PersistentEntity} type the {@link MappingContext} implementation creates
59
60
* @param P the concrete {@link PersistentProperty} type the {@link MappingContext} implementation creates
60
61
* @author Jon Brisbin
61
62
* @author Oliver Gierke
62
63
* @author Michael Hunger
63
64
* @author Thomas Darimont
64
65
* @author Tomasz Wysocki
66
+ * @author Mark Paluch
65
67
*/
66
68
public abstract class AbstractMappingContext <E extends MutablePersistentEntity <?, P >, P extends PersistentProperty <P >>
67
69
implements MappingContext <E , P >, ApplicationEventPublisherAware , InitializingBean {
68
70
69
71
private final Map <TypeInformation <?>, E > persistentEntities = new HashMap <TypeInformation <?>, E >();
72
+ private final DefaultPersistentPropertyAccessorFactory persistentPropertyAccessorFactory = new DefaultPersistentPropertyAccessorFactory ();
70
73
71
74
private ApplicationEventPublisher applicationEventPublisher ;
72
75
@@ -78,7 +81,7 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
78
81
private final Lock read = lock .readLock ();
79
82
private final Lock write = lock .writeLock ();
80
83
81
- /*
84
+ /*
82
85
* (non-Javadoc)
83
86
* @see org.springframework.context.ApplicationEventPublisherAware#setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
84
87
*/
@@ -88,7 +91,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher applicationEv
88
91
89
92
/**
90
93
* Sets the {@link Set} of types to populate the context initially.
91
- *
94
+ *
92
95
* @param initialEntitySet
93
96
*/
94
97
public void setInitialEntitySet (Set <? extends Class <?>> initialEntitySet ) {
@@ -100,7 +103,7 @@ public void setInitialEntitySet(Set<? extends Class<?>> initialEntitySet) {
100
103
* {@link MappingException}s in case one tries to lookup a {@link PersistentEntity} not already in the context. This
101
104
* defaults to {@literal false} so that unknown types will be transparently added to the MappingContext if not known
102
105
* in advance.
103
- *
106
+ *
104
107
* @param strict
105
108
*/
106
109
public void setStrict (boolean strict ) {
@@ -111,7 +114,7 @@ public void setStrict(boolean strict) {
111
114
* Configures the {@link SimpleTypeHolder} to be used by the {@link MappingContext}. Allows customization of what
112
115
* types will be regarded as simple types and thus not recursively analysed. Setting this to {@literal null} will
113
116
* reset the context to use the default {@link SimpleTypeHolder}.
114
- *
117
+ *
115
118
* @param simpleTypes
116
119
*/
117
120
public void setSimpleTypeHolder (SimpleTypeHolder simpleTypes ) {
@@ -139,7 +142,7 @@ public E getPersistentEntity(Class<?> type) {
139
142
return getPersistentEntity (ClassTypeInformation .from (type ));
140
143
}
141
144
142
- /*
145
+ /*
143
146
* (non-Javadoc)
144
147
* @see org.springframework.data.mapping.context.MappingContext#hasPersistentEntityFor(java.lang.Class)
145
148
*/
@@ -216,7 +219,7 @@ public PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,
216
219
return getPersistentPropertyPath (propertyPath , ClassTypeInformation .from (type ));
217
220
}
218
221
219
- /*
222
+ /*
220
223
* (non-Javadoc)
221
224
* @see org.springframework.data.mapping.context.MappingContext#getPersistentPropertyPath(org.springframework.data.mapping.context.InvalidPersistentPropertyPath)
222
225
*/
@@ -231,7 +234,7 @@ private PersistentPropertyPath<P> getPersistentPropertyPath(String propertyPath,
231
234
232
235
/**
233
236
* Creates a {@link PersistentPropertyPath} for the given parts and {@link TypeInformation}.
234
- *
237
+ *
235
238
* @param parts must not be {@literal null} or empty.
236
239
* @param type must not be {@literal null}.
237
240
* @return
@@ -268,7 +271,7 @@ private PersistentPropertyPath<P> getPersistentPropertyPath(Collection<String> p
268
271
269
272
/**
270
273
* Adds the given type to the {@link MappingContext}.
271
- *
274
+ *
272
275
* @param type
273
276
* @return
274
277
*/
@@ -278,7 +281,7 @@ protected E addPersistentEntity(Class<?> type) {
278
281
279
282
/**
280
283
* Adds the given {@link TypeInformation} to the {@link MappingContext}.
281
- *
284
+ *
282
285
* @param typeInformation
283
286
* @return
284
287
*/
@@ -316,6 +319,9 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {
316
319
317
320
entity .verify ();
318
321
322
+ if (persistentPropertyAccessorFactory .isSupported (entity )) {
323
+ entity .setPersistentPropertyAccessorFactory (persistentPropertyAccessorFactory );
324
+ }
319
325
} catch (MappingException e ) {
320
326
persistentEntities .remove (typeInformation );
321
327
throw e ;
@@ -335,7 +341,7 @@ protected E addPersistentEntity(TypeInformation<?> typeInformation) {
335
341
}
336
342
}
337
343
338
- /*
344
+ /*
339
345
* (non-Javadoc)
340
346
* @see org.springframework.data.mapping.context.PersistentEntityAware#getManagedTypes()
341
347
*/
@@ -354,7 +360,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {
354
360
355
361
/**
356
362
* Creates the concrete {@link PersistentEntity} instance.
357
- *
363
+ *
358
364
* @param <T>
359
365
* @param typeInformation
360
366
* @return
@@ -363,7 +369,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {
363
369
364
370
/**
365
371
* Creates the concrete instance of {@link PersistentProperty}.
366
- *
372
+ *
367
373
* @param field
368
374
* @param descriptor
369
375
* @param owner
@@ -373,7 +379,7 @@ public Collection<TypeInformation<?>> getManagedTypes() {
373
379
protected abstract P createPersistentProperty (Field field , PropertyDescriptor descriptor , E owner ,
374
380
SimpleTypeHolder simpleTypeHolder );
375
381
376
- /*
382
+ /*
377
383
* (non-Javadoc)
378
384
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
379
385
*/
@@ -398,7 +404,7 @@ public void initialize() {
398
404
* default this will reject this for all types considered simple, but it might be necessary to tweak that in case you
399
405
* have registered custom converters for top level types (which renders them to be considered simple) but still need
400
406
* meta-information about them.
401
- *
407
+ *
402
408
* @param type will never be {@literal null}.
403
409
* @return
404
410
*/
@@ -408,7 +414,7 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
408
414
409
415
/**
410
416
* {@link FieldCallback} to create {@link PersistentProperty} instances.
411
- *
417
+ *
412
418
* @author Oliver Gierke
413
419
*/
414
420
private final class PersistentPropertyCreator implements FieldCallback {
@@ -420,7 +426,7 @@ private final class PersistentPropertyCreator implements FieldCallback {
420
426
/**
421
427
* Creates a new {@link PersistentPropertyCreator} for the given {@link PersistentEntity} and
422
428
* {@link PropertyDescriptor}s.
423
- *
429
+ *
424
430
* @param entity must not be {@literal null}.
425
431
* @param descriptors must not be {@literal null}.
426
432
*/
@@ -451,7 +457,7 @@ public void doWith(Field field) {
451
457
/**
452
458
* Adds {@link PersistentProperty} instances for all suitable {@link PropertyDescriptor}s without a backing
453
459
* {@link Field}.
454
- *
460
+ *
455
461
* @see PersistentPropertyFilter
456
462
*/
457
463
public void addPropertiesForRemainingDescriptors () {
@@ -494,7 +500,7 @@ private void createAndRegisterProperty(Field field, PropertyDescriptor descripto
494
500
/**
495
501
* Filter rejecting static fields as well as artifically introduced ones. See
496
502
* {@link PersistentPropertyFilter#UNMAPPED_PROPERTIES} for details.
497
- *
503
+ *
498
504
* @author Oliver Gierke
499
505
*/
500
506
static enum PersistentPropertyFilter implements FieldFilter {
@@ -513,7 +519,7 @@ static enum PersistentPropertyFilter implements FieldFilter {
513
519
UNMAPPED_PROPERTIES = Collections .unmodifiableCollection (matches );
514
520
}
515
521
516
- /*
522
+ /*
517
523
* (non-Javadoc)
518
524
* @see org.springframework.util.ReflectionUtils.FieldFilter#matches(java.lang.reflect.Field)
519
525
*/
@@ -534,7 +540,7 @@ public boolean matches(Field field) {
534
540
535
541
/**
536
542
* Returns whether the given {@link PropertyDescriptor} is one to create a {@link PersistentProperty} for.
537
- *
543
+ *
538
544
* @param descriptor must not be {@literal null}.
539
545
* @return
540
546
*/
@@ -557,7 +563,7 @@ public boolean matches(PropertyDescriptor descriptor) {
557
563
558
564
/**
559
565
* Value object to help defining property exclusion based on name patterns and types.
560
- *
566
+ *
561
567
* @since 1.4
562
568
* @author Oliver Gierke
563
569
*/
@@ -569,7 +575,7 @@ static class PropertyMatch {
569
575
/**
570
576
* Creates a new {@link PropertyMatch} for the given name pattern and type name. At least one of the paramters
571
577
* must not be {@literal null}.
572
- *
578
+ *
573
579
* @param namePattern a regex pattern to match field names, can be {@literal null}.
574
580
* @param typeName the name of the type to exclude, can be {@literal null}.
575
581
*/
@@ -583,7 +589,7 @@ public PropertyMatch(String namePattern, String typeName) {
583
589
584
590
/**
585
591
* Returns whether the given {@link Field} matches the defined {@link PropertyMatch}.
586
- *
592
+ *
587
593
* @param field must not be {@literal null}.
588
594
* @return
589
595
*/
0 commit comments