@@ -96,17 +96,19 @@ class MongoCollectionImpl<TDocument> implements MongoCollection<TDocument> {
96
96
private final ReadPreference readPreference ;
97
97
private final CodecRegistry codecRegistry ;
98
98
private final WriteConcern writeConcern ;
99
+ private final boolean retryWrites ;
99
100
private final ReadConcern readConcern ;
100
101
private final AsyncOperationExecutor executor ;
101
102
102
103
MongoCollectionImpl (final MongoNamespace namespace , final Class <TDocument > documentClass , final CodecRegistry codecRegistry ,
103
- final ReadPreference readPreference , final WriteConcern writeConcern , final ReadConcern readConcern ,
104
- final AsyncOperationExecutor executor ) {
104
+ final ReadPreference readPreference , final WriteConcern writeConcern , final boolean retryWrites ,
105
+ final ReadConcern readConcern , final AsyncOperationExecutor executor ) {
105
106
this .namespace = notNull ("namespace" , namespace );
106
107
this .documentClass = notNull ("documentClass" , documentClass );
107
108
this .codecRegistry = notNull ("codecRegistry" , codecRegistry );
108
109
this .readPreference = notNull ("readPreference" , readPreference );
109
110
this .writeConcern = notNull ("writeConcern" , writeConcern );
111
+ this .retryWrites = retryWrites ;
110
112
this .readConcern = notNull ("readConcern" , readConcern );
111
113
this .executor = notNull ("executor" , executor );
112
114
}
@@ -143,32 +145,32 @@ public ReadConcern getReadConcern() {
143
145
144
146
@ Override
145
147
public <NewTDocument > MongoCollection <NewTDocument > withDocumentClass (final Class <NewTDocument > newDocumentClass ) {
146
- return new MongoCollectionImpl <NewTDocument >(namespace , newDocumentClass , codecRegistry , readPreference , writeConcern , readConcern ,
147
- executor );
148
+ return new MongoCollectionImpl <NewTDocument >(namespace , newDocumentClass , codecRegistry , readPreference , writeConcern , retryWrites ,
149
+ readConcern , executor );
148
150
}
149
151
150
152
@ Override
151
153
public MongoCollection <TDocument > withCodecRegistry (final CodecRegistry codecRegistry ) {
152
- return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , readConcern ,
153
- executor );
154
+ return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , retryWrites ,
155
+ readConcern , executor );
154
156
}
155
157
156
158
@ Override
157
159
public MongoCollection <TDocument > withReadPreference (final ReadPreference readPreference ) {
158
- return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , readConcern ,
159
- executor );
160
+ return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , retryWrites ,
161
+ readConcern , executor );
160
162
}
161
163
162
164
@ Override
163
165
public MongoCollection <TDocument > withWriteConcern (final WriteConcern writeConcern ) {
164
- return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , readConcern ,
165
- executor );
166
+ return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , retryWrites ,
167
+ readConcern , executor );
166
168
}
167
169
168
170
@ Override
169
171
public MongoCollection <TDocument > withReadConcern (final ReadConcern readConcern ) {
170
- return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , readConcern ,
171
- executor );
172
+ return new MongoCollectionImpl <TDocument >(namespace , documentClass , codecRegistry , readPreference , writeConcern , retryWrites ,
173
+ readConcern , executor );
172
174
}
173
175
174
176
@ Override
@@ -333,7 +335,7 @@ public void bulkWrite(final List<? extends WriteModel<? extends TDocument>> requ
333
335
writeRequests .add (writeRequest );
334
336
}
335
337
336
- executor .execute (new MixedBulkWriteOperation (namespace , writeRequests , options .isOrdered (), writeConcern )
338
+ executor .execute (new MixedBulkWriteOperation (namespace , writeRequests , options .isOrdered (), writeConcern , retryWrites )
337
339
.bypassDocumentValidation (options .getBypassDocumentValidation ()), callback );
338
340
}
339
341
@@ -376,7 +378,7 @@ public void insertMany(final List<? extends TDocument> documents, final InsertMa
376
378
}
377
379
requests .add (new InsertRequest (documentToBsonDocument (document )));
378
380
}
379
- executor .execute (new MixedBulkWriteOperation (namespace , requests , options .isOrdered (), writeConcern )
381
+ executor .execute (new MixedBulkWriteOperation (namespace , requests , options .isOrdered (), writeConcern , retryWrites )
380
382
.bypassDocumentValidation (options .getBypassDocumentValidation ()), errorHandlingCallback (
381
383
new SingleResultCallback <BulkWriteResult >() {
382
384
@ Override
@@ -457,7 +459,7 @@ public void findOneAndDelete(final Bson filter, final SingleResultCallback<TDocu
457
459
458
460
@ Override
459
461
public void findOneAndDelete (final Bson filter , final FindOneAndDeleteOptions options , final SingleResultCallback <TDocument > callback ) {
460
- executor .execute (new FindAndDeleteOperation <TDocument >(namespace , writeConcern , getCodec ())
462
+ executor .execute (new FindAndDeleteOperation <TDocument >(namespace , writeConcern , retryWrites , getCodec ())
461
463
.filter (toBsonDocument (filter ))
462
464
.projection (toBsonDocument (options .getProjection ()))
463
465
.sort (toBsonDocument (options .getSort ()))
@@ -473,15 +475,16 @@ public void findOneAndReplace(final Bson filter, final TDocument replacement, fi
473
475
@ Override
474
476
public void findOneAndReplace (final Bson filter , final TDocument replacement , final FindOneAndReplaceOptions options ,
475
477
final SingleResultCallback <TDocument > callback ) {
476
- executor .execute (new FindAndReplaceOperation <TDocument >(namespace , writeConcern , getCodec (), documentToBsonDocument (replacement ))
477
- .filter (toBsonDocument (filter ))
478
- .projection (toBsonDocument (options .getProjection ()))
479
- .sort (toBsonDocument (options .getSort ()))
480
- .returnOriginal (options .getReturnDocument () == ReturnDocument .BEFORE )
481
- .upsert (options .isUpsert ())
482
- .maxTime (options .getMaxTime (MILLISECONDS ), MILLISECONDS )
483
- .bypassDocumentValidation (options .getBypassDocumentValidation ())
484
- .collation (options .getCollation ()), callback );
478
+ executor .execute (new FindAndReplaceOperation <TDocument >(namespace , writeConcern , retryWrites , getCodec (),
479
+ documentToBsonDocument (replacement ))
480
+ .filter (toBsonDocument (filter ))
481
+ .projection (toBsonDocument (options .getProjection ()))
482
+ .sort (toBsonDocument (options .getSort ()))
483
+ .returnOriginal (options .getReturnDocument () == ReturnDocument .BEFORE )
484
+ .upsert (options .isUpsert ())
485
+ .maxTime (options .getMaxTime (MILLISECONDS ), MILLISECONDS )
486
+ .bypassDocumentValidation (options .getBypassDocumentValidation ())
487
+ .collation (options .getCollation ()), callback );
485
488
}
486
489
487
490
@ Override
@@ -492,7 +495,7 @@ public void findOneAndUpdate(final Bson filter, final Bson update, final SingleR
492
495
@ Override
493
496
public void findOneAndUpdate (final Bson filter , final Bson update , final FindOneAndUpdateOptions options ,
494
497
final SingleResultCallback <TDocument > callback ) {
495
- executor .execute (new FindAndUpdateOperation <TDocument >(namespace , writeConcern , getCodec (), toBsonDocument (update ))
498
+ executor .execute (new FindAndUpdateOperation <TDocument >(namespace , writeConcern , retryWrites , getCodec (), toBsonDocument (update ))
496
499
.filter (toBsonDocument (filter ))
497
500
.projection (toBsonDocument (options .getProjection ()))
498
501
.sort (toBsonDocument (options .getSort ()))
@@ -646,7 +649,7 @@ public void onResult(final BulkWriteResult result, final Throwable t) {
646
649
647
650
private void executeSingleWriteRequest (final WriteRequest request , final Boolean bypassDocumentValidation ,
648
651
final SingleResultCallback <BulkWriteResult > callback ) {
649
- executor .execute (new MixedBulkWriteOperation (namespace , singletonList (request ), true , writeConcern )
652
+ executor .execute (new MixedBulkWriteOperation (namespace , singletonList (request ), true , writeConcern , retryWrites )
650
653
.bypassDocumentValidation (bypassDocumentValidation ),
651
654
new SingleResultCallback <BulkWriteResult >() {
652
655
@ Override
0 commit comments