Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide ClientUpdateOptions and ClientDeleteOptions #1593

Merged
merged 22 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ext {
junitBomVersion = '5.10.2'
logbackVersion = '1.3.14'
graalSdkVersion = '24.0.0'
reflectionsVersion = '0.9.10'
gitVersion = getGitVersion()
}

Expand Down Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions driver-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Comment on lines +28 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]

  1. These three methods seem to be shared by all options, including replace options. It seems trivial to add BaseClientWriteModelOptions that declares them, and is a super-interface for BaseClientDeleteOptions, BaseClientUpdateOptions, ClientReplaceOptions.
  2. upsert is shared by BaseClientUpdateOptions and ClientReplaceOptions. Do you think it makes sense to add something like BaseClientUpsertableWriteModelOptions, such that it's a supertype for BaseClientUpdateOptions and ClientReplaceOptions?

}
Original file line number Diff line number Diff line change
@@ -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<? extends Bson> arrayFilters);

BaseClientUpdateOptions collation(@Nullable Collation collation);

BaseClientUpdateOptions hint(@Nullable Bson hint);

BaseClientUpdateOptions hintString(@Nullable String hintString);

BaseClientUpdateOptions upsert(@Nullable Boolean upsert);
}
stIncMale marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
Expand All @@ -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);
stIncMale marked this conversation as resolved.
Show resolved Hide resolved

/**
* Sets the index specification,
Expand All @@ -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,
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static <TDocument> 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.
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -131,7 +131,7 @@ static ClientNamespacedUpdateOneModel updateOne(
* @see Aggregates
*/
static ClientNamespacedUpdateOneModel updateOne(
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateOptions options) {
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateOneOptions options) {
notNull("namespace", namespace);
notNull("filter", filter);
notNull("updatePipeline", updatePipeline);
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -210,7 +210,7 @@ static ClientNamespacedUpdateManyModel updateMany(
* @see Aggregates
*/
static ClientNamespacedUpdateManyModel updateMany(
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateOptions options) {
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateManyOptions options) {
notNull("namespace", namespace);
notNull("filter", filter);
notNull("updatePipeline", updatePipeline);
Expand All @@ -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.
Expand Down Expand Up @@ -251,7 +251,7 @@ static <TDocument> ClientNamespacedReplaceOneModel replaceOne(final MongoNamespa
* @see Filters
*/
static <TDocument> 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);
Expand All @@ -261,8 +261,8 @@ static <TDocument> 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.
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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);
Expand Down
Loading