Skip to content

Commit cb3557a

Browse files
Hacking: More intermediate types for path mapping
fix issues with property path vs mongo path mapping by introducing segments that can represent various combinations
1 parent e90b869 commit cb3557a

File tree

4 files changed

+635
-101
lines changed

4 files changed

+635
-101
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.bson.Document;
3737
import org.bson.conversions.Bson;
3838
import org.bson.types.ObjectId;
39-
4039
import org.springframework.core.convert.ConversionService;
4140
import org.springframework.core.convert.converter.Converter;
4241
import org.springframework.data.annotation.Reference;
@@ -57,14 +56,9 @@
5756
import org.springframework.data.mongodb.core.aggregation.RelaxedTypeBasedAggregationOperationContext;
5857
import org.springframework.data.mongodb.core.convert.MappingMongoConverter.NestedDocument;
5958
import org.springframework.data.mongodb.core.mapping.FieldName;
60-
import org.springframework.data.mongodb.core.mapping.MongoPath.MappedMongoPath;
61-
import org.springframework.data.mongodb.core.mapping.MongoPath.MappedMongoPath.MappedSegment;
6259
import org.springframework.data.mongodb.core.mapping.MongoPath;
6360
import org.springframework.data.mongodb.core.mapping.MongoPath.PathSegment;
6461
import org.springframework.data.mongodb.core.mapping.MongoPaths;
65-
import org.springframework.data.mongodb.core.mapping.MongoPath.RawMongoPath;
66-
import org.springframework.data.mongodb.core.mapping.MongoPath.RawMongoPath.Segment;
67-
import org.springframework.data.mongodb.core.mapping.MongoPath.RawMongoPath.TargetType;
6862
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
6963
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
7064
import org.springframework.data.mongodb.core.query.Query;
@@ -1140,7 +1134,8 @@ public Class<?> getFieldType() {
11401134
*/
11411135
@Nullable
11421136
public PropertyPath toPropertyPath(
1143-
MongoPath mongoPath, MongoPersistentEntity<?> persistentEntity) {
1137+
1138+
MongoPath mongoPath, MongoPersistentEntity<?> persistentEntity) {
11441139

11451140
StringBuilder path = new StringBuilder();
11461141
MongoPersistentEntity<?> entity = persistentEntity;
@@ -1184,7 +1179,6 @@ public PropertyPath toPropertyPath(
11841179
return PropertyPath.from(path.toString(), persistentEntity.getType());
11851180
}
11861181

1187-
11881182
/**
11891183
* Extension of {@link Field} to be backed with mapping metadata.
11901184
*
@@ -1331,7 +1325,6 @@ public String getMappedKey() {
13311325
return name;
13321326
}
13331327

1334-
13351328
@Nullable
13361329
protected PersistentPropertyPath<MongoPersistentProperty> getPath() {
13371330
return propertyPath;
@@ -1351,7 +1344,7 @@ private PersistentPropertyPath<MongoPersistentProperty> getPath(MongoPath mongoP
13511344
PropertyPath.from(Pattern.quote(sourceProperty.getName()), entity.getTypeInformation()));
13521345
}
13531346

1354-
PropertyPath path = toPropertyPath(mongoPath, entity);
1347+
PropertyPath path = paths.mappedPath(mongoPath, entity.getTypeInformation()).propertyPath();
13551348

13561349
if (path == null || isPathToJavaLangClassProperty(path)) {
13571350
return null;

0 commit comments

Comments
 (0)