45
45
46
46
/**
47
47
* Simple value object to capture information of {@link PersistentEntity}s.
48
- *
48
+ *
49
49
* @author Oliver Gierke
50
50
* @author Jon Brisbin
51
51
* @author Patryk Wasik
52
52
* @author Thomas Darimont
53
53
* @author Christoph Strobl
54
+ * @author Mark Paluch
54
55
*/
55
56
public class BasicPersistentEntity <T , P extends PersistentProperty <P >> implements MutablePersistentEntity <T , P > {
56
57
@@ -66,9 +67,11 @@ public class BasicPersistentEntity<T, P extends PersistentProperty<P>> implement
66
67
private P idProperty ;
67
68
private P versionProperty ;
68
69
70
+ private final PersistentPropertyAccessorFactory propertyAccessorFactory ;
71
+
69
72
/**
70
73
* Creates a new {@link BasicPersistentEntity} from the given {@link TypeInformation}.
71
- *
74
+ *
72
75
* @param information must not be {@literal null}.
73
76
*/
74
77
public BasicPersistentEntity (TypeInformation <T > information ) {
@@ -79,7 +82,7 @@ public BasicPersistentEntity(TypeInformation<T> information) {
79
82
* Creates a new {@link BasicPersistentEntity} for the given {@link TypeInformation} and {@link Comparator}. The given
80
83
* {@link Comparator} will be used to define the order of the {@link PersistentProperty} instances added to the
81
84
* entity.
82
- *
85
+ *
83
86
* @param information must not be {@literal null}.
84
87
* @param comparator can be {@literal null}.
85
88
*/
@@ -91,14 +94,15 @@ public BasicPersistentEntity(TypeInformation<T> information, Comparator<P> compa
91
94
this .properties = new ArrayList <P >();
92
95
this .comparator = comparator ;
93
96
this .constructor = new PreferredConstructorDiscoverer <T , P >(information , this ).getConstructor ();
94
- this .associations = comparator == null ? new HashSet <Association <P >>() : new TreeSet < Association < P >>(
95
- new AssociationComparator <P >(comparator ));
97
+ this .associations = comparator == null ? new HashSet <Association <P >>()
98
+ : new TreeSet < Association < P >>( new AssociationComparator <P >(comparator ));
96
99
97
100
this .propertyCache = new HashMap <String , P >();
98
101
this .annotationCache = new HashMap <Class <? extends Annotation >, Annotation >();
102
+ this .propertyAccessorFactory = new DefaultPersistentPropertyAccessorFactory ();
99
103
}
100
104
101
- /*
105
+ /*
102
106
* (non-Javadoc)
103
107
* @see org.springframework.data.mapping.PersistentEntity#getPersistenceConstructor()
104
108
*/
@@ -122,7 +126,7 @@ public boolean isIdProperty(PersistentProperty<?> property) {
122
126
return this .idProperty == null ? false : this .idProperty .equals (property );
123
127
}
124
128
125
- /*
129
+ /*
126
130
* (non-Javadoc)
127
131
* @see org.springframework.data.mapping.PersistentEntity#isVersionProperty(org.springframework.data.mapping.PersistentProperty)
128
132
*/
@@ -146,31 +150,31 @@ public P getIdProperty() {
146
150
return idProperty ;
147
151
}
148
152
149
- /*
153
+ /*
150
154
* (non-Javadoc)
151
155
* @see org.springframework.data.mapping.PersistentEntity#getVersionProperty()
152
156
*/
153
157
public P getVersionProperty () {
154
158
return versionProperty ;
155
159
}
156
160
157
- /*
161
+ /*
158
162
* (non-Javadoc)
159
163
* @see org.springframework.data.mapping.PersistentEntity#hasIdProperty()
160
164
*/
161
165
public boolean hasIdProperty () {
162
166
return idProperty != null ;
163
167
}
164
168
165
- /*
169
+ /*
166
170
* (non-Javadoc)
167
171
* @see org.springframework.data.mapping.PersistentEntity#hasVersionProperty()
168
172
*/
169
173
public boolean hasVersionProperty () {
170
174
return versionProperty != null ;
171
175
}
172
176
173
- /*
177
+ /*
174
178
* (non-Javadoc)
175
179
* @see org.springframework.data.mapping.MutablePersistentEntity#addPersistentProperty(P)
176
180
*/
@@ -197,9 +201,11 @@ public void addPersistentProperty(P property) {
197
201
if (property .isVersionProperty ()) {
198
202
199
203
if (this .versionProperty != null ) {
200
- throw new MappingException (String .format (
201
- "Attempt to add version property %s but already have property %s registered "
202
- + "as version. Check your mapping configuration!" , property .getField (), versionProperty .getField ()));
204
+ throw new MappingException (
205
+ String .format (
206
+ "Attempt to add version property %s but already have property %s registered "
207
+ + "as version. Check your mapping configuration!" ,
208
+ property .getField (), versionProperty .getField ()));
203
209
}
204
210
205
211
this .versionProperty = property ;
@@ -208,7 +214,7 @@ public void addPersistentProperty(P property) {
208
214
209
215
/**
210
216
* Returns the given property if it is a better candidate for the id property than the current id property.
211
- *
217
+ *
212
218
* @param property the new id property candidate, will never be {@literal null}.
213
219
* @return the given id property or {@literal null} if the given property is not an id property.
214
220
*/
@@ -244,7 +250,7 @@ public P getPersistentProperty(String name) {
244
250
return propertyCache .get (name );
245
251
}
246
252
247
- /*
253
+ /*
248
254
* (non-Javadoc)
249
255
* @see org.springframework.data.mapping.PersistentEntity#getPersistentProperty(java.lang.Class)
250
256
*/
@@ -279,7 +285,7 @@ public Class<T> getType() {
279
285
return information .getType ();
280
286
}
281
287
282
- /*
288
+ /*
283
289
* (non-Javadoc)
284
290
* @see org.springframework.data.mapping.PersistentEntity#getTypeAlias()
285
291
*/
@@ -312,7 +318,7 @@ public void doWithProperties(PropertyHandler<P> handler) {
312
318
}
313
319
}
314
320
315
- /*
321
+ /*
316
322
* (non-Javadoc)
317
323
* @see org.springframework.data.mapping.PersistentEntity#doWithProperties(org.springframework.data.mapping.PropertyHandler.Simple)
318
324
*/
@@ -354,7 +360,7 @@ public void doWithAssociations(SimpleAssociationHandler handler) {
354
360
}
355
361
}
356
362
357
- /*
363
+ /*
358
364
* (non-Javadoc)
359
365
* @see org.springframework.data.mapping.PersistentEntity#findAnnotation(java.lang.Class)
360
366
*/
@@ -372,7 +378,7 @@ public <A extends Annotation> A findAnnotation(Class<A> annotationType) {
372
378
return annotation ;
373
379
}
374
380
375
- /*
381
+ /*
376
382
* (non-Javadoc)
377
383
* @see org.springframework.data.mapping.MutablePersistentEntity#verify()
378
384
*/
@@ -383,7 +389,7 @@ public void verify() {
383
389
}
384
390
}
385
391
386
- /*
392
+ /*
387
393
* (non-Javadoc)
388
394
* @see org.springframework.data.mapping.PersistentEntity#getPropertyAccessor(java.lang.Object)
389
395
*/
@@ -393,10 +399,10 @@ public PersistentPropertyAccessor getPropertyAccessor(Object bean) {
393
399
Assert .notNull (bean , "Target bean must not be null!" );
394
400
Assert .isTrue (getType ().isInstance (bean ), "Target bean is not of type of the persistent entity!" );
395
401
396
- return new BeanWrapper < Object >( bean );
402
+ return propertyAccessorFactory . getPropertyAccessor ( this , bean );
397
403
}
398
404
399
- /*
405
+ /*
400
406
* (non-Javadoc)
401
407
* @see org.springframework.data.mapping.PersistentEntity#getIdentifierAccessor(java.lang.Object)
402
408
*/
@@ -419,7 +425,7 @@ private static enum NullReturningIdentifierAccessor implements IdentifierAccesso
419
425
420
426
INSTANCE ;
421
427
422
- /*
428
+ /*
423
429
* (non-Javadoc)
424
430
* @see org.springframework.data.mapping.IdentifierAccessor#getIdentifier()
425
431
*/
@@ -431,11 +437,11 @@ public Object getIdentifier() {
431
437
432
438
/**
433
439
* Simple {@link Comparator} adaptor to delegate ordering to the inverse properties of the association.
434
- *
440
+ *
435
441
* @author Oliver Gierke
436
442
*/
437
- private static final class AssociationComparator <P extends PersistentProperty <P >> implements
438
- Comparator <Association <P >>, Serializable {
443
+ private static final class AssociationComparator <P extends PersistentProperty <P >>
444
+ implements Comparator <Association <P >>, Serializable {
439
445
440
446
private static final long serialVersionUID = 4508054194886854513L ;
441
447
private final Comparator <P > delegate ;
0 commit comments