CosmosContainer Class
- java.lang.Object
- com.azure.cosmos.CosmosContainer
public class CosmosContainer
Provides synchronous methods for reading, deleting, and replacing existing Containers Provides methods for interacting with child resources (Items, Scripts, Conflicts)
Method Summary
Methods inherited from java.lang.Object
Method Details
createItem
public CosmosItemResponse
Creates a new item synchronously and returns its respective Cosmos item response.
Parameters:
Returns:
createItem
public CosmosItemResponse
Creates a new item synchronously and returns its respective Cosmos item response while specifying additional options.
The partition key value will be automatically extracted from the item's content.
Parameters:
Returns:
createItem
public CosmosItemResponse
Creates a new item synchronously and returns its respective Cosmos item response while specifying additional options.
Parameters:
Returns:
deleteItem
public CosmosItemResponse
Deletes an item in the current container.
Parameters:
Returns:
patchItem
public CosmosItemResponse
Run patch operations on an Item.
Parameters:
Returns:
patchItem
public CosmosItemResponse
Run patch operations on an Item.
Parameters:
Returns:
queryChangeFeed
public CosmosPagedIterable
Query for items in the change feed of the current container using the CosmosChangeFeedRequestOptions.
The next page can be retrieved by calling queryChangeFeed again with a new instance of CosmosChangeFeedRequestOptions created from the continuation token of the previously returned FeedResponse<T> instance.
Parameters:
Returns:
queryItems
public CosmosPagedIterable
Query items in the current container returning the results as CosmosPagedIterable<T>.
Parameters:
Returns:
queryItems
public CosmosPagedIterable
Query items in the current container returning the results as CosmosPagedIterable<T>.
Parameters:
Returns:
readAllItems
public CosmosPagedIterable
Reads all the items of a logical partition returning the results as CosmosPagedIterable<T>.
Parameters:
Returns:
readAllItems
public CosmosPagedIterable
Reads all the items of a logical partition returning the results as CosmosPagedIterable<T>.
Parameters:
Returns:
readItem
public CosmosItemResponse
Reads an item in the current container while specifying additional options.
Parameters:
Returns:
readItem
public CosmosItemResponse
Reads an item in the current container.
Parameters:
Returns:
readMany
public FeedResponse
Reads many documents.
Parameters:
Returns:
readMany
public FeedResponse
Reads many documents.
Parameters:
Returns:
replaceItem
public CosmosItemResponse
Replaces an item in the current container.
Parameters:
Returns:
upsertItem
public CosmosItemResponse
Upserts an Cosmos item in the current container.
Parameters:
Returns:
upsertItem
public CosmosItemResponse
Upserts a item Cosmos sync item while specifying additional options.
Parameters:
Returns:
upsertItem
public CosmosItemResponse
Upserts a item Cosmos sync item while specifying additional options.
Parameters:
Returns:
executeBulkOperations
public Iterable<>
Executes list of operations in Bulk.
Parameters:
Returns:
executeBulkOperations
public Iterable<>
Executes list of operations in Bulk.
Parameters:
Returns:
delete
public CosmosContainerResponse delete()
Deletes the current cosmos container.
Returns:
delete
public CosmosContainerResponse delete(CosmosContainerRequestOptions options)
Deletes the current Cosmos container while specifying additional options such as If-Match.
Parameters:
Returns:
deleteAllItemsByPartitionKey
public CosmosItemResponse
Deletes all items in the Container with the specified partitionKey value. Starts an asynchronous Cosmos DB background operation which deletes all items in the Container with the specified value. The asynchronous Cosmos DB background operation runs using a percentage of user RUs.
Parameters:
Returns:
deleteItem
public CosmosItemResponse
Deletes an item in the current container.
Parameters:
Returns:
enableGlobalThroughputControlGroup
public void enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig, GlobalThroughputControlConfig globalControlConfig)
Enable the throughput control group with global control mode. The defined throughput limit will be shared across different clients.
ThroughputControlGroupConfig groupConfig =
new ThroughputControlGroupConfigBuilder()
.groupName("localControlGroup")
.targetThroughputThreshold(0.1)
.build();
GlobalThroughputControlConfig globalControlConfig =
this.client.createGlobalThroughputControlConfigBuilder(database.getId(), container.getId())
.setControlItemRenewInterval(Duration.ofSeconds(5))
.setControlItemExpireInterval(Duration.ofSeconds(10))
.build();
container.enableGlobalThroughputControlGroup(groupConfig, globalControlConfig);
Parameters:
enableLocalThroughputControlGroup
public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig)
Enable the throughput control group with local control mode.
ThroughputControlGroupConfig groupConfig =
new ThroughputControlGroupConfigBuilder()
.groupName("localControlGroup")
.targetThroughputThreshold(0.1)
.build();
container.enableLocalThroughputControlGroup(groupConfig);
Parameters:
executeCosmosBatch
public CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch)
Executes the transactional batch.
Parameters:
Returns:
If the transactional batch executes successfully, the value returned by CosmosBatchResponse#getStatusCode on the response returned will be set to 200}.
If an operation within the transactional batch fails during execution, no changes from the batch will be committed and the status of the failing operation is made available by CosmosBatchResponse#getStatusCode or by the exception. To obtain information about the operations that failed in case of some user error like conflict, not found etc, the response can be enumerated. This returns CosmosBatchOperationResult instances corresponding to each operation in the transactional batch in the order they were added to the transactional batch. For a result corresponding to an operation within the transactional batch, use CosmosBatchOperationResult#getStatusCode to access the status of the operation. If the operation was not executed or it was aborted due to the failure of another operation within the transactional batch, the value of this field will be 424; for the operation that caused the batch to abort, the value of this field will indicate the cause of failure.
If there are issues such as request timeouts, Gone, session not available, network failure or if the service somehow returns 5xx then this will throw an exception instead of returning a CosmosBatchResponse.
Use CosmosBatchResponse#isSuccessStatusCode on the response returned to ensure that the transactional batch succeeded.
executeCosmosBatch
public CosmosBatchResponse executeCosmosBatch(CosmosBatch cosmosBatch, CosmosBatchRequestOptions requestOptions)
Executes the transactional batch.
Parameters:
Returns:
If the transactional batch executes successfully, the value returned by CosmosBatchResponse#getStatusCode on the response returned will be set to 200}.
If an operation within the transactional batch fails during execution, no changes from the batch will be committed and the status of the failing operation is made available by CosmosBatchResponse#getStatusCode or by the exception. To obtain information about the operations that failed in case of some user error like conflict, not found etc, the response can be enumerated. This returns CosmosBatchOperationResult instances corresponding to each operation in the transactional batch in the order they were added to the transactional batch. For a result corresponding to an operation within the transactional batch, use CosmosBatchOperationResult#getStatusCode to access the status of the operation. If the operation was not executed or it was aborted due to the failure of another operation within the transactional batch, the value of this field will be 424; for the operation that caused the batch to abort, the value of this field will indicate the cause of failure.
If there are issues such as request timeouts, Gone, session not available, network failure or if the service somehow returns 5xx then this will throw an exception instead of returning a CosmosBatchResponse.
Use CosmosBatchResponse#isSuccessStatusCode on the response returned to ensure that the transactional batch succeeded.
getFeedRanges
getId
public String getId()
Gets the current container id.
Returns:
getScripts
public CosmosScripts getScripts()
Gets the Cosmos scripts using the current container as context.
Returns:
openConnectionsAndInitCaches
public void openConnectionsAndInitCaches()
Initializes the container by warming up the caches and connections for the current read region.
NOTE: This API ideally should be called only once during application initialization before any workload. In case of any transient error, caller should consume the error and continue the regular workload.
openConnectionsAndInitCaches
public void openConnectionsAndInitCaches(int numProactiveConnectionRegions)
Initializes the container by warming up the caches and connections to a specified no. of proactive connection regions. For more information about proactive connection regions, see getProactiveConnectionRegionsCount()
NOTE: This API ideally should be called only once during application initialization before any workload. In case of any transient error, caller should consume the error and continue the regular workload.
Parameters:
read
public CosmosContainerResponse read()
Reads the current container.
Returns:
read
public CosmosContainerResponse read(CosmosContainerRequestOptions options)
Reads the current container while specifying additional options such as If-Match.
Parameters:
Returns:
readThroughput
public ThroughputResponse readThroughput()
Gets the throughput for the current container.
Returns:
replace
public CosmosContainerResponse replace(CosmosContainerProperties containerProperties)
Replaces the current container properties.
Parameters:
Returns:
replace
public CosmosContainerResponse replace(CosmosContainerProperties containerProperties, CosmosContainerRequestOptions options)
Replaces the current container properties while specifying additional options such as If-Match.
Parameters:
Returns:
replaceThroughput
public ThroughputResponse replaceThroughput(ThroughputProperties throughputProperties)
Sets the throughput for the current container.
Parameters:
Returns: