use of com.mongodb.internal.connection.BulkWriteBatchCombiner in project mongo-java-driver by mongodb.
the class BulkWriteBatch method createBulkWriteBatch.
static BulkWriteBatch createBulkWriteBatch(final MongoNamespace namespace, final ServerDescription serverDescription, final ConnectionDescription connectionDescription, final boolean ordered, final WriteConcern writeConcern, final Boolean bypassDocumentValidation, final boolean retryWrites, final List<? extends WriteRequest> writeRequests, final SessionContext sessionContext) {
if (sessionContext.hasSession() && !sessionContext.isImplicitSession() && !sessionContext.hasActiveTransaction() && !writeConcern.isAcknowledged()) {
throw new MongoClientException("Unacknowledged writes are not supported when using an explicit session");
}
boolean canRetryWrites = isRetryableWrite(retryWrites, writeConcern, serverDescription, connectionDescription, sessionContext);
List<WriteRequestWithIndex> writeRequestsWithIndex = new ArrayList<WriteRequestWithIndex>();
boolean writeRequestsAreRetryable = true;
for (int i = 0; i < writeRequests.size(); i++) {
WriteRequest writeRequest = writeRequests.get(i);
writeRequestsAreRetryable = writeRequestsAreRetryable && isRetryable(writeRequest);
writeRequestsWithIndex.add(new WriteRequestWithIndex(writeRequest, i));
}
if (canRetryWrites && !writeRequestsAreRetryable) {
canRetryWrites = false;
LOGGER.debug("retryWrites set but one or more writeRequests do not support retryable writes");
}
return new BulkWriteBatch(namespace, connectionDescription, ordered, writeConcern, bypassDocumentValidation, canRetryWrites, new BulkWriteBatchCombiner(connectionDescription.getServerAddress(), ordered, writeConcern), writeRequestsWithIndex, sessionContext);
}
Aggregations