TableAsyncClient Class

  • java.lang.Object
    • com.azure.data.tables.TableAsyncClient

public final class TableAsyncClient

Provides an asynchronous service client for accessing a table in the Azure Tables service.

Overview

The client encapsulates the URL for the table within the Tables service endpoint, the name of the table, and the credentials for accessing the storage or CosmosDB table API account. It provides methods to create and delete the table itself, as well as methods to create, upsert, update, delete, list, and get entities within the table. These methods invoke REST API operations to make the requests and obtain the results that are returned.

Getting Started

Authenticating and building instances of this client are handled by TableClientBuilder. This sample shows how to authenticate and build a TableClient instance using the TableClientBuilder and a connection string.

TableAsyncClient tableAsyncClient = new TableClientBuilder()
     .connectionString("connectionstring")
     .tableName("myTable")
     .buildAsyncClient();

For more information on building and authenticating, see the TableClientBuilder documentation.

The following code samples provide examples of common operations preformed with this client.


Create a TableEntity

The createEntity(TableEntity entity) method can be used to create a table entity within a table in your Azure Storage or Azure Cosmos account.

The sample below creates a TableEntity with a partition key of "partitionKey" and a row key of "rowKey".

TableEntity tableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.createEntity(tableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was created.", "partitionKey",
             "rowKey"));

Note: for a synchronous sample, refer to TableClient


Retrieve a TableEntity

The getEntity(String partitionKey, String rowKey) method can be used to retrieve a table entity within a table in your Azure Storage or Azure Cosmos account.

The sample below retrieves a TableEntity with a partition key of "partitionKey" and a row key of "rowKey".

tableAsyncClient.getEntity("partitionKey", "rowKey")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(tableEntity ->
         System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.",
             tableEntity.getPartitionKey(), tableEntity.getRowKey()));

Note: for a synchronous sample, refer to TableClient


Update a TableEntity

The updateEntity(TableEntity entity) method can be used to update a table entity within a table in your Azure Storage or Azure Cosmos account.

The sample below updates a TableEntity with a partition key of "partitionKey" and a row key of "rowKey", adding a new property with a key of "Property" and a value of "Value".

TableEntity myTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.updateEntity(myTableEntity, TableEntityUpdateMode.REPLACE)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was updated/created.",
             "partitionKey", "rowKey"));

Note: for a synchronous sample, refer to TableClient


Listing TableEntity

The listEntities() method can be used to list the entities within a table in your Azure Storage or Azure Cosmos account.

The sample below lists all TableEntity within the table without filtering out any entities.

tableAsyncClient.listEntities()
     .subscribe(tableEntity ->
         System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.%n",
             tableEntity.getPartitionKey(), tableEntity.getRowKey()));

List TableEntity with filtering and selecting

The sample below lists TableEntity within the table, filtering out any entities that do not have a partition key of "partitionKey" and a row key of "rowKey" and only selects the "name", "lastname", and "age" properties.

List<String> propertiesToSelect = new ArrayList<>();
 propertiesToSelect.add("name");
 propertiesToSelect.add("lastname");
 propertiesToSelect.add("age");

 ListEntitiesOptions listEntitiesOptions = new ListEntitiesOptions()
     .setTop(15)
     .setFilter("PartitionKey eq 'MyPartitionKey' and RowKey eq 'MyRowKey'")
     .setSelect(propertiesToSelect);

 tableAsyncClient.listEntities(listEntitiesOptions)
     .subscribe(tableEntity -> {
         System.out.printf("Retrieved entity with partition key '%s', row key '%s' and properties:%n",
             tableEntity.getPartitionKey(), tableEntity.getRowKey());

         tableEntity.getProperties().forEach((key, value) ->
             System.out.printf("Name: '%s'. Value: '%s'.%n", key, value));
     });

Note: for a synchronous sample, refer to TableClient


Delete a TableEntity

The deleteEntity(String partitionKey, String rowKey) method can be used to delete a table entity within a table in your Azure Storage or Azure Cosmos account.

The sample below deletes a TableEntity with a partition key of "partitionKey" and a row key of "rowKey".

tableAsyncClient.deleteEntity("partitionKey", "rowKey")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was deleted.", "partitionKey",
             "rowKey"));

Note: for a synchronous sample, refer to TableClient


Submit a transactional batch

The submitTransaction(List<TableTransactionAction> transactionActions) method can be used to submit a transactional batch of actions to perform on the table in your Azure Storage or Azure Cosmos account.

