From 83fb2f1070916b3a631422ed0a007905fc062896 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 13 Nov 2023 15:25:13 +0100 Subject: [PATCH] Polishing. Adjust grammar. Mention that we use proxies for PropertyValueConverter registration when using method handles. Original pull request: #4553 See #4536 --- .../data/mongodb/core/MongoOperations.java | 28 ++--- .../mongodb/core/ReactiveMongoOperations.java | 109 ++++++++++-------- .../reference/mongo-property-converters.adoc | 2 + 3 files changed, 74 insertions(+), 65 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java index 314e8e5e0..990d92bb1 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java @@ -942,8 +942,8 @@ public interface MongoOperations extends FluentMongoOperations { * Triggers findAndModify * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional * fields specification. Must not be {@literal null}. @@ -961,8 +961,8 @@ public interface MongoOperations extends FluentMongoOperations { * Triggers findAndModify * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional * fields specification. Must not be {@literal null}. @@ -982,8 +982,8 @@ public interface MongoOperations extends FluentMongoOperations { * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query} taking * {@link FindAndModifyOptions} into account. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional * fields specification. @@ -1005,8 +1005,8 @@ public interface MongoOperations extends FluentMongoOperations { * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query} taking * {@link FindAndModifyOptions} into account. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional * fields specification. Must not be {@literal null}. @@ -1532,8 +1532,8 @@ public interface MongoOperations extends FluentMongoOperations { * Performs an upsert. If no document is found that matches the query, a new document is created and inserted by * combining the query document and the update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. *

