diff --git a/build.gradle b/build.gradle index e846ea53d93..df2f70c49de 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,7 @@ ext { junitBomVersion = '5.10.2' logbackVersion = '1.3.14' graalSdkVersion = '24.0.0' + reflectionsVersion = '0.9.10' gitVersion = getGitVersion() } @@ -128,7 +129,7 @@ configure(scalaProjects) { testImplementation('org.scalatestplus:junit-4-13_%%:3.2.9.0') testImplementation('org.scalatestplus:mockito-3-12_%%:3.2.10.0') testImplementation("ch.qos.logback:logback-classic:$logbackVersion") - testImplementation('org.reflections:reflections:0.9.10') + testImplementation("org.reflections:reflections:$reflectionsVersion") } test{ diff --git a/driver-core/build.gradle b/driver-core/build.gradle index 70061ca2b1e..a44f65bbc1b 100644 --- a/driver-core/build.gradle +++ b/driver-core/build.gradle @@ -60,6 +60,7 @@ dependencies { testImplementation project(':bson').sourceSets.test.output testImplementation('org.junit.jupiter:junit-jupiter-api') + testImplementation("org.reflections:reflections:$reflectionsVersion") testRuntimeOnly "io.netty:netty-tcnative-boringssl-static" classifiers.forEach { diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientDeleteOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientDeleteOptions.java new file mode 100644 index 00000000000..025865a7217 --- /dev/null +++ b/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientDeleteOptions.java @@ -0,0 +1,33 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * The methods declared in this interface are part of the public API of subclasses or sub-interfaces. + */ +interface BaseClientDeleteOptions { + + BaseClientDeleteOptions collation(@Nullable Collation collation); + + BaseClientDeleteOptions hint(@Nullable Bson hint); + + BaseClientDeleteOptions hintString(@Nullable String hintString); +} diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientUpdateOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientUpdateOptions.java new file mode 100644 index 00000000000..13ce34ee8bc --- /dev/null +++ b/driver-core/src/main/com/mongodb/client/model/bulk/BaseClientUpdateOptions.java @@ -0,0 +1,36 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * The methods declared in this interface are part of the public API of subclasses or sub-interfaces. + */ +interface BaseClientUpdateOptions { + + BaseClientUpdateOptions arrayFilters(@Nullable Iterable arrayFilters); + + BaseClientUpdateOptions collation(@Nullable Collation collation); + + BaseClientUpdateOptions hint(@Nullable Bson hint); + + BaseClientUpdateOptions hintString(@Nullable String hintString); + + BaseClientUpdateOptions upsert(@Nullable Boolean upsert); +} diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteManyOptions.java similarity index 79% rename from driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOptions.java rename to driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteManyOptions.java index 54b941776e0..f899c5244c3 100644 --- a/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteManyOptions.java @@ -17,7 +17,7 @@ import com.mongodb.annotations.Sealed; import com.mongodb.client.model.Collation; -import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteManyOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -27,14 +27,14 @@ * @since 5.3 */ @Sealed -public interface ClientDeleteOptions { +public interface ClientDeleteManyOptions extends BaseClientDeleteOptions { /** * Creates the default options. * * @return The default options. */ - static ClientDeleteOptions clientDeleteOptions() { - return new ConcreteClientDeleteOptions(); + static ClientDeleteManyOptions clientDeleteManyOptions() { + return new ConcreteClientDeleteManyOptions(); } /** @@ -43,7 +43,8 @@ static ClientDeleteOptions clientDeleteOptions() { * @param collation The collation. {@code null} represents the server default. * @return {@code this}. */ - ClientDeleteOptions collation(@Nullable Collation collation); + @Override + ClientDeleteManyOptions collation(@Nullable Collation collation); /** * Sets the index specification, @@ -52,7 +53,8 @@ static ClientDeleteOptions clientDeleteOptions() { * @param hint The index specification. {@code null} represents the server default. * @return {@code this}. */ - ClientDeleteOptions hint(@Nullable Bson hint); + @Override + ClientDeleteManyOptions hint(@Nullable Bson hint); /** * Sets the index name, @@ -61,5 +63,6 @@ static ClientDeleteOptions clientDeleteOptions() { * @param hintString The index name. {@code null} represents the server default. * @return {@code this}. */ - ClientDeleteOptions hintString(@Nullable String hintString); + @Override + ClientDeleteManyOptions hintString(@Nullable String hintString); } diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOneOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOneOptions.java new file mode 100644 index 00000000000..0c515c7960b --- /dev/null +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOneOptions.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.annotations.Sealed; +import com.mongodb.client.model.Collation; +import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOneOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * The options to apply when deleting a document. + * + * @since 5.3 + */ +@Sealed +public interface ClientDeleteOneOptions extends BaseClientDeleteOptions { + /** + * Creates the default options. + * + * @return The default options. + */ + static ClientDeleteOneOptions clientDeleteOneOptions() { + return new ConcreteClientDeleteOneOptions(); + } + + /** + * Sets the collation. + * + * @param collation The collation. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientDeleteOneOptions collation(@Nullable Collation collation); + + /** + * Sets the index specification, + * {@code null}-ifies {@linkplain #hintString(String) hint string}. + * + * @param hint The index specification. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientDeleteOneOptions hint(@Nullable Bson hint); + + /** + * Sets the index name, + * {@code null}-ifies {@linkplain #hint(Bson) hint}. + * + * @param hintString The index name. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientDeleteOneOptions hintString(@Nullable String hintString); +} diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientNamespacedWriteModel.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientNamespacedWriteModel.java index 5a2e0a672c4..3673c35a9de 100644 --- a/driver-core/src/main/com/mongodb/client/model/bulk/ClientNamespacedWriteModel.java +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientNamespacedWriteModel.java @@ -62,8 +62,8 @@ static ClientNamespacedInsertOneModel insertOne(final MongoNamespace /** * Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Bson, ClientUpdateOptions)} - * with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}. + * This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Bson, ClientUpdateOneOptions)} + * with the {@linkplain ClientUpdateOneOptions#clientUpdateOneOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -91,7 +91,7 @@ static ClientNamespacedUpdateOneModel updateOne(final MongoNamespace namespace, * @see Updates */ static ClientNamespacedUpdateOneModel updateOne( - final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateOptions options) { + final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateOneOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("update", update); @@ -101,8 +101,8 @@ static ClientNamespacedUpdateOneModel updateOne( /** * Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Iterable, ClientUpdateOptions)} - * with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}. + * This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Iterable, ClientUpdateOneOptions)} + * with the {@linkplain ClientUpdateOneOptions#clientUpdateOneOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -131,7 +131,7 @@ static ClientNamespacedUpdateOneModel updateOne( * @see Aggregates */ static ClientNamespacedUpdateOneModel updateOne( - final MongoNamespace namespace, final Bson filter, final Iterable updatePipeline, final ClientUpdateOptions options) { + final MongoNamespace namespace, final Bson filter, final Iterable updatePipeline, final ClientUpdateOneOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("updatePipeline", updatePipeline); @@ -141,8 +141,8 @@ static ClientNamespacedUpdateOneModel updateOne( /** * Creates a model for updating all documents in the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Bson, ClientUpdateOptions)} - * with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default}. + * This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Bson, ClientUpdateManyOptions)} + * with the {@linkplain ClientUpdateManyOptions#clientUpdateManyOptions() default}. * * @param namespace The namespace. * @param filter The filter. @@ -170,7 +170,7 @@ static ClientNamespacedUpdateManyModel updateMany(final MongoNamespace namespace * @see Updates */ static ClientNamespacedUpdateManyModel updateMany( - final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateOptions options) { + final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateManyOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("update", update); @@ -180,8 +180,8 @@ static ClientNamespacedUpdateManyModel updateMany( /** * Creates a model for updating all documents in the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Iterable, ClientUpdateOptions)} - * with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}. + * This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Iterable, ClientUpdateManyOptions)} + * with the {@linkplain ClientUpdateManyOptions#clientUpdateManyOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -210,7 +210,7 @@ static ClientNamespacedUpdateManyModel updateMany( * @see Aggregates */ static ClientNamespacedUpdateManyModel updateMany( - final MongoNamespace namespace, final Bson filter, final Iterable updatePipeline, final ClientUpdateOptions options) { + final MongoNamespace namespace, final Bson filter, final Iterable updatePipeline, final ClientUpdateManyOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("updatePipeline", updatePipeline); @@ -220,8 +220,8 @@ static ClientNamespacedUpdateManyModel updateMany( /** * Creates a model for replacing at most one document in the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #replaceOne(MongoNamespace, Bson, Object, ClientReplaceOptions)} - * with the {@linkplain ClientReplaceOptions#clientReplaceOptions() default options}. + * This method is functionally equivalent to {@link #replaceOne(MongoNamespace, Bson, Object, ClientReplaceOneOptions)} + * with the {@linkplain ClientReplaceOneOptions#clientReplaceOneOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -251,7 +251,7 @@ static ClientNamespacedReplaceOneModel replaceOne(final MongoNamespa * @see Filters */ static ClientNamespacedReplaceOneModel replaceOne( - final MongoNamespace namespace, final Bson filter, final TDocument replacement, final ClientReplaceOptions options) { + final MongoNamespace namespace, final Bson filter, final TDocument replacement, final ClientReplaceOneOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("replacement", replacement); @@ -261,8 +261,8 @@ static ClientNamespacedReplaceOneModel replaceOne( /** * Creates a model for deleting at most one document from the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #deleteOne(MongoNamespace, Bson, ClientDeleteOptions)} - * with the {@linkplain ClientDeleteOptions#clientDeleteOptions() default options}. + * This method is functionally equivalent to {@link #deleteOne(MongoNamespace, Bson, ClientDeleteOneOptions)} + * with the {@linkplain ClientDeleteOneOptions#clientDeleteOneOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -284,7 +284,7 @@ static ClientNamespacedDeleteOneModel deleteOne(final MongoNamespace namespace, * @return The requested {@link ClientNamespacedDeleteOneModel}. * @see Filters */ - static ClientNamespacedDeleteOneModel deleteOne(final MongoNamespace namespace, final Bson filter, final ClientDeleteOptions options) { + static ClientNamespacedDeleteOneModel deleteOne(final MongoNamespace namespace, final Bson filter, final ClientDeleteOneOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("options", options); @@ -293,8 +293,8 @@ static ClientNamespacedDeleteOneModel deleteOne(final MongoNamespace namespace, /** * Creates a model for deleting all documents from the {@code namespace} matching the {@code filter}. - * This method is functionally equivalent to {@link #deleteMany(MongoNamespace, Bson, ClientDeleteOptions)} - * with the {@linkplain ClientDeleteOptions#clientDeleteOptions() default options}. + * This method is functionally equivalent to {@link #deleteMany(MongoNamespace, Bson, ClientDeleteManyOptions)} + * with the {@linkplain ClientDeleteManyOptions#clientDeleteManyOptions() default options}. * * @param namespace The namespace. * @param filter The filter. @@ -316,7 +316,7 @@ static ClientNamespacedDeleteManyModel deleteMany(final MongoNamespace namespace * @return The requested {@link ClientNamespacedDeleteManyModel}. * @see Filters */ - static ClientNamespacedDeleteManyModel deleteMany(final MongoNamespace namespace, final Bson filter, final ClientDeleteOptions options) { + static ClientNamespacedDeleteManyModel deleteMany(final MongoNamespace namespace, final Bson filter, final ClientDeleteManyOptions options) { notNull("namespace", namespace); notNull("filter", filter); notNull("options", options); diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOneOptions.java similarity index 79% rename from driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOptions.java rename to driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOneOptions.java index b6ad2c9c048..4aa08ae81e1 100644 --- a/driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientReplaceOneOptions.java @@ -17,24 +17,24 @@ import com.mongodb.annotations.Sealed; import com.mongodb.client.model.Collation; -import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** - * The options to apply when replacing documents. + * The options to apply when replacing a document. * * @since 5.3 */ @Sealed -public interface ClientReplaceOptions { +public interface ClientReplaceOneOptions { /** * Creates the default options. * * @return The default options. */ - static ClientReplaceOptions clientReplaceOptions() { - return new ConcreteClientReplaceOptions(); + static ClientReplaceOneOptions clientReplaceOneOptions() { + return new ConcreteClientReplaceOneOptions(); } /** @@ -43,7 +43,7 @@ static ClientReplaceOptions clientReplaceOptions() { * @param collation The collation. {@code null} represents the server default. * @return {@code this}. */ - ClientReplaceOptions collation(@Nullable Collation collation); + ClientReplaceOneOptions collation(@Nullable Collation collation); /** * Sets the index specification, @@ -52,7 +52,7 @@ static ClientReplaceOptions clientReplaceOptions() { * @param hint The index specification. {@code null} represents the server default. * @return {@code this}. */ - ClientReplaceOptions hint(@Nullable Bson hint); + ClientReplaceOneOptions hint(@Nullable Bson hint); /** * Sets the index name, @@ -61,7 +61,7 @@ static ClientReplaceOptions clientReplaceOptions() { * @param hintString The index name. {@code null} represents the server default. * @return {@code this}. */ - ClientReplaceOptions hintString(@Nullable String hintString); + ClientReplaceOneOptions hintString(@Nullable String hintString); /** * Enables or disables creation of a document if no documents match the filter. @@ -69,5 +69,5 @@ static ClientReplaceOptions clientReplaceOptions() { * @param upsert The upsert flag. {@code null} represents the server default. * @return {@code this}. */ - ClientReplaceOptions upsert(@Nullable Boolean upsert); + ClientReplaceOneOptions upsert(@Nullable Boolean upsert); } diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateManyOptions.java similarity index 77% rename from driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOptions.java rename to driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateManyOptions.java index 4a74c8846e9..fd0b0d12f08 100644 --- a/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOptions.java +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateManyOptions.java @@ -18,7 +18,7 @@ import com.mongodb.annotations.Sealed; import com.mongodb.client.model.Collation; import com.mongodb.client.model.Filters; -import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateManyOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -28,14 +28,14 @@ * @since 5.3 */ @Sealed -public interface ClientUpdateOptions { +public interface ClientUpdateManyOptions extends BaseClientUpdateOptions { /** * Creates the default options. * * @return The default options. */ - static ClientUpdateOptions clientUpdateOptions() { - return new ConcreteClientUpdateOptions(); + static ClientUpdateManyOptions clientUpdateManyOptions() { + return new ConcreteClientUpdateManyOptions(); } /** @@ -45,7 +45,8 @@ static ClientUpdateOptions clientUpdateOptions() { * @return {@code this}. * @see Filters */ - ClientUpdateOptions arrayFilters(@Nullable Iterable arrayFilters); + @Override + ClientUpdateManyOptions arrayFilters(@Nullable Iterable arrayFilters); /** * Sets the collation. @@ -53,7 +54,8 @@ static ClientUpdateOptions clientUpdateOptions() { * @param collation The collation. {@code null} represents the server default. * @return {@code this}. */ - ClientUpdateOptions collation(@Nullable Collation collation); + @Override + ClientUpdateManyOptions collation(@Nullable Collation collation); /** * Sets the index specification, @@ -62,7 +64,8 @@ static ClientUpdateOptions clientUpdateOptions() { * @param hint The index specification. {@code null} represents the server default. * @return {@code this}. */ - ClientUpdateOptions hint(@Nullable Bson hint); + @Override + ClientUpdateManyOptions hint(@Nullable Bson hint); /** * Sets the index name, @@ -71,7 +74,8 @@ static ClientUpdateOptions clientUpdateOptions() { * @param hintString The index name. {@code null} represents the server default. * @return {@code this}. */ - ClientUpdateOptions hintString(@Nullable String hintString); + @Override + ClientUpdateManyOptions hintString(@Nullable String hintString); /** * Enables or disables creation of a document if no documents match the filter. @@ -79,5 +83,6 @@ static ClientUpdateOptions clientUpdateOptions() { * @param upsert The upsert flag. {@code null} represents the server default. * @return {@code this}. */ - ClientUpdateOptions upsert(@Nullable Boolean upsert); + @Override + ClientUpdateManyOptions upsert(@Nullable Boolean upsert); } diff --git a/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOneOptions.java b/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOneOptions.java new file mode 100644 index 00000000000..a0e85e065e9 --- /dev/null +++ b/driver-core/src/main/com/mongodb/client/model/bulk/ClientUpdateOneOptions.java @@ -0,0 +1,88 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.annotations.Sealed; +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.Filters; +import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOneOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * The options to apply when updating a document. + * + * @since 5.3 + */ +@Sealed +public interface ClientUpdateOneOptions extends BaseClientUpdateOptions{ + /** + * Creates the default options. + * + * @return The default options. + */ + static ClientUpdateOneOptions clientUpdateOneOptions() { + return new ConcreteClientUpdateOneOptions(); + } + + /** + * Sets the filters specifying to which array elements an update should apply. + * + * @param arrayFilters The array filters. {@code null} represents the server default. + * @return {@code this}. + * @see Filters + */ + @Override + ClientUpdateOneOptions arrayFilters(@Nullable Iterable arrayFilters); + + /** + * Sets the collation. + * + * @param collation The collation. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientUpdateOneOptions collation(@Nullable Collation collation); + + /** + * Sets the index specification, + * {@code null}-ifies {@linkplain #hintString(String) hint string}. + * + * @param hint The index specification. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientUpdateOneOptions hint(@Nullable Bson hint); + + /** + * Sets the index name, + * {@code null}-ifies {@linkplain #hint(Bson) hint}. + * + * @param hintString The index name. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientUpdateOneOptions hintString(@Nullable String hintString); + + /** + * Enables or disables creation of a document if no documents match the filter. + * + * @param upsert The upsert flag. {@code null} represents the server default. + * @return {@code this}. + */ + @Override + ClientUpdateOneOptions upsert(@Nullable Boolean upsert); +} diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteModel.java index 3d3829661cf..f7cc0dd4e66 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteModel.java @@ -15,37 +15,25 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientDeleteOptions; -import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** * This class is not part of the public API and may be removed or changed at any time. */ -public abstract class AbstractClientDeleteModel implements ClientWriteModel { +public abstract class AbstractClientDeleteModel implements ClientWriteModel { private final Bson filter; - private final ConcreteClientDeleteOptions options; + private final O options; - AbstractClientDeleteModel(final Bson filter, @Nullable final ClientDeleteOptions options) { + AbstractClientDeleteModel(final Bson filter, final O options) { this.filter = filter; - this.options = options == null ? ConcreteClientDeleteOptions.MUTABLE_EMPTY : (ConcreteClientDeleteOptions) options; + this.options = options; } public final Bson getFilter() { return filter; } - public final ConcreteClientDeleteOptions getOptions() { + public final O getOptions() { return options; } - - abstract String getToStringDescription(); - - @Override - public final String toString() { - return getToStringDescription() - + "{filter=" + filter - + ", options=" + options - + '}'; - } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteOptions.java similarity index 64% rename from driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOptions.java rename to driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteOptions.java index 1acef43052b..fdacf540073 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOptions.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteOptions.java @@ -16,7 +16,8 @@ package com.mongodb.internal.client.model.bulk; import com.mongodb.client.model.Collation; -import com.mongodb.client.model.bulk.ClientDeleteOptions; +import com.mongodb.client.model.bulk.ClientDeleteManyOptions; +import com.mongodb.client.model.bulk.ClientDeleteOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -27,9 +28,7 @@ /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientDeleteOptions implements ClientDeleteOptions { - static final ConcreteClientDeleteOptions MUTABLE_EMPTY = new ConcreteClientDeleteOptions(); - +public abstract class AbstractClientDeleteOptions { @Nullable private Collation collation; @Nullable @@ -37,56 +36,47 @@ public final class ConcreteClientDeleteOptions implements ClientDeleteOptions { @Nullable private String hintString; - public ConcreteClientDeleteOptions() { + AbstractClientDeleteOptions() { } - @Override - public ClientDeleteOptions collation(@Nullable final Collation collation) { + public AbstractClientDeleteOptions collation(@Nullable final Collation collation) { this.collation = collation; return this; } /** - * @see #collation(Collation) + * @see ClientDeleteOneOptions#collation(Collation) + * @see ClientDeleteManyOptions#collation(Collation) */ public Optional getCollation() { return ofNullable(collation); } - @Override - public ClientDeleteOptions hint(@Nullable final Bson hint) { + public AbstractClientDeleteOptions hint(@Nullable final Bson hint) { this.hint = hint; this.hintString = null; return this; } /** - * @see #hint(Bson) + * @see ClientDeleteOneOptions#hint(Bson) + * @see ClientDeleteManyOptions#hint(Bson) */ public Optional getHint() { return ofNullable(hint); } - @Override - public ClientDeleteOptions hintString(@Nullable final String hintString) { + public AbstractClientDeleteOptions hintString(@Nullable final String hintString) { this.hintString = hintString; this.hint = null; return this; } /** - * @see #hintString(String) + * @see ClientDeleteOneOptions#hintString(String) + * @see ClientDeleteManyOptions#hintString(String) */ public Optional getHintString() { return ofNullable(hintString); } - - @Override - public String toString() { - return "ClientDeleteOptions{" - + "collation=" + collation - + ", hint=" + hint - + ", hintString='" + hintString + '\'' - + '}'; - } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateModel.java index 2c8cadf3d88..38ff85ae7b2 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateModel.java @@ -15,7 +15,6 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientUpdateOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -27,26 +26,25 @@ /** * This class is not part of the public API and may be removed or changed at any time. */ -public abstract class AbstractClientUpdateModel { +public abstract class AbstractClientUpdateModel { private final Bson filter; @Nullable private final Bson update; @Nullable private final Iterable updatePipeline; - private final ConcreteClientUpdateOptions options; + private final O options; AbstractClientUpdateModel( final Bson filter, @Nullable final Bson update, - @Nullable - final Iterable updatePipeline, - @Nullable final ClientUpdateOptions options) { + @Nullable final Iterable updatePipeline, + final O options) { this.filter = filter; assertTrue(update == null ^ updatePipeline == null); this.update = update; this.updatePipeline = updatePipeline; - this.options = options == null ? ConcreteClientUpdateOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOptions) options; + this.options = options; } public final Bson getFilter() { @@ -61,18 +59,7 @@ public final Optional> getUpdatePipeline() { return ofNullable(updatePipeline); } - public final ConcreteClientUpdateOptions getOptions() { + public final O getOptions() { return options; } - - abstract String getToStringDescription(); - - @Override - public final String toString() { - return getToStringDescription() - + "{filter=" + filter - + ", update=" + (update != null ? update : updatePipeline) - + ", options=" + options - + '}'; - } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateOptions.java similarity index 62% rename from driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOptions.java rename to driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateOptions.java index cdb0d08839b..508330bd8b7 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOptions.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateOptions.java @@ -16,7 +16,8 @@ package com.mongodb.internal.client.model.bulk; import com.mongodb.client.model.Collation; -import com.mongodb.client.model.bulk.ClientUpdateOptions; +import com.mongodb.client.model.bulk.ClientUpdateManyOptions; +import com.mongodb.client.model.bulk.ClientUpdateOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -27,9 +28,7 @@ /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientUpdateOptions implements ClientUpdateOptions { - static final ConcreteClientUpdateOptions MUTABLE_EMPTY = new ConcreteClientUpdateOptions(); - +public abstract class AbstractClientUpdateOptions { @Nullable private Iterable arrayFilters; @Nullable @@ -41,84 +40,73 @@ public final class ConcreteClientUpdateOptions implements ClientUpdateOptions { @Nullable private Boolean upsert; - public ConcreteClientUpdateOptions() { + AbstractClientUpdateOptions() { } - @Override - public ClientUpdateOptions arrayFilters(@Nullable final Iterable arrayFilters) { + public AbstractClientUpdateOptions arrayFilters(@Nullable final Iterable arrayFilters) { this.arrayFilters = arrayFilters; return this; } /** - * @see #arrayFilters(Iterable) + * @see ClientUpdateOneOptions#arrayFilters(Iterable) + * @see ClientUpdateManyOptions#arrayFilters(Iterable) */ public Optional> getArrayFilters() { return ofNullable(arrayFilters); } - @Override - public ClientUpdateOptions collation(@Nullable final Collation collation) { + public AbstractClientUpdateOptions collation(@Nullable final Collation collation) { this.collation = collation; return this; } /** - * @see #collation(Collation) + * @see ClientUpdateOneOptions#collation(Collation) + * @see ClientUpdateManyOptions#collation(Collation) */ public Optional getCollation() { return ofNullable(collation); } - @Override - public ClientUpdateOptions hint(@Nullable final Bson hint) { + public AbstractClientUpdateOptions hint(@Nullable final Bson hint) { this.hint = hint; this.hintString = null; return this; } /** - * @see #hint(Bson) + * @see ClientUpdateOneOptions#hint(Bson) + * @see ClientUpdateManyOptions#hint(Bson) */ public Optional getHint() { return ofNullable(hint); } - @Override - public ClientUpdateOptions hintString(@Nullable final String hintString) { + public AbstractClientUpdateOptions hintString(@Nullable final String hintString) { this.hintString = hintString; this.hint = null; return this; } /** - * @see #hintString(String) + * @see ClientUpdateOneOptions#hintString(String) + * @see ClientUpdateManyOptions#hintString(String) */ public Optional getHintString() { return ofNullable(hintString); } - @Override - public ClientUpdateOptions upsert(@Nullable final Boolean upsert) { + public AbstractClientUpdateOptions upsert(@Nullable final Boolean upsert) { this.upsert = upsert; return this; } /** - * @see #isUpsert() + * @see ClientUpdateOneOptions#upsert(Boolean) + * @see ClientUpdateManyOptions#upsert(Boolean) */ public Optional isUpsert() { return ofNullable(upsert); } - - @Override - public String toString() { - return "ClientUpdateOptions{" - + "arrayFilters=" + arrayFilters - + ", collation=" + collation - + ", hint=" + hint - + ", hintString='" + hintString + '\'' - + ", upsert=" + upsert - + '}'; - } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyModel.java index 7603c5a7df0..7db1a47d053 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyModel.java @@ -15,20 +15,23 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientDeleteOptions; +import com.mongodb.client.model.bulk.ClientDeleteManyOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientDeleteManyModel extends AbstractClientDeleteModel implements ClientWriteModel { - public ConcreteClientDeleteManyModel(final Bson filter, @Nullable final ClientDeleteOptions options) { - super(filter, options); +public final class ConcreteClientDeleteManyModel extends AbstractClientDeleteModel implements ClientWriteModel { + public ConcreteClientDeleteManyModel(final Bson filter, @Nullable final ClientDeleteManyOptions options) { + super(filter, options == null ? ConcreteClientDeleteManyOptions.MUTABLE_EMPTY : (ConcreteClientDeleteManyOptions) options); } @Override - String getToStringDescription() { - return "ClientDeleteManyModel"; + public String toString() { + return "ClientDeleteManyModel{" + + "filter=" + getFilter() + + ", options=" + getOptions() + + '}'; } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyOptions.java new file mode 100644 index 00000000000..381cd84fa50 --- /dev/null +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyOptions.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.internal.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.bulk.ClientDeleteManyOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * This class is not part of the public API and may be removed or changed at any time. + */ +public final class ConcreteClientDeleteManyOptions extends AbstractClientDeleteOptions implements ClientDeleteManyOptions { + static final ConcreteClientDeleteManyOptions MUTABLE_EMPTY = new ConcreteClientDeleteManyOptions(); + + public ConcreteClientDeleteManyOptions() { + } + + @Override + public ConcreteClientDeleteManyOptions collation(@Nullable final Collation collation) { + return (ConcreteClientDeleteManyOptions) super.collation(collation); + } + + @Override + public ConcreteClientDeleteManyOptions hint(@Nullable final Bson hint) { + return (ConcreteClientDeleteManyOptions) super.hint(hint); + } + + @Override + public ConcreteClientDeleteManyOptions hintString(@Nullable final String hintString) { + return (ConcreteClientDeleteManyOptions) super.hintString(hintString); + } + + @Override + public String toString() { + return "ClientDeleteManyOptions{" + + "collation=" + getCollation().orElse(null) + + ", hint=" + getHint().orElse(null) + + ", hintString=" + getHintString().map(s -> '\'' + s + '\'') .orElse(null) + + '}'; + } +} diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneModel.java index 708f0d3e2ff..9e969ba9eeb 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneModel.java @@ -15,20 +15,23 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientDeleteOptions; +import com.mongodb.client.model.bulk.ClientDeleteOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientDeleteOneModel extends AbstractClientDeleteModel implements ClientWriteModel { - public ConcreteClientDeleteOneModel(final Bson filter, @Nullable final ClientDeleteOptions options) { - super(filter, options); +public final class ConcreteClientDeleteOneModel extends AbstractClientDeleteModel implements ClientWriteModel { + public ConcreteClientDeleteOneModel(final Bson filter, @Nullable final ClientDeleteOneOptions options) { + super(filter, options == null ? ConcreteClientDeleteOneOptions.MUTABLE_EMPTY : (ConcreteClientDeleteOneOptions) options); } @Override - String getToStringDescription() { - return "ClientDeleteOneModel"; + public String toString() { + return "ClientDeleteOneModel{" + + "filter=" + getFilter() + + ", options=" + getOptions() + + '}'; } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneOptions.java new file mode 100644 index 00000000000..3126903cfc5 --- /dev/null +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteOneOptions.java @@ -0,0 +1,55 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.internal.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.bulk.ClientDeleteOneOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * This class is not part of the public API and may be removed or changed at any time. + */ +public final class ConcreteClientDeleteOneOptions extends AbstractClientDeleteOptions implements ClientDeleteOneOptions { + static final ConcreteClientDeleteOneOptions MUTABLE_EMPTY = new ConcreteClientDeleteOneOptions(); + + public ConcreteClientDeleteOneOptions() { + } + + @Override + public ConcreteClientDeleteOneOptions collation(@Nullable final Collation collation) { + return (ConcreteClientDeleteOneOptions) super.collation(collation); + } + + @Override + public ConcreteClientDeleteOneOptions hint(@Nullable final Bson hint) { + return (ConcreteClientDeleteOneOptions) super.hint(hint); + } + + @Override + public ConcreteClientDeleteOneOptions hintString(@Nullable final String hintString) { + return (ConcreteClientDeleteOneOptions) super.hintString(hintString); + } + + @Override + public String toString() { + return "ClientDeleteOneOptions{" + + "collation=" + getCollation().orElse(null) + + ", hint=" + getHint().orElse(null) + + ", hintString=" + getHintString().map(s -> '\'' + s + '\'') .orElse(null) + + '}'; + } +} diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneModel.java index 3bdf08d424a..7102fe6257d 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneModel.java @@ -15,7 +15,7 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientReplaceOptions; +import com.mongodb.client.model.bulk.ClientReplaceOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -25,12 +25,12 @@ public final class ConcreteClientReplaceOneModel implements ClientWriteModel { private final Bson filter; private final Object replacement; - private final ConcreteClientReplaceOptions options; + private final ConcreteClientReplaceOneOptions options; - public ConcreteClientReplaceOneModel(final Bson filter, final Object replacement, @Nullable final ClientReplaceOptions options) { + public ConcreteClientReplaceOneModel(final Bson filter, final Object replacement, @Nullable final ClientReplaceOneOptions options) { this.filter = filter; this.replacement = replacement; - this.options = options == null ? ConcreteClientReplaceOptions.MUTABLE_EMPTY : (ConcreteClientReplaceOptions) options; + this.options = options == null ? ConcreteClientReplaceOneOptions.MUTABLE_EMPTY : (ConcreteClientReplaceOneOptions) options; } public Bson getFilter() { @@ -41,7 +41,7 @@ public Object getReplacement() { return replacement; } - public ConcreteClientReplaceOptions getOptions() { + public ConcreteClientReplaceOneOptions getOptions() { return options; } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneOptions.java similarity index 77% rename from driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOptions.java rename to driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneOptions.java index 703e6b48df0..18e9d060763 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOptions.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientReplaceOneOptions.java @@ -16,7 +16,7 @@ package com.mongodb.internal.client.model.bulk; import com.mongodb.client.model.Collation; -import com.mongodb.client.model.bulk.ClientReplaceOptions; +import com.mongodb.client.model.bulk.ClientReplaceOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; @@ -27,8 +27,8 @@ /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientReplaceOptions implements ClientReplaceOptions { - static final ConcreteClientReplaceOptions MUTABLE_EMPTY = new ConcreteClientReplaceOptions(); +public final class ConcreteClientReplaceOneOptions implements ClientReplaceOneOptions { + static final ConcreteClientReplaceOneOptions MUTABLE_EMPTY = new ConcreteClientReplaceOneOptions(); @Nullable private Collation collation; @@ -39,11 +39,11 @@ public final class ConcreteClientReplaceOptions implements ClientReplaceOptions @Nullable private Boolean upsert; - public ConcreteClientReplaceOptions() { + public ConcreteClientReplaceOneOptions() { } @Override - public ClientReplaceOptions collation(@Nullable final Collation collation) { + public ClientReplaceOneOptions collation(@Nullable final Collation collation) { this.collation = collation; return this; } @@ -56,7 +56,7 @@ public Optional getCollation() { } @Override - public ClientReplaceOptions hint(@Nullable final Bson hint) { + public ClientReplaceOneOptions hint(@Nullable final Bson hint) { this.hint = hint; this.hintString = null; return this; @@ -70,7 +70,7 @@ public Optional getHint() { } @Override - public ClientReplaceOptions hintString(@Nullable final String hintString) { + public ClientReplaceOneOptions hintString(@Nullable final String hintString) { this.hintString = hintString; this.hint = null; return this; @@ -84,7 +84,7 @@ public Optional getHintString() { } @Override - public ClientReplaceOptions upsert(@Nullable final Boolean upsert) { + public ClientReplaceOneOptions upsert(@Nullable final Boolean upsert) { this.upsert = upsert; return this; } @@ -98,7 +98,7 @@ public Optional isUpsert() { @Override public String toString() { - return "ClientReplaceOptions{" + return "ClientReplaceOneOptions{" + "collation=" + collation + ", hint=" + hint + ", hintString='" + hintString + '\'' diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyModel.java index a7a0b1ac900..83d72e937f6 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyModel.java @@ -15,26 +15,33 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientUpdateOptions; +import com.mongodb.assertions.Assertions; +import com.mongodb.client.model.bulk.ClientUpdateManyOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientUpdateManyModel extends AbstractClientUpdateModel implements ClientWriteModel { +public final class ConcreteClientUpdateManyModel extends AbstractClientUpdateModel implements ClientWriteModel { public ConcreteClientUpdateManyModel( final Bson filter, @Nullable final Bson update, @Nullable final Iterable updatePipeline, - @Nullable final ClientUpdateOptions options) { - super(filter, update, updatePipeline, options); + @Nullable final ClientUpdateManyOptions options) { + super(filter, update, updatePipeline, + options == null ? ConcreteClientUpdateManyOptions.MUTABLE_EMPTY : (ConcreteClientUpdateManyOptions) options); } @Override - String getToStringDescription() { - return "ClientUpdateManyModel"; + public String toString() { + return "ClientUpdateManyModel{" + + "filter=" + getFilter() + + ", update=" + getUpdate().map(Object::toString).orElseGet(() -> + getUpdatePipeline().map(Object::toString).orElseThrow(Assertions::fail)) + + ", options=" + getOptions() + + '}'; } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyOptions.java new file mode 100644 index 00000000000..755b6fb56d7 --- /dev/null +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateManyOptions.java @@ -0,0 +1,67 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.internal.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.bulk.ClientUpdateManyOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * This class is not part of the public API and may be removed or changed at any time. + */ +public final class ConcreteClientUpdateManyOptions extends AbstractClientUpdateOptions implements ClientUpdateManyOptions { + static final ConcreteClientUpdateManyOptions MUTABLE_EMPTY = new ConcreteClientUpdateManyOptions(); + + public ConcreteClientUpdateManyOptions() { + } + + @Override + public ConcreteClientUpdateManyOptions arrayFilters(@Nullable final Iterable arrayFilters) { + return (ConcreteClientUpdateManyOptions) super.arrayFilters(arrayFilters); + } + + @Override + public ConcreteClientUpdateManyOptions collation(@Nullable final Collation collation) { + return (ConcreteClientUpdateManyOptions) super.collation(collation); + } + + @Override + public ConcreteClientUpdateManyOptions hint(@Nullable final Bson hint) { + return (ConcreteClientUpdateManyOptions) super.hint(hint); + } + + @Override + public ConcreteClientUpdateManyOptions hintString(@Nullable final String hintString) { + return (ConcreteClientUpdateManyOptions) super.hintString(hintString); + } + + @Override + public ConcreteClientUpdateManyOptions upsert(@Nullable final Boolean upsert) { + return (ConcreteClientUpdateManyOptions) super.upsert(upsert); + } + + @Override + public String toString() { + return "ClientUpdateManyOptions{" + + "arrayFilters=" + getArrayFilters().orElse(null) + + ", collation=" + getCollation().orElse(null) + + ", hint=" + getHint().orElse(null) + + ", hintString=" + getHintString().map(s -> '\'' + s + '\'') .orElse(null) + + ", upsert=" + isUpsert().orElse(null) + + '}'; + } +} diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneModel.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneModel.java index aa922a803c6..83d02669514 100644 --- a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneModel.java +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneModel.java @@ -15,26 +15,33 @@ */ package com.mongodb.internal.client.model.bulk; -import com.mongodb.client.model.bulk.ClientUpdateOptions; +import com.mongodb.assertions.Assertions; +import com.mongodb.client.model.bulk.ClientUpdateOneOptions; import com.mongodb.lang.Nullable; import org.bson.conversions.Bson; /** * This class is not part of the public API and may be removed or changed at any time. */ -public final class ConcreteClientUpdateOneModel extends AbstractClientUpdateModel implements ClientWriteModel { +public final class ConcreteClientUpdateOneModel extends AbstractClientUpdateModel implements ClientWriteModel { public ConcreteClientUpdateOneModel( final Bson filter, @Nullable final Bson update, @Nullable final Iterable updatePipeline, - @Nullable final ClientUpdateOptions options) { - super(filter, update, updatePipeline, options); + @Nullable final ClientUpdateOneOptions options) { + super(filter, update, updatePipeline, + options == null ? ConcreteClientUpdateOneOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOneOptions) options); } @Override - String getToStringDescription() { - return "ClientUpdateOneModel"; + public String toString() { + return "ClientUpdateOneModel{" + + "filter=" + getFilter() + + ", update=" + getUpdate().map(Object::toString).orElseGet(() -> + getUpdatePipeline().map(Object::toString).orElseThrow(Assertions::fail)) + + ", options=" + getOptions() + + '}'; } } diff --git a/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneOptions.java b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneOptions.java new file mode 100644 index 00000000000..fdf960ed1df --- /dev/null +++ b/driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientUpdateOneOptions.java @@ -0,0 +1,67 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.internal.client.model.bulk; + +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.bulk.ClientUpdateOneOptions; +import com.mongodb.lang.Nullable; +import org.bson.conversions.Bson; + +/** + * This class is not part of the public API and may be removed or changed at any time. + */ +public final class ConcreteClientUpdateOneOptions extends AbstractClientUpdateOptions implements ClientUpdateOneOptions { + static final ConcreteClientUpdateOneOptions MUTABLE_EMPTY = new ConcreteClientUpdateOneOptions(); + + public ConcreteClientUpdateOneOptions() { + } + + @Override + public ConcreteClientUpdateOneOptions arrayFilters(@Nullable final Iterable arrayFilters) { + return (ConcreteClientUpdateOneOptions) super.arrayFilters(arrayFilters); + } + + @Override + public ConcreteClientUpdateOneOptions collation(@Nullable final Collation collation) { + return (ConcreteClientUpdateOneOptions) super.collation(collation); + } + + @Override + public ConcreteClientUpdateOneOptions hint(@Nullable final Bson hint) { + return (ConcreteClientUpdateOneOptions) super.hint(hint); + } + + @Override + public ConcreteClientUpdateOneOptions hintString(@Nullable final String hintString) { + return (ConcreteClientUpdateOneOptions) super.hintString(hintString); + } + + @Override + public ConcreteClientUpdateOneOptions upsert(@Nullable final Boolean upsert) { + return (ConcreteClientUpdateOneOptions) super.upsert(upsert); + } + + @Override + public String toString() { + return "ClientUpdateOneOptions{" + + "arrayFilters=" + getArrayFilters().orElse(null) + + ", collation=" + getCollation().orElse(null) + + ", hint=" + getHint().orElse(null) + + ", hintString=" + getHintString().map(s -> '\'' + s + '\'') .orElse(null) + + ", upsert=" + isUpsert().orElse(null) + + '}'; + } +} diff --git a/driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java b/driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java index 6592fcbaed3..ccd7f272e95 100644 --- a/driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java +++ b/driver-core/src/main/com/mongodb/internal/operation/ClientBulkWriteOperation.java @@ -52,15 +52,16 @@ import com.mongodb.internal.binding.ConnectionSource; import com.mongodb.internal.binding.WriteBinding; import com.mongodb.internal.client.model.bulk.AbstractClientDeleteModel; +import com.mongodb.internal.client.model.bulk.AbstractClientDeleteOptions; import com.mongodb.internal.client.model.bulk.AbstractClientNamespacedWriteModel; import com.mongodb.internal.client.model.bulk.AbstractClientUpdateModel; +import com.mongodb.internal.client.model.bulk.AbstractClientUpdateOptions; import com.mongodb.internal.client.model.bulk.AcknowledgedSummaryClientBulkWriteResult; import com.mongodb.internal.client.model.bulk.AcknowledgedVerboseClientBulkWriteResult; import com.mongodb.internal.client.model.bulk.ClientWriteModel; import com.mongodb.internal.client.model.bulk.ConcreteClientBulkWriteOptions; import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteManyModel; import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOneModel; -import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOptions; import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteResult; import com.mongodb.internal.client.model.bulk.ConcreteClientInsertOneModel; import com.mongodb.internal.client.model.bulk.ConcreteClientInsertOneResult; @@ -71,10 +72,9 @@ import com.mongodb.internal.client.model.bulk.ConcreteClientNamespacedUpdateManyModel; import com.mongodb.internal.client.model.bulk.ConcreteClientNamespacedUpdateOneModel; import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOneModel; -import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOneOptions; import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateManyModel; import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOneModel; -import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOptions; import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateResult; import com.mongodb.internal.client.model.bulk.UnacknowledgedClientBulkWriteResult; import com.mongodb.internal.connection.AsyncConnection; @@ -1247,7 +1247,7 @@ private void encodeWriteModelInternals( }); } - private void encodeWriteModelInternals(final BsonWriter writer, final AbstractClientUpdateModel model) { + private void encodeWriteModelInternals(final BsonWriter writer, final AbstractClientUpdateModel model) { writer.writeName("filter"); encodeUsingRegistry(writer, model.getFilter()); model.getUpdate().ifPresent(value -> { @@ -1259,7 +1259,7 @@ private void encodeWriteModelInternals(final BsonWriter writer, final AbstractCl value.forEach(pipelineStage -> encodeUsingRegistry(writer, pipelineStage)); writer.writeEndArray(); }); - ConcreteClientUpdateOptions options = model.getOptions(); + AbstractClientUpdateOptions options = model.getOptions(); options.getArrayFilters().ifPresent(value -> { writer.writeStartArray("arrayFilters"); value.forEach(filter -> encodeUsingRegistry(writer, filter)); @@ -1283,7 +1283,7 @@ private void encodeWriteModelInternals(final BsonBinaryWriter writer, final Conc encodeUsingRegistry(writer, model.getFilter()); writer.writeName("updateMods"); encodeUsingRegistry(writer, model.getReplacement(), COLLECTIBLE_DOCUMENT_ENCODER_CONTEXT); - ConcreteClientReplaceOptions options = model.getOptions(); + ConcreteClientReplaceOneOptions options = model.getOptions(); options.getCollation().ifPresent(value -> { writer.writeName("collation"); encodeUsingRegistry(writer, value.asDocument()); @@ -1296,10 +1296,10 @@ private void encodeWriteModelInternals(final BsonBinaryWriter writer, final Conc options.isUpsert().ifPresent(value -> writer.writeBoolean("upsert", value)); } - private void encodeWriteModelInternals(final BsonWriter writer, final AbstractClientDeleteModel model) { + private void encodeWriteModelInternals(final BsonWriter writer, final AbstractClientDeleteModel model) { writer.writeName("filter"); encodeUsingRegistry(writer, model.getFilter()); - ConcreteClientDeleteOptions options = model.getOptions(); + AbstractClientDeleteOptions options = model.getOptions(); options.getCollation().ifPresent(value -> { writer.writeName("collation"); encodeUsingRegistry(writer, value.asDocument()); diff --git a/driver-core/src/test/unit/com/mongodb/MongoBaseInterfaceAssertions.java b/driver-core/src/test/unit/com/mongodb/MongoBaseInterfaceAssertions.java new file mode 100644 index 00000000000..93f784b0506 --- /dev/null +++ b/driver-core/src/test/unit/com/mongodb/MongoBaseInterfaceAssertions.java @@ -0,0 +1,69 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb; + +import org.reflections.Reflections; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public final class MongoBaseInterfaceAssertions { + + private MongoBaseInterfaceAssertions() { + //NOP + } + + public static void assertSubtypeReturn(final Class baseClass) { + Reflections reflections = new Reflections("com.mongodb"); + Set> subtypes = reflections.getSubTypesOf(baseClass).stream() + .filter(aClass -> Modifier.isPublic(aClass.getModifiers())) + .filter(aClass -> !aClass.getPackage().getName().contains(".internal")) + .collect(Collectors.toSet()); + + Method[] baseMethods = baseClass.getDeclaredMethods(); + + for (Class subtype : subtypes) { + for (Method baseMethod : baseMethods) { + Method method = assertDoesNotThrow( + () -> subtype.getDeclaredMethod(baseMethod.getName(), baseMethod.getParameterTypes()), + String.format( + "`%s` does not override `%s`. The methods must be copied into the implementing class/interface.", + subtype, + baseMethod + ) + ); + + assertEquals( + subtype, + method.getReturnType(), + String.format( + "Method `%s` in `%s` does not return `%s`. " + + "The return type must match the defining class/interface.", + method, + subtype, + subtype + ) + ); + } + } + } +} diff --git a/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientDeleteOptionsTest.java b/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientDeleteOptionsTest.java new file mode 100644 index 00000000000..e9832c24b21 --- /dev/null +++ b/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientDeleteOptionsTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.MongoBaseInterfaceAssertions; +import org.junit.jupiter.api.Test; + +class BaseClientDeleteOptionsTest { + + @Test + void testAllSubInterfacesOverrideMethods() { + MongoBaseInterfaceAssertions.assertSubtypeReturn(BaseClientDeleteOptions.class); + } +} diff --git a/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientUpdateOptionsTest.java b/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientUpdateOptionsTest.java new file mode 100644 index 00000000000..43ba8e0967e --- /dev/null +++ b/driver-core/src/test/unit/com/mongodb/client/model/bulk/BaseClientUpdateOptionsTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2008-present MongoDB, Inc. + * + * 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 + * + * http://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 com.mongodb.client.model.bulk; + +import com.mongodb.MongoBaseInterfaceAssertions; +import org.junit.jupiter.api.Test; + +class BaseClientUpdateOptionsTest { + + @Test + void testAllSubInterfacesOverrideMethods() { + MongoBaseInterfaceAssertions.assertSubtypeReturn(BaseClientUpdateOptions.class); + } +} diff --git a/driver-scala/src/test/scala/org/mongodb/scala/ApiAliasAndCompanionSpec.scala b/driver-scala/src/test/scala/org/mongodb/scala/ApiAliasAndCompanionSpec.scala index a1ee2467f9d..b6d86bf8118 100644 --- a/driver-scala/src/test/scala/org/mongodb/scala/ApiAliasAndCompanionSpec.scala +++ b/driver-scala/src/test/scala/org/mongodb/scala/ApiAliasAndCompanionSpec.scala @@ -90,7 +90,10 @@ class ApiAliasAndCompanionSpec extends BaseSpec { "SyncMongoCluster", "SyncGridFSBucket", "SyncMongoDatabase", - "SyncClientEncryption" + "SyncClientEncryption", + "BaseClientUpdateOptions", + "BaseClientDeleteOptions", + "MongoBaseInterfaceAssertions" ) val scalaExclusions = Set( "BuildInfo", diff --git a/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java b/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java index 101865079e0..7138cdfe67e 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java +++ b/driver-sync/src/test/functional/com/mongodb/client/CrudProseTest.java @@ -72,7 +72,7 @@ import static com.mongodb.client.Fixture.getPrimary; import static com.mongodb.client.model.bulk.ClientBulkWriteOptions.clientBulkWriteOptions; import static com.mongodb.client.model.bulk.ClientNamespacedWriteModel.insertOne; -import static com.mongodb.client.model.bulk.ClientUpdateOptions.clientUpdateOptions; +import static com.mongodb.client.model.bulk.ClientUpdateOneOptions.clientUpdateOneOptions; import static java.lang.String.join; import static java.util.Arrays.asList; import static java.util.Collections.nCopies; @@ -297,12 +297,12 @@ private void assertBulkWriteHandlesCursorRequiringGetMore(final boolean transact NAMESPACE, Filters.eq(join("", nCopies(maxBsonObjectSize / 2, "a"))), Updates.set("x", 1), - clientUpdateOptions().upsert(true)), + clientUpdateOneOptions().upsert(true)), ClientNamespacedWriteModel.updateOne( NAMESPACE, Filters.eq(join("", nCopies(maxBsonObjectSize / 2, "b"))), Updates.set("x", 1), - clientUpdateOptions().upsert(true))), + clientUpdateOneOptions().upsert(true))), clientBulkWriteOptions().verboseResults(true) ); diff --git a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java index 03afe429cbc..811321ad2d1 100644 --- a/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java +++ b/driver-sync/src/test/functional/com/mongodb/client/unified/UnifiedCrudHelper.java @@ -77,10 +77,14 @@ import com.mongodb.client.model.UpdateOptions; import com.mongodb.client.model.WriteModel; import com.mongodb.client.model.bulk.ClientBulkWriteOptions; -import com.mongodb.client.model.bulk.ClientDeleteOptions; -import com.mongodb.client.model.bulk.ClientReplaceOptions; -import com.mongodb.client.model.bulk.ClientUpdateOptions; +import com.mongodb.client.model.bulk.ClientBulkWriteResult; +import com.mongodb.client.model.bulk.ClientDeleteManyOptions; +import com.mongodb.client.model.bulk.ClientDeleteOneOptions; import com.mongodb.client.model.bulk.ClientNamespacedWriteModel; +import com.mongodb.client.model.bulk.ClientReplaceOneOptions; +import com.mongodb.client.model.bulk.ClientUpdateManyOptions; +import com.mongodb.client.model.bulk.ClientUpdateOneOptions; +import com.mongodb.client.model.bulk.ClientUpdateResult; import com.mongodb.client.model.changestream.ChangeStreamDocument; import com.mongodb.client.model.changestream.FullDocument; import com.mongodb.client.model.changestream.FullDocumentBeforeChange; @@ -88,8 +92,12 @@ import com.mongodb.client.result.InsertManyResult; import com.mongodb.client.result.InsertOneResult; import com.mongodb.client.result.UpdateResult; -import com.mongodb.client.model.bulk.ClientBulkWriteResult; -import com.mongodb.client.model.bulk.ClientUpdateResult; +import com.mongodb.internal.client.model.bulk.AbstractClientDeleteOptions; +import com.mongodb.internal.client.model.bulk.AbstractClientUpdateOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteManyOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOneOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateManyOptions; +import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOneOptions; import com.mongodb.lang.NonNull; import com.mongodb.lang.Nullable; import org.bson.BsonArray; @@ -121,9 +129,7 @@ import java.util.function.Supplier; import static com.mongodb.client.model.bulk.ClientBulkWriteOptions.clientBulkWriteOptions; -import static com.mongodb.client.model.bulk.ClientDeleteOptions.clientDeleteOptions; -import static com.mongodb.client.model.bulk.ClientReplaceOptions.clientReplaceOptions; -import static com.mongodb.client.model.bulk.ClientUpdateOptions.clientUpdateOptions; +import static com.mongodb.client.model.bulk.ClientReplaceOneOptions.clientReplaceOneOptions; import static java.lang.String.format; import static java.util.Arrays.asList; import static java.util.Collections.singleton; @@ -1850,48 +1856,48 @@ private static ClientNamespacedWriteModel toClientNamespacedWriteModel(final Bso namespace, arguments.getDocument("filter"), arguments.getDocument("replacement"), - getClientReplaceOptions(arguments)); + getClientReplaceOneOptions(arguments)); case "updateOne": return arguments.isDocument("update") ? ClientNamespacedWriteModel.updateOne( namespace, arguments.getDocument("filter"), arguments.getDocument("update"), - getClientUpdateOptions(arguments)) + getClientUpdateOneOptions(arguments)) : ClientNamespacedWriteModel.updateOne( namespace, arguments.getDocument("filter"), arguments.getArray("update").stream().map(BsonValue::asDocument).collect(toList()), - getClientUpdateOptions(arguments)); + getClientUpdateOneOptions(arguments)); case "updateMany": return arguments.isDocument("update") ? ClientNamespacedWriteModel.updateMany( namespace, arguments.getDocument("filter"), arguments.getDocument("update"), - getClientUpdateOptions(arguments)) + getClientUpdateManyOptions(arguments)) : ClientNamespacedWriteModel.updateMany( namespace, arguments.getDocument("filter"), arguments.getArray("update").stream().map(BsonValue::asDocument).collect(toList()), - getClientUpdateOptions(arguments)); + getClientUpdateManyOptions(arguments)); case "deleteOne": return ClientNamespacedWriteModel.deleteOne( namespace, arguments.getDocument("filter"), - getClientDeleteOptions(arguments)); + getClientDeleteOneOptions(arguments)); case "deleteMany": return ClientNamespacedWriteModel.deleteMany( namespace, arguments.getDocument("filter"), - getClientDeleteOptions(arguments)); + getClientDeleteManyOptions(arguments)); default: throw new UnsupportedOperationException("Unsupported client write model type: " + modelType); } } - private static ClientReplaceOptions getClientReplaceOptions(final BsonDocument arguments) { - ClientReplaceOptions options = clientReplaceOptions(); + private static ClientReplaceOneOptions getClientReplaceOneOptions(final BsonDocument arguments) { + ClientReplaceOneOptions options = clientReplaceOneOptions(); arguments.forEach((key, argument) -> { switch (key) { case "namespace": @@ -1918,8 +1924,17 @@ private static ClientReplaceOptions getClientReplaceOptions(final BsonDocument a return options; } - private static ClientUpdateOptions getClientUpdateOptions(final BsonDocument arguments) { - ClientUpdateOptions options = clientUpdateOptions(); + private static ClientUpdateOneOptions getClientUpdateOneOptions(final BsonDocument arguments) { + return fillAbstractClientUpdateOptions(new ConcreteClientUpdateOneOptions(), arguments); + } + + private static ClientUpdateManyOptions getClientUpdateManyOptions(final BsonDocument arguments) { + return fillAbstractClientUpdateOptions(new ConcreteClientUpdateManyOptions(), arguments); + } + + private static T fillAbstractClientUpdateOptions( + final T options, + final BsonDocument arguments) { arguments.forEach((key, argument) -> { switch (key) { case "namespace": @@ -1949,8 +1964,17 @@ private static ClientUpdateOptions getClientUpdateOptions(final BsonDocument arg return options; } - private static ClientDeleteOptions getClientDeleteOptions(final BsonDocument arguments) { - ClientDeleteOptions options = clientDeleteOptions(); + private static ClientDeleteOneOptions getClientDeleteOneOptions(final BsonDocument arguments) { + return fillAbstractClientDeleteOptions(new ConcreteClientDeleteOneOptions(), arguments); + } + + private static ClientDeleteManyOptions getClientDeleteManyOptions(final BsonDocument arguments) { + return fillAbstractClientDeleteOptions(new ConcreteClientDeleteManyOptions(), arguments); + } + + private static T fillAbstractClientDeleteOptions( + final T options, + final BsonDocument arguments) { arguments.forEach((key, argument) -> { switch (key) { case "namespace":