DocumentBulkExecutor Class
- java.
lang. Object - com.
microsoft. azure. documentdb. bulkexecutor. DocumentBulkExecutor
- com.
Implements
public class DocumentBulkExecutor
implements java.lang.AutoCloseable
Method Summary
Modifier and Type | Method and Description |
---|---|
static Builder |
builder()
Creates a new DocumentBulkExecutor.Builder instance |
void |
close()
Releases any internal resources. |
Bulk |
deleteAll(List<Pair<String,String>> pkIdPairsToDelete)
Executes a bulk delete in the Azure Cosmos DB database service. |
Bulk |
importAll(Collection<String> documents, boolean isUpsert, boolean disableAutomaticIdGeneration, Integer maxConcurrencyPerPartitionRange)
Executes a bulk import in the Azure Cosmos DB database service. |
Bulk |
mergeAll(Collection<Document> patchDocuments, Integer maxConcurrencyPerPartitionRange)
Executes a bulk update in the Azure Cosmos DB database service with given set of patch documents. |
Bulk |
updateAll(Collection<UpdateItem> updateItems, Integer maxConcurrencyPerPartitionRange)
Executes a bulk update in the Azure Cosmos DB database service. |
Methods inherited from java.lang.Object
Method Details
builder
public static DocumentBulkExecutor.Builder builder()
Creates a new DocumentBulkExecutor.Builder instance
Returns:
close
public void close()
Releases any internal resources. It is responsibility of the caller to close DocumentClient.
deleteAll
public BulkDeleteResponse deleteAll(List
Executes a bulk delete in the Azure Cosmos DB database service.
Parameters:
Returns:
Throws:
importAll
public BulkImportResponse importAll(Collection
Executes a bulk import in the Azure Cosmos DB database service.
ConnectionPolicy connectionPolicy = new ConnectionPolicy(); RetryOptions retryOptions = new RetryOptions(); // Set client's retry options high for initialization retryOptions.setMaxRetryWaitTimeInSeconds(120); retryOptions.setMaxRetryAttemptsOnThrottledRequests(100); connectionPolicy.setRetryOptions(retryOptions); connectionPolicy.setMaxPoolSize(1000); DocumentClient client = new DocumentClient(HOST, MASTER_KEY, connectionPolicy, null); String collectionLink = String.format("/dbs/%s/colls/%s", "mydb", "mycol"); DocumentCollection collection = client.readCollection(collectionLink, null).getResource(); DocumentBulkExecutor executor = DocumentBulkExecutor.builder().from(client, collection, collection.getPartitionKey(), collectionOfferThroughput).build(); // Set retries to 0 to pass control to bulk executor client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(0); client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(0); for(int i = 0; i < 10; i++) { List documents = documentSource.getMoreDocuments(); BulkImportResponse bulkImportResponse = executor.importAll(documents, false, true, 40); // Validate that all documents inserted to ensure no failure. if (bulkImportResponse.getNumberOfDocumentsImported() < documents.size()) { for(Exception e: bulkImportResponse.getErrors()) { // Validate why there were some failures. e.printStackTrace(); } break; } } executor.close(); client.close();
Parameters:
Returns:
Throws:
mergeAll
public BulkUpdateResponse mergeAll(Collection
Executes a bulk update in the Azure Cosmos DB database service with given set of patch documents.
Parameters:
Returns:
Throws:
updateAll
public BulkUpdateResponse updateAll(Collection
Executes a bulk update in the Azure Cosmos DB database service.
Parameters:
Returns:
Throws:
Applies to
Azure SDK for Java