* NOTE: {@link Query#getSortObject() sorting} is not supported by {@code db.collection.updateOne}. * Use {@link #findAndModify(Query, UpdateDefinition, FindAndModifyOptions, Class, String)} instead. @@ -1577,8 +1577,8 @@ public interface MongoOperations extends FluentMongoOperations { * Performs an upsert. If no document is found that matches the query, a new document is created and inserted by * combining the query document and the update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be upserted. Must not be * {@literal null}. @@ -1597,8 +1597,8 @@ public interface MongoOperations extends FluentMongoOperations { * Updates the first object that is found in the collection of the entity class that matches the query document with * the provided update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be updated. Must not be * {@literal null}. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java index 84397c377..0e5728e3a 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java @@ -41,6 +41,7 @@ import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.data.mongodb.core.index.ReactiveIndexOperations; import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions; import org.springframework.data.mongodb.core.query.BasicQuery; +import org.springframework.data.mongodb.core.query.Collation; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.NearQuery; import org.springframework.data.mongodb.core.query.Query; @@ -758,11 +759,11 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Triggers findAndModify * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}. *

- *A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - *incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param update the {@link UpdateDefinition} to apply on matching documents. Must not be {@literal null}. * @param entityClass the parametrized type. Must not be {@literal null}. * @return the converted object that was updated before it was updated. @@ -776,11 +777,11 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Triggers findAndModify * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query}. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param update the {@link UpdateDefinition} to apply on matching documents. Must not be {@literal null}. * @param entityClass the parametrized type. Must not be {@literal null}. * @param collectionName the collection to query. Must not be {@literal null}. @@ -796,11 +797,11 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query} taking * {@link FindAndModifyOptions} into account. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. * @param update the {@link UpdateDefinition} to apply on matching documents. * @param options the {@link FindAndModifyOptions} holding additional information. * @param entityClass the parametrized type. @@ -817,11 +818,11 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * to apply provided {@link Update} on documents matching {@link Criteria} of given {@link Query} taking * {@link FindAndModifyOptions} into account. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param update the {@link UpdateDefinition} to apply on matching documents. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @param entityClass the parametrized type. Must not be {@literal null}. @@ -843,8 +844,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Options are defaulted to {@link FindAndReplaceOptions#empty()}.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @return the converted object that was updated or {@link Mono#empty()}, if not found. * @throws org.springframework.data.mapping.MappingException if the collection name cannot be @@ -863,8 +864,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Options are defaulted to {@link FindAndReplaceOptions#empty()}.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param collectionName the collection to query. Must not be {@literal null}. * @return the converted object that was updated or {@link Mono#empty()}, if not found. @@ -881,8 +882,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * taking {@link FindAndReplaceOptions} into account.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @return the converted object that was updated or {@link Mono#empty()}, if not found. Depending on the value of @@ -903,8 +904,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * taking {@link FindAndReplaceOptions} into account.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @return the converted object that was updated or {@link Mono#empty()}, if not found. Depending on the value of @@ -925,8 +926,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * taking {@link FindAndReplaceOptions} into account.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @param entityType the parametrized type. Must not be {@literal null}. @@ -949,8 +950,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * taking {@link FindAndReplaceOptions} into account.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @param entityType the type used for mapping the {@link Query} to domain type fields and deriving the collection @@ -978,8 +979,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * taking {@link FindAndReplaceOptions} into account.
* NOTE: The replacement entity must not hold an {@literal id}. * - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional - * fields specification. Must not be {@literal null}. + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an + * optional fields specification. Must not be {@literal null}. * @param replacement the replacement document. Must not be {@literal null}. * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. * @param entityType the type used for mapping the {@link Query} to domain type fields and deriving the collection @@ -1289,6 +1290,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { *

* A potential {@link org.springframework.data.annotation.Version} the property will be auto incremented. The * operation raises an error in case the document has been modified in between. + * * @param objectToSave the object to store in the collection. Must not be {@literal null}. * @return the inserted objects. */ @@ -1436,8 +1438,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Performs an upsert. If no document is found that matches the query, a new document is created and inserted by * combining the query document and the update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. *

* NOTE: {@link Query#getSortObject() sorting} is not supported by {@code db.collection.updateOne}. * Use {@link #findAndModify(Query, UpdateDefinition, Class)} instead. @@ -1479,8 +1481,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Performs an upsert. If no document is found that matches the query, a new document is created and inserted by * combining the query document and the update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be upserted. Must not be * {@literal null}. @@ -1499,11 +1501,10 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Updates the first object that is found in the collection of the entity class that matches the query document with * the provided update document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. - * - * NOTE: {@link Query#getSortObject() sorting} is not supported by {@code db.collection.updateOne}. - * Use {@link #findAndModify(Query, UpdateDefinition, Class)} instead. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. NOTE: {@link Query#getSortObject() + * sorting} is not supported by {@code db.collection.updateOne}. Use + * {@link #findAndModify(Query, UpdateDefinition, Class)} instead. * * @param query the query document that specifies the criteria used to select a record to be updated. Must not be * {@literal null}. @@ -1544,8 +1545,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Updates the first object that is found in the specified collection that matches the query document criteria with * the provided updated document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be updated. Must not be * {@literal null}. @@ -1564,8 +1565,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Updates all objects that are found in the collection for the entity class that matches the query document criteria * with the provided updated document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be updated. Must not be * {@literal null}. @@ -1604,8 +1605,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Updates all objects that are found in the collection for the entity class that matches the query document criteria * with the provided updated document. *

- * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be auto - * incremented if not explicitly specified in the update. + * A potential {@link org.springframework.data.annotation.Version} property of the {@literal entityClass} will be + * auto-incremented if not explicitly specified in the update. * * @param query the query document that specifies the criteria used to select a record to be updated. Must not be * {@literal null}. @@ -1635,7 +1636,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * Removes the given object from the given collection. * * @param object must not be {@literal null}. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link DeleteResult} which lets you access the results of the previous delete. */ Mono remove(Object object, String collectionName); @@ -1656,7 +1658,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * {@link org.springframework.data.annotation.Version}. * * @param objectToRemove must not be {@literal null}. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link DeleteResult} which lets you access the results of the previous delete. */ Mono remove(Mono objectToRemove, String collectionName); @@ -1679,7 +1682,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * * @param query the query document that specifies the criteria used to remove a record. * @param entityClass class of the pojo to be operated on. Can be {@literal null}. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link DeleteResult} which lets you access the results of the previous delete. */ Mono remove(Query query, @Nullable Class entityClass, String collectionName); @@ -1691,7 +1695,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * information. Use {@link #remove(Query, Class, String)} to get full type specific support. * * @param query the query document that specifies the criteria used to remove a record. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link DeleteResult} which lets you access the results of the previous delete. */ Mono remove(Query query, String collectionName); @@ -1702,7 +1707,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * information. Use {@link #findAllAndRemove(Query, Class, String)} to get full type specific support. * * @param query the query document that specifies the criteria used to find and remove documents. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link Flux} converted objects deleted by this operation. */ Flux findAllAndRemove(Query query, String collectionName); @@ -1725,7 +1731,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations { * * @param query the query document that specifies the criteria used to find and remove documents. * @param entityClass class of the pojo to be operated on. - * @param collectionName name of the collection where the objects will removed, must not be {@literal null} or empty. + * @param collectionName name of the collection where the objects will removed, must not be {@literal null} + * or empty. * @return the {@link Flux} converted objects deleted by this operation. */ Flux findAllAndRemove(Query query, Class entityClass, String collectionName); diff --git a/src/main/asciidoc/reference/mongo-property-converters.adoc b/src/main/asciidoc/reference/mongo-property-converters.adoc index c6d9fde32..64abc2cd0 100644 --- a/src/main/asciidoc/reference/mongo-property-converters.adoc +++ b/src/main/asciidoc/reference/mongo-property-converters.adoc @@ -74,6 +74,8 @@ registrar.registerConverter(Person.class, Person::getSsn()) <1> Register a converter for the field identified by its name. <2> Type safe variant that allows to register a converter and its conversion functions. +This method uses class proxies to determine the property. +Make sure that neither the class nor the accessors are `final` as otherwise this approach doesn't work. ==== WARNING: Dot notation (such as `registerConverter(Person.class, "address.street", …)`) for nagivating across properties into subdocuments is *not* supported when registering converters.