Browse Source

Update a bit of java doc

issue/4462
Christoph Strobl 2 years ago
parent
commit
1762491714
No known key found for this signature in database
GPG Key ID: 8CC1AB53391458C8
  1. 44
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java
  2. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
  3. 43
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReplaceOptions.java

44
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java

@ -1754,11 +1754,10 @@ public interface MongoOperations extends FluentMongoOperations { @@ -1754,11 +1754,10 @@ public interface MongoOperations extends FluentMongoOperations {
<T> List<T> findAllAndRemove(Query query, Class<T> entityClass, String collectionName);
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document.
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document.
* <br />
* The collection name is derived from the {@literal replacement} type. <br />
* Options are defaulted to {@link ReplaceOptions#empty()}. <br />
* Options are defaulted to {@link ReplaceOptions#none()}. <br />
* <strong>NOTE:</strong> 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
@ -1767,16 +1766,15 @@ public interface MongoOperations extends FluentMongoOperations { @@ -1767,16 +1766,15 @@ public interface MongoOperations extends FluentMongoOperations {
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
default <T> UpdateResult replace(Query query, T replacement) {
return replace(query, replacement, ReplaceOptions.empty());
return replace(query, replacement, ReplaceOptions.none());
}
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement}
* document.<br />
* Options are defaulted to {@link ReplaceOptions#empty()}. <br />
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document.
* Options are defaulted to {@link ReplaceOptions#none()}. <br />
* <strong>NOTE:</strong> 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
@ -1786,42 +1784,43 @@ public interface MongoOperations extends FluentMongoOperations { @@ -1786,42 +1784,43 @@ public interface MongoOperations extends FluentMongoOperations {
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
default <T> UpdateResult replace(Query query, T replacement, String collectionName) {
return replace(query, replacement, ReplaceOptions.empty(), collectionName);
return replace(query, replacement, ReplaceOptions.none(), collectionName);
}
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document
* taking {@link ReplaceOptions} into account.<br />
* <strong>NOTE:</strong> 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 replacement the replacement document. Must not be {@literal null}.
* @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
* @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}.
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
default <T> UpdateResult replace(Query query, T replacement, ReplaceOptions options) {
return replace(query, replacement, options, getCollectionName(ClassUtils.getUserClass(replacement)));
}
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document
* taking {@link ReplaceOptions} into account.<br />
* <strong>NOTE:</strong> 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 replacement the replacement document. Must not be {@literal null}.
* @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
* @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}.
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
default <T> UpdateResult replace(Query query, T replacement, ReplaceOptions options, String collectionName) {
@ -1830,41 +1829,38 @@ public interface MongoOperations extends FluentMongoOperations { @@ -1830,41 +1829,38 @@ public interface MongoOperations extends FluentMongoOperations {
}
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document
* taking {@link ReplaceOptions} into account.<br />
* <strong>NOTE:</strong> 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 replacement the replacement document. Must not be {@literal null}.
* @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
* @param options the {@link ReplaceOptions} 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
* from. Must not be {@literal null}.
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
default <S> UpdateResult replace(Query query, S replacement, ReplaceOptions options, Class<S> entityType) {
return replace(query, replacement, options, entityType, getCollectionName(ClassUtils.getUserClass(entityType)));
}
/**
* Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to
* replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document
* Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} document
* taking {@link ReplaceOptions} into account.<br />
* <strong>NOTE:</strong> 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 replacement the replacement document. Must not be {@literal null}.
* @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}.
* @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}.
* @param entityType the type used for mapping the {@link Query} to domain type fields. Must not be {@literal null}.
* @param collectionName the collection to query. Must not be {@literal null}.
* @return the {@link UpdateResult} which lets you access the results of the previous replacement.
* @throws org.springframework.data.mapping.MappingException if the collection name cannot be
* {@link #getCollectionName(Class) derived} from the given replacement value.
* @since 4.2
*/
<S> UpdateResult replace(Query query, S replacement, ReplaceOptions options, Class<S> entityType,
String collectionName);

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

@ -3425,9 +3425,10 @@ public class MongoTemplate @@ -3425,9 +3425,10 @@ public class MongoTemplate
@Override
public <S> UpdateResult replace(Query query, S replacement, ReplaceOptions options, Class<S> entityType,
String collectionName) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(replacement, "Replacement must not be null");
Assert.notNull(options, "Options must not be null Use ReplaceOptions#empty() instead");
Assert.notNull(options, "Options must not be null Use ReplaceOptions#none() instead");
Assert.notNull(entityType, "EntityType must not be null");
Assert.notNull(collectionName, "CollectionName must not be null");

43
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReplaceOptions.java

@ -1,18 +1,35 @@ @@ -1,18 +1,35 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core;
import org.springframework.data.mongodb.core.query.Query;
/**
* Options for
* <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a>.
* <br />
* Defaults to
* Options for {@link org.springframework.data.mongodb.core.MongoOperations#replace(Query, Object) replace operations}. Defaults to
* <dl>
* <dt>upsert</dt>
* <dd>false</dd>
* </dl>
*
* @author Jakub Zurawa
* @author Christoph Strob
* @since 4.2
*/
package org.springframework.data.mongodb.core;
public class ReplaceOptions {
private boolean upsert;
private static final ReplaceOptions NONE = new ReplaceOptions() {
@ -42,25 +59,11 @@ public class ReplaceOptions { @@ -42,25 +59,11 @@ public class ReplaceOptions {
* Static factory method returning an unmodifiable {@link ReplaceOptions} instance.
*
* @return unmodifiable {@link ReplaceOptions} instance.
* @since 2.2
*/
public static ReplaceOptions none() {
return NONE;
}
/**
* Static factory method to create a {@link ReplaceOptions} instance with
* <dl>
* <dt>upsert</dt>
* <dd>false</dd>
* </dl>
*
* @return new instance of {@link ReplaceOptions}.
*/
public static ReplaceOptions empty() {
return new ReplaceOptions();
}
/**
* Insert a new document if not exists.
*

Loading…
Cancel
Save