The sample below shows how to prepare and submit a transactional batch with multiple actions.

List<TableTransactionAction> transactionActions = new ArrayList<>();

 String partitionKey = "markers";
 String firstEntityRowKey = "m001";
 String secondEntityRowKey = "m002";

 TableEntity firstEntity = new TableEntity(partitionKey, firstEntityRowKey)
     .addProperty("Type", "Dry")
     .addProperty("Color", "Red");

 transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, firstEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", partitionKey,
     firstEntityRowKey);

 TableEntity secondEntity = new TableEntity(partitionKey, secondEntityRowKey)
     .addProperty("Type", "Wet")
     .addProperty("Color", "Blue");

 transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, secondEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", partitionKey,
     secondEntityRowKey);

 tableAsyncClient.submitTransaction(transactionActions)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(tableTransactionResult -> {
         System.out.print("Submitted transaction. The ordered response status codes for the actions are:");

         tableTransactionResult.getTransactionActionResponses().forEach(tableTransactionActionResponse ->
             System.out.printf("%n%d", tableTransactionActionResponse.getStatusCode()));
     });

Note: for a synchronous sample, refer to TableClient

Method Summary

Modifier and Type Method and Description
Mono<Void> createEntity(TableEntity entity)

Inserts an TableEntity into the table.

Mono<Response<Void>> createEntityWithResponse(TableEntity entity)

Inserts an TableEntity into the table.

Mono<TableItem> createTable()

Creates the table within the Tables service.

Mono<Response<TableItem>> createTableWithResponse()

Creates the table within the Tables service.

Mono<Void> deleteEntity(TableEntity entity)

Deletes an TableEntity from the table.

Mono<Void> deleteEntity(String partitionKey, String rowKey)

Deletes an TableEntity from the table.

Mono<Response<Void>> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged)

Deletes an TableEntity from the table.

Mono<Void> deleteTable()

Deletes the table within the Tables service.

Mono<Response<Void>> deleteTableWithResponse()

Deletes the table within the Tables service.

String generateSas(TableSasSignatureValues tableSasSignatureValues)

Generates a service SAS for the table using the specified TableSasSignatureValues.

Mono<TableAccessPolicies> getAccessPolicies()

Retrieves details about any stored TableAccessPolicies specified on the table that may be used with Shared Access Signatures.

Mono<Response<TableAccessPolicies>> getAccessPoliciesWithResponse()

Retrieves details about any stored TableAccessPolicies specified on the table that may be used with Shared Access Signatures.

String getAccountName()

Gets the name of the account containing the table.

Mono<TableEntity> getEntity(String partitionKey, String rowKey)

Gets a single TableEntity from the table.

Mono<Response<TableEntity>> getEntityWithResponse(String partitionKey, String rowKey, List<String> select)

Gets a single TableEntity from the table.

TableServiceVersion getServiceVersion()

Gets the REST API version used by this client.

String getTableEndpoint()

Gets the endpoint for this table.

String getTableName()

Gets the name of the table.

PagedFlux<TableEntity> listEntities()

Lists all TableEntity within the table.

PagedFlux<TableEntity> listEntities(ListEntitiesOptions options)

Lists TableEntity using the parameters in the provided options.

Mono<Void> setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers)

Sets stored TableAccessPolicies for the table that may be used with Shared Access Signatures.

Mono<Response<Void>> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers)

Sets stored TableAccessPolicies for the table that may be used with Shared Access Signatures.

Mono<TableTransactionResult> submitTransaction(List<TableTransactionAction> transactionActions)

Executes all TableTransactionAction within the list inside a transaction.

Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableTransactionAction> transactionActions)

Executes all TableTransactionAction within the list inside a transaction.

Mono<Void> updateEntity(TableEntity entity)

Updates an existing TableEntity by merging the provided TableEntity with the existing TableEntity.

Mono<Void> updateEntity(TableEntity entity, TableEntityUpdateMode updateMode)

Updates an existing TableEntity using the specified TableEntityUpdateMode.

Mono<Response<Void>> updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged)

Updates an existing TableEntity using the specified TableEntityUpdateMode.

Mono<Void> upsertEntity(TableEntity entity)

Inserts an TableEntity into the table if it does not exist, or merges the TableEntity with the existing TableEntity otherwise.

Mono<Response<Void>> upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode)

Inserts an TableEntity into the table if it does not exist, or updates the existing TableEntity using the specified TableEntityUpdateMode otherwise.

Methods inherited from java.lang.Object

Method Details

createEntity

public Mono createEntity(TableEntity entity)

Inserts an TableEntity into the table.

Code Samples

Inserts an TableEntity into the table. Prints out the details of the created TableEntity.

TableEntity tableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.createEntity(tableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was created.", "partitionKey",
             "rowKey"));

Parameters:

entity - The TableEntity to insert.

Returns:

An empty Mono.

createEntityWithResponse

public Mono<>> createEntityWithResponse(TableEntity entity)

Inserts an TableEntity into the table.

Code Samples

Inserts an TableEntity into the table. Prints out the details of the Response<T> and the created TableEntity.

TableEntity myTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.createEntityWithResponse(myTableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and"
             + " row key '%s' was created.", response.getStatusCode(), "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to insert.

Returns:

A Mono containing the Response<T>.

createTable

public Mono createTable()

Creates the table within the Tables service.

Code Samples

Creates a table. Prints out the details of the created table.

tableAsyncClient.createTable()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(tableItem ->
         System.out.printf("Table with name '%s' was created.", tableItem.getName()));

Returns:

A Mono containing a TableItem that represents the table.

createTableWithResponse

public Mono<>> createTableWithResponse()

Creates the table within the Tables service.

Code Samples

Creates a table. Prints out the details of the Response<T> and the created table.

tableAsyncClient.createTableWithResponse()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table with name '%s' was created.",
             response.getStatusCode(), response.getValue().getName()));

Returns:

A Mono containing the Response<T> that in turn contains a TableItem that represents the table.

deleteEntity

public Mono deleteEntity(TableEntity entity)

Deletes an TableEntity from the table.

Code Samples

Deletes a TableEntity on the table. Prints out the details of the deleted TableEntity.

TableEntity myTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.deleteEntity(myTableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was created.", "partitionKey",
             "rowKey"));

Parameters:

entity - The TableEntity to delete.

Returns:

An empty Mono.

deleteEntity

public Mono deleteEntity(String partitionKey, String rowKey)

Deletes an TableEntity from the table.

Code Samples

Deletes an TableEntity on the table. Prints out the entity's partitionKey and rowKey.

tableAsyncClient.deleteEntity("partitionKey", "rowKey")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was deleted.", "partitionKey",
             "rowKey"));

Parameters:

partitionKey - The partition key of the TableEntity.
rowKey - The row key of the TableEntity.

Returns:

An empty Mono.

deleteEntityWithResponse

public Mono<>> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged)

Deletes an TableEntity from the table.

Code Samples

Deletes a TableEntity on the table. Prints out the details of the Response<T> and the deleted TableEntity.

TableEntity someTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.deleteEntityWithResponse(someTableEntity, true)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and"
             + " row key '%s' was deleted.", response.getStatusCode(), "partitionKey", "rowKey"));

Parameters:

entity - The table TableEntity to delete.
ifUnchanged - When true, the ETag of the provided TableEntity must match the ETag of the TableEntity in the Table service. If the values do not match, the update will not occur and an exception will be thrown.

Returns:

A Mono containing the Response<T>.

deleteTable

public Mono deleteTable()

Deletes the table within the Tables service.

Code Samples

Deletes a table.

tableAsyncClient.deleteTable()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused -> System.out.print("Table was deleted."));

Returns:

An empty Mono.

deleteTableWithResponse

public Mono<>> deleteTableWithResponse()

Deletes the table within the Tables service.

Code Samples

Deletes a table. Prints out the details of the Response<T>.

tableAsyncClient.deleteTableWithResponse()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Table was deleted successfully with status code: %d.",
             response.getStatusCode()));

Returns:

A Mono containing the Response<T>.

generateSas

public String generateSas(TableSasSignatureValues tableSasSignatureValues)

Generates a service SAS for the table using the specified TableSasSignatureValues.

Note: The client must be authenticated via AzureNamedKeyCredential.

See TableSasSignatureValues for more information on how to construct a service SAS.

Parameters:

tableSasSignatureValues - TableSasSignatureValues.

Returns:

A String representing the SAS query parameters.

getAccessPolicies

public Mono getAccessPolicies()

Retrieves details about any stored TableAccessPolicies specified on the table that may be used with Shared Access Signatures.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets a table's TableAccessPolicies. Prints out the details of the retrieved TableAccessPolicies.

