Class TableClient
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();
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidcreateEntity(TableEntity entity) Inserts anentityinto the table.createEntityWithResponse(TableEntity entity, Duration timeout, Context context) Inserts anentityinto the table.Creates the table within the Tables service.createTableWithResponse(Duration timeout, Context context) Creates the table within the Tables service.voiddeleteEntity(TableEntity entity) Deletes anentityfrom the table.voiddeleteEntity(String partitionKey, String rowKey) Deletes anentityfrom the table.deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context) Deletes anentityfrom the table.voidDeletes the table within the Tables service.deleteTableWithResponse(Duration timeout, Context context) Deletes the table within the Tables service.generateSas(TableSasSignatureValues tableSasSignatureValues) Generates a service SAS for the table using the specifiedTableSasSignatureValues.Retrieves details about any storedaccess policiesspecified on the table that may be used with Shared Access Signatures.getAccessPoliciesWithResponse(Duration timeout, Context context) Retrieves details about any storedaccess policiesspecified on the table that may be used with Shared Access Signatures.Gets the name of the account containing the table.Gets a singleentityfrom the table.getEntityWithResponse(String partitionKey, String rowKey, List<String> select, Duration timeout, Context context) Gets a singleentityfrom the table.Gets the REST API version used by this client.Gets the endpoint for this table.Gets the name of the table.Lists allentitieswithin the table.listEntities(ListEntitiesOptions options, Duration timeout, Context context) Listsentitiesusing the parameters in the provided options.voidsetAccessPolicies(List<TableSignedIdentifier> tableSignedIdentifiers) Sets storedaccess policiesfor the table that may be used with Shared Access Signatures.setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers, Duration timeout, Context context) Sets storedaccess policiesfor the table that may be used with Shared Access Signatures.submitTransaction(List<TableTransactionAction> transactionActions) Executes allactionswithin the list inside a transaction.submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Duration timeout, Context context) Executes allactionswithin the list inside a transaction.voidupdateEntity(TableEntity entity) voidupdateEntity(TableEntity entity, TableEntityUpdateMode updateMode) Updates an existingentityusing the specifiedupdate mode.updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged, Duration timeout, Context context) Updates an existingentityusing the specifiedupdate mode.voidupsertEntity(TableEntity entity) upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, Duration timeout, Context context) Inserts anentityinto the table if it does not exist, or updates the existingentityusing the specifiedupdate modeotherwise.
-
Method Details
-
getTableName
Gets the name of the table.- Returns:
- The name of the table.
-
getAccountName
Gets the name of the account containing the table.- Returns:
- The name of the account containing the table.
-
getTableEndpoint
Gets the endpoint for this table.- Returns:
- The endpoint for this table.
-
getServiceVersion
Gets the REST API version used by this client.- Returns:
- The REST API version used by this client.
-
generateSas
Generates a service SAS for the table using the specifiedTableSasSignatureValues.Note: The client must be authenticated via
AzureNamedKeyCredential.See
TableSasSignatureValuesfor more information on how to construct a service SAS.- Parameters:
tableSasSignatureValues-TableSasSignatureValues.- Returns:
- A
Stringrepresenting the SAS query parameters. - Throws:
IllegalStateException- If thisTableClientis not authenticated with anAzureNamedKeyCredential.
-
createTable
Creates the table within the Tables service.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());- Returns:
- A
TableItemthat represents the table. - Throws:
TableServiceException- If a table with the same name already exists within the service.
-
createTableWithResponse
Creates the table within the Tables service.Code Samples
Creates a table. Prints out the details of the
HTTP responseand 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());- Parameters:
timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP responsecontaining aTableItemthat represents the table. - Throws:
TableServiceException- If a table with the same name already exists within the service.
-
deleteTable
public void deleteTable()Deletes the table within the Tables service.Code Samples
Deletes a table.
tableClient.deleteTable(); System.out.print("Table was deleted.");- Throws:
TableServiceException- If the request is rejected by the service.
-
deleteTableWithResponse
Deletes the table within the Tables service.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());- Parameters:
timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
TableServiceException- If the request is rejected by the service.
-
createEntity
Inserts anentityinto the table.Code Samples
Inserts an
entityinto the table. Prints out the details of the createdentity.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);- Parameters:
entity- Theentityto insert.- Throws:
TableServiceException- If anentitywith the same partition key and row key already exists within the table.IllegalArgumentException- If the providedentityisnull.
-
createEntityWithResponse
public Response<Void> createEntityWithResponse(TableEntity entity, Duration timeout, Context context) Inserts anentityinto the table.Code Samples
Inserts an
entityinto the table. Prints out the details of theHTTP responseand the createdentity.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);- Parameters:
entity- Theentityto insert.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
TableServiceException- If anentitywith the same partition key and row key already exists within the table.IllegalArgumentException- If the providedentityisnull.
-
upsertEntity
Inserts anentityinto the table if it does not exist, or merges theentitywith the existingentityotherwise.Code Samples
Upserts an
entityinto the table. Prints out the details of the upsertedentity.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);- Parameters:
entity- Theentityto upsert.- Throws:
IllegalArgumentException- If the providedentityisnull.TableServiceException- If the request is rejected by the service.
-
upsertEntityWithResponse
public Response<Void> upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, Duration timeout, Context context) Inserts anentityinto the table if it does not exist, or updates the existingentityusing the specifiedupdate modeotherwise. The defaultupdate modeisMERGE.When the
update modeisMERGE, the providedentity's properties will be merged into the existingentity. When theupdate modeisREPLACE, the providedentity's properties will completely replace those in the existingentity.Code Samples
Upserts an
entityinto the table with the specifiedupdate modeif saidentityalready exists. Prints out the details of theHTTP responseand the upsertedentity.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);- Parameters:
entity- Theentityto upsert.updateMode- The type of update to perform if theentityalready exits.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
IllegalArgumentException- If the providedentityisnull.TableServiceException- If the request is rejected by the service.
-
updateEntity
Updates an existingentityby merging the providedentitywith the existingentity.Code Samples
Updates a
entityon the table. Prints out the details of the updatedentity.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);- Parameters:
entity- Theentityto update.- Throws:
IllegalArgumentException- If the providedentityisnull.TableServiceException- If noentitywith the same partition key and row key exists within the table.
-
updateEntity
Updates an existingentityusing the specifiedupdate mode. The defaultupdate modeisMERGE.When the
update modeisMERGE, the providedentity's properties will be merged into the existingentity. When theupdate modeisREPLACE, the providedentity's properties will completely replace those in the existingentity.Code Samples
Updates a
entityon the table with the specifiedupdate mode. Prints out the details of the updatedentity.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);- Parameters:
entity- Theentityto update.updateMode- The type of update to perform.- Throws:
IllegalArgumentException- If the providedentityisnull.TableServiceException- If noentitywith the same partition key and row key exists within the table.
-
updateEntityWithResponse
public Response<Void> updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged, Duration timeout, Context context) Updates an existingentityusing the specifiedupdate mode. The defaultupdate modeisMERGE.When the
update modeisMERGE, the providedentity's properties will be merged into the existingentity. When theupdate modeisREPLACE, the providedentity's properties will completely replace those in the existingentity.Code Samples
Updates a
entityon the table with the specifiedupdate modeif theETagson bothentitiesmatch. Prints out the details of theHTTP responseupdatedentity.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);- Parameters:
entity- Theentityto update.updateMode- The type of update to perform.ifUnchanged- When true, the ETag of the providedentitymust match the ETag of theentityin 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 aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
IllegalArgumentException- If the providedentityisnull.TableServiceException- If noentitywith the same partition key and row key exists within the table, or ififUnchangedistrueand the existingentity's ETag does not match that of the providedentity.
-
deleteEntity
Deletes anentityfrom the table.Code Samples
Deletes an
entityon the table. Prints out the entity'spartitionKeyandrowKey.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);- Parameters:
partitionKey- The partition key of theentity.rowKey- The row key of theentity.- Throws:
IllegalArgumentException- If the providedpartitionKeyorrowKeyarenullor empty.TableServiceException- If the request is rejected by the service.
-
deleteEntity
Deletes anentityfrom the table.Code Samples
Deletes a
entityon the table. Prints out the details of the deletedentity.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);- Parameters:
entity- Theentityto delete.- Throws:
TableServiceException- If the request is rejected by the service.
-
deleteEntityWithResponse
public Response<Void> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context) Deletes anentityfrom the table.Code Samples
Deletes a
entityon the table. Prints out the details of theHTTP responseand the deletedentity.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);- Parameters:
entity- The tableentityto delete.ifUnchanged- When true, the ETag of the providedentitymust match the ETag of theentityin 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 aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
TableServiceException- If the request is rejected by the service.
-
listEntities
Lists allentitieswithin the table.Code Samples
Lists all
entitieson the table. Prints out the details of the retrievedentities.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()));- Returns:
- A
PagedIterablecontaining allentitieswithin the table. - Throws:
TableServiceException- If the request is rejected by the service.
-
listEntities
public PagedIterable<TableEntity> listEntities(ListEntitiesOptions options, Duration timeout, Context context) Listsentitiesusing the parameters in the provided options.If the
filterparameter in the options is set, onlyentitiesmatching the filter will be returned. If theselectparameter is set, only the properties included in the select parameter will be returned for eachentity. If thetopparameter is set, the maximum number of returnedentitiesper page will be limited to that value.Code Samples
Lists all
entitieson the table. Prints out the details of theHTTP responseand all the retrievedentities.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)); });- Parameters:
options- Thefilter,select, andtopOData query options to apply to this operation.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- A
PagedIterablecontaining matchingentitieswithin the table. - Throws:
IllegalArgumentException- If one or more of the OData query options inoptionsis malformed.TableServiceException- If the request is rejected by the service.
-
getEntity
Gets a singleentityfrom the table.Code Samples
Gets an
entityon the table. Prints out the details of the retrievedentity.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());- Parameters:
partitionKey- The partition key of theentity.rowKey- The partition key of theentity.- Returns:
- The
entity. - Throws:
IllegalArgumentException- If the providedpartitionKeyorrowKeyarenullor empty.TableServiceException- If noentitywith the providedpartitionKeyandrowKeyexists within the table.
-
getEntityWithResponse
public Response<TableEntity> getEntityWithResponse(String partitionKey, String rowKey, List<String> select, Duration timeout, Context context) Gets a singleentityfrom the table.Code Samples
Gets an
entityon the table. Prints out the details of theHTTP responseretrievedentity.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));- Parameters:
partitionKey- The partition key of theentity.rowKey- The partition key of theentity.select- A list of properties to select on theentity.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP responsecontaining theentity. - Throws:
IllegalArgumentException- If the providedpartitionKeyorrowKeyarenullor empty, or if theselectOData query option is malformed.TableServiceException- If noentitywith the providedpartitionKeyandrowKeyexists within the table.
-
getAccessPolicies
Retrieves details about any storedaccess policiesspecified 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 retrievedaccess policies.TableAccessPolicies accessPolicies = tableClient.getAccessPolicies(); accessPolicies.getIdentifiers().forEach(signedIdentifier -> System.out.printf("Retrieved table access policy with id '%s'.", signedIdentifier.getId()));- Returns:
- The table's
access policies. - Throws:
TableServiceException- If the request is rejected by the service.
-
getAccessPoliciesWithResponse
public Response<TableAccessPolicies> getAccessPoliciesWithResponse(Duration timeout, Context context) Retrieves details about any storedaccess policiesspecified 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 theHTTP responseand the retrievedaccess 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()));- Parameters:
timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- An
HTTP responsecontaining the table'saccess policies. - Throws:
TableServiceException- If the request is rejected by the service.
-
setAccessPolicies
Sets storedaccess policiesfor the table that may be used with Shared Access Signatures.This operation is only supported on Azure Storage endpoints.
Code Samples
Sets stored
access policieson 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.");- Parameters:
tableSignedIdentifiers- Theaccess policiesfor the table.- Throws:
TableServiceException- If the request is rejected by the service.
-
setAccessPoliciesWithResponse
public Response<Void> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers, Duration timeout, Context context) Sets storedaccess policiesfor the table that may be used with Shared Access Signatures.This operation is only supported on Azure Storage endpoints.
Code Samples
Sets stored
access policieson a table. Prints out details of theHTTP 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());- Parameters:
tableSignedIdentifiers- Theaccess policiesfor the table.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- The
HTTP response. - Throws:
TableServiceException- If the request is rejected by the service.
-
submitTransaction
Executes allactionswithin the list inside a transaction. When the call completes, either allactionsin the transaction will succeed, or if a failure occurs, allactionsin the transaction will be rolled back.Actionsare executed sequantially. Eachactionmust operate on a distinct row key. Attempting to pass multipleactionsthat share the same row key will cause an error.Code Samples
Submits a transaction that contains multiple
actionsto be applied toentitieson a table. Prints out details of eachaction'sHTTP 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
actionvia the providedexception, 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())); });- Parameters:
transactionActions- AListofactionsto perform onentitiesin a table.- Returns:
- A
Listofsub-responsesthat correspond to eachactionin the transaction. - Throws:
IllegalArgumentException- If noactionshave been added to the list.TableServiceException- If the request is rejected by the service.TableTransactionFailedException- If anyactionwithin the transaction fails. See the documentation for the client methods inTableClientto understand the conditions that may cause a givenactionto fail.
-
submitTransactionWithResponse
public Response<TableTransactionResult> submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Duration timeout, Context context) Executes allactionswithin the list inside a transaction. When the call completes, either allactionsin the transaction will succeed, or if a failure occurs, allactionsin the transaction will be rolled back.Actionsare executed sequantially. Eachactionmust operate on a distinct row key. Attempting to pass multipleactionsthat share the same row key will cause an error.Code Samples
Submits a transaction that contains multiple
actionsto be applied toentitieson a table. Prints out details of theHTTP responsefor the operation, as well as eachaction's correspondingHTTP 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
actionvia the providedexception, 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. }- Parameters:
transactionActions- AListoftransaction actionsto perform onentitiesin a table.timeout- An optional timeout value beyond which aRuntimeExceptionwill be raised.context- AdditionalContextthat is passed through theHTTP pipelineduring the service call.- Returns:
- An
HTTP responseproduced for the transaction itself. The response's value will contain aListofsub-responsesthat correspond to eachactionin the transaction. - Throws:
IllegalArgumentException- If noactionshave been added to the list.TableServiceException- If the request is rejected by the service.TableTransactionFailedException- If anyactionwithin the transaction fails. See the documentation for the client methods inTableClientto understand the conditions that may cause a givenactionto fail.
-