Skip to content

Commit

Permalink
First pass of review polishing.
Browse files Browse the repository at this point in the history
Original pull request: #3647.
Closes #3602.
  • Loading branch information
mp911de committed May 21, 2021
1 parent a51c962 commit 48ac7e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ default Document fetch(ReferenceFilter filter, ReferenceContext context) {
return bulkFetch(filter, context).findFirst().orElse(null);
}

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

// Reference query
interface ReferenceFilter {

Bson getFilter();
Expand All @@ -45,6 +47,8 @@ default Bson getSort() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public 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) {

Expand All @@ -94,6 +95,8 @@ Object readReference(MongoPersistentProperty property, Object value,
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
Expand Down Expand Up @@ -165,7 +168,7 @@ private <T> T parseValueOrGet(String value, ParameterBindingContext bindingConte

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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ default Object resolveReference(MongoPersistentProperty property, Object source,

ReferenceLoader getReferenceLoader();

// TODO: ReferenceCollection
class ReferenceContext {

@Nullable final String database;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @author Christoph Strobl
*/
@FunctionalInterface
// TODO: ObjectPointer or DocumentPointer
public interface ObjectReference<T> {
T getPointer();
}

0 comments on commit 48ac7e7

Please # to comment.