Skip to content

Commit dbb6ec8

Browse files
committed
Rearrange ClientWriteModel inheritance: neither "one" nor "many" should extend each other
Such extending turned out to be confusing JAVA-5527
1 parent c057390 commit dbb6ec8

9 files changed

+143
-78
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.bulk.ClientDeleteOptions;
19+
import com.mongodb.lang.Nullable;
20+
import org.bson.conversions.Bson;
21+
22+
/**
23+
* This class is not part of the public API and may be removed or changed at any time.
24+
*/
25+
abstract class AbstractClientDeleteModel implements ClientWriteModel {
26+
private final Bson filter;
27+
private final ConcreteClientDeleteOptions options;
28+
29+
AbstractClientDeleteModel(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 final Bson getFilter() {
35+
return filter;
36+
}
37+
38+
public final ConcreteClientDeleteOptions getOptions() {
39+
return options;
40+
}
41+
42+
abstract String getToStringDescription();
43+
44+
@Override
45+
public final String toString() {
46+
return getToStringDescription()
47+
+ "{filter=" + filter
48+
+ ", options=" + options
49+
+ '}';
50+
}
51+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.bulk.ClientUpdateOptions;
19+
import com.mongodb.lang.Nullable;
20+
import org.bson.conversions.Bson;
21+
22+
import java.util.Optional;
23+
24+
import static com.mongodb.assertions.Assertions.assertTrue;
25+
import static java.util.Optional.ofNullable;
26+
27+
abstract class AbstractClientUpdateModel {
28+
private final Bson filter;
29+
@Nullable
30+
private final Bson update;
31+
@Nullable
32+
private final Iterable<? extends Bson> updatePipeline;
33+
private final ConcreteClientUpdateOptions options;
34+
35+
AbstractClientUpdateModel(
36+
final Bson filter,
37+
@Nullable
38+
final Bson update,
39+
@Nullable
40+
final Iterable<? extends Bson> updatePipeline,
41+
@Nullable final ClientUpdateOptions options) {
42+
this.filter = filter;
43+
assertTrue(update == null ^ updatePipeline == null);
44+
this.update = update;
45+
this.updatePipeline = updatePipeline;
46+
this.options = options == null ? ConcreteClientUpdateOptions.MUTABLE_EMPTY : (ConcreteClientUpdateOptions) options;
47+
}
48+
49+
public final Bson getFilter() {
50+
return filter;
51+
}
52+
53+
public final Optional<Bson> getUpdate() {
54+
return ofNullable(update);
55+
}
56+
57+
public final Optional<Iterable<? extends Bson>> getUpdatePipeline() {
58+
return ofNullable(updatePipeline);
59+
}
60+
61+
public final ConcreteClientUpdateOptions getOptions() {
62+
return options;
63+
}
64+
65+
abstract String getToStringDescription();
66+
67+
@Override
68+
public final String toString() {
69+
return getToStringDescription()
70+
+ "{filter=" + filter
71+
+ ", update=" + (update != null ? update : updatePipeline)
72+
+ ", options=" + options
73+
+ '}';
74+
}
75+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public int hashCode() {
160160
@Override
161161
public String toString() {
162162
return "AcknowledgedVerboseClientBulkWriteResult.Verbose{"
163-
+ ", insertResults=" + insertResults
163+
+ "insertResults=" + insertResults
164164
+ ", updateResults=" + updateResults
165165
+ ", deleteResults=" + deleteResults
166166
+ '}';

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,13 @@
2222
/**
2323
* This class is not part of the public API and may be removed or changed at any time.
2424
*/
25-
public class ConcreteClientDeleteManyModel implements ClientWriteModel {
26-
private final Bson filter;
27-
private final ConcreteClientDeleteOptions options;
28-
25+
public final class ConcreteClientDeleteManyModel extends AbstractClientDeleteModel implements ClientWriteModel {
2926
public ConcreteClientDeleteManyModel(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
43-
public String toString() {
44-
return "ClientDeleteManyModel{"
45-
+ ", filter=" + filter
46-
+ ", options=" + options
47-
+ '}';
31+
String getToStringDescription() {
32+
return "ClientDeleteManyModel";
4833
}
4934
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
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 ConcreteClientDeleteOneModel extends ConcreteClientDeleteManyModel {
25+
public final class ConcreteClientDeleteOneModel extends AbstractClientDeleteModel implements ClientWriteModel {
2626
public ConcreteClientDeleteOneModel(final Bson filter, @Nullable final ClientDeleteOptions options) {
2727
super(filter, options);
2828
}
2929

3030
@Override
31-
public String toString() {
32-
return "ClientDeleteOneModel{"
33-
+ ", filter=" + getFilter()
34-
+ ", options=" + getOptions()
35-
+ '}';
31+
String getToStringDescription() {
32+
return "ClientDeleteOneModel";
3633
}
3734
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Object getDocument() {
3232
@Override
3333
public String toString() {
3434
return "ClientInsertOneModel{"
35-
+ ", document=" + document
35+
+ "document=" + document
3636
+ '}';
3737
}
3838
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ConcreteClientReplaceOptions getOptions() {
4848
@Override
4949
public String toString() {
5050
return "ClientReplaceOneModel{"
51-
+ ", filter=" + filter
51+
+ "filter=" + filter
5252
+ ", replacement=" + replacement
5353
+ ", options=" + options
5454
+ '}';

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

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,22 @@
1919
import com.mongodb.lang.Nullable;
2020
import org.bson.conversions.Bson;
2121

22-
import java.util.Optional;
23-
24-
import static com.mongodb.assertions.Assertions.assertTrue;
25-
import static java.util.Optional.ofNullable;
26-
2722
/**
2823
* This class is not part of the public API and may be removed or changed at any time.
2924
*/
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-
25+
public final class ConcreteClientUpdateManyModel extends AbstractClientUpdateModel implements ClientWriteModel {
3826
public ConcreteClientUpdateManyModel(
3927
final Bson filter,
4028
@Nullable
4129
final Bson update,
4230
@Nullable
4331
final Iterable<? extends Bson> updatePipeline,
4432
@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;
33+
super(filter, update, updatePipeline, options);
6634
}
6735

6836
@Override
69-
public String toString() {
70-
return "ClientUpdateManyModel{"
71-
+ ", filter=" + filter
72-
+ ", update=" + (update != null ? update : updatePipeline)
73-
+ ", options=" + options
74-
+ '}';
37+
String getToStringDescription() {
38+
return "ClientUpdateManyModel";
7539
}
7640
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
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

2322
/**
2423
* This class is not part of the public API and may be removed or changed at any time.
2524
*/
26-
public final class ConcreteClientUpdateOneModel extends ConcreteClientUpdateManyModel {
25+
public final class ConcreteClientUpdateOneModel extends AbstractClientUpdateModel implements ClientWriteModel {
2726
public ConcreteClientUpdateOneModel(
2827
final Bson filter,
2928
@Nullable
@@ -35,13 +34,7 @@ public ConcreteClientUpdateOneModel(
3534
}
3635

3736
@Override
38-
public String toString() {
39-
return "ClientUpdateOneModel{"
40-
+ ", filter=" + getFilter()
41-
+ ", update=" + getUpdate().map(Object::toString)
42-
.orElse(getUpdatePipeline().map(Object::toString)
43-
.orElseThrow(Assertions::fail))
44-
+ ", options=" + getOptions()
45-
+ '}';
37+
String getToStringDescription() {
38+
return "ClientUpdateOneModel";
4639
}
4740
}

0 commit comments

Comments
 (0)