Skip to content

Commit 48ac7e7

Browse files
committed
First pass of review polishing.
Original pull request: #3647. Closes #3602.
1 parent a51c962 commit 48ac7e7

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReferenceLoader.java

+4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ default Document fetch(ReferenceFilter filter, ReferenceContext context) {
3535
return bulkFetch(filter, context).findFirst().orElse(null);
3636
}
3737

38+
// meh, Stream!
3839
Stream<Document> bulkFetch(ReferenceFilter filter, ReferenceContext context);
3940

41+
// Reference query
4042
interface ReferenceFilter {
4143

4244
Bson getFilter();
@@ -45,6 +47,8 @@ default Bson getSort() {
4547
return new Document();
4648
}
4749

50+
// TODO: Move apply method into something else that holds the collection and knows about single item/multi-item
51+
// processing
4852
default Stream<Document> apply(MongoCollection<Document> collection) {
4953
return restoreOrder(StreamSupport.stream(collection.find(getFilter()).sort(getSort()).spliterator(), false));
5054
}

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReferenceReader.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public ReferenceReader(
8080
this.codec = new ParameterBindingDocumentCodec();
8181
}
8282

83+
// TODO: Move documentConversionFunction to here. Having a contextual read allows projections in references
8384
Object readReference(MongoPersistentProperty property, Object value,
8485
BiFunction<ReferenceContext, ReferenceFilter, Stream<Document>> lookupFunction) {
8586

@@ -94,6 +95,8 @@ Object readReference(MongoPersistentProperty property, Object value,
9495
return result.map(it -> documentConversionFunction.apply(property, it)).collect(Collectors.toList());
9596
}
9697

98+
// TODO: retain target type and extract types here so the conversion function doesn't require type fiddling
99+
// BiFunction<TypeInformation, Document, Object> instead of MongoPersistentProperty
97100
if (property.isMap()) {
98101

99102
// the order is a real problem here
@@ -165,7 +168,7 @@ private <T> T parseValueOrGet(String value, ParameterBindingContext bindingConte
165168

166169
if (!BsonUtils.isJsonDocument(value) && value.contains("?#{")) {
167170
String s = "{ 'target-value' : " + value + "}";
168-
T evaluated = (T) new ParameterBindingDocumentCodec().decode(s, bindingContext).get("target-value ");
171+
T evaluated = (T) codec.decode(s, bindingContext).get("target-value ");
169172
return evaluated != null ? evaluated : defaultValue.get();
170173
}
171174

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/ReferenceResolver.java

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ default Object resolveReference(MongoPersistentProperty property, Object source,
4747

4848
ReferenceLoader getReferenceLoader();
4949

50+
// TODO: ReferenceCollection
5051
class ReferenceContext {
5152

5253
@Nullable final String database;

Diff for: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/ObjectReference.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* @author Christoph Strobl
2020
*/
2121
@FunctionalInterface
22+
// TODO: ObjectPointer or DocumentPointer
2223
public interface ObjectReference<T> {
2324
T getPointer();
2425
}

0 commit comments

Comments
 (0)