From 38fe8d4601da4bdba94b5e95a72a9d0563aa565f Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 5 Mar 2019 10:45:24 +0100 Subject: [PATCH] DATAMONGO-2215 - Polishing. Update Javadoc to reflect that array filters are used in their raw form without domain-type related type- or field mapping. Original pull request: #656. --- .../springframework/data/mongodb/core/query/Update.java | 9 ++++++--- .../data/mongodb/core/query/UpdateDefinition.java | 7 ++++--- .../data/mongodb/core/convert/UpdateMapperUnitTests.java | 3 ++- src/main/asciidoc/new-features.adoc | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java index 5154d4ea0..668ba2eab 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Update.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Set; import org.bson.Document; + import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; @@ -402,7 +403,8 @@ public class Update implements UpdateDefinition { } /** - * Filter elements in an array that match the given criteria for update. + * Filter elements in an array that match the given criteria for update. {@link CriteriaDefinition} is passed directly + * to the driver without further type or field mapping. * * @param criteria must not be {@literal null}. * @return this. @@ -410,12 +412,13 @@ public class Update implements UpdateDefinition { */ public Update filterArray(CriteriaDefinition criteria) { - this.arrayFilters.add(() -> criteria.getCriteriaObject()); + this.arrayFilters.add(criteria::getCriteriaObject); return this; } /** - * Filter elements in an array that match the given criteria for update. + * Filter elements in an array that match the given criteria for update. {@code expression} is used directly with the + * driver without further further type or field mapping. * * @param identifier the positional operator identifier filter criteria name. * @param expression the positional operator filter expression. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/UpdateDefinition.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/UpdateDefinition.java index c2b223676..07b6388fe 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/UpdateDefinition.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/UpdateDefinition.java @@ -57,7 +57,8 @@ public interface UpdateDefinition { void inc(String key); /** - * Get the specification which elements to modify in an array field. + * Get the specification which elements to modify in an array field. {@link ArrayFilter} are passed directly to the + * driver without further type or field mapping. * * @return never {@literal null}. * @since 2.2 @@ -80,8 +81,8 @@ public interface UpdateDefinition { interface ArrayFilter { /** - * Get the {@link Document} representation of the filter to apply. The returned Document is subject to mapping - * domain type filed names. + * Get the {@link Document} representation of the filter to apply. The returned {@link Document} is used directly + * with the driver without further type or field mapping. * * @return never {@literal null}. */ diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java index ed522c442..214ffefa8 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/UpdateMapperUnitTests.java @@ -37,6 +37,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; + import org.springframework.core.convert.converter.Converter; import org.springframework.data.annotation.Id; import org.springframework.data.convert.CustomConversions; @@ -1058,7 +1059,7 @@ public class UpdateMapperUnitTests { .filterArray(Criteria.where("element").gte(100)); Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(), - context.getPersistentEntity(EntityWithListOfSimple.class)); + context.getPersistentEntity(EntityWithListOfIntegers.class)); assertThat(mappedUpdate).isEqualTo(new Document("$set", new Document("grades.$[element]", 10))); } diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc index c4965642e..178ebe56d 100644 --- a/src/main/asciidoc/new-features.adoc +++ b/src/main/asciidoc/new-features.adoc @@ -11,6 +11,7 @@ * Repository deletes now throw `OptimisticLockingFailureException` when a versioned entity cannot be deleted. * Support `Range` in repository between queries. * Kotlin extension methods accepting `KClass` are deprecated now in favor of `reified` methods. +* Support of array filters in `Update` operations. [[new-features.2-1-0]] == What's New in Spring Data MongoDB 2.1