63
63
import org .springframework .data .mapping .model .SpELExpressionParameterValueProvider ;
64
64
import org .springframework .data .mongodb .CodecRegistryProvider ;
65
65
import org .springframework .data .mongodb .MongoDatabaseFactory ;
66
+ import org .springframework .data .mongodb .core .mapping .DocumentPointer ;
66
67
import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
67
68
import org .springframework .data .mongodb .core .mapping .MongoPersistentProperty ;
68
- import org .springframework .data .mongodb .core .mapping .DocumentPointer ;
69
69
import org .springframework .data .mongodb .core .mapping .Unwrapped ;
70
70
import org .springframework .data .mongodb .core .mapping .Unwrapped .OnEmpty ;
71
71
import org .springframework .data .mongodb .core .mapping .event .AfterConvertCallback ;
@@ -364,7 +364,7 @@ private <S extends Object> S read(ConversionContext context, MongoPersistentEnti
364
364
SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator (bson , spELContext );
365
365
DocumentAccessor documentAccessor = new DocumentAccessor (bson );
366
366
367
- if (bson .get ("_id" ) != null ) {
367
+ if (bson .get ("_id" ) != null ) {
368
368
369
369
Object existing = context .getPath ().getPathItem (bson .get ("_id" ), entity .getCollection (), entity .getType ());
370
370
if (existing != null ) {
@@ -458,7 +458,8 @@ private void readProperties(ConversionContext context, MongoPersistentEntity<?>
458
458
callback = getDbRefResolverCallback (context , documentAccessor , evaluator );
459
459
}
460
460
461
- readAssociation (prop .getRequiredAssociation (), accessor , documentAccessor , dbRefProxyHandler , callback , context , evaluator );
461
+ readAssociation (prop .getRequiredAssociation (), accessor , documentAccessor , dbRefProxyHandler , callback , context ,
462
+ evaluator );
462
463
continue ;
463
464
}
464
465
@@ -485,7 +486,8 @@ private void readProperties(ConversionContext context, MongoPersistentEntity<?>
485
486
callback = getDbRefResolverCallback (context , documentAccessor , evaluator );
486
487
}
487
488
488
- readAssociation (prop .getRequiredAssociation (), accessor , documentAccessor , dbRefProxyHandler , callback , context , evaluator );
489
+ readAssociation (prop .getRequiredAssociation (), accessor , documentAccessor , dbRefProxyHandler , callback , context ,
490
+ evaluator );
489
491
continue ;
490
492
}
491
493
@@ -501,7 +503,8 @@ private DbRefResolverCallback getDbRefResolverCallback(ConversionContext context
501
503
}
502
504
503
505
private void readAssociation (Association <MongoPersistentProperty > association , PersistentPropertyAccessor <?> accessor ,
504
- DocumentAccessor documentAccessor , DbRefProxyHandler handler , DbRefResolverCallback callback , ConversionContext context , SpELExpressionEvaluator evaluator ) {
506
+ DocumentAccessor documentAccessor , DbRefProxyHandler handler , DbRefResolverCallback callback ,
507
+ ConversionContext context , SpELExpressionEvaluator evaluator ) {
505
508
506
509
MongoPersistentProperty property = association .getInverse ();
507
510
final Object value = documentAccessor .get (property );
@@ -524,13 +527,16 @@ public Object getPointer() {
524
527
}
525
528
}, property .getActualType ()));
526
529
} else {
527
- accessor .setProperty (property , dbRefResolver . resolveReference ( property , value , referenceReader ,
528
- ( document , prop ) -> context . convert ( document , prop . getTypeInformation ()) ));
530
+ accessor .setProperty (property ,
531
+ dbRefResolver . resolveReference ( property , value , referenceReader , context :: convert ));
529
532
}
530
533
return ;
531
534
}
532
535
533
536
DBRef dbref = value instanceof DBRef ? (DBRef ) value : null ;
537
+
538
+ // TODO: accessor.setProperty(property, dbRefResolver.resolveReference(property, value, referenceReader,
539
+ // context::convert));
534
540
accessor .setProperty (property , dbRefResolver .resolveDbRef (property , dbref , callback , handler ));
535
541
}
536
542
@@ -863,15 +869,15 @@ protected Bson createMap(Map<Object, Object> map, MongoPersistentProperty proper
863
869
if (conversions .isSimpleType (key .getClass ())) {
864
870
865
871
String simpleKey = prepareMapKey (key .toString ());
866
- if (property .isDbReference ()) {
872
+ if (property .isDbReference ()) {
867
873
document .put (simpleKey , value != null ? createDBRef (value , property ) : null );
868
874
} else {
869
875
if (conversionService .canConvert (value .getClass (), DocumentPointer .class )) {
870
876
document .put (simpleKey , conversionService .convert (value , DocumentPointer .class ).getPointer ());
871
877
} else {
872
878
// just take the id as a reference
873
- document .put (simpleKey , mappingContext .getPersistentEntity (property .getAssociationTargetType ()). getIdentifierAccessor ( value )
874
- .getIdentifier ());
879
+ document .put (simpleKey , mappingContext .getPersistentEntity (property .getAssociationTargetType ())
880
+ .getIdentifierAccessor ( value ). getIdentifier ());
875
881
}
876
882
}
877
883
0 commit comments