Skip to content

Commit f67af3f

Browse files
committed
Move constructor methods to ClientNamespacedWriteModel
JAVA-5527
1 parent 39386fe commit f67af3f

File tree

14 files changed

+380
-354
lines changed

14 files changed

+380
-354
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.mongodb.annotations.Sealed;
2020

2121
/**
22-
* A model for removing all documents matching a filter.
22+
* A model for deleting all documents matching a filter.
2323
*
2424
* @since 5.3
2525
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.mongodb.annotations.Sealed;
2020

2121
/**
22-
* A model for removing at most one document matching a filter.
22+
* A model for deleting at most one document matching a filter.
2323
*
2424
* @since 5.3
2525
*/
Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
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+
17+
package com.mongodb.client.model.bulk;
18+
19+
import com.mongodb.MongoNamespace;
20+
import com.mongodb.annotations.Sealed;
21+
import com.mongodb.client.model.Aggregates;
22+
import com.mongodb.client.model.Filters;
23+
import com.mongodb.client.model.Updates;
24+
import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteManyModel;
25+
import com.mongodb.internal.client.model.bulk.ConcreteClientDeleteOneModel;
26+
import com.mongodb.internal.client.model.bulk.ConcreteClientInsertOneModel;
27+
import com.mongodb.internal.client.model.bulk.ConcreteClientNamespacedWriteModel;
28+
import com.mongodb.internal.client.model.bulk.ConcreteClientReplaceOneModel;
29+
import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateManyModel;
30+
import com.mongodb.internal.client.model.bulk.ConcreteClientUpdateOneModel;
31+
import org.bson.Document;
32+
import org.bson.conversions.Bson;
33+
34+
import static com.mongodb.assertions.Assertions.notNull;
35+
36+
/**
37+
* A combination of an {@linkplain ClientWriteModel individual write operation} and a {@linkplain MongoNamespace namespace}
38+
* the operation is targeted at.
39+
*
40+
* @since 5.3
41+
*/
42+
@Sealed
43+
public interface ClientNamespacedWriteModel {
44+
/**
45+
* Creates a model for inserting the {@code document} into the {@code namespace}.
46+
*
47+
* @param namespace The namespace.
48+
* @param document The document.
49+
* @return The requested {@link ClientInsertOneModel} model with the {@code namespace}.
50+
* @param <TDocument> The document type, for example {@link Document}.
51+
* @see Filters
52+
*/
53+
static <TDocument> ClientNamespacedWriteModel insertOne(final MongoNamespace namespace, final TDocument document) {
54+
notNull("namespace", namespace);
55+
notNull("document", document);
56+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientInsertOneModel(document));
57+
}
58+
59+
/**
60+
* Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}.
61+
* This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Bson, ClientUpdateOptions)}
62+
* with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}.
63+
*
64+
* @param namespace The namespace.
65+
* @param filter The filter.
66+
* @param update The update.
67+
* @return The requested {@link ClientUpdateOneModel} model with the {@code namespace}.
68+
* @see Filters
69+
* @see Updates
70+
*/
71+
static ClientNamespacedWriteModel updateOne(final MongoNamespace namespace, final Bson filter, final Bson update) {
72+
notNull("namespace", namespace);
73+
notNull("filter", filter);
74+
notNull("update", update);
75+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateOneModel(filter, update, null, null));
76+
}
77+
78+
/**
79+
* Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}.
80+
*
81+
* @param namespace The namespace.
82+
* @param filter The filter.
83+
* @param update The update.
84+
* @param options The options.
85+
* @return The requested {@link ClientUpdateOneModel} model with the {@code namespace}.
86+
* @see Filters
87+
* @see Updates
88+
*/
89+
static ClientNamespacedWriteModel updateOne(
90+
final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateOptions options) {
91+
notNull("namespace", namespace);
92+
notNull("filter", filter);
93+
notNull("update", update);
94+
notNull("options", options);
95+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateOneModel(filter, update, null, options));
96+
}
97+
98+
/**
99+
* Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}.
100+
* This method is functionally equivalent to {@link #updateOne(MongoNamespace, Bson, Iterable, ClientUpdateOptions)}
101+
* with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}.
102+
*
103+
* @param namespace The namespace.
104+
* @param filter The filter.
105+
* @param updatePipeline The update pipeline.
106+
* @return The requested {@link ClientUpdateOneModel} model with the {@code namespace}.
107+
* @see Filters
108+
* @see Aggregates
109+
*/
110+
static ClientNamespacedWriteModel updateOne(final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline) {
111+
notNull("namespace", namespace);
112+
notNull("filter", filter);
113+
notNull("updatePipeline", updatePipeline);
114+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateOneModel(filter, null, updatePipeline, null));
115+
}
116+
117+
/**
118+
* Creates a model for updating at most one document in the {@code namespace} matching the {@code filter}.
119+
*
120+
* @param namespace The namespace.
121+
* @param filter The filter.
122+
* @param updatePipeline The update pipeline.
123+
* @param options The options.
124+
* @return The requested {@link ClientUpdateOneModel} model with the {@code namespace}.
125+
* @see Filters
126+
* @see Aggregates
127+
*/
128+
static ClientNamespacedWriteModel updateOne(
129+
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateOptions options) {
130+
notNull("namespace", namespace);
131+
notNull("filter", filter);
132+
notNull("updatePipeline", updatePipeline);
133+
notNull("options", options);
134+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateOneModel(filter, null, updatePipeline, options));
135+
}
136+
137+
/**
138+
* Creates a model for updating all documents in the {@code namespace} matching the {@code filter}.
139+
* This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Bson, ClientUpdateOptions)}
140+
* with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default}.
141+
*
142+
* @param namespace The namespace.
143+
* @param filter The filter.
144+
* @param update The update.
145+
* @return The requested {@link ClientUpdateManyModel} model with the {@code namespace}.
146+
* @see Filters
147+
* @see Updates
148+
*/
149+
static ClientNamespacedWriteModel updateMany(final MongoNamespace namespace, final Bson filter, final Bson update) {
150+
notNull("namespace", namespace);
151+
notNull("filter", filter);
152+
notNull("update", update);
153+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateManyModel(filter, update, null, null));
154+
}
155+
156+
/**
157+
* Creates a model for updating all documents in the {@code namespace} matching the {@code filter}.
158+
*
159+
* @param namespace The namespace.
160+
* @param filter The filter.
161+
* @param update The update.
162+
* @param options The options.
163+
* @return The requested {@link ClientUpdateManyModel} model with the {@code namespace}.
164+
* @see Filters
165+
* @see Updates
166+
*/
167+
static ClientNamespacedWriteModel updateMany(
168+
final MongoNamespace namespace, final Bson filter, final Bson update, final ClientUpdateOptions options) {
169+
notNull("namespace", namespace);
170+
notNull("filter", filter);
171+
notNull("update", update);
172+
notNull("options", options);
173+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateManyModel(filter, update, null, options));
174+
}
175+
176+
/**
177+
* Creates a model for updating all documents in the {@code namespace} matching the {@code filter}.
178+
* This method is functionally equivalent to {@link #updateMany(MongoNamespace, Bson, Iterable, ClientUpdateOptions)}
179+
* with the {@linkplain ClientUpdateOptions#clientUpdateOptions() default options}.
180+
*
181+
* @param namespace The namespace.
182+
* @param filter The filter.
183+
* @param updatePipeline The update pipeline.
184+
* @return The requested {@link ClientUpdateManyModel} model with the {@code namespace}.
185+
* @see Filters
186+
* @see Aggregates
187+
*/
188+
static ClientNamespacedWriteModel updateMany(final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline) {
189+
notNull("namespace", namespace);
190+
notNull("filter", filter);
191+
notNull("updatePipeline", updatePipeline);
192+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateManyModel(filter, null, updatePipeline, null));
193+
}
194+
195+
/**
196+
* Creates a model for updating all documents in the {@code namespace} matching the {@code filter}.
197+
*
198+
* @param namespace The namespace.
199+
* @param filter The filter.
200+
* @param updatePipeline The update pipeline.
201+
* @param options The options.
202+
* @return The requested {@link ClientUpdateManyModel} model with the {@code namespace}.
203+
* @see Filters
204+
* @see Aggregates
205+
*/
206+
static ClientNamespacedWriteModel updateMany(
207+
final MongoNamespace namespace, final Bson filter, final Iterable<? extends Bson> updatePipeline, final ClientUpdateOptions options) {
208+
notNull("namespace", namespace);
209+
notNull("filter", filter);
210+
notNull("updatePipeline", updatePipeline);
211+
notNull("options", options);
212+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientUpdateManyModel(filter, null, updatePipeline, options));
213+
}
214+
215+
/**
216+
* Creates a model for replacing at most one document in the {@code namespace} matching the {@code filter}.
217+
* This method is functionally equivalent to {@link #replaceOne(MongoNamespace, Bson, Object, ClientReplaceOptions)}
218+
* with the {@linkplain ClientReplaceOptions#clientReplaceOptions() default options}.
219+
*
220+
* @param namespace The namespace.
221+
* @param filter The filter.
222+
* @param replacement The replacement.
223+
* The keys of this document must not start with {@code $}, unless they express a {@linkplain com.mongodb.DBRef database reference}.
224+
* @return The requested {@link ClientReplaceOneModel} model with the {@code namespace}.
225+
* @param <TDocument> The document type, for example {@link Document}.
226+
* @see Filters
227+
*/
228+
static <TDocument> ClientNamespacedWriteModel replaceOne(final MongoNamespace namespace, final Bson filter, final TDocument replacement) {
229+
notNull("namespace", namespace);
230+
notNull("filter", filter);
231+
notNull("replacement", replacement);
232+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientReplaceOneModel(filter, replacement, null));
233+
}
234+
235+
/**
236+
* Creates a model for replacing at most one document in the {@code namespace} matching the {@code filter}.
237+
*
238+
* @param namespace The namespace.
239+
* @param filter The filter.
240+
* @param replacement The replacement.
241+
* The keys of this document must not start with {@code $}, unless they express a {@linkplain com.mongodb.DBRef database reference}.
242+
* @param options The options.
243+
* @return The requested {@link ClientReplaceOneModel} model with the {@code namespace}.
244+
* @param <TDocument> The document type, for example {@link Document}.
245+
* @see Filters
246+
*/
247+
static <TDocument> ClientNamespacedWriteModel replaceOne(
248+
final MongoNamespace namespace, final Bson filter, final TDocument replacement, final ClientReplaceOptions options) {
249+
notNull("namespace", namespace);
250+
notNull("filter", filter);
251+
notNull("replacement", replacement);
252+
notNull("options", options);
253+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientReplaceOneModel(filter, replacement, options));
254+
}
255+
256+
/**
257+
* Creates a model for deleting at most one document from the {@code namespace} matching the {@code filter}.
258+
* This method is functionally equivalent to {@link #deleteOne(MongoNamespace, Bson, ClientDeleteOptions)}
259+
* with the {@linkplain ClientDeleteOptions#clientDeleteOptions() default options}.
260+
*
261+
* @param namespace The namespace.
262+
* @param filter The filter.
263+
* @return The requested {@link ClientDeleteOneModel} model with the {@code namespace}.
264+
* @see Filters
265+
*/
266+
static ClientNamespacedWriteModel deleteOne(final MongoNamespace namespace, final Bson filter) {
267+
notNull("namespace", namespace);
268+
notNull("filter", filter);
269+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientDeleteOneModel(filter, null));
270+
}
271+
272+
/**
273+
* Creates a model for deleting at most one document from the {@code namespace} matching the {@code filter}.
274+
*
275+
* @param namespace The namespace.
276+
* @param filter The filter.
277+
* @param options The options.
278+
* @return The requested {@link ClientDeleteOneModel} model with the {@code namespace}.
279+
* @see Filters
280+
*/
281+
static ClientNamespacedWriteModel deleteOne(final MongoNamespace namespace, final Bson filter, final ClientDeleteOptions options) {
282+
notNull("namespace", namespace);
283+
notNull("filter", filter);
284+
notNull("options", options);
285+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientDeleteOneModel(filter, options));
286+
}
287+
288+
/**
289+
* Creates a model for deleting all documents from the {@code namespace} matching the {@code filter}.
290+
* This method is functionally equivalent to {@link #deleteMany(MongoNamespace, Bson, ClientDeleteOptions)}
291+
* with the {@linkplain ClientDeleteOptions#clientDeleteOptions() default options}.
292+
*
293+
* @param namespace The namespace.
294+
* @param filter The filter.
295+
* @return The requested {@link ClientDeleteManyModel} model with the {@code namespace}.
296+
* @see Filters
297+
*/
298+
static ClientNamespacedWriteModel deleteMany(final MongoNamespace namespace, final Bson filter) {
299+
notNull("namespace", namespace);
300+
notNull("filter", filter);
301+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientDeleteManyModel(filter, null));
302+
}
303+
304+
/**
305+
* Creates a model for deleting all documents from the {@code namespace} matching the {@code filter}.
306+
*
307+
* @param namespace The namespace.
308+
* @param filter The filter.
309+
* @param options The options.
310+
* @return The requested {@link ClientDeleteManyModel} model with the {@code namespace}.
311+
* @see Filters
312+
*/
313+
static ClientNamespacedWriteModel deleteMany(final MongoNamespace namespace, final Bson filter, final ClientDeleteOptions options) {
314+
notNull("namespace", namespace);
315+
notNull("filter", filter);
316+
notNull("options", options);
317+
return new ConcreteClientNamespacedWriteModel(namespace, new ConcreteClientDeleteManyModel(filter, options));
318+
}
319+
}

0 commit comments

Comments
 (0)