public final class TableClient extends Object
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.
Instances of this client are obtained by calling the TableClientBuilder.buildClient() method on a
TableClientBuilder object.
Samples to construct a sync client
TableClient tableClient = new TableClientBuilder()
.endpoint("https://myaccount.core.windows.net/")
.credential(new AzureNamedKeyCredential("name", "key"))
.tableName("myTable")
.buildClient();
TableClientBuilder| Modifier and Type | Method and Description |
|---|---|
void |
createEntity(TableEntity entity)
Inserts an
entity into the table. |
com.azure.core.http.rest.Response<Void> |
createEntityWithResponse(TableEntity entity,
Duration timeout,
com.azure.core.util.Context context)
Inserts an
entity into the table. |
TableItem |
createTable()
Creates the table within the Tables service.
|
com.azure.core.http.rest.Response<TableItem> |
createTableWithResponse(Duration timeout,
com.azure.core.util.Context context)
Creates the table within the Tables service.
|
void |
deleteEntity(String partitionKey,
String rowKey)
Deletes an
entity from the table. |
void |
deleteEntity(TableEntity entity)
Deletes an
entity from the table. |
com.azure.core.http.rest.Response<Void> |
deleteEntityWithResponse(TableEntity entity,
boolean ifUnchanged,
Duration timeout,
com.azure.core.util.Context context)
Deletes an
entity from the table. |
void |
deleteTable()
Deletes the table within the Tables service.
|
com.azure.core.http.rest.Response<Void> |
deleteTableWithResponse(Duration timeout,
com.azure.core.util.Context context)
Deletes the table within the Tables service.
|
String |
generateSas(TableSasSignatureValues tableSasSignatureValues)
Generates a service SAS for the table using the specified
TableSasSignatureValues. |
TableAccessPolicies |
getAccessPolicies()
Retrieves details about any stored
access policies specified on the table that may
be used with Shared Access Signatures. |
com.azure.core.http.rest.Response<TableAccessPolicies> |
getAccessPoliciesWithResponse(Duration timeout,
com.azure.core.util.Context context)
Retrieves details about any stored
access policies specified on the table that may be
used with Shared Access Signatures. |
String |
getAccountName()
Gets the name of the account containing the table.
|
TableEntity |
getEntity(String partitionKey,
String rowKey)
Gets a single
entity from the table. |
com.azure.core.http.rest.Response<TableEntity> |
getEntityWithResponse(String partitionKey,
String rowKey,
List<String> select,
Duration timeout,
com.azure.core.util.Context context)
Gets a single
entity 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.
|
com.azure.core.http.rest.PagedIterable<TableEntity> |
listEntities()
Lists all
entities within the table. |
com.azure.core.http.rest.PagedIterable<TableEntity> |
listEntities(ListEntitiesOptions options,
Duration timeout,
com.azure.core.util.Context context)
Lists
entities using the parameters in the provided options. |
void |
setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers)
Sets stored
access policies for the table that may be used with Shared Access
Signatures. |
com.azure.core.http.rest.Response<Void> |
setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers,
Duration timeout,
com.azure.core.util.Context context)
Sets stored
access policies for the table that may be used with Shared Access
Signatures. |
TableTransactionResult |
submitTransaction(List<TableTransactionAction> transactionActions)
Executes all
actions within the list inside a transaction. |
com.azure.core.http.rest.Response<TableTransactionResult> |
submitTransactionWithResponse(List<TableTransactionAction> transactionActions,
Duration timeout,
com.azure.core.util.Context context)
Executes all
actions within the list inside a transaction. |
void |
updateEntity(TableEntity entity)
|
void |
updateEntity(TableEntity entity,
TableEntityUpdateMode updateMode)
Updates an existing
entity using the specified update mode. |
com.azure.core.http.rest.Response<Void> |
updateEntityWithResponse(TableEntity entity,
TableEntityUpdateMode updateMode,
boolean ifUnchanged,
Duration timeout,
com.azure.core.util.Context context)
Updates an existing
entity using the specified update mode. |
void |
upsertEntity(TableEntity entity)
|
com.azure.core.http.rest.Response<Void> |
upsertEntityWithResponse(TableEntity entity,
TableEntityUpdateMode updateMode,
Duration timeout,
com.azure.core.util.Context context)
Inserts an
entity into the table if it does not exist, or updates the existing
entity using the specified update mode otherwise. |
public String getTableName()
public String getAccountName()
public String getTableEndpoint()
public TableServiceVersion getServiceVersion()
public String generateSas(TableSasSignatureValues tableSasSignatureValues)
TableSasSignatureValues.
Note: The client must be authenticated via AzureNamedKeyCredential.
See TableSasSignatureValues for more information on how to construct a service SAS.
tableSasSignatureValues - TableSasSignatureValues.String representing the SAS query parameters.IllegalStateException - If this TableClient is not authenticated with an
AzureNamedKeyCredential.public TableItem createTable()
Code Samples
Creates a table. Prints out the details of the created table.
TableItem tableItem = tableClient.createTable();
System.out.printf("Table with name '%s' was created.", tableItem.getName());
TableItem that represents the table.TableServiceException - If a table with the same name already exists within the service.public com.azure.core.http.rest.Response<TableItem> createTableWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Creates a table. Prints out the details of the HTTP response and the created table.
Response<TableItem> response = tableClient.createTableWithResponse(Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Response successful with status code: %d. Table with name '%s' was created.",
response.getStatusCode(), response.getValue().getName());
timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response containing a TableItem that represents the table.TableServiceException - If a table with the same name already exists within the service.public void deleteTable()
Code Samples
Deletes a table.
tableClient.deleteTable();
System.out.print("Table was deleted.");
TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> deleteTableWithResponse(Duration timeout, com.azure.core.util.Context context)
Code Samples
Deletes a table. Prints out the details of the HTTP response.
Response<Void> response = tableClient.deleteTableWithResponse(Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Table was deleted successfully with status code: %d.", response.getStatusCode());
timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.TableServiceException - If the request is rejected by the service.public void createEntity(TableEntity entity)
entity into the table.
Code Samples
Inserts an entity into the table. Prints out the details of the created
entity.
String partitionKey = "partitionKey";
String rowKey = "rowKey";
TableEntity tableEntity = new TableEntity(partitionKey, rowKey)
.addProperty("Property", "Value");
tableClient.createEntity(tableEntity);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was created.", partitionKey, rowKey);
entity - The entity to insert.TableServiceException - If an entity with the same partition key and row key already
exists within the table.IllegalArgumentException - If the provided entity is null.public com.azure.core.http.rest.Response<Void> createEntityWithResponse(TableEntity entity, Duration timeout, com.azure.core.util.Context context)
entity into the table.
Code Samples
Inserts an entity into the table. Prints out the details of the
HTTP response and the created entity.
String myPartitionKey = "partitionKey";
String myRowKey = "rowKey";
TableEntity myTableEntity = new TableEntity(myPartitionKey, myRowKey)
.addProperty("Property", "Value");
Response<Void> response = tableClient.createEntityWithResponse(myTableEntity, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and row key"
+ " '%s' was created.", response.getStatusCode(), myPartitionKey, myRowKey);
entity - The entity to insert.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.TableServiceException - If an entity with the same partition key and row key already
exists within the table.IllegalArgumentException - If the provided entity is null.public void upsertEntity(TableEntity entity)
entity into the table if it does not exist, or merges the
entity with the existing entity otherwise.
Code Samples
Upserts an entity into the table. Prints out the details of the upserted
entity.
String partitionKey = "partitionKey";
String rowKey = "rowKey";
TableEntity tableEntity = new TableEntity(partitionKey, rowKey)
.addProperty("Property", "Value");
tableClient.upsertEntity(tableEntity);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was updated/created.", partitionKey,
rowKey);
entity - The entity to upsert.IllegalArgumentException - If the provided entity is null.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, Duration timeout, com.azure.core.util.Context context)
entity into the table if it does not exist, or updates the existing
entity using the specified update mode otherwise. The default
update mode is MERGE.
When the update mode is MERGE, the provided
entity's properties will be merged into the existing entity. When the
update mode is REPLACE, the provided
entity's properties will completely replace those in the existing entity.
Code Samples
Upserts an entity into the table with the specified
update mode if said entity already exists. Prints out the
details of the HTTP response and the upserted entity.
String myPartitionKey = "partitionKey";
String myRowKey = "rowKey";
TableEntity myTableEntity = new TableEntity(myPartitionKey, myRowKey)
.addProperty("Property", "Value");
Response<Void> response = tableClient.upsertEntityWithResponse(myTableEntity, TableEntityUpdateMode.REPLACE,
Duration.ofSeconds(5), new Context("key1", "value1"));
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);
entity - The entity to upsert.updateMode - The type of update to perform if the entity already exits.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.IllegalArgumentException - If the provided entity is null.TableServiceException - If the request is rejected by the service.public void updateEntity(TableEntity entity)
entity by merging the provided entity with the
existing entity.
Code Samples
Updates a entity on the table. Prints out the details of the updated
entity.
String partitionKey = "partitionKey";
String rowKey = "rowKey";
TableEntity tableEntity = new TableEntity(partitionKey, rowKey)
.addProperty("Property", "Value");
tableClient.updateEntity(tableEntity);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was updated/created.", partitionKey,
rowKey);
entity - The entity to update.IllegalArgumentException - If the provided entity is null.TableServiceException - If no entity with the same partition key and row key exists
within the table.public void updateEntity(TableEntity entity, TableEntityUpdateMode updateMode)
entity using the specified update mode.
The default update mode is MERGE.
When the update mode is MERGE, the provided
entity's properties will be merged into the existing entity. When the
update mode is REPLACE, the provided
entity's properties will completely replace those in the existing entity.
Code Samples
Updates a entity on the table with the specified
update mode. Prints out the details of the updated entity.
String myPartitionKey = "partitionKey";
String myRowKey = "rowKey";
TableEntity myTableEntity = new TableEntity(myPartitionKey, myRowKey)
.addProperty("Property", "Value");
tableClient.updateEntity(myTableEntity, TableEntityUpdateMode.REPLACE);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was updated/created.", partitionKey,
rowKey);
entity - The entity to update.updateMode - The type of update to perform.IllegalArgumentException - If the provided entity is null.TableServiceException - If no entity with the same partition key and row key exists
within the table.public com.azure.core.http.rest.Response<Void> updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged, Duration timeout, com.azure.core.util.Context context)
entity using the specified update mode.
The default update mode is MERGE.
When the update mode is MERGE, the provided
entity's properties will be merged into the existing entity. When the
update mode is REPLACE, the provided
entity's properties will completely replace those in the existing entity.
Code Samples
Updates a entity on the table with the specified update
mode
if the ETags on both entities match. Prints out the details of the
HTTP response updated entity.
String somePartitionKey = "partitionKey";
String someRowKey = "rowKey";
TableEntity someTableEntity = new TableEntity(somePartitionKey, someRowKey)
.addProperty("Property", "Value");
Response<Void> response = tableClient.updateEntityWithResponse(someTableEntity, TableEntityUpdateMode.REPLACE,
true, Duration.ofSeconds(5), new Context("key1", "value1"));
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);
entity - The entity to update.updateMode - The type of update to perform.ifUnchanged - When true, the ETag of the provided entity must match the ETag of the
entity in the Table service. If the values do not match, the update will not occur and an
exception will be thrown.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.IllegalArgumentException - If the provided entity is null.TableServiceException - If no entity with the same partition key and row key exists
within the table, or if ifUnchanged is true and the existing entity's ETag
does not match that of the provided entity.public void deleteEntity(String partitionKey, String rowKey)
entity from the table.
Code Samples
Deletes an entity on the table. Prints out the entity's partitionKey and
rowKey.
String partitionKey = "partitionKey";
String rowKey = "rowKey";
tableClient.deleteEntity(partitionKey, rowKey);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was deleted.", partitionKey, rowKey);
partitionKey - The partition key of the entity.rowKey - The row key of the entity.IllegalArgumentException - If the provided partitionKey or rowKey are null or
empty.TableServiceException - If the request is rejected by the service.public void deleteEntity(TableEntity entity)
entity from the table.
Code Samples
Deletes a entity on the table. Prints out the details of the deleted
entity.
String myPartitionKey = "partitionKey";
String myRowKey = "rowKey";
TableEntity myTableEntity = new TableEntity(myPartitionKey, myRowKey)
.addProperty("Property", "Value");
tableClient.deleteEntity(myTableEntity);
System.out.printf("Table entity with partition key '%s' and row key: '%s' was created.", partitionKey, rowKey);
entity - The entity to delete.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, com.azure.core.util.Context context)
entity from the table.
Code Samples
Deletes a entity on the table. Prints out the details of the
HTTP response and the deleted entity.
String somePartitionKey = "partitionKey";
String someRowKey = "rowKey";
TableEntity someTableEntity = new TableEntity(somePartitionKey, someRowKey)
.addProperty("Property", "Value");
Response<Void> response = tableClient.deleteEntityWithResponse(someTableEntity, true, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Response successful with status code: %d. Table entity with partition key '%s' and row key"
+ " '%s' was deleted.", response.getStatusCode(), somePartitionKey, someRowKey);
entity - The table entity to delete.ifUnchanged - When true, the ETag of the provided entity must match the ETag of the
entity in the Table service. If the values do not match, the update will not occur and an
exception will be thrown.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.PagedIterable<TableEntity> listEntities()
entities within the table.
Code Samples
Lists all entities on the table. Prints out the details of the
retrieved entities.
PagedIterable<TableEntity> tableEntities = tableClient.listEntities();
tableEntities.forEach(tableEntity ->
System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.%n",
tableEntity.getPartitionKey(), tableEntity.getRowKey()));
PagedIterable containing all entities within the table.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.PagedIterable<TableEntity> listEntities(ListEntitiesOptions options, Duration timeout, com.azure.core.util.Context context)
entities using the parameters in the provided options.
If the filter parameter in the options is set, only entities 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 entity. If the top parameter is set, the maximum number of
returned entities per page will be limited to that value.
Code Samples
Lists all entities on the table. Prints out the details of the
HTTP response and all the retrieved entities.
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);
PagedIterable<TableEntity> myTableEntities = tableClient.listEntities(listEntitiesOptions,
Duration.ofSeconds(5), new Context("key1", "value1"));
myTableEntities.forEach(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));
});
options - The filter, select, and top OData query options to apply to this
operation.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.PagedIterable containing matching entities within the table.IllegalArgumentException - If one or more of the OData query options in options is malformed.TableServiceException - If the request is rejected by the service.public TableEntity getEntity(String partitionKey, String rowKey)
entity from the table.
Code Samples
Gets an entity on the table. Prints out the details of the retrieved
entity.
String partitionKey = "partitionKey";
String rowKey = "rowKey";
TableEntity tableEntity = tableClient.getEntity(partitionKey, rowKey);
System.out.printf("Retrieved entity with partition key '%s' and row key '%s'.", tableEntity.getPartitionKey(),
tableEntity.getRowKey());
partitionKey - The partition key of the entity.rowKey - The partition key of the entity.entity.IllegalArgumentException - If the provided partitionKey or rowKey are null or
empty.TableServiceException - If no entity with the provided partitionKey and
rowKey exists within the table.public com.azure.core.http.rest.Response<TableEntity> getEntityWithResponse(String partitionKey, String rowKey, List<String> select, Duration timeout, com.azure.core.util.Context context)
entity from the table.
Code Samples
Gets an entity on the table. Prints out the details of the HTTP response
retrieved entity.
String myPartitionKey = "partitionKey";
String myRowKey = "rowKey";
List<String> propertiesToSelect = new ArrayList<>();
propertiesToSelect.add("name");
propertiesToSelect.add("lastname");
propertiesToSelect.add("age");
Response<TableEntity> response = tableClient.getEntityWithResponse(myPartitionKey, myRowKey, propertiesToSelect,
Duration.ofSeconds(5), new Context("key1", "value1"));
TableEntity myTableEntity = response.getValue();
System.out.printf("Response successful with status code: %d. Retrieved entity with partition key '%s', row key"
+ " '%s' and properties:", response.getStatusCode(), myTableEntity.getPartitionKey(),
myTableEntity.getRowKey());
myTableEntity.getProperties().forEach((key, value) ->
System.out.printf("%nName: '%s'. Value: '%s'.", key, value));
partitionKey - The partition key of the entity.rowKey - The partition key of the entity.select - A list of properties to select on the entity.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response containing the entity.IllegalArgumentException - If the provided partitionKey or rowKey are null or
empty, or if the select OData query option is malformed.TableServiceException - If no entity with the provided partitionKey and
rowKey exists within the table.public TableAccessPolicies getAccessPolicies()
access policies 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 access policies. Prints out the details of the retrieved
access policies.
TableAccessPolicies accessPolicies = tableClient.getAccessPolicies();
accessPolicies.getIdentifiers().forEach(signedIdentifier ->
System.out.printf("Retrieved table access policy with id '%s'.", signedIdentifier.getId()));
access policies.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<TableAccessPolicies> getAccessPoliciesWithResponse(Duration timeout, com.azure.core.util.Context context)
access policies 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 access policies. Prints out the details of the
HTTP response and the retrieved access policies.
List<String> propertiesToSelect = new ArrayList<>();
propertiesToSelect.add("name");
propertiesToSelect.add("lastname");
propertiesToSelect.add("age");
Response<TableAccessPolicies> response = tableClient.getAccessPoliciesWithResponse(Duration.ofSeconds(5),
new Context("key1", "value1"));
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()));
timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response containing the table's access policies.TableServiceException - If the request is rejected by the service.public void setAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers)
access policies for the table that may be used with Shared Access
Signatures.
This operation is only supported on Azure Storage endpoints.
Code Samples
Sets stored access policies 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")));
tableClient.setAccessPolicies(signedIdentifiers);
System.out.print("Set table access policies.");
tableSignedIdentifiers - The access policies for the table.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers, Duration timeout, com.azure.core.util.Context context)
access policies for the table that may be used with Shared Access
Signatures.
This operation is only supported on Azure Storage endpoints.
Code Samples
Sets stored access policies on a table. Prints out details of the
HTTP response.
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")));
Response<Void> response = tableClient.setAccessPoliciesWithResponse(mySignedIdentifiers, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Set table access policies successfully with status code: %d.", response.getStatusCode());
tableSignedIdentifiers - The access policies for the table.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response.TableServiceException - If the request is rejected by the service.public TableTransactionResult submitTransaction(List<TableTransactionAction> transactionActions)
actions within the list inside a transaction. When the call
completes, either all actions in the transaction will succeed, or if a failure
occurs, all actions in the transaction will be rolled back.
Actions are executed sequantially. Each action
must operate on a distinct row key. Attempting to pass multiple actions that
share the same row key will cause an error.
Code Samples
Submits a transaction that contains multiple actions to be applied to
entities on a table. Prints out details of each action's
HTTP response.
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);
TableTransactionResult tableTransactionResult = tableClient.submitTransaction(transactionActions);
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 action via the provided
exception, which contains the index of the first failing action in the
transaction.
tableAsyncClient.submitTransaction(transactionActions)
.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(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()));
});
transactionActions - A List of actions to perform on
entities in a table.List of sub-responses that correspond to each
action in the transaction.IllegalArgumentException - If no actions have been added to the list.TableServiceException - If the request is rejected by the service.TableTransactionFailedException - If any action within the transaction
fails. See the documentation for the client methods in TableClient to understand the conditions that
may cause a given action to fail.public com.azure.core.http.rest.Response<TableTransactionResult> submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Duration timeout, com.azure.core.util.Context context)
actions within the list inside a transaction. When the call
completes, either all actions in the transaction will succeed, or if a failure
occurs, all actions in the transaction will be rolled back.
Actions are executed sequantially. Each action
must operate on a distinct row key. Attempting to pass multiple actions that
share the same row key will cause an error.
Code Samples
Submits a transaction that contains multiple actions to be applied to
entities on a table. Prints out details of the HTTP response for the
operation, as well as each action'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);
Response<TableTransactionResult> response = tableClient.submitTransactionWithResponse(myTransactionActions,
Duration.ofSeconds(5), new Context("key1", "value1"));
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 action via the provided
exception, which contains the index of the first failing action in the
transaction.
try {
Response<TableTransactionResult> transactionResultResponse =
tableClient.submitTransactionWithResponse(myTransactionActions, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Response successful with status code: %d. The ordered response status codes of the"
+ " submitted actions are:", transactionResultResponse.getStatusCode());
transactionResultResponse.getValue().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.
myTransactionActions.remove(failedActionIndex);
// And then retry submitting the transaction.
}
transactionActions - A List of transaction actions to perform on
entities in a table.timeout - An optional timeout value beyond which a RuntimeException will be raised.context - Additional Context that is passed through the HTTP pipeline during
the service call.HTTP response produced for the transaction itself. The response's value will contain
a List of sub-responses that correspond to each
action in the transaction.IllegalArgumentException - If no actions have been added to the list.TableServiceException - If the request is rejected by the service.TableTransactionFailedException - If any action within the transaction
fails. See the documentation for the client methods in TableClient to understand the conditions that
may cause a given action to fail.Copyright © 2021 Microsoft Corporation. All rights reserved.