Search in sources :

Example 11 with CosmosPatchOperations

use of com.azure.cosmos.models.CosmosPatchOperations in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SamplePatchQuickstart method patchIncrement.

private void patchIncrement(String id, String partitionKey) {
    logger.info("Executing Patch with 'increment' operations");
    CosmosPatchOperations cosmosPatchOperations = CosmosPatchOperations.create();
    cosmosPatchOperations.add("/int", 42).increment("/int", 1).increment("/int", -1).add("/float", 42).increment("/float", 4.2).increment("/float", -4.2);
    CosmosPatchItemRequestOptions options = new CosmosPatchItemRequestOptions();
    try {
        CosmosItemResponse<Family> response = this.container.patchItem(id, new PartitionKey(partitionKey), cosmosPatchOperations, options, Family.class);
        logger.info("Item with ID {} has been patched", response.getItem().getId());
    } catch (Exception e) {
        logger.error("failed", e);
    }
}
Also used : CosmosPatchItemRequestOptions(com.azure.cosmos.models.CosmosPatchItemRequestOptions) Family(com.azure.cosmos.examples.common.Family) PartitionKey(com.azure.cosmos.models.PartitionKey) CosmosPatchOperations(com.azure.cosmos.models.CosmosPatchOperations)

Aggregations

Family (com.azure.cosmos.examples.common.Family)11 CosmosPatchOperations (com.azure.cosmos.models.CosmosPatchOperations)11 PartitionKey (com.azure.cosmos.models.PartitionKey)11 CosmosPatchItemRequestOptions (com.azure.cosmos.models.CosmosPatchItemRequestOptions)9 Child (com.azure.cosmos.examples.common.Child)3 CosmosBatch (com.azure.cosmos.models.CosmosBatch)2 CosmosBatchResponse (com.azure.cosmos.models.CosmosBatchResponse)2 CosmosBatchOperationResult (com.azure.cosmos.models.CosmosBatchOperationResult)1 CosmosBatchPatchItemRequestOptions (com.azure.cosmos.models.CosmosBatchPatchItemRequestOptions)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1