Hi Xu, Kyson K •,
Thanks for posting this question in Microsoft Q&A forum.
As I understand, you need to know how to control CosmosDB acid transactions (commit and rollback) using JAVA SDK.
In the .NET and Java SDKs, the TransactionalBatch class is used to define this batch of operations. If all operations succeed in the order they're described within the transactional batch operation, the transaction will be committed. However, if any operation fails, the entire transaction is rolled back.
Reference Link: Transaction Batch Operations in Azure Cosmos DB using the .NET or Java SDK.
When the ExecuteAsync
method is called, all operations in the TransactionalBatch
object are grouped, serialized into a single payload, and sent as a single request to the Azure Cosmos DB service.
The service receives the request and executes all operations within a transactional scope, and returns a response using the same serialization protocol. This response is either a success, or a failure, and supplies individual operation responses per operation.
The SDK exposes the response for you to verify the result and, optionally, extract each of the internal operation results.
Hope this information helps.
Do let us know if you have further queries. Thank you.