21
21
import java .util .Collections ;
22
22
import java .util .Map ;
23
23
import java .util .Optional ;
24
+ import java .util .function .Supplier ;
24
25
25
26
import org .springframework .data .mapping .Association ;
26
27
import org .springframework .data .mapping .PersistentEntity ;
@@ -56,15 +57,13 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
56
57
private final Class <?> rawType ;
57
58
private final Lazy <Association <P >> association ;
58
59
private final PersistentEntity <?, P > owner ;
59
-
60
- @ SuppressWarnings ("null" ) //
61
60
private final Property property ;
62
61
private final Lazy <Integer > hashCode ;
63
62
private final Lazy <Boolean > usePropertyAccess ;
64
- private final Lazy <Optional <? extends TypeInformation <?> >> entityTypeInformation ;
63
+ private final Lazy <TypeInformation <?>> entityTypeInformation ;
65
64
66
65
private final Lazy <Boolean > isAssociation ;
67
- private final Lazy <Class <?>> associationTargetType ;
66
+ private final Lazy <TypeInformation <?>> associationTargetType ;
68
67
69
68
private final Method getter ;
70
69
private final Method setter ;
@@ -94,13 +93,13 @@ public AbstractPersistentProperty(Property property, PersistentEntity<?, P> owne
94
93
: Lazy .of (() -> Optional .of (getTypeInformation ())
95
94
.map (it -> it .getSuperTypeInformation (ASSOCIATION_TYPE ))
96
95
.map (TypeInformation ::getComponentType )
97
- .map (TypeInformation ::getType )
98
96
.orElse (null ));
99
97
100
- this .entityTypeInformation = Lazy .of (() -> Optional .ofNullable (information .getActualType ())//
101
- .filter (it -> !simpleTypeHolder .isSimpleType (it .getType ()))//
102
- .filter (it -> !it .isCollectionLike ())//
103
- .filter (it -> !it .isMap ()));
98
+ this .entityTypeInformation = Lazy .of (() -> Optional .ofNullable (getAssociationOrActualType ())
99
+ .filter (it -> !simpleTypeHolder .isSimpleType (it .getType ())) //
100
+ .filter (it -> !it .isCollectionLike ()) //
101
+ .filter (it -> !it .isMap ())
102
+ .orElse (null ));
104
103
105
104
this .getter = property .getGetter ().orElse (null );
106
105
this .setter = property .getSetter ().orElse (null );
@@ -172,9 +171,9 @@ public Iterable<? extends TypeInformation<?>> getPersistentEntityTypes() {
172
171
return Collections .emptySet ();
173
172
}
174
173
175
- return entityTypeInformation .get () //
176
- . map ( Collections :: singleton ) //
177
- . orElseGet ( Collections :: emptySet );
174
+ TypeInformation <?> result = getAssociationTypeOr (() -> entityTypeInformation .getNullable ());
175
+
176
+ return result != null ? Collections . singleton ( result ) : Collections . emptySet ( );
178
177
}
179
178
180
179
/*
@@ -279,7 +278,10 @@ public Association<P> getAssociation() {
279
278
@ Nullable
280
279
@ Override
281
280
public Class <?> getAssociationTargetType () {
282
- return associationTargetType .getNullable ();
281
+
282
+ TypeInformation <?> result = associationTargetType .getNullable ();
283
+
284
+ return result != null ? result .getType () : null ;
283
285
}
284
286
285
287
/*
@@ -315,7 +317,7 @@ public boolean isArray() {
315
317
*/
316
318
@ Override
317
319
public boolean isEntity () {
318
- return !isTransient () && entityTypeInformation .get (). isPresent () ;
320
+ return !isTransient () && entityTypeInformation .getNullable () != null ;
319
321
}
320
322
321
323
/*
@@ -339,6 +341,7 @@ public Class<?> getMapValueType() {
339
341
if (isMap ()) {
340
342
341
343
TypeInformation <?> mapValueType = information .getMapValueType ();
344
+
342
345
if (mapValueType != null ) {
343
346
return mapValueType .getType ();
344
347
}
@@ -353,7 +356,7 @@ public Class<?> getMapValueType() {
353
356
*/
354
357
@ Override
355
358
public Class <?> getActualType () {
356
- return information . getRequiredActualType ().getType ();
359
+ return getRequiredAssociationOrActualType ().getType ();
357
360
}
358
361
359
362
/*
@@ -364,7 +367,6 @@ public boolean usePropertyAccess() {
364
367
return usePropertyAccess .get ();
365
368
}
366
369
367
- @ SuppressWarnings ("null" )
368
370
protected Property getProperty () {
369
371
return this .property ;
370
372
}
@@ -406,4 +408,24 @@ public int hashCode() {
406
408
public String toString () {
407
409
return property .toString ();
408
410
}
411
+
412
+ @ Nullable
413
+ private TypeInformation <?> getAssociationOrActualType () {
414
+ return getAssociationTypeOr (() -> information .getActualType ());
415
+ }
416
+
417
+ private TypeInformation <?> getRequiredAssociationOrActualType () {
418
+ return getAssociationTypeOr (() -> information .getRequiredActualType ());
419
+ }
420
+
421
+ private TypeInformation <?> getAssociationTypeOr (Supplier <TypeInformation <?>> fallback ) {
422
+
423
+ TypeInformation <?> result = associationTargetType .getNullable ();
424
+
425
+ if (result != null ) {
426
+ return result ;
427
+ }
428
+
429
+ return fallback .get ();
430
+ }
409
431
}
0 commit comments