First pass of review polishing.
Original pull request: #3647. Closes #3602.
This commit is contained in:
@@ -35,8 +35,10 @@ public interface ReferenceLoader {
|
||||
return bulkFetch(filter, context).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
// meh, Stream!
|
||||
Stream<Document> bulkFetch(ReferenceFilter filter, ReferenceContext context);
|
||||
|
||||
// Reference query
|
||||
interface ReferenceFilter {
|
||||
|
||||
Bson getFilter();
|
||||
@@ -45,6 +47,8 @@ public interface ReferenceLoader {
|
||||
return new Document();
|
||||
}
|
||||
|
||||
// TODO: Move apply method into something else that holds the collection and knows about single item/multi-item
|
||||
// processing
|
||||
default Stream<Document> apply(MongoCollection<Document> collection) {
|
||||
return restoreOrder(StreamSupport.stream(collection.find(getFilter()).sort(getSort()).spliterator(), false));
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public class ReferenceReader {
|
||||
this.codec = new ParameterBindingDocumentCodec();
|
||||
}
|
||||
|
||||
// TODO: Move documentConversionFunction to here. Having a contextual read allows projections in references
|
||||
Object readReference(MongoPersistentProperty property, Object value,
|
||||
BiFunction<ReferenceContext, ReferenceFilter, Stream<Document>> lookupFunction) {
|
||||
|
||||
@@ -94,6 +95,8 @@ public class ReferenceReader {
|
||||
return result.map(it -> documentConversionFunction.apply(property, it)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// TODO: retain target type and extract types here so the conversion function doesn't require type fiddling
|
||||
// BiFunction<TypeInformation, Document, Object> instead of MongoPersistentProperty
|
||||
if (property.isMap()) {
|
||||
|
||||
// the order is a real problem here
|
||||
@@ -165,7 +168,7 @@ public class ReferenceReader {
|
||||
|
||||
if (!BsonUtils.isJsonDocument(value) && value.contains("?#{")) {
|
||||
String s = "{ 'target-value' : " + value + "}";
|
||||
T evaluated = (T) new ParameterBindingDocumentCodec().decode(s, bindingContext).get("target-value ");
|
||||
T evaluated = (T) codec.decode(s, bindingContext).get("target-value ");
|
||||
return evaluated != null ? evaluated : defaultValue.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ public interface ReferenceResolver {
|
||||
|
||||
ReferenceLoader getReferenceLoader();
|
||||
|
||||
// TODO: ReferenceCollection
|
||||
class ReferenceContext {
|
||||
|
||||
@Nullable final String database;
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.mongodb.core.mapping;
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@FunctionalInterface
|
||||
// TODO: ObjectPointer or DocumentPointer
|
||||
public interface ObjectReference<T> {
|
||||
T getPointer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user