Skip to content

Commit 6b77f78

Browse files
committed
Add ClientWriteModelWithNamespace
JAVA-5527
1 parent 0d518d8 commit 6b77f78

File tree

17 files changed

+191
-229
lines changed

17 files changed

+191
-229
lines changed

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

Lines changed: 64 additions & 129 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
22+
/**
23+
* A combination of an {@linkplain ClientWriteModel individual write operation} and a {@linkplain MongoNamespace namespace}
24+
* the operation is targeted at.
25+
*
26+
* @since 5.3
27+
*/
28+
@Sealed
29+
public interface ClientWriteModelWithNamespace {
30+
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.client.model.bulk.ClientDeleteManyModel;
2019
import com.mongodb.client.model.bulk.ClientDeleteOptions;
2120
import com.mongodb.lang.Nullable;
@@ -25,17 +24,13 @@
2524
* This class is not part of the public API and may be removed or changed at any time.
2625
*/
2726
public final class ConcreteClientDeleteManyModel extends ConcreteClientDeleteOneModel implements ClientDeleteManyModel {
28-
public ConcreteClientDeleteManyModel(
29-
final MongoNamespace namespace,
30-
final Bson filter,
31-
@Nullable final ClientDeleteOptions options) {
32-
super(namespace, filter, options);
27+
public ConcreteClientDeleteManyModel(final Bson filter, @Nullable final ClientDeleteOptions options) {
28+
super(filter, options);
3329
}
3430

3531
@Override
3632
public String toString() {
3733
return "ClientDeleteManyModel{"
38-
+ "namespace=" + getNamespace()
3934
+ ", filter=" + getFilter()
4035
+ ", options=" + getOptions()
4136
+ '}';

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.client.model.bulk.ClientDeleteOneModel;
2019
import com.mongodb.client.model.bulk.ClientDeleteOptions;
2120
import com.mongodb.lang.Nullable;
@@ -25,23 +24,14 @@
2524
* This class is not part of the public API and may be removed or changed at any time.
2625
*/
2726
public class ConcreteClientDeleteOneModel implements ClientDeleteOneModel {
28-
private final MongoNamespace namespace;
2927
private final Bson filter;
3028
private final ConcreteClientDeleteOptions options;
3129

32-
public ConcreteClientDeleteOneModel(
33-
final MongoNamespace namespace,
34-
final Bson filter,
35-
@Nullable final ClientDeleteOptions options) {
36-
this.namespace = namespace;
30+
public ConcreteClientDeleteOneModel(final Bson filter, @Nullable final ClientDeleteOptions options) {
3731
this.filter = filter;
3832
this.options = options == null ? ConcreteClientDeleteOptions.MUTABLE_EMPTY : (ConcreteClientDeleteOptions) options;
3933
}
4034

41-
public MongoNamespace getNamespace() {
42-
return namespace;
43-
}
44-
4535
public Bson getFilter() {
4636
return filter;
4737
}
@@ -53,7 +43,6 @@ public ConcreteClientDeleteOptions getOptions() {
5343
@Override
5444
public String toString() {
5545
return "ClientDeleteOneModel{"
56-
+ "namespace=" + namespace
5746
+ ", filter=" + filter
5847
+ ", options=" + options
5948
+ '}';

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,25 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.client.model.bulk.ClientInsertOneModel;
2019

2120
/**
2221
* This class is not part of the public API and may be removed or changed at any time.
2322
*/
2423
public final class ConcreteClientInsertOneModel implements ClientInsertOneModel {
25-
private final MongoNamespace namespace;
2624
private final Object document;
2725

28-
public ConcreteClientInsertOneModel(
29-
final MongoNamespace namespace,
30-
final Object document) {
31-
this.namespace = namespace;
26+
public ConcreteClientInsertOneModel(final Object document) {
3227
this.document = document;
3328
}
3429

35-
public MongoNamespace getNamespace() {
36-
return namespace;
37-
}
38-
3930
public Object getDocument() {
4031
return document;
4132
}
4233

4334
@Override
4435
public String toString() {
4536
return "ClientInsertOneModel{"
46-
+ "namespace=" + namespace
4737
+ ", document=" + document
4838
+ '}';
4939
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.client.model.bulk.ClientReplaceOneModel;
2019
import com.mongodb.client.model.bulk.ClientReplaceOptions;
2120
import com.mongodb.lang.Nullable;
@@ -25,26 +24,16 @@
2524
* This class is not part of the public API and may be removed or changed at any time.
2625
*/
2726
public final class ConcreteClientReplaceOneModel implements ClientReplaceOneModel {
28-
private final MongoNamespace namespace;
2927
private final Bson filter;
3028
private final Object replacement;
3129
private final ConcreteClientReplaceOptions options;
3230

33-
public ConcreteClientReplaceOneModel(
34-
final MongoNamespace namespace,
35-
final Bson filter,
36-
final Object replacement,
37-
@Nullable final ClientReplaceOptions options) {
38-
this.namespace = namespace;
31+
public ConcreteClientReplaceOneModel(final Bson filter, final Object replacement, @Nullable final ClientReplaceOptions options) {
3932
this.filter = filter;
4033
this.replacement = replacement;
4134
this.options = options == null ? ConcreteClientReplaceOptions.MUTABLE_EMPTY : (ConcreteClientReplaceOptions) options;
4235
}
4336

44-
public MongoNamespace getNamespace() {
45-
return namespace;
46-
}
47-
4837
public Bson getFilter() {
4938
return filter;
5039
}
@@ -60,7 +49,6 @@ public ConcreteClientReplaceOptions getOptions() {
6049
@Override
6150
public String toString() {
6251
return "ClientReplaceOneModel{"
63-
+ "namespace=" + namespace
6452
+ ", filter=" + filter
6553
+ ", replacement=" + replacement
6654
+ ", options=" + options

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.assertions.Assertions;
2019
import com.mongodb.client.model.bulk.ClientUpdateManyModel;
2120
import com.mongodb.client.model.bulk.ClientUpdateOptions;
@@ -27,20 +26,18 @@
2726
*/
2827
public final class ConcreteClientUpdateManyModel extends ConcreteClientUpdateOneModel implements ClientUpdateManyModel {
2928
public ConcreteClientUpdateManyModel(
30-
final MongoNamespace namespace,
3129
final Bson filter,
3230
@Nullable
3331
final Bson update,
3432
@Nullable
3533
final Iterable<? extends Bson> updatePipeline,
3634
@Nullable final ClientUpdateOptions options) {
37-
super(namespace, filter, update, updatePipeline, options);
35+
super(filter, update, updatePipeline, options);
3836
}
3937

4038
@Override
4139
public String toString() {
4240
return "ClientUpdateManyModel{"
43-
+ "namespace=" + getNamespace()
4441
+ ", filter=" + getFilter()
4542
+ ", update=" + getUpdate().map(Object::toString)
4643
.orElse(getUpdatePipeline().map(Object::toString)

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.mongodb.internal.client.model.bulk;
1717

18-
import com.mongodb.MongoNamespace;
1918
import com.mongodb.client.model.bulk.ClientUpdateOneModel;
2019
import com.mongodb.client.model.bulk.ClientUpdateOptions;
2120
import com.mongodb.lang.Nullable;
@@ -30,7 +29,6 @@
3029
* This class is not part of the public API and may be removed or changed at any time.
3130
*/
3231
public class ConcreteClientUpdateOneModel implements ClientUpdateOneModel {
33-
private final MongoNamespace namespace;
3432
private final Bson filter;
3533
@Nullable
3634
private final Bson update;
@@ -39,25 +37,19 @@ public class ConcreteClientUpdateOneModel implements ClientUpdateOneModel {
3937
private final ConcreteClientUpdateOptions options;
4038

4139
public ConcreteClientUpdateOneModel(
42-
final MongoNamespace namespace,
4340
final Bson filter,
4441
@Nullable
4542
final Bson update,
4643
@Nullable
4744
final Iterable<? extends Bson> updatePipeline,
4845
@Nullable final ClientUpdateOptions options) {
49-
this.namespace = namespace;
5046
this.filter = filter;
5147
assertTrue(update == null ^ updatePipeline == null);
5248
this.update = update;
5349
this.updatePipeline = updatePipeline;
5450
this.options = options == null ? ConcreteClientUpdateOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOptions) options;
5551
}
5652

57-
public MongoNamespace getNamespace() {
58-
return namespace;
59-
}
60-
6153
public Bson getFilter() {
6254
return filter;
6355
}
@@ -77,7 +69,6 @@ public ConcreteClientUpdateOptions getOptions() {
7769
@Override
7870
public String toString() {
7971
return "ClientUpdateOneModel{"
80-
+ "namespace=" + namespace
8172
+ ", filter=" + filter
8273
+ ", update=" + (update != null ? update : updatePipeline)
8374
+ ", options=" + options
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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.internal.client.model.bulk;
18+
19+
import com.mongodb.MongoNamespace;
20+
import com.mongodb.client.model.bulk.ClientWriteModel;
21+
import com.mongodb.client.model.bulk.ClientWriteModelWithNamespace;
22+
23+
public final class ConcreteClientWriteModelWithNamespace implements ClientWriteModelWithNamespace {
24+
private final ClientWriteModel model;
25+
private final MongoNamespace namespace;
26+
27+
public ConcreteClientWriteModelWithNamespace(final ClientWriteModel model, final MongoNamespace namespace) {
28+
this.model = model;
29+
this.namespace = namespace;
30+
}
31+
32+
public ClientWriteModel getModel() {
33+
return model;
34+
}
35+
36+
public MongoNamespace getNamespace() {
37+
return namespace;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "ClientWriteModelWithNamespace{"
43+
+ "model=" + model
44+
+ ", namespace=" + namespace
45+
+ '}';
46+
}
47+
}

driver-kotlin-coroutine/src/integration/kotlin/com/mongodb/kotlin/client/coroutine/syncadapter/SyncMongoCluster.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import com.mongodb.client.MongoCluster as JMongoCluster
2626
import com.mongodb.client.MongoDatabase
2727
import com.mongodb.client.MongoIterable
2828
import com.mongodb.client.model.bulk.ClientBulkWriteOptions
29-
import com.mongodb.client.model.bulk.ClientWriteModel
29+
import com.mongodb.client.model.bulk.ClientWriteModelWithNamespace
3030
import com.mongodb.client.result.bulk.ClientBulkWriteResult
3131
import com.mongodb.kotlin.client.coroutine.MongoCluster
3232
import java.util.concurrent.TimeUnit
@@ -114,27 +114,27 @@ internal open class SyncMongoCluster(open val wrapped: MongoCluster) : JMongoClu
114114
): ChangeStreamIterable<T> =
115115
SyncChangeStreamIterable(wrapped.watch(clientSession.unwrapped(), pipeline, resultClass))
116116

117-
override fun bulkWrite(models: MutableList<out ClientWriteModel>): ClientBulkWriteResult {
117+
override fun bulkWrite(models: MutableList<out ClientWriteModelWithNamespace>): ClientBulkWriteResult {
118118
TODO("BULK-TODO implement")
119119
}
120120

121121
override fun bulkWrite(
122-
models: MutableList<out ClientWriteModel>,
122+
models: MutableList<out ClientWriteModelWithNamespace>,
123123
options: ClientBulkWriteOptions
124124
): ClientBulkWriteResult {
125125
TODO("BULK-TODO implement")
126126
}
127127

128128
override fun bulkWrite(
129129
clientSession: ClientSession,
130-
models: MutableList<out ClientWriteModel>
130+
models: MutableList<out ClientWriteModelWithNamespace>
131131
): ClientBulkWriteResult {
132132
TODO("BULK-TODO implement")
133133
}
134134

135135
override fun bulkWrite(
136136
clientSession: ClientSession,
137-
models: MutableList<out ClientWriteModel>,
137+
models: MutableList<out ClientWriteModelWithNamespace>,
138138
options: ClientBulkWriteOptions
139139
): ClientBulkWriteResult {
140140
TODO("BULK-TODO implement")

driver-kotlin-sync/src/integration/kotlin/com/mongodb/kotlin/client/syncadapter/SyncMongoCluster.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import com.mongodb.client.MongoCluster as JMongoCluster
2626
import com.mongodb.client.MongoDatabase
2727
import com.mongodb.client.MongoIterable
2828
import com.mongodb.client.model.bulk.ClientBulkWriteOptions
29-
import com.mongodb.client.model.bulk.ClientWriteModel
29+
import com.mongodb.client.model.bulk.ClientWriteModelWithNamespace
3030
import com.mongodb.client.result.bulk.ClientBulkWriteResult
3131
import com.mongodb.kotlin.client.MongoCluster
3232
import java.util.concurrent.TimeUnit
@@ -113,27 +113,27 @@ internal open class SyncMongoCluster(open val wrapped: MongoCluster) : JMongoClu
113113
): ChangeStreamIterable<T> =
114114
SyncChangeStreamIterable(wrapped.watch(clientSession.unwrapped(), pipeline, resultClass))
115115

116-
override fun bulkWrite(models: MutableList<out ClientWriteModel>): ClientBulkWriteResult {
116+
override fun bulkWrite(models: MutableList<out ClientWriteModelWithNamespace>): ClientBulkWriteResult {
117117
TODO("BULK-TODO implement")
118118
}
119119

120120
override fun bulkWrite(
121-
models: MutableList<out ClientWriteModel>,
121+
models: MutableList<out ClientWriteModelWithNamespace>,
122122
options: ClientBulkWriteOptions
123123
): ClientBulkWriteResult {
124124
TODO("BULK-TODO implement")
125125
}
126126

127127
override fun bulkWrite(
128128
clientSession: ClientSession,
129-
models: MutableList<out ClientWriteModel>
129+
models: MutableList<out ClientWriteModelWithNamespace>
130130
): ClientBulkWriteResult {
131131
TODO("BULK-TODO implement")
132132
}
133133

134134
override fun bulkWrite(
135135
clientSession: ClientSession,
136-
models: MutableList<out ClientWriteModel>,
136+
models: MutableList<out ClientWriteModelWithNamespace>,
137137
options: ClientBulkWriteOptions
138138
): ClientBulkWriteResult {
139139
TODO("BULK-TODO implement")

0 commit comments

Comments
 (0)