use of com.mongodb.internal.bulk.WriteRequest.Type.UPDATE in project mongo-java-driver by mongodb.
the class MixedBulkWriteOperation method executeLegacyBatchesAsync.
private void executeLegacyBatchesAsync(final AsyncWriteBinding binding, final AsyncConnection connection, final SingleResultCallback<BulkWriteResult> callback) {
List<? extends WriteRequest> writeRequests = getWriteRequests();
LoopState loopState = new LoopState();
AsyncCallbackRunnable loop = new AsyncCallbackLoop(loopState, iterationCallback -> {
int i = loopState.iteration();
if (loopState.breakAndCompleteIf(() -> i == writeRequests.size(), iterationCallback)) {
return;
}
WriteRequest writeRequest = writeRequests.get(i);
SingleResultCallback<WriteConcernResult> commandCallback = (ignored, t) -> iterationCallback.onResult(null, t);
if (writeRequest.getType() == INSERT) {
connection.insertAsync(getNamespace(), isOrdered(), (InsertRequest) writeRequest, binding.getRequestContext(), commandCallback);
} else if (writeRequest.getType() == UPDATE || writeRequest.getType() == REPLACE) {
connection.updateAsync(getNamespace(), isOrdered(), (UpdateRequest) writeRequest, binding.getRequestContext(), commandCallback);
} else {
connection.deleteAsync(getNamespace(), isOrdered(), (DeleteRequest) writeRequest, binding.getRequestContext(), commandCallback);
}
});
loop.run((voidResult, t) -> {
if (t != null) {
callback.onResult(null, t);
} else {
callback.onResult(BulkWriteResult.unacknowledged(), null);
}
});
}
Aggregations