Skip to content

Commit 5acf582

Browse files
committed
Let's introduce AbstractClientDeleteOptions, AbstractClientUpdateOptions
This allows for code reuse. mongodb#1593
1 parent 88b7cd2 commit 5acf582

File tree

11 files changed

+298
-370
lines changed

11 files changed

+298
-370
lines changed

driver-core/src/main/com/mongodb/client/model/bulk/ClientDeleteOneOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @since 5.3
2828
*/
2929
@Sealed
30-
public interface ClientDeleteOneOptions extends BaseClientDeleteOptions{
30+
public interface ClientDeleteOneOptions extends BaseClientDeleteOptions {
3131
/**
3232
* Creates the default options.
3333
*

driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientDeleteModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
/**
2121
* This class is not part of the public API and may be removed or changed at any time.
2222
*/
23-
public abstract class AbstractClientDeleteModel<T> implements ClientWriteModel {
23+
public abstract class AbstractClientDeleteModel<O extends AbstractClientDeleteOptions> implements ClientWriteModel {
2424
private final Bson filter;
25-
private final T options;
25+
private final O options;
2626

27-
AbstractClientDeleteModel(final Bson filter, final T options) {
27+
AbstractClientDeleteModel(final Bson filter, final O options) {
2828
this.filter = filter;
2929
this.options = options;
3030
}
@@ -33,7 +33,7 @@ public final Bson getFilter() {
3333
return filter;
3434
}
3535

36-
public final T getOptions() {
36+
public final O getOptions() {
3737
return options;
3838
}
3939

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.mongodb.internal.client.model.bulk;
17+
18+
import com.mongodb.client.model.Collation;
19+
import com.mongodb.client.model.bulk.ClientDeleteManyOptions;
20+
import com.mongodb.client.model.bulk.ClientDeleteOneOptions;
21+
import com.mongodb.lang.Nullable;
22+
import org.bson.conversions.Bson;
23+
24+
import java.util.Optional;
25+
26+
import static java.util.Optional.ofNullable;
27+
28+
/**
29+
* This class is not part of the public API and may be removed or changed at any time.
30+
*/
31+
public abstract class AbstractClientDeleteOptions {
32+
@Nullable
33+
private Collation collation;
34+
@Nullable
35+
private Bson hint;
36+
@Nullable
37+
private String hintString;
38+
39+
AbstractClientDeleteOptions() {
40+
}
41+
42+
public AbstractClientDeleteOptions collation(@Nullable final Collation collation) {
43+
this.collation = collation;
44+
return this;
45+
}
46+
47+
/**
48+
* @see ClientDeleteOneOptions#collation(Collation)
49+
* @see ClientDeleteManyOptions#collation(Collation)
50+
*/
51+
public Optional<Collation> getCollation() {
52+
return ofNullable(collation);
53+
}
54+
55+
public AbstractClientDeleteOptions hint(@Nullable final Bson hint) {
56+
this.hint = hint;
57+
this.hintString = null;
58+
return this;
59+
}
60+
61+
/**
62+
* @see ClientDeleteOneOptions#hint(Bson)
63+
* @see ClientDeleteManyOptions#hint(Bson)
64+
*/
65+
public Optional<Bson> getHint() {
66+
return ofNullable(hint);
67+
}
68+
69+
public AbstractClientDeleteOptions hintString(@Nullable final String hintString) {
70+
this.hintString = hintString;
71+
this.hint = null;
72+
return this;
73+
}
74+
75+
/**
76+
* @see ClientDeleteOneOptions#hintString(String)
77+
* @see ClientDeleteManyOptions#hintString(String)
78+
*/
79+
public Optional<String> getHintString() {
80+
return ofNullable(hintString);
81+
}
82+
83+
abstract String getToStringDescription();
84+
85+
@Override
86+
public String toString() {
87+
return getToStringDescription()
88+
+ "{collation=" + collation
89+
+ ", hint=" + hint
90+
+ ", hintString='" + hintString + '\''
91+
+ '}';
92+
}
93+
}

driver-core/src/main/com/mongodb/internal/client/model/bulk/AbstractClientUpdateModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626
/**
2727
* This class is not part of the public API and may be removed or changed at any time.
2828
*/
29-
public abstract class AbstractClientUpdateModel<T> {
29+
public abstract class AbstractClientUpdateModel<O extends AbstractClientUpdateOptions> {
3030
private final Bson filter;
3131
@Nullable
3232
private final Bson update;
3333
@Nullable
3434
private final Iterable<? extends Bson> updatePipeline;
35-
private final T options;
35+
private final O options;
3636

3737
AbstractClientUpdateModel(
3838
final Bson filter,
3939
@Nullable
4040
final Bson update,
4141
@Nullable final Iterable<? extends Bson> updatePipeline,
42-
final T options) {
42+
final O options) {
4343
this.filter = filter;
4444
assertTrue(update == null ^ updatePipeline == null);
4545
this.update = update;
@@ -59,7 +59,7 @@ public final Optional<Iterable<? extends Bson>> getUpdatePipeline() {
5959
return ofNullable(updatePipeline);
6060
}
6161

62-
public final T getOptions() {
62+
public final O getOptions() {
6363
return options;
6464
}
6565

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.mongodb.internal.client.model.bulk;
17+
18+
import com.mongodb.client.model.Collation;
19+
import com.mongodb.client.model.bulk.ClientUpdateManyOptions;
20+
import com.mongodb.client.model.bulk.ClientUpdateOneOptions;
21+
import com.mongodb.lang.Nullable;
22+
import org.bson.conversions.Bson;
23+
24+
import java.util.Optional;
25+
26+
import static java.util.Optional.ofNullable;
27+
28+
/**
29+
* This class is not part of the public API and may be removed or changed at any time.
30+
*/
31+
public abstract class AbstractClientUpdateOptions {
32+
@Nullable
33+
private Iterable<? extends Bson> arrayFilters;
34+
@Nullable
35+
private Collation collation;
36+
@Nullable
37+
private Bson hint;
38+
@Nullable
39+
private String hintString;
40+
@Nullable
41+
private Boolean upsert;
42+
43+
AbstractClientUpdateOptions() {
44+
}
45+
46+
public AbstractClientUpdateOptions arrayFilters(@Nullable final Iterable<? extends Bson> arrayFilters) {
47+
this.arrayFilters = arrayFilters;
48+
return this;
49+
}
50+
51+
/**
52+
* @see ClientUpdateOneOptions#arrayFilters(Iterable)
53+
* @see ClientUpdateManyOptions#arrayFilters(Iterable)
54+
*/
55+
public Optional<Iterable<? extends Bson>> getArrayFilters() {
56+
return ofNullable(arrayFilters);
57+
}
58+
59+
public AbstractClientUpdateOptions collation(@Nullable final Collation collation) {
60+
this.collation = collation;
61+
return this;
62+
}
63+
64+
/**
65+
* @see ClientUpdateOneOptions#collation(Collation)
66+
* @see ClientUpdateManyOptions#collation(Collation)
67+
*/
68+
public Optional<Collation> getCollation() {
69+
return ofNullable(collation);
70+
}
71+
72+
public AbstractClientUpdateOptions hint(@Nullable final Bson hint) {
73+
this.hint = hint;
74+
this.hintString = null;
75+
return this;
76+
}
77+
78+
/**
79+
* @see ClientUpdateOneOptions#hint(Bson)
80+
* @see ClientUpdateManyOptions#hint(Bson)
81+
*/
82+
public Optional<Bson> getHint() {
83+
return ofNullable(hint);
84+
}
85+
86+
public AbstractClientUpdateOptions hintString(@Nullable final String hintString) {
87+
this.hintString = hintString;
88+
this.hint = null;
89+
return this;
90+
}
91+
92+
/**
93+
* @see ClientUpdateOneOptions#hintString(String)
94+
* @see ClientUpdateManyOptions#hintString(String)
95+
*/
96+
public Optional<String> getHintString() {
97+
return ofNullable(hintString);
98+
}
99+
100+
public AbstractClientUpdateOptions upsert(@Nullable final Boolean upsert) {
101+
this.upsert = upsert;
102+
return this;
103+
}
104+
105+
/**
106+
* @see ClientUpdateOneOptions#upsert(Boolean)
107+
* @see ClientUpdateManyOptions#upsert(Boolean)
108+
*/
109+
public Optional<Boolean> isUpsert() {
110+
return ofNullable(upsert);
111+
}
112+
113+
abstract String getToStringDescription();
114+
115+
@Override
116+
public String toString() {
117+
return getToStringDescription()
118+
+ "{arrayFilters=" + arrayFilters
119+
+ ", collation=" + collation
120+
+ ", hint=" + hint
121+
+ ", hintString='" + hintString + '\''
122+
+ ", upsert=" + upsert
123+
+ '}';
124+
}
125+
}

driver-core/src/main/com/mongodb/internal/client/model/bulk/ConcreteClientDeleteManyOptions.java

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,29 @@
2020
import com.mongodb.lang.Nullable;
2121
import org.bson.conversions.Bson;
2222

23-
import java.util.Optional;
24-
25-
import static java.util.Optional.ofNullable;
26-
2723
/**
2824
* This class is not part of the public API and may be removed or changed at any time.
2925
*/
30-
public final class ConcreteClientDeleteManyOptions implements ClientDeleteManyOptions {
26+
public final class ConcreteClientDeleteManyOptions extends AbstractClientDeleteOptions implements ClientDeleteManyOptions {
3127
static final ConcreteClientDeleteManyOptions MUTABLE_EMPTY = new ConcreteClientDeleteManyOptions();
3228

33-
@Nullable
34-
private Collation collation;
35-
@Nullable
36-
private Bson hint;
37-
@Nullable
38-
private String hintString;
39-
4029
public ConcreteClientDeleteManyOptions() {
4130
}
4231

43-
@Override
44-
public ClientDeleteManyOptions collation(@Nullable final Collation collation) {
45-
this.collation = collation;
46-
return this;
47-
}
48-
49-
/**
50-
* @see #collation(Collation)
51-
*/
52-
public Optional<Collation> getCollation() {
53-
return ofNullable(collation);
32+
public ConcreteClientDeleteManyOptions collation(@Nullable final Collation collation) {
33+
return (ConcreteClientDeleteManyOptions) super.collation(collation);
5434
}
5535

56-
@Override
57-
public ClientDeleteManyOptions hint(@Nullable final Bson hint) {
58-
this.hint = hint;
59-
this.hintString = null;
60-
return this;
61-
}
62-
63-
/**
64-
* @see #hint(Bson)
65-
*/
66-
public Optional<Bson> getHint() {
67-
return ofNullable(hint);
68-
}
69-
70-
@Override
71-
public ClientDeleteManyOptions hintString(@Nullable final String hintString) {
72-
this.hintString = hintString;
73-
this.hint = null;
74-
return this;
36+
public ConcreteClientDeleteManyOptions hint(@Nullable final Bson hint) {
37+
return (ConcreteClientDeleteManyOptions) super.hint(hint);
7538
}
7639

77-
/**
78-
* @see #hintString(String)
79-
*/
80-
public Optional<String> getHintString() {
81-
return ofNullable(hintString);
40+
public ConcreteClientDeleteManyOptions hintString(@Nullable final String hintString) {
41+
return (ConcreteClientDeleteManyOptions) super.hintString(hintString);
8242
}
8343

8444
@Override
85-
public String toString() {
86-
return "ClientDeleteManyOptions{"
87-
+ "collation=" + collation
88-
+ ", hint=" + hint
89-
+ ", hintString='" + hintString + '\''
90-
+ '}';
45+
String getToStringDescription() {
46+
return "ConcreteClientDeleteManyOptions";
9147
}
9248
}

0 commit comments

Comments
 (0)