tableAsyncClient.getAccessPolicies()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(accessPolicies ->
         accessPolicies.getIdentifiers().forEach(signedIdentifier ->
             System.out.printf("Retrieved table access policy with id '%s'.", signedIdentifier.getId())));

Returns:

A Mono containing the table's TableAccessPolicies.

getAccessPoliciesWithResponse

public Mono<>> getAccessPoliciesWithResponse()

Retrieves details about any stored TableAccessPolicies specified on the table that may be used with Shared Access Signatures.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets a table's TableAccessPolicies. Prints out the details of the Response<T> and the retrieved TableAccessPolicies.

List<String> propertiesToSelect = new ArrayList<>();
 propertiesToSelect.add("name");
 propertiesToSelect.add("lastname");
 propertiesToSelect.add("age");

 tableAsyncClient.getAccessPoliciesWithResponse()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response -> {
         System.out.printf("Response successful with status code: %d. Retrieved table access policies with the"
             + " following IDs:", response.getStatusCode());

         response.getValue().getIdentifiers().forEach(signedIdentifier ->
             System.out.printf("%n%s", signedIdentifier.getId()));
     });

Returns:

A Mono containing an Response<T> that in turn contains the table's TableAccessPolicies.

getAccountName

public String getAccountName()

Gets the name of the account containing the table.

Returns:

The name of the account containing the table.

getEntity

public Mono getEntity(String partitionKey, String rowKey)

Gets a single TableEntity from the table.

Code Samples

Gets an TableEntity on the table. Prints out the details of the retrieved TableEntity.

tableAsyncClient.getEntity("partitionKey", "rowKey")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(tableEntity ->
         System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.",
             tableEntity.getPartitionKey(), tableEntity.getRowKey()));

Parameters:

partitionKey - The partition key of the TableEntity.
rowKey - The partition key of the TableEntity.

Returns:

A Mono containing the TableEntity.

getEntityWithResponse

public Mono<>> getEntityWithResponse(String partitionKey, String rowKey, List select)

Gets a single TableEntity from the table.

Code Samples

Gets an TableEntity on the table. Prints out the details of the Response<T> retrieved TableEntity.

List<String> propertiesToSelect = new ArrayList<>();
 propertiesToSelect.add("name");
 propertiesToSelect.add("lastname");
 propertiesToSelect.add("age");

 tableAsyncClient.getEntityWithResponse("partitionKey", "rowKey", propertiesToSelect)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response -> {
         TableEntity tableEntity = response.getValue();

         System.out.printf("Response successful with status code: %d. Retrieved entity with partition key '%s',"
                 + " row key '%s' and properties:", response.getStatusCode(), tableEntity.getPartitionKey(),
             tableEntity.getRowKey());

         tableEntity.getProperties().forEach((key, value) ->
             System.out.printf("%nName: '%s'. Value: '%s'.", key, value));
     });

Parameters:

partitionKey - The partition key of the TableEntity.
rowKey - The partition key of the TableEntity.
select - A list of properties to select on the TableEntity.

Returns:

A Mono containing the Response<T> that in turn contains the TableEntity.

getServiceVersion

public TableServiceVersion getServiceVersion()

Gets the REST API version used by this client.

Returns:

The REST API version used by this client.

getTableEndpoint

public String getTableEndpoint()

Gets the endpoint for this table.

Returns:

The endpoint for this table.

getTableName

public String getTableName()

Gets the name of the table.

Returns:

The name of the table.

listEntities

public PagedFlux listEntities()

Lists all TableEntity within the table.

Code Samples

Lists all TableEntity on the table. Prints out the details of the retrieved TableEntity.

tableAsyncClient.listEntities()
     .subscribe(tableEntity ->
         System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.%n",
             tableEntity.getPartitionKey(), tableEntity.getRowKey()));

Returns:

A PagedFlux<T> containing all TableEntity within the table.

listEntities

public PagedFlux listEntities(ListEntitiesOptions options)

Lists TableEntity using the parameters in the provided options.

If the filter parameter in the options is set, only TableEntity matching the filter will be returned. If the select parameter is set, only the properties included in the select parameter will be returned for each TableEntity. If the top parameter is set, the maximum number of returned TableEntity per page will be limited to that value.

Code Samples

Lists all TableEntity on the table. Prints out the details of the Response<T> and all the retrieved TableEntity.

List<String> propertiesToSelect = new ArrayList<>();
 propertiesToSelect.add("name");
 propertiesToSelect.add("lastname");
 propertiesToSelect.add("age");

 ListEntitiesOptions listEntitiesOptions = new ListEntitiesOptions()
     .setTop(15)
     .setFilter("PartitionKey eq 'MyPartitionKey' and RowKey eq 'MyRowKey'")
     .setSelect(propertiesToSelect);

 tableAsyncClient.listEntities(listEntitiesOptions)
     .subscribe(tableEntity -> {
         System.out.printf("Retrieved entity with partition key '%s', row key '%s' and properties:%n",
             tableEntity.getPartitionKey(), tableEntity.getRowKey());

         tableEntity.getProperties().forEach((key, value) ->
             System.out.printf("Name: '%s'. Value: '%s'.%n", key, value));
     });

Parameters:

options - The filter, select, and top OData query options to apply to this operation.

Returns:

A PagedFlux<T> containing matching TableEntity within the table.

setAccessPolicies

public Mono setAccessPolicies(List tableSignedIdentifiers)

Sets stored TableAccessPolicies for the table that may be used with Shared Access Signatures.

This operation is only supported on Azure Storage endpoints.

Code Samples

Sets stored TableAccessPolicies on a table.

