Skip to content

Commit

Permalink
Moved batch operations APIs to TableAsyncClient and TableClient. (#21796
Browse files Browse the repository at this point in the history
)

* Introduced TableTransactionAction and TableTransactionActionType. Created the submitTransaction() and submitTransactionWithResponse() methods in TableAsyncClient and TableClient.

* Corrected the Exception type thrown by TableServiceAsyncClient.listTables() and TableAsyncClient.listEntitites()

* Removed TableAsyncBatch and TableBatch and re-recorded tests.

* Fixed SpotBugs issue.

* Changed batch-related class names from Batch* to TransactionalBatch*. Intoduced a new exception for transactional batch operations : TablesTransactionFailedException. Introduced a new return type containing all sub-responses from submitting a transactional batch of actions: TableTransactionResult.

* Added more tests.

* Added transactional batch samples.

* Updated TableTransactionAction's JavaDoc to better reflect the delete scenario's behavior.

* Fixed CheckStyle issues.

* Updated JavaDoc comments.
  • Loading branch information
vcolin7 authored May 28, 2021
1 parent 34a7365 commit 0bd247d
Show file tree
Hide file tree
Showing 43 changed files with 1,439 additions and 1,593 deletions.
11 changes: 11 additions & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## 12.0.0-beta.8 (Unreleased)

### New Features

- Introduced the `TableTransactionAction` class and the `TableTransactionActionType` enum.

### Breaking Changes

- Removed the `TableBatch` and `TableAsyncBatch` types, as well as the methods `TableAsyncClient.createBatch()` and `TableClient.createBatch()`. In their place, batch operations can now be submitted via the following methods:
- `TableAsyncClient.submitTransaction(List<TableTransactionAction> transactionalBatch)`
- `TableAsyncClient.submitTransactionWithResponse(List<TableTransactionAction> transactionalBatch)`
- `TableClient.submitTransaction(List<TableTransactionAction> transactionalBatch)`
- `TableClient.submitTransactionWithResponse(List<TableTransactionAction> transactionalBatch, Duration timeout, Context context)`

## 12.0.0-beta.7 (2021-05-15)

Expand Down

This file was deleted.

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;
import com.azure.data.tables.models.TableTransactionActionResponse;
import com.azure.data.tables.models.ListEntitiesOptions;
import com.azure.data.tables.models.TableEntity;
import com.azure.data.tables.models.TableEntityUpdateMode;
import com.azure.data.tables.models.TableItem;
import com.azure.data.tables.models.TableServiceException;
import com.azure.data.tables.models.TableSignedIdentifier;
import com.azure.data.tables.models.TableTransactionAction;
import com.azure.data.tables.models.TableTransactionFailedException;
import com.azure.data.tables.models.TableTransactionResult;

import java.time.Duration;
import java.util.List;
Expand Down Expand Up @@ -76,24 +80,6 @@ public TableServiceVersion getServiceVersion() {
return this.client.getServiceVersion();
}

/**
* Creates a new {@link TableBatch} object. Batch objects allow you to enqueue multiple create, update, upsert,
* and/or delete operations on entities that share the same partition key. When the batch is executed, all of the
* operations will be performed as part of a single transaction. As a result, either all operations in the batch
* will succeed, or if a failure occurs, all operations in the batch will be rolled back. Each operation in a batch
* must operate on a distinct row key. Attempting to add multiple operations to a batch that share the same row key
* will cause an exception to be thrown.
*
* @param partitionKey The partition key shared by all operations in the batch.
*
* @return An object representing the batch, to which operations can be added.
*
* @throws IllegalArgumentException If the provided partition key is {@code null} or empty.
*/
public TableBatch createBatch(String partitionKey) {
return new TableBatch(this.client.createBatch(partitionKey));
}

/**
* Creates the table within the Tables service.
*
Expand Down Expand Up @@ -360,7 +346,7 @@ public void deleteEntity(TableEntity tableEntity) {
*
* @param partitionKey The partition key of the entity.
* @param rowKey The row key of the entity.
* @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match,
* @param eTag The value to compare with the ETag of the entity in the Tables service. If the values do not match,
* the delete will not occur and an exception will be thrown.
* @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
Expand Down Expand Up @@ -520,4 +506,50 @@ public Response<Void> setAccessPolicyWithResponse(List<TableSignedIdentifier> ta
Duration timeout, Context context) {
return blockWithOptionalTimeout(client.setAccessPolicyWithResponse(tableSignedIdentifiers, context), timeout);
}

/**
* Executes all operations within the list inside a transaction. When the call completes, either all operations in
* the transaction will succeed, or if a failure occurs, all operations in the transaction will be rolled back.
* Each operation must operate on a distinct row key. Attempting to pass multiple operations that share the same
* row key will cause an error.
*
* @param transactionActions A list of {@link TableTransactionAction transaction actions} to perform on entities
* in a table.
*
* @return A list of {@link TableTransactionActionResponse sub-responses} that correspond to each operation in the
* transaction.
*
* @throws IllegalStateException If no operations have been added to the list.
* @throws TableTransactionFailedException if any operation within the transaction fails. See the documentation
* for the client methods in {@link TableClient} to understand the conditions that may cause a given operation to
* fail.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TableTransactionResult submitTransaction(List<TableTransactionAction> transactionActions) {
return client.submitTransaction(transactionActions).block();
}

/**
* Executes all operations within the list inside a transaction. When the call completes, either all operations in
* the transaction will succeed, or if a failure occurs, all operations in the transaction will be rolled back.
* Each operation must operate on a distinct row key. Attempting to pass multiple operations that share the same
* row key will cause an error.
*
* @param transactionActions A list of {@link TableTransactionAction transaction actions} to perform on entities
* in a table.
* @param timeout Duration to wait for the operation to complete.
* @param context Additional context that is passed through the HTTP pipeline during the service call.
*
* @return An HTTP response produced for the transaction itself. The response's value will contain a list of
* {@link TableTransactionActionResponse sub-responses} that correspond to each operation in the transaction.
*
* @throws IllegalStateException If no operations have been added to the list.
* @throws TableTransactionFailedException if any operation within the transaction fails. See the documentation
* for the client methods in {@link TableClient} to understand the conditions that may cause a given operation to
* fail.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<TableTransactionResult> submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Duration timeout, Context context) {
return blockWithOptionalTimeout(client.submitTransactionWithResponse(transactionActions, context), timeout);
}
}
Loading

0 comments on commit 0bd247d

Please sign in to comment.