31
31
import org .springframework .context .ApplicationContextAware ;
32
32
import org .springframework .core .convert .ConversionException ;
33
33
import org .springframework .core .convert .ConversionService ;
34
- import org .springframework .core .convert .support .ConversionServiceFactory ;
34
+ import org .springframework .core .convert .support .DefaultConversionService ;
35
35
import org .springframework .data .convert .CollectionFactory ;
36
36
import org .springframework .data .convert .EntityInstantiator ;
37
37
import org .springframework .data .convert .TypeMapper ;
74
74
* @author Thomas Darimont
75
75
* @author Christoph Strobl
76
76
*/
77
- public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware {
77
+ public class MappingMongoConverter extends AbstractMongoConverter implements ApplicationContextAware , ValueResolver {
78
78
79
79
protected static final Logger LOGGER = LoggerFactory .getLogger (MappingMongoConverter .class );
80
80
81
81
protected final MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ;
82
82
protected final SpelExpressionParser spelExpressionParser = new SpelExpressionParser ();
83
83
protected final QueryMapper idMapper ;
84
84
protected final DbRefResolver dbRefResolver ;
85
+
85
86
protected ApplicationContext applicationContext ;
86
87
protected MongoTypeMapper typeMapper ;
87
88
protected String mapKeyDotReplacement = null ;
@@ -94,11 +95,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
94
95
* @param mongoDbFactory must not be {@literal null}.
95
96
* @param mappingContext must not be {@literal null}.
96
97
*/
97
- @ SuppressWarnings ("deprecation" )
98
98
public MappingMongoConverter (DbRefResolver dbRefResolver ,
99
99
MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ) {
100
100
101
- super (ConversionServiceFactory . createDefaultConversionService ());
101
+ super (new DefaultConversionService ());
102
102
103
103
Assert .notNull (dbRefResolver , "DbRefResolver must not be null!" );
104
104
Assert .notNull (mappingContext , "MappingContext must not be null!" );
@@ -277,21 +277,21 @@ public void doWithPersistentProperty(MongoPersistentProperty prop) {
277
277
entity .doWithAssociations (new AssociationHandler <MongoPersistentProperty >() {
278
278
public void doWithAssociation (Association <MongoPersistentProperty > association ) {
279
279
280
- MongoPersistentProperty property = association .getInverse ();
280
+ final MongoPersistentProperty property = association .getInverse ();
281
281
Object value = dbo .get (property .getName ());
282
282
283
283
if (value == null ) {
284
284
return ;
285
285
}
286
286
287
287
DBRef dbref = value instanceof DBRef ? (DBRef ) value : null ;
288
- wrapper .setProperty (property , dbRefResolver .resolveDbRef (property , dbref , new DbRefResolverCallback () {
289
288
290
- @ Override
291
- public Object resolve (MongoPersistentProperty property ) {
292
- return getValueInternal (property , dbo , evaluator , currentPath );
293
- }
294
- }));
289
+ DbRefProxyHandler handler = new DefaultDbRefProxyHandler (spELContext , mappingContext ,
290
+ MappingMongoConverter .this );
291
+ DbRefResolverCallback callback = new DefaultDbRefResolverCallback (dbo , currentPath , evaluator ,
292
+ MappingMongoConverter .this );
293
+
294
+ wrapper .setProperty (property , dbRefResolver .resolveDbRef (property , dbref , callback , handler ));
295
295
}
296
296
});
297
297
@@ -813,9 +813,13 @@ protected DBRef createDBRef(Object target, MongoPersistentProperty property) {
813
813
idMapper .convertId (id ));
814
814
}
815
815
816
- protected Object getValueInternal (MongoPersistentProperty prop , DBObject dbo , SpELExpressionEvaluator evaluator ,
816
+ /*
817
+ * (non-Javadoc)
818
+ * @see org.springframework.data.mongodb.core.convert.ValueResolver#getValueInternal(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty, com.mongodb.DBObject, org.springframework.data.mapping.model.SpELExpressionEvaluator, java.lang.Object)
819
+ */
820
+ @ Override
821
+ public Object getValueInternal (MongoPersistentProperty prop , DBObject dbo , SpELExpressionEvaluator evaluator ,
817
822
ObjectPath path ) {
818
-
819
823
return new MongoDbPropertyValueProvider (dbo , evaluator , path ).getPropertyValue (prop );
820
824
}
821
825
@@ -1036,11 +1040,11 @@ private class MongoDbPropertyValueProvider implements PropertyValueProvider<Mong
1036
1040
1037
1041
/**
1038
1042
* Creates a new {@link MongoDbPropertyValueProvider} for the given source, {@link SpELExpressionEvaluator} and
1039
- * parent object .
1043
+ * {@link ObjectPath} .
1040
1044
*
1041
1045
* @param source must not be {@literal null}.
1042
1046
* @param evaluator must not be {@literal null}.
1043
- * @param parent can be {@literal null}.
1047
+ * @param path can be {@literal null}.
1044
1048
*/
1045
1049
public MongoDbPropertyValueProvider (DBObject source , SpELExpressionEvaluator evaluator , ObjectPath path ) {
1046
1050
@@ -1078,7 +1082,7 @@ public <T> T getPropertyValue(MongoPersistentProperty property) {
1078
1082
private class ConverterAwareSpELExpressionParameterValueProvider extends
1079
1083
SpELExpressionParameterValueProvider <MongoPersistentProperty > {
1080
1084
1081
- private final ObjectPath parent ;
1085
+ private final ObjectPath path ;
1082
1086
1083
1087
/**
1084
1088
* Creates a new {@link ConverterAwareSpELExpressionParameterValueProvider}.
@@ -1088,10 +1092,10 @@ private class ConverterAwareSpELExpressionParameterValueProvider extends
1088
1092
* @param delegate must not be {@literal null}.
1089
1093
*/
1090
1094
public ConverterAwareSpELExpressionParameterValueProvider (SpELExpressionEvaluator evaluator ,
1091
- ConversionService conversionService , ParameterValueProvider <MongoPersistentProperty > delegate , ObjectPath parent ) {
1095
+ ConversionService conversionService , ParameterValueProvider <MongoPersistentProperty > delegate , ObjectPath path ) {
1092
1096
1093
1097
super (evaluator , conversionService , delegate );
1094
- this .parent = parent ;
1098
+ this .path = path ;
1095
1099
}
1096
1100
1097
1101
/*
@@ -1100,23 +1104,23 @@ public ConverterAwareSpELExpressionParameterValueProvider(SpELExpressionEvaluato
1100
1104
*/
1101
1105
@ Override
1102
1106
protected <T > T potentiallyConvertSpelValue (Object object , Parameter <T , MongoPersistentProperty > parameter ) {
1103
- return readValue (object , parameter .getType (), parent );
1107
+ return readValue (object , parameter .getType (), path );
1104
1108
}
1105
1109
}
1106
1110
1107
1111
@ SuppressWarnings ("unchecked" )
1108
- private <T > T readValue (Object value , TypeInformation <?> type , ObjectPath parent ) {
1112
+ private <T > T readValue (Object value , TypeInformation <?> type , ObjectPath path ) {
1109
1113
1110
1114
Class <?> rawType = type .getType ();
1111
1115
1112
1116
if (conversions .hasCustomReadTarget (value .getClass (), rawType )) {
1113
1117
return (T ) conversionService .convert (value , rawType );
1114
1118
} else if (value instanceof DBRef ) {
1115
- return potentiallyReadOrResolveDbRef ((DBRef ) value , type , parent , rawType );
1119
+ return potentiallyReadOrResolveDbRef ((DBRef ) value , type , path , rawType );
1116
1120
} else if (value instanceof BasicDBList ) {
1117
- return (T ) readCollectionOrArray (type , (BasicDBList ) value , parent );
1121
+ return (T ) readCollectionOrArray (type , (BasicDBList ) value , path );
1118
1122
} else if (value instanceof DBObject ) {
1119
- return (T ) read (type , (DBObject ) value , parent );
1123
+ return (T ) read (type , (DBObject ) value , path );
1120
1124
} else {
1121
1125
return (T ) getPotentiallyConvertedSimpleRead (value , rawType );
1122
1126
}
0 commit comments