List<TableSignedIdentifier> signedIdentifiers = new ArrayList<>();

 signedIdentifiers.add(new TableSignedIdentifier("id1")
     .setAccessPolicy(new TableAccessPolicy()
         .setStartsOn(OffsetDateTime.of(2021, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setExpiresOn(OffsetDateTime.of(2022, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setPermissions("r")));
 signedIdentifiers.add(new TableSignedIdentifier("id2")
     .setAccessPolicy(new TableAccessPolicy()
         .setStartsOn(OffsetDateTime.of(2021, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setExpiresOn(OffsetDateTime.of(2021, 1, 2, 0, 0, 0, 0, ZoneOffset.UTC))
         .setPermissions("raud")));

 tableAsyncClient.setAccessPolicies(signedIdentifiers)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused -> System.out.print("Set table access policies."));

Parameters:

tableSignedIdentifiers - The TableSignedIdentifier for the table.

Returns:

An empty Mono.

setAccessPoliciesWithResponse

public Mono<>> setAccessPoliciesWithResponse(List tableSignedIdentifiers)

Sets stored TableAccessPolicies for the table that may be used with Shared Access Signatures.

This operation is only supported on Azure Storage endpoints.

Code Samples

Sets stored TableAccessPolicies on a table. Prints out details of the Response<T>.

List<TableSignedIdentifier> mySignedIdentifiers = new ArrayList<>();

 mySignedIdentifiers.add(new TableSignedIdentifier("id1")
     .setAccessPolicy(new TableAccessPolicy()
         .setStartsOn(OffsetDateTime.of(2021, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setExpiresOn(OffsetDateTime.of(2022, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setPermissions("r")));
 mySignedIdentifiers.add(new TableSignedIdentifier("id2")
     .setAccessPolicy(new TableAccessPolicy()
         .setStartsOn(OffsetDateTime.of(2021, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
         .setExpiresOn(OffsetDateTime.of(2021, 1, 2, 0, 0, 0, 0, ZoneOffset.UTC))
         .setPermissions("raud")));

 tableAsyncClient.setAccessPoliciesWithResponse(mySignedIdentifiers)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Set table access policies successfully with status code: %d.",
             response.getStatusCode()));

Parameters:

tableSignedIdentifiers - The TableSignedIdentifier for the table.

Returns:

A Mono containing the Response<T>.

submitTransaction

public Mono submitTransaction(List transactionActions)

Executes all TableTransactionAction within the list inside a transaction. When the call completes, either all TableTransactionAction in the transaction will succeed, or if a failure occurs, all TableTransactionAction in the transaction will be rolled back. Each TableTransactionAction must operate on a distinct row key. Attempting to pass multiple TableTransactionAction that share the same row key will cause an error.

Code Samples

Submits a transaction that contains multiple TableTransactionAction to be applied to TableEntity on a table. Prints out details of each TableTransactionAction's Response<T>.

List<TableTransactionAction> transactionActions = new ArrayList<>();

 String partitionKey = "markers";
 String firstEntityRowKey = "m001";
 String secondEntityRowKey = "m002";

 TableEntity firstEntity = new TableEntity(partitionKey, firstEntityRowKey)
     .addProperty("Type", "Dry")
     .addProperty("Color", "Red");

 transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, firstEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", partitionKey,
     firstEntityRowKey);

 TableEntity secondEntity = new TableEntity(partitionKey, secondEntityRowKey)
     .addProperty("Type", "Wet")
     .addProperty("Color", "Blue");

 transactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, secondEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", partitionKey,
     secondEntityRowKey);

 tableAsyncClient.submitTransaction(transactionActions)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(tableTransactionResult -> {
         System.out.print("Submitted transaction. The ordered response status codes for the actions are:");

         tableTransactionResult.getTransactionActionResponses().forEach(tableTransactionActionResponse ->
             System.out.printf("%n%d", tableTransactionActionResponse.getStatusCode()));
     });

Shows how to handle a transaction with a failing TableTransactionAction via the provided TableTransactionFailedException, which contains the index of the first failing action in the transaction.

try {
     TableTransactionResult transactionResult = tableClient.submitTransaction(transactionActions);

     System.out.print("Submitted transaction. The ordered response status codes for the actions are:");

     transactionResult.getTransactionActionResponses().forEach(tableTransactionActionResponse ->
         System.out.printf("%n%d", tableTransactionActionResponse.getStatusCode()));
 } catch (TableTransactionFailedException e) {
     // If the transaction fails, the resulting exception contains the index of the first action that failed.
     int failedActionIndex = e.getFailedTransactionActionIndex();
     // You can use this index to modify the offending action or remove it from the list of actions to send in
     // the transaction, for example.
     transactionActions.remove(failedActionIndex);
     // And then retry submitting the transaction.
 }

Parameters:

transactionActions - A List of TableTransactionAction to perform on TableEntity in a table.

Returns:

A Mono containing a List of TableTransactionActionResponse that correspond to each TableTransactionAction in the transaction.

submitTransactionWithResponse

public Mono<>> submitTransactionWithResponse(List transactionActions)

Executes all TableTransactionAction within the list inside a transaction. When the call completes, either all TableTransactionAction in the transaction will succeed, or if a failure occurs, all TableTransactionAction in the transaction will be rolled back. Each TableTransactionAction must operate on a distinct row key. Attempting to pass multiple TableTransactionAction that share the same row key will cause an error.

Code Samples

Submits a transaction that contains multiple TableTransactionAction to be applied to TableEntity on a table. Prints out details of the Response<T> for the operation, as well as each TableTransactionAction's corresponding HTTP response.

List<TableTransactionAction> myTransactionActions = new ArrayList<>();

 String myPartitionKey = "markers";
 String myFirstEntityRowKey = "m001";
 String mySecondEntityRowKey = "m002";

 TableEntity myFirstEntity = new TableEntity(myPartitionKey, myFirstEntityRowKey)
     .addProperty("Type", "Dry")
     .addProperty("Color", "Red");

 myTransactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, myFirstEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", myPartitionKey,
     myFirstEntityRowKey);

 TableEntity mySecondEntity = new TableEntity(myPartitionKey, mySecondEntityRowKey)
     .addProperty("Type", "Wet")
     .addProperty("Color", "Blue");

 myTransactionActions.add(new TableTransactionAction(TableTransactionActionType.CREATE, mySecondEntity));

 System.out.printf("Added create action for entity with partition key '%s', and row key '%s'.%n", myPartitionKey,
     mySecondEntityRowKey);

 tableAsyncClient.submitTransactionWithResponse(myTransactionActions)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response -> {
         System.out.printf("Response successful with status code: %d. The ordered response status codes of the"
             + " submitted actions are:", response.getStatusCode());

         response.getValue().getTransactionActionResponses().forEach(tableTransactionActionResponse ->
             System.out.printf("%n%d", tableTransactionActionResponse.getStatusCode()));
     });

Shows how to handle a transaction with a failing TableTransactionAction via the provided TableTransactionFailedException, which contains the index of the first failing action in the transaction.

tableAsyncClient.submitTransactionWithResponse(myTransactionActions)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .doOnError(TableTransactionFailedException.class, e -> {
         // If the transaction fails, the resulting exception contains the index of the first action that failed.
         int failedActionIndex = e.getFailedTransactionActionIndex();
         // You can use this index to modify the offending action or remove it from the list of actions to send
         // in the transaction, for example.
         transactionActions.remove(failedActionIndex);
         // And then retry submitting the transaction.
     })
     .subscribe(response -> {
         System.out.printf("Response successful with status code: %d. The ordered response status codes of the"
             + " submitted actions are:", response.getStatusCode());

         response.getValue().getTransactionActionResponses().forEach(tableTransactionActionResponse ->
             System.out.printf("%n%d", tableTransactionActionResponse.getStatusCode()));
     });

Parameters:

transactionActions - A List of TableTransactionAction to perform on TableEntity in a table.

Returns:

A Mono containing the Response<T> produced for the transaction itself. The response's value will contain a List of TableTransactionActionResponse that correspond to each TableTransactionAction in the transaction.

updateEntity

public Mono updateEntity(TableEntity entity)

Updates an existing TableEntity by merging the provided TableEntity with the existing TableEntity.

Code Samples

Updates a TableEntity on the table. Prints out the details of the updated TableEntity.

TableEntity tableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.updateEntity(tableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was updated/created.",
             "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to update.

Returns:

An empty Mono.

updateEntity

public Mono updateEntity(TableEntity entity, TableEntityUpdateMode updateMode)

Updates an existing TableEntity using the specified TableEntityUpdateMode. The default TableEntityUpdateMode is MERGE.

When the TableEntityUpdateMode is MERGE, the provided TableEntity's properties will be merged into the existing TableEntity. When the TableEntityUpdateMode is REPLACE, the provided TableEntity's properties will completely replace those in the existing TableEntity.

Code Samples

Updates a TableEntity on the table with the specified TableEntityUpdateMode. Prints out the details of the updated TableEntity.

TableEntity myTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.updateEntity(myTableEntity, TableEntityUpdateMode.REPLACE)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was updated/created.",
             "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to update.
updateMode - The type of update to perform.

Returns:

An empty Mono.

updateEntityWithResponse

public Mono<>> updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged)

Updates an existing TableEntity using the specified TableEntityUpdateMode. The default TableEntityUpdateMode is MERGE.

When the TableEntityUpdateMode is MERGE, the provided TableEntity's properties will be merged into the existing TableEntity. When the TableEntityUpdateMode is REPLACE, the provided TableEntity's properties will completely replace those in the existing TableEntity.

Code Samples

Updates a TableEntity on the table with the specified update mode if the ETags on both TableEntity match. Prints out the details of the Response<T> updated TableEntity.

TableEntity someTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.updateEntityWithResponse(someTableEntity, TableEntityUpdateMode.REPLACE, true)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and"
             + " row key '%s' was updated.", response.getStatusCode(), "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to update.
updateMode - The type of update to perform.
ifUnchanged - When true, the ETag of the provided TableEntity must match the ETag of the TableEntity in the Table service. If the values do not match, the update will not occur and an exception will be thrown.

Returns:

A Mono containing the Response<T>.

upsertEntity

public Mono upsertEntity(TableEntity entity)

Inserts an TableEntity into the table if it does not exist, or merges the TableEntity with the existing TableEntity otherwise.

Code Samples

Upserts an TableEntity into the table. Prints out the details of the upserted TableEntity.

TableEntity tableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.upsertEntity(tableEntity)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table entity with partition key '%s' and row key '%s' was updated/created.",
             "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to upsert.

Returns:

An empty Mono.

upsertEntityWithResponse

public Mono<>> upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode)

Inserts an TableEntity into the table if it does not exist, or updates the existing TableEntity using the specified TableEntityUpdateMode otherwise. The default TableEntityUpdateMode is MERGE.

When the TableEntityUpdateMode is MERGE, the provided TableEntity's properties will be merged into the existing TableEntity. When the TableEntityUpdateMode is REPLACE, the provided TableEntity's properties will completely replace those in the existing TableEntity.

Code Samples

Upserts an TableEntity into the table with the specified TableEntityUpdateMode if said TableEntity already exists. Prints out the details of the Response<T> and the upserted TableEntity.

TableEntity myTableEntity = new TableEntity("partitionKey", "rowKey")
     .addProperty("Property", "Value");

 tableAsyncClient.upsertEntityWithResponse(myTableEntity, TableEntityUpdateMode.REPLACE)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and"
             + " row key '%s' was updated/created.", response.getStatusCode(), "partitionKey", "rowKey"));

Parameters:

entity - The TableEntity to upsert.
updateMode - The type of update to perform if the TableEntity already exits.

Returns:

A Mono containing the Response<T>.

Applies to