Skip to content

Commit c3224e9

Browse files
committed
Rearrange ClientWriteModel inheritance: "one" should extend "many", not vice versa
JAVA-5527
1 parent 6f01e61 commit c3224e9

File tree

4 files changed

+65
-65
lines changed

4 files changed

+65
-65
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,28 @@
2222
/**
2323
* This class is not part of the public API and may be removed or changed at any time.
2424
*/
25-
public final class ConcreteClientDeleteManyModel extends ConcreteClientDeleteOneModel implements ClientWriteModel {
25+
public class ConcreteClientDeleteManyModel implements ClientWriteModel {
26+
private final Bson filter;
27+
private final ConcreteClientDeleteOptions options;
28+
2629
public ConcreteClientDeleteManyModel(final Bson filter, @Nullable final ClientDeleteOptions options) {
27-
super(filter, options);
30+
this.filter = filter;
31+
this.options = options == null ? ConcreteClientDeleteOptions.MUTABLE_EMPTY : (ConcreteClientDeleteOptions) options;
32+
}
33+
34+
public Bson getFilter() {
35+
return filter;
36+
}
37+
38+
public ConcreteClientDeleteOptions getOptions() {
39+
return options;
2840
}
2941

3042
@Override
3143
public String toString() {
3244
return "ClientDeleteManyModel{"
33-
+ ", filter=" + getFilter()
34-
+ ", options=" + getOptions()
45+
+ ", filter=" + filter
46+
+ ", options=" + options
3547
+ '}';
3648
}
3749
}

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,16 @@
2222
/**
2323
* This class is not part of the public API and may be removed or changed at any time.
2424
*/
25-
public class ConcreteClientDeleteOneModel implements ClientWriteModel {
26-
private final Bson filter;
27-
private final ConcreteClientDeleteOptions options;
28-
25+
public final class ConcreteClientDeleteOneModel extends ConcreteClientDeleteManyModel {
2926
public ConcreteClientDeleteOneModel(final Bson filter, @Nullable final ClientDeleteOptions options) {
30-
this.filter = filter;
31-
this.options = options == null ? ConcreteClientDeleteOptions.MUTABLE_EMPTY : (ConcreteClientDeleteOptions) options;
32-
}
33-
34-
public Bson getFilter() {
35-
return filter;
36-
}
37-
38-
public ConcreteClientDeleteOptions getOptions() {
39-
return options;
27+
super(filter, options);
4028
}
4129

4230
@Override
4331
public String toString() {
4432
return "ClientDeleteOneModel{"
45-
+ ", filter=" + filter
46-
+ ", options=" + options
33+
+ ", filter=" + getFilter()
34+
+ ", options=" + getOptions()
4735
+ '}';
4836
}
4937
}

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

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

18-
import com.mongodb.assertions.Assertions;
1918
import com.mongodb.client.model.bulk.ClientUpdateOptions;
2019
import com.mongodb.lang.Nullable;
2120
import org.bson.conversions.Bson;
2221

22+
import java.util.Optional;
23+
24+
import static com.mongodb.assertions.Assertions.assertTrue;
25+
import static java.util.Optional.ofNullable;
26+
2327
/**
2428
* This class is not part of the public API and may be removed or changed at any time.
2529
*/
26-
public final class ConcreteClientUpdateManyModel extends ConcreteClientUpdateOneModel implements ClientWriteModel {
30+
public class ConcreteClientUpdateManyModel implements ClientWriteModel {
31+
private final Bson filter;
32+
@Nullable
33+
private final Bson update;
34+
@Nullable
35+
private final Iterable<? extends Bson> updatePipeline;
36+
private final ConcreteClientUpdateOptions options;
37+
2738
public ConcreteClientUpdateManyModel(
2839
final Bson filter,
2940
@Nullable
3041
final Bson update,
3142
@Nullable
3243
final Iterable<? extends Bson> updatePipeline,
3344
@Nullable final ClientUpdateOptions options) {
34-
super(filter, update, updatePipeline, options);
45+
this.filter = filter;
46+
assertTrue(update == null ^ updatePipeline == null);
47+
this.update = update;
48+
this.updatePipeline = updatePipeline;
49+
this.options = options == null ? ConcreteClientUpdateOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOptions) options;
50+
}
51+
52+
public Bson getFilter() {
53+
return filter;
54+
}
55+
56+
public Optional<Bson> getUpdate() {
57+
return ofNullable(update);
58+
}
59+
60+
public Optional<Iterable<? extends Bson>> getUpdatePipeline() {
61+
return ofNullable(updatePipeline);
62+
}
63+
64+
public ConcreteClientUpdateOptions getOptions() {
65+
return options;
3566
}
3667

3768
@Override
3869
public String toString() {
3970
return "ClientUpdateManyModel{"
40-
+ ", filter=" + getFilter()
41-
+ ", update=" + getUpdate().map(Object::toString)
42-
.orElse(getUpdatePipeline().map(Object::toString)
43-
.orElseThrow(Assertions::fail))
44-
+ ", options=" + getOptions()
71+
+ ", filter=" + filter
72+
+ ", update=" + (update != null ? update : updatePipeline)
73+
+ ", options=" + options
4574
+ '}';
4675
}
4776
}

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

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

18+
import com.mongodb.assertions.Assertions;
1819
import com.mongodb.client.model.bulk.ClientUpdateOptions;
1920
import com.mongodb.lang.Nullable;
2021
import org.bson.conversions.Bson;
2122

22-
import java.util.Optional;
23-
24-
import static com.mongodb.assertions.Assertions.assertTrue;
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 class ConcreteClientUpdateOneModel implements ClientWriteModel {
31-
private final Bson filter;
32-
@Nullable
33-
private final Bson update;
34-
@Nullable
35-
private final Iterable<? extends Bson> updatePipeline;
36-
private final ConcreteClientUpdateOptions options;
37-
26+
public final class ConcreteClientUpdateOneModel extends ConcreteClientUpdateManyModel {
3827
public ConcreteClientUpdateOneModel(
3928
final Bson filter,
4029
@Nullable
4130
final Bson update,
4231
@Nullable
4332
final Iterable<? extends Bson> updatePipeline,
4433
@Nullable final ClientUpdateOptions options) {
45-
this.filter = filter;
46-
assertTrue(update == null ^ updatePipeline == null);
47-
this.update = update;
48-
this.updatePipeline = updatePipeline;
49-
this.options = options == null ? ConcreteClientUpdateOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOptions) options;
50-
}
51-
52-
public Bson getFilter() {
53-
return filter;
54-
}
55-
56-
public Optional<Bson> getUpdate() {
57-
return ofNullable(update);
58-
}
59-
60-
public Optional<Iterable<? extends Bson>> getUpdatePipeline() {
61-
return ofNullable(updatePipeline);
62-
}
63-
64-
public ConcreteClientUpdateOptions getOptions() {
65-
return options;
34+
super(filter, update, updatePipeline, options);
6635
}
6736

6837
@Override
6938
public String toString() {
7039
return "ClientUpdateOneModel{"
71-
+ ", filter=" + filter
72-
+ ", update=" + (update != null ? update : updatePipeline)
73-
+ ", options=" + options
40+
+ ", filter=" + getFilter()
41+
+ ", update=" + getUpdate().map(Object::toString)
42+
.orElse(getUpdatePipeline().map(Object::toString)
43+
.orElseThrow(Assertions::fail))
44+
+ ", options=" + getOptions()
7445
+ '}';
7546
}
7647
}

0 commit comments

Comments
 (0)