### YamlMime:JavaType uid: "com.azure.cosmos.models.CosmosBatch" fullName: "com.azure.cosmos.models.CosmosBatch" name: "CosmosBatch" nameWithType: "CosmosBatch" summary: "Represents a batch of operations against items with the same in a container that will be performed in a Cosmos manner at the Azure Cosmos DB service." inheritances: - "" inheritedClassMethods: - classRef: "java.lang.Object" methodsRef: - "clone" - "equals" - "finalize" - "getClass" - "hashCode" - "notify" - "notifyAll" - "toString" - "wait" - "wait" - "wait" syntax: "public final class **CosmosBatch**" methods: - uid: "com.azure.cosmos.models.CosmosBatch.createItemOperation(T)" fullName: "com.azure.cosmos.models.CosmosBatch.createItemOperation(T item)" name: "createItemOperation(T item)" nameWithType: "CosmosBatch.createItemOperation(T item)" summary: "Adds an operation to create an item into the batch." parameters: - description: "A JSON serializable object that must contain an id property." name: "item" type: "" syntax: "public CosmosItemOperation createItemOperation(T item)" desc: "Adds an operation to create an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.createItemOperation(T,com.azure.cosmos.models.CosmosBatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.createItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" name: "createItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.createItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" summary: "Adds an operation to create an item into the batch." parameters: - description: "A JSON serializable object that must contain an id property." name: "item" type: "" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation createItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" desc: "Adds an operation to create an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.replaceItemOperation(java.lang.String,T)" fullName: "com.azure.cosmos.models.CosmosBatch.replaceItemOperation(String id, T item)" name: "replaceItemOperation(String id, T item)" nameWithType: "CosmosBatch.replaceItemOperation(String id, T item)" summary: "Adds an operation to replace an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" - description: "A JSON serializable object that must contain an id property." name: "item" type: "" syntax: "public CosmosItemOperation replaceItemOperation(String id, T item)" desc: "Adds an operation to replace an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.replaceItemOperation(java.lang.String,T,com.azure.cosmos.models.CosmosBatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.replaceItemOperation(String id, T item, CosmosBatchItemRequestOptions requestOptions)" name: "replaceItemOperation(String id, T item, CosmosBatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.replaceItemOperation(String id, T item, CosmosBatchItemRequestOptions requestOptions)" summary: "Adds an operation to replace an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" - description: "A JSON serializable object that must contain an id property." name: "item" type: "" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation replaceItemOperation(String id, T item, CosmosBatchItemRequestOptions requestOptions)" desc: "Adds an operation to replace an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.upsertItemOperation(T)" fullName: "com.azure.cosmos.models.CosmosBatch.upsertItemOperation(T item)" name: "upsertItemOperation(T item)" nameWithType: "CosmosBatch.upsertItemOperation(T item)" summary: "Adds an operation to upsert an item into the batch." parameters: - description: "A JSON serializable object that must contain an id property." name: "item" type: "" syntax: "public CosmosItemOperation upsertItemOperation(T item)" desc: "Adds an operation to upsert an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.upsertItemOperation(T,com.azure.cosmos.models.CosmosBatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.upsertItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" name: "upsertItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.upsertItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" summary: "Adds an operation to upsert an item into the batch." parameters: - description: "A JSON serializable object that must contain an id property." name: "item" type: "" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation upsertItemOperation(T item, CosmosBatchItemRequestOptions requestOptions)" desc: "Adds an operation to upsert an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.createCosmosBatch(com.azure.cosmos.models.PartitionKey)" fullName: "com.azure.cosmos.models.CosmosBatch.createCosmosBatch(PartitionKey partitionKey)" name: "createCosmosBatch(PartitionKey partitionKey)" nameWithType: "CosmosBatch.createCosmosBatch(PartitionKey partitionKey)" summary: "Initializes a new instance of that will contain operations to be performed across multiple items in the container with the provided partition key in a transactional manner" modifiers: - "static" parameters: - description: "the partition key for all items in the batch." name: "partitionKey" type: "" syntax: "public static CosmosBatch createCosmosBatch(PartitionKey partitionKey)" desc: "Initializes a new instance of that will contain operations to be performed across multiple items in the container with the provided partition key in a transactional manner" returns: description: "A new instance of ." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.deleteItemOperation(java.lang.String)" fullName: "com.azure.cosmos.models.CosmosBatch.deleteItemOperation(String id)" name: "deleteItemOperation(String id)" nameWithType: "CosmosBatch.deleteItemOperation(String id)" summary: "Adds an operation to delete an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" syntax: "public CosmosItemOperation deleteItemOperation(String id)" desc: "Adds an operation to delete an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.deleteItemOperation(java.lang.String,com.azure.cosmos.models.CosmosBatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.deleteItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" name: "deleteItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.deleteItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" summary: "Adds an operation to delete an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation deleteItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" desc: "Adds an operation to delete an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.getOperations()" fullName: "com.azure.cosmos.models.CosmosBatch.getOperations()" name: "getOperations()" nameWithType: "CosmosBatch.getOperations()" summary: "Return the list of operation in an unmodifiable instance so no one can change it in the down path." syntax: "public List getOperations()" desc: "Return the list of operation in an unmodifiable instance so no one can change it in the down path." returns: description: "The list of operations which are to be executed." type: "List<>" - uid: "com.azure.cosmos.models.CosmosBatch.getPartitionKeyValue()" fullName: "com.azure.cosmos.models.CosmosBatch.getPartitionKeyValue()" name: "getPartitionKeyValue()" nameWithType: "CosmosBatch.getPartitionKeyValue()" summary: "Return the partition key for this batch." syntax: "public PartitionKey getPartitionKeyValue()" desc: "Return the partition key for this batch." returns: description: "The partition key for this batch." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.patchItemOperation(java.lang.String,com.azure.cosmos.models.CosmosPatchOperations)" fullName: "com.azure.cosmos.models.CosmosBatch.patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations)" name: "patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations)" nameWithType: "CosmosBatch.patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations)" summary: "Adds a patch operations for an item into the batch." parameters: - description: "the item id." name: "id" type: "String" - description: "Represents a container having list of operations to be sequentially applied to the referred Cosmos item." name: "cosmosPatchOperations" type: "" syntax: "public CosmosItemOperation patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations)" desc: "Adds a patch operations for an item into the batch." returns: description: "The added operation." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.patchItemOperation(java.lang.String,com.azure.cosmos.models.CosmosPatchOperations,com.azure.cosmos.models.CosmosBatchPatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations, CosmosBatchPatchItemRequestOptions requestOptions)" name: "patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations, CosmosBatchPatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations, CosmosBatchPatchItemRequestOptions requestOptions)" summary: "Adds a patch operations for an item into the batch." parameters: - description: "the item id." name: "id" type: "String" - description: "Represents a container having list of operations to be sequentially applied to the referred Cosmos item." name: "cosmosPatchOperations" type: "" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation patchItemOperation(String id, CosmosPatchOperations cosmosPatchOperations, CosmosBatchPatchItemRequestOptions requestOptions)" desc: "Adds a patch operations for an item into the batch." returns: description: "The added operation." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.readItemOperation(java.lang.String)" fullName: "com.azure.cosmos.models.CosmosBatch.readItemOperation(String id)" name: "readItemOperation(String id)" nameWithType: "CosmosBatch.readItemOperation(String id)" summary: "Adds an operation to read an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" syntax: "public CosmosItemOperation readItemOperation(String id)" desc: "Adds an operation to read an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" - uid: "com.azure.cosmos.models.CosmosBatch.readItemOperation(java.lang.String,com.azure.cosmos.models.CosmosBatchItemRequestOptions)" fullName: "com.azure.cosmos.models.CosmosBatch.readItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" name: "readItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" nameWithType: "CosmosBatch.readItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" summary: "Adds an operation to read an item into the batch." parameters: - description: "The unique id of the item." name: "id" type: "String" - description: "The options for the item request." name: "requestOptions" type: "" syntax: "public CosmosItemOperation readItemOperation(String id, CosmosBatchItemRequestOptions requestOptions)" desc: "Adds an operation to read an item into the batch." returns: description: "The Cosmos batch instance with the operation added." type: "" type: "class" desc: "Represents a batch of operations against items with the same in a container that will be performed in a Cosmos manner at the Azure Cosmos DB service.\n\nUse to create an instance of . **Example** This example atomically modifies a set of items as a batch.\n\n```java\npublic class ToDoActivity {\n public final String type;\n public final String id;\n public final String status;\n public ToDoActivity(String type, String id, String status) {\n this.type = type;\n this.id = id;\n this.status = status;\n }\n }\n\n String activityType = \"personal\";\n\n ToDoActivity test1 = new ToDoActivity(activityType, \"learning\", \"ToBeDone\");\n ToDoActivity test2 = new ToDoActivity(activityType, \"shopping\", \"Done\");\n ToDoActivity test3 = new ToDoActivity(activityType, \"swimming\", \"ToBeDone\");\n\n CosmosBatch batch = CosmosBatch.createCosmosBatch(new Cosmos.PartitionKey(activityType));\n batch.createItemOperation(test1);\n batch.replaceItemOperation(test2.id, test2);\n batch.upsertItemOperation(test3);\n batch.deleteItemOperation(\"reading\");\n\n CosmosBatchResponse response = container.executeTransactionalBatch(batch);\n\n if (!response.isSuccessStatusCode()) {\n // Handle and log exception\n return;\n }\n\n // Look up interested results - e.g., via typed access on operation results\n\n CosmosBatchOperationResult result = response.get(0);\n ToDoActivity readActivity = result.getItem(ToDoActivity.class);\n```\n\n**Example**\n\nThis example atomically reads a set of items as a batch.\n\n```java\nString activityType = \"personal\";\n\n CosmosBatch batch = CosmosBatch.createCosmosBatch(new Cosmos.PartitionKey(activityType));\n batch.readItemOperation(\"playing\");\n batch.readItemOperation(\"walking\");\n batch.readItemOperation(\"jogging\");\n batch.readItemOperation(\"running\");\n\n CosmosBatchResponse response = container.executeTransactionalBatch(batch);\n List resultItems = new ArrayList();\n\n for (int i = 0; i < response.size(); i++) {\n CosmosBatchOperationResult result = response.get(0);\n resultItems.add(result.getItem(ToDoActivity.class));\n }\n```\n\n**See:** [Limits on CosmosBatch requests][].\n\n\n[Limits on CosmosBatch requests]: https://docs.microsoft.com/azure/cosmos-db/concepts-limits" metadata: {} package: "com.azure.cosmos.models" artifact: com.azure:azure-cosmos:4.63.4