public class CosmosContainer extends Object
Modifier and Type | Method and Description |
---|---|
<T> CosmosItemResponse<T> |
createItem(T item)
Creates a new item synchronously and returns its respective Cosmos item response.
|
<T> CosmosItemResponse<T> |
createItem(T item,
CosmosItemRequestOptions options)
Creates a new item synchronously and returns its respective Cosmos item response
while specifying additional options.
|
<T> CosmosItemResponse<T> |
createItem(T item,
PartitionKey partitionKey,
CosmosItemRequestOptions options)
Creates a new item synchronously and returns its respective Cosmos item response
while specifying additional options.
|
CosmosContainerResponse |
delete()
Deletes the current cosmos container.
|
CosmosContainerResponse |
delete(CosmosContainerRequestOptions options)
Deletes the current Cosmos container while specifying additional options such as If-Match.
|
CosmosItemResponse<Object> |
deleteItem(String itemId,
PartitionKey partitionKey,
CosmosItemRequestOptions options)
Deletes an item in the current container.
|
<T> CosmosItemResponse<Object> |
deleteItem(T item,
CosmosItemRequestOptions options)
Deletes an item in the current container.
|
void |
enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig,
GlobalThroughputControlConfig globalControlConfig)
Enable the throughput control group with global control mode.
|
void |
enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig)
Enable the throughput control group with local control mode.
|
TransactionalBatchResponse |
executeTransactionalBatch(TransactionalBatch transactionalBatch)
Executes the transactional batch.
|
TransactionalBatchResponse |
executeTransactionalBatch(TransactionalBatch transactionalBatch,
TransactionalBatchRequestOptions requestOptions)
Executes the transactional batch.
|
List<FeedRange> |
getFeedRanges()
Obtains a list of
FeedRange that can be used to parallelize Feed
operations. |
String |
getId()
Gets the current container id.
|
CosmosScripts |
getScripts()
Gets the Cosmos scripts using the current container as context.
|
void |
openConnectionsAndInitCaches()
Initializes the container by warming up the caches and connections for the current read region.
|
<T> CosmosItemResponse<T> |
patchItem(String itemId,
PartitionKey partitionKey,
CosmosPatchOperations cosmosPatchOperations,
Class<T> itemType)
Run patch operations on an Item.
|
<T> CosmosItemResponse<T> |
patchItem(String itemId,
PartitionKey partitionKey,
CosmosPatchOperations cosmosPatchOperations,
CosmosPatchItemRequestOptions options,
Class<T> itemType)
Run patch operations on an Item.
|
<TContext> List<CosmosBulkOperationResponse<TContext>> |
processBulkOperations(Iterable<CosmosItemOperation> operations)
Executes list of operations in Bulk.
|
<TContext> List<CosmosBulkOperationResponse<TContext>> |
processBulkOperations(Iterable<CosmosItemOperation> operations,
BulkExecutionOptions bulkOptions)
Executes list of operations in Bulk.
|
<TContext> List<CosmosBulkOperationResponse<TContext>> |
processBulkOperations(Iterable<CosmosItemOperation> operations,
BulkProcessingOptions<TContext> bulkOptions)
Deprecated.
forRemoval = true, since = "4.18"
This overload will be removed. Please use one of the following overloads instead
-
CosmosAsyncContainer.processBulkOperations(Flux)
- CosmosAsyncContainer.processBulkOperations(Flux, BulkExecutionOptions)
- CosmosContainer.processBulkOperations(Iterable)
- CosmosContainer.processBulkOperations(Iterable, BulkExecutionOptions)
and to pass in a custom context use one of the BulkOperations factory methods allowing to provide
an operation specific context |
<T> CosmosPagedIterable<T> |
queryChangeFeed(CosmosChangeFeedRequestOptions options,
Class<T> classType)
Query for items in the change feed of the current container using the
CosmosChangeFeedRequestOptions . |
<T> CosmosPagedIterable<T> |
queryItems(SqlQuerySpec querySpec,
CosmosQueryRequestOptions options,
Class<T> classType)
Query items in the current container returning the results as
CosmosPagedIterable . |
<T> CosmosPagedIterable<T> |
queryItems(String query,
CosmosQueryRequestOptions options,
Class<T> classType)
Query items in the current container returning the results as
CosmosPagedIterable . |
CosmosContainerResponse |
read()
Reads the current container.
|
CosmosContainerResponse |
read(CosmosContainerRequestOptions options)
Reads the current container while specifying additional options such as If-Match.
|
<T> CosmosPagedIterable<T> |
readAllItems(PartitionKey partitionKey,
Class<T> classType)
Reads all the items of a logical partition returning the results as
CosmosPagedIterable . |
<T> CosmosPagedIterable<T> |
readAllItems(PartitionKey partitionKey,
CosmosQueryRequestOptions options,
Class<T> classType)
Reads all the items of a logical partition returning the results as
CosmosPagedIterable . |
<T> CosmosItemResponse<T> |
readItem(String itemId,
PartitionKey partitionKey,
Class<T> itemType)
Reads an item in the current container.
|
<T> CosmosItemResponse<T> |
readItem(String itemId,
PartitionKey partitionKey,
CosmosItemRequestOptions options,
Class<T> itemType)
Reads an item in the current container while specifying additional options.
|
<T> FeedResponse<T> |
readMany(List<CosmosItemIdentity> itemIdentityList,
Class<T> classType)
Reads many documents.
|
<T> FeedResponse<T> |
readMany(List<CosmosItemIdentity> itemIdentityList,
String sessionToken,
Class<T> classType)
Reads many documents.
|
ThroughputResponse |
readThroughput()
Gets the throughput for the current container.
|
CosmosContainerResponse |
replace(CosmosContainerProperties containerProperties)
Replaces the current container properties.
|
CosmosContainerResponse |
replace(CosmosContainerProperties containerProperties,
CosmosContainerRequestOptions options)
Replaces the current container properties while specifying additional options such as If-Match.
|
<T> CosmosItemResponse<T> |
replaceItem(T item,
String itemId,
PartitionKey partitionKey,
CosmosItemRequestOptions options)
Replaces an item in the current container.
|
ThroughputResponse |
replaceThroughput(ThroughputProperties throughputProperties)
Sets the throughput for the current container.
|
<T> CosmosItemResponse<T> |
upsertItem(T item)
Upserts an Cosmos item in the current container.
|
<T> CosmosItemResponse<T> |
upsertItem(T item,
CosmosItemRequestOptions options)
Upserts a item Cosmos sync item while specifying additional options.
|
<T> CosmosItemResponse<T> |
upsertItem(T item,
PartitionKey partitionKey,
CosmosItemRequestOptions options)
Upserts a item Cosmos sync item while specifying additional options.
|
public String getId()
public CosmosContainerResponse read()
public CosmosContainerResponse read(CosmosContainerRequestOptions options)
options
- the options.public CosmosContainerResponse delete(CosmosContainerRequestOptions options)
options
- the options.public CosmosContainerResponse delete()
public CosmosContainerResponse replace(CosmosContainerProperties containerProperties)
containerProperties
- the container properties.public CosmosContainerResponse replace(CosmosContainerProperties containerProperties, CosmosContainerRequestOptions options)
containerProperties
- the container properties.options
- the options.public ThroughputResponse replaceThroughput(ThroughputProperties throughputProperties)
throughputProperties
- the throughput properties.public ThroughputResponse readThroughput()
public <T> CosmosItemResponse<T> createItem(T item)
T
- the type parameteritem
- the itempublic <T> CosmosItemResponse<T> createItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)
T
- the type parameter.item
- the item.partitionKey
- the partition key.options
- the options.public <T> CosmosItemResponse<T> createItem(T item, CosmosItemRequestOptions options)
The partition key value will be automatically extracted from the item's content.
T
- the type parameter.item
- the item.options
- the options.public <T> CosmosItemResponse<T> upsertItem(T item)
T
- the type parameter.item
- the item.public <T> CosmosItemResponse<T> upsertItem(T item, CosmosItemRequestOptions options)
T
- the type parameter.item
- the item.options
- the options.public <T> CosmosItemResponse<T> upsertItem(T item, PartitionKey partitionKey, CosmosItemRequestOptions options)
T
- the type parameter.item
- the item.partitionKey
- the partitionKey.options
- the options.public <T> CosmosPagedIterable<T> queryItems(String query, CosmosQueryRequestOptions options, Class<T> classType)
CosmosPagedIterable
.T
- the type parameter.query
- the query.options
- the options.classType
- the class type.CosmosPagedIterable
.public <T> CosmosPagedIterable<T> queryItems(SqlQuerySpec querySpec, CosmosQueryRequestOptions options, Class<T> classType)
CosmosPagedIterable
.T
- the type parameter.querySpec
- the query spec.options
- the options.classType
- the class type.CosmosPagedIterable
.@Beta(value=V4_12_0, warningText="Preview API - subject to change in non-backwards compatible way") public <T> CosmosPagedIterable<T> queryChangeFeed(CosmosChangeFeedRequestOptions options, Class<T> classType)
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
instance.
T
- the type parameter.options
- the change feed request options.classType
- the class type.CosmosPagedFlux
containing one feed response pagepublic <T> FeedResponse<T> readMany(List<CosmosItemIdentity> itemIdentityList, Class<T> classType)
T
- the type parameteritemIdentityList
- CosmosItem id and partition key tuple of items that that needs to be readclassType
- class typepublic <T> FeedResponse<T> readMany(List<CosmosItemIdentity> itemIdentityList, String sessionToken, Class<T> classType)
T
- the type parameteritemIdentityList
- CosmosItem id and partition key tuple of items that that needs to be readsessionToken
- the optional Session token - null if the read can be made without specific session tokenclassType
- class typepublic <T> CosmosPagedIterable<T> readAllItems(PartitionKey partitionKey, Class<T> classType)
CosmosPagedIterable
.T
- the type parameter.partitionKey
- the partition key value of the documents that need to be readclassType
- the class type.CosmosPagedIterable
.public <T> CosmosPagedIterable<T> readAllItems(PartitionKey partitionKey, CosmosQueryRequestOptions options, Class<T> classType)
CosmosPagedIterable
.
T
- the type parameter.partitionKey
- the partition key value of the documents that need to be readoptions
- the feed options.classType
- the class type.CosmosPagedIterable
.public <T> CosmosItemResponse<T> readItem(String itemId, PartitionKey partitionKey, Class<T> itemType)
T
- the type parameter.itemId
- the item id.partitionKey
- the partition key.itemType
- the class type of item.public <T> CosmosItemResponse<T> readItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options, Class<T> itemType)
T
- the type parameter.itemId
- the item id.partitionKey
- the partition key.options
- the options.itemType
- the class type of item.public <T> CosmosItemResponse<T> replaceItem(T item, String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)
T
- the type parameter.item
- the item.itemId
- the item id.partitionKey
- the partition key.options
- the options.@Beta(value=V4_11_0, warningText="Preview API - subject to change in non-backwards compatible way") public <T> CosmosItemResponse<T> patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, Class<T> itemType)
T
- the type parameter.itemId
- the item id.partitionKey
- the partition key.cosmosPatchOperations
- Represents a container having list of operations to be sequentially applied to the referred Cosmos item.itemType
- the item type.@Beta(value=V4_11_0, warningText="Preview API - subject to change in non-backwards compatible way") public <T> CosmosItemResponse<T> patchItem(String itemId, PartitionKey partitionKey, CosmosPatchOperations cosmosPatchOperations, CosmosPatchItemRequestOptions options, Class<T> itemType)
T
- the type parameter.itemId
- the item id.partitionKey
- the partition key.cosmosPatchOperations
- Represents a container having list of operations to be sequentially applied to the referred Cosmos item.options
- the request options.itemType
- the item type.public CosmosItemResponse<Object> deleteItem(String itemId, PartitionKey partitionKey, CosmosItemRequestOptions options)
itemId
- the item id.partitionKey
- the partition key.options
- the options.public <T> CosmosItemResponse<Object> deleteItem(T item, CosmosItemRequestOptions options)
T
- the type parameter.item
- the item to be deleted.options
- the options.@Beta(value=V4_7_0, warningText="Preview API - subject to change in non-backwards compatible way") public TransactionalBatchResponse executeTransactionalBatch(TransactionalBatch transactionalBatch)
transactionalBatch
- Batch having list of operation and partition key which will be executed by this container.
If the transactional batch executes successfully, the value returned by TransactionalBatchResponse.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 TransactionalBatchResponse.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 TransactionalBatchOperationResult
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
TransactionalBatchOperationResult.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 TransactionalBatchResponse.
Use TransactionalBatchResponse.isSuccessStatusCode()
on the response returned to ensure that the
transactional batch succeeded.
@Beta(value=V4_7_0, warningText="Preview API - subject to change in non-backwards compatible way") public TransactionalBatchResponse executeTransactionalBatch(TransactionalBatch transactionalBatch, TransactionalBatchRequestOptions requestOptions)
transactionalBatch
- Batch having list of operation and partition key which will be executed by this container.requestOptions
- Options that apply specifically to batch request.
If the transactional batch executes successfully, the value returned by TransactionalBatchResponse.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 TransactionalBatchResponse.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 TransactionalBatchOperationResult
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
TransactionalBatchOperationResult.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 TransactionalBatchResponse.
Use TransactionalBatchResponse.isSuccessStatusCode()
on the response returned to ensure that the
transactional batch succeeded.
@Beta(value=V4_9_0, warningText="Preview API - subject to change in non-backwards compatible way") public <TContext> List<CosmosBulkOperationResponse<TContext>> processBulkOperations(Iterable<CosmosItemOperation> operations)
TContext
- The context for the bulk processing.operations
- list of operation which will be executed by this container.CosmosBulkOperationResponse
which contains operation and it's response or exception.
To create a operation which can be executed here, use BulkOperations
. For eg.
for a upsert operation use BulkOperations.getUpsertItemOperation(Object, PartitionKey)
We can get the corresponding operation using CosmosBulkOperationResponse.getOperation()
and
it's response using CosmosBulkOperationResponse.getResponse()
. If the operation was executed
successfully, the value returned by CosmosBulkItemResponse.isSuccessStatusCode()
will be true. To get
actual status use CosmosBulkItemResponse.getStatusCode()
.
CosmosBulkOperationResponse.getException()
to
get the exception.@Beta(value=V4_9_0, warningText="Preview API - subject to change in non-backwards compatible way") @Deprecated public <TContext> List<CosmosBulkOperationResponse<TContext>> processBulkOperations(Iterable<CosmosItemOperation> operations, BulkProcessingOptions<TContext> bulkOptions)
CosmosAsyncContainer.processBulkOperations(Flux)
- CosmosAsyncContainer.processBulkOperations(Flux, BulkExecutionOptions)
- CosmosContainer.processBulkOperations(Iterable)
- CosmosContainer.processBulkOperations(Iterable, BulkExecutionOptions)
and to pass in a custom context use one of the BulkOperations
factory methods allowing to provide
an operation specific contextTContext
- The context for the bulk processing.operations
- list of operation which will be executed by this container.bulkOptions
- Options that apply for this Bulk request which specifies options regarding execution like
concurrency, batching size, interval and context.CosmosBulkOperationResponse
which contains operation and it's response or exception.
To create a operation which can be executed here, use BulkOperations
. For eg.
for a upsert operation use BulkOperations.getUpsertItemOperation(Object, PartitionKey)
We can get the corresponding operation using CosmosBulkOperationResponse.getOperation()
and
it's response using CosmosBulkOperationResponse.getResponse()
. If the operation was executed
successfully, the value returned by CosmosBulkItemResponse.isSuccessStatusCode()
will be true. To get
actual status use CosmosBulkItemResponse.getStatusCode()
.
CosmosBulkOperationResponse.getException()
to
get the exception.@Beta(value=V4_18_0, warningText="Preview API - subject to change in non-backwards compatible way") public <TContext> List<CosmosBulkOperationResponse<TContext>> processBulkOperations(Iterable<CosmosItemOperation> operations, BulkExecutionOptions bulkOptions)
TContext
- The context for the bulk processing.operations
- list of operation which will be executed by this container.bulkOptions
- Options that apply for this Bulk request which specifies options regarding execution like
concurrency, batching size, interval and context.CosmosBulkOperationResponse
which contains operation and it's response or exception.
To create a operation which can be executed here, use BulkOperations
. For eg.
for a upsert operation use BulkOperations.getUpsertItemOperation(Object, PartitionKey)
We can get the corresponding operation using CosmosBulkOperationResponse.getOperation()
and
it's response using CosmosBulkOperationResponse.getResponse()
. If the operation was executed
successfully, the value returned by CosmosBulkItemResponse.isSuccessStatusCode()
will be true. To get
actual status use CosmosBulkItemResponse.getStatusCode()
.
CosmosBulkOperationResponse.getException()
to
get the exception.public CosmosScripts getScripts()
@Beta(value=V4_9_0, warningText="Preview API - subject to change in non-backwards compatible way") public List<FeedRange> getFeedRanges()
FeedRange
that can be used to parallelize Feed
operations.FeedRange
@Beta(value=V4_13_0, warningText="Preview API - subject to change in non-backwards compatible way") public void enableLocalThroughputControlGroup(ThroughputControlGroupConfig groupConfig)
ThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder() .setGroupName("localControlGroup") .setTargetThroughputThreshold(0.1) .build(); container.enableLocalThroughputControlGroup(groupConfig);
groupConfig
- A GlobalThroughputControlConfig
.@Beta(value=V4_13_0, warningText="Preview API - subject to change in non-backwards compatible way") public void enableGlobalThroughputControlGroup(ThroughputControlGroupConfig groupConfig, GlobalThroughputControlConfig globalControlConfig)
ThroughputControlGroupConfig groupConfig = new ThroughputControlGroupConfigBuilder() .setGroupName("localControlGroup") .setTargetThroughputThreshold(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);
groupConfig
- The throughput control group configuration, see GlobalThroughputControlGroup
.globalControlConfig
- The global throughput control configuration, see GlobalThroughputControlConfig
.@Beta(value=V4_14_0, warningText="Preview API - subject to change in non-backwards compatible way") public void openConnectionsAndInitCaches()
The execution of this method is expected to result in some RU charges to your account.
The number of RU consumed by this request varies, depending on data consistency, size of the overall data in the container,
item indexing, number of projections. For more information regarding RU considerations please visit
https://docs.microsoft.com/en-us/azure/cosmos-db/request-units#request-unit-considerations.
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.
Copyright © 2021 Microsoft Corporation. All rights reserved.