Compartilhar via


TableServiceAsyncClient Class

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

public final class TableServiceAsyncClient

Provides an asynchronous service client for accessing the Azure Tables service.

Overview

The client encapsulates the URL for the Tables service endpoint and the credentials for accessing the storage or CosmosDB table API account. It provides methods to create, delete, and list tables within the account. These methods invoke REST API operations to make the requests and obtain the results that are returned.

Getting Started

The building and authenticating of instances of this client are handled by TableServiceClientBuilder instances. The sample below shows how to authenticate and build a TableServiceAsyncClient using a connection string.

TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder()
     .connectionString("connectionstring")
     .buildAsyncClient();

See TableServiceClientBuilder documentation for more information on constructing and authenticating a client.

The following code samples show the various ways you can interact with the tables service using this client.


Create a Table

The createTable(String tableName) method can be used to create a new table within an Azure Storage or Azure Cosmos account. It returns a TableClient for the newly created table.

The following sample creates a table with the name "myTable".

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

Note: for synchronous sample, refer to TableServiceClient.


Delete a Table

The deleteTable(String tableName) method can be used to delete a table within an Azure Storage or Azure Cosmos account.

The following sample deletes the table with the name "myTable".

tableServiceAsyncClient.deleteTable("myTable")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table with name '%s' was deleted.", "myTable"));

Note: for synchronous sample, refer to TableServiceClient


Get a TableServiceAsyncClient

The getTableClient(String tableName) method can be used to retrieve a TableAsyncClient for a table within an Azure Storage or Azure Cosmos account.

The following sample gets a TableServiceAsyncClient using the table name "myTable".

TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableClient("myTable");

 System.out.printf("Table with name '%s' was retrieved.", tableAsyncClient.getTableName());

Note: for synchronous sample, refer to TableServiceClient


List Tables

The listTables() method can be used to list all the tables in an Azure Storage or Azure Cosmos account.

The following samples list the tables in the Table service account.

Without filtering, returning all tables:

tableServiceAsyncClient.listTables().subscribe(tableItem ->
     System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));

With filtering:

tableServiceAsyncClient.listTables(new ListTablesOptions().setFilter("TableName eq 'myTable'")).
     subscribe(tableItem -> System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));

Note: for synchronous sample, refer to TableServiceClient


Get Table Properties

The getProperties() method can be used to get the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules. This operation is only supported on Azure Storage endpoints.

The following sample gets the properties of the Table service account.

tableServiceAsyncClient.getProperties()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(properties -> System.out.print("Retrieved service properties successfully."));

Note: for synchronous sample, refer to TableServiceClient


Set Table Properties

The setProperties(TableServiceProperties tableServiceProperties) method can be used to set the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules. This operation is only supported on Azure Storage endpoints.

The following sample sets the properties of the Table service account.

TableServiceProperties properties = new TableServiceProperties()
     .setHourMetrics(new TableServiceMetrics()
         .setVersion("1.0")
         .setEnabled(true))
     .setLogging(new TableServiceLogging()
         .setAnalyticsVersion("1.0")
         .setReadLogged(true)
         .setRetentionPolicy(new TableServiceRetentionPolicy()
             .setEnabled(true)
             .setDaysToRetain(5)));

 tableServiceAsyncClient.setProperties(properties)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused -> System.out.print("Set service properties successfully."));

Note: for synchronous sample, refer to TableServiceClient


Get Table Statistics

The getStatistics() method can be used to retrieve statistics related to replication for the account's Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the account. This operation is only supported on Azure Storage endpoints.

The following sample gets the statistics of the Table service account.

tableServiceAsyncClient.getStatistics()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(statistics -> System.out.print("Retrieved service statistics successfully."));

Note: for synchronous sample, refer to TableServiceClient

Method Summary

Modifier and Type Method and Description
Mono<TableAsyncClient> createTable(String tableName)

Creates a table within the Tables service.

Mono<TableAsyncClient> createTableIfNotExists(String tableName)

Creates a table within the Tables service if the table does not already exist.

Mono<Response<TableAsyncClient>> createTableIfNotExistsWithResponse(String tableName)

Creates a table within the Tables service if the table does not already exist.

Mono<Response<TableAsyncClient>> createTableWithResponse(String tableName)

Creates a table within the Tables service.

Mono<Void> deleteTable(String tableName)

Deletes a table within the Tables service.

Mono<Response<Void>> deleteTableWithResponse(String tableName)

Deletes a table within the Tables service.

String generateAccountSas(TableAccountSasSignatureValues tableAccountSasSignatureValues)

Generates an account SAS for the Azure Storage account using the specified TableAccountSasSignatureValues.

String getAccountName()

Gets the name of the account containing the table.

Mono<TableServiceProperties> getProperties()

Gets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

Mono<Response<TableServiceProperties>> getPropertiesWithResponse()

Gets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

String getServiceEndpoint()

Gets the endpoint for the Tables service.

TableServiceVersion getServiceVersion()

Gets the REST API version used by this client.

Mono<TableServiceStatistics> getStatistics()

Retrieves statistics related to replication for the account's Table service.

Mono<Response<TableServiceStatistics>> getStatisticsWithResponse()

Retrieves statistics related to replication for the account's Table service.

TableAsyncClient getTableClient(String tableName)

Gets a TableAsyncClient instance for the table in the account with the provided tableName.

PagedFlux<TableItem> listTables()

Lists all tables within the account.

PagedFlux<TableItem> listTables(ListTablesOptions options)

Lists tables using the parameters in the provided options.

Mono<Void> setProperties(TableServiceProperties tableServiceProperties)

Sets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

Mono<Response<Void>> setPropertiesWithResponse(TableServiceProperties tableServiceProperties)

Sets the properties of an account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

Methods inherited from java.lang.Object

Method Details

createTable

public Mono createTable(String tableName)

Creates a table within the Tables service.

Code Samples

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

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

Parameters:

tableName - The name of the table to create.

Returns:

A Mono containing a TableAsyncClient for the created table.

createTableIfNotExists

public Mono createTableIfNotExists(String tableName)

Creates a table within the Tables service if the table does not already exist. If the table already exists, a TableAsyncClient for the existing table is returned.

Code Samples

Creates a table if it does not already exist. Prints out the details of the created table.

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

Parameters:

tableName - The name of the table to create.

Returns:

A Mono containing a TableAsyncClient for the created table.

createTableIfNotExistsWithResponse

public Mono> createTableIfNotExistsWithResponse(String tableName)

Creates a table within the Tables service if the table does not already exist. If the table already exists, a TableAsyncClient for the existing table is returned.

Code Samples

Creates a table if it does not already exist. Prints out the details of the created table.

tableServiceAsyncClient.createTableIfNotExistsWithResponse("myTable")
     .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().getTableName()));

Parameters:

tableName - The name of the table to create.

Returns:

A Mono containing the Response<T> that in turn contains a TableAsyncClient for the created table.

createTableWithResponse

public Mono> createTableWithResponse(String tableName)

Creates a table within the Tables service.

Code Samples

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

tableServiceAsyncClient.createTableWithResponse("myTable")
     .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().getTableName()));

Parameters:

tableName - The name of the table to create.

Returns:

A Mono containing the Response<T> that in turn contains a TableAsyncClient for the created table.

deleteTable

public Mono deleteTable(String tableName)

Deletes a table within the Tables service.

Code Samples

Deletes a table.

tableServiceAsyncClient.deleteTable("myTable")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused ->
         System.out.printf("Table with name '%s' was deleted.", "myTable"));

Parameters:

tableName - The name of the table to delete.

Returns:

An empty Mono.

deleteTableWithResponse

public Mono> deleteTableWithResponse(String tableName)

Deletes a table within the Tables service.

Code Samples

Deletes a table.

tableServiceAsyncClient.deleteTableWithResponse("myTable")
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Response successful with status code: %d. Table with name '%s' was deleted.",
             response.getStatusCode(), "myTable"));

Parameters:

tableName - The name of the table to delete.

Returns:

A Mono containing the Response<T>.

generateAccountSas

public String generateAccountSas(TableAccountSasSignatureValues tableAccountSasSignatureValues)

Generates an account SAS for the Azure Storage account using the specified TableAccountSasSignatureValues.

Note: The client must be authenticated via AzureNamedKeyCredential.

See TableAccountSasSignatureValues for more information on how to construct an account SAS.

Parameters:

tableAccountSasSignatureValues - TableAccountSasSignatureValues.

Returns:

A String representing the SAS query parameters.

getAccountName

public String getAccountName()

Gets the name of the account containing the table.

Returns:

The name of the account containing the table.

getProperties

public Mono getProperties()

Gets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets the properties of the account's Table service.

tableServiceAsyncClient.getProperties()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(properties -> System.out.print("Retrieved service properties successfully."));

Returns:

A Mono containing the TableServiceProperties of the account's Table service.

getPropertiesWithResponse

public Mono> getPropertiesWithResponse()

Gets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets the properties of the account's Table service. Prints out the details of the Response<T>.

tableServiceAsyncClient.getPropertiesWithResponse()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Retrieved service properties successfully with status code: %d.",
             response.getStatusCode()));

Returns:

A Mono containing the Response<T> that in turn contains the TableServiceProperties of the account's Table service.

getServiceEndpoint

public String getServiceEndpoint()

Gets the endpoint for the Tables service.

Returns:

The endpoint for the Tables service.

getServiceVersion

public TableServiceVersion getServiceVersion()

Gets the REST API version used by this client.

Returns:

The REST API version used by this client.

getStatistics

public Mono getStatistics()

Retrieves statistics related to replication for the account's Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the account.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets the replication statistics of the account's Table service.

tableServiceAsyncClient.getStatistics()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(statistics -> System.out.print("Retrieved service statistics successfully."));

Returns:

A Mono containing TableServiceStatistics for the account's Table service.

getStatisticsWithResponse

public Mono> getStatisticsWithResponse()

Retrieves statistics related to replication for the account's Table service. It is only available on the secondary location endpoint when read-access geo-redundant replication is enabled for the account.

This operation is only supported on Azure Storage endpoints.

Code Samples

Gets the replication statistics of the account's Table service. Prints out the details of the Response<T>.

tableServiceAsyncClient.getStatisticsWithResponse()
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Retrieved service statistics successfully with status code: %d.",
             response.getStatusCode()));

Returns:

A Mono containing the Response<T> that in turn contains TableServiceStatistics for the account's Table service.

getTableClient

public TableAsyncClient getTableClient(String tableName)

Gets a TableAsyncClient instance for the table in the account with the provided tableName. The resulting TableAsyncClient will use the same HttpPipeline and TableServiceVersion as this TableServiceAsyncClient.

Parameters:

tableName - The name of the table.

Returns:

A TableAsyncClient instance for the table in the account with the provided tableName.

listTables

public PagedFlux listTables()

Lists all tables within the account.

Code Samples

Lists all tables. Prints out the details of the retrieved tables.

tableServiceAsyncClient.listTables().subscribe(tableItem ->
     System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));

Returns:

A PagedFlux<T> containing all tables within the account.

listTables

public PagedFlux listTables(ListTablesOptions options)

Lists tables using the parameters in the provided options. If the filter parameter in the options is set, only tables matching the filter will be returned. If the top parameter is set, the maximum number of returned tables per page will be limited to that value.

Code Samples

Lists all tables that match the filter. Prints out the details of the retrieved tables.

tableServiceAsyncClient.listTables(new ListTablesOptions().setFilter("TableName eq 'myTable'")).
     subscribe(tableItem -> System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));

Parameters:

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

Returns:

A PagedFlux<T> containing matching tables within the account.

setProperties

public Mono setProperties(TableServiceProperties tableServiceProperties)

Sets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

This operation is only supported on Azure Storage endpoints.

Code Samples

Sets the properties of the account's Table service.

TableServiceProperties properties = new TableServiceProperties()
     .setHourMetrics(new TableServiceMetrics()
         .setVersion("1.0")
         .setEnabled(true))
     .setLogging(new TableServiceLogging()
         .setAnalyticsVersion("1.0")
         .setReadLogged(true)
         .setRetentionPolicy(new TableServiceRetentionPolicy()
             .setEnabled(true)
             .setDaysToRetain(5)));

 tableServiceAsyncClient.setProperties(properties)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(unused -> System.out.print("Set service properties successfully."));

Parameters:

tableServiceProperties - The TableServiceProperties to set.

Returns:

An empty Mono.

setPropertiesWithResponse

public Mono> setPropertiesWithResponse(TableServiceProperties tableServiceProperties)

Sets the properties of an account's Table service, including properties for Analytics and CORS (Cross-Origin Resource Sharing) rules.

This operation is only supported on Azure Storage endpoints.

Code Samples

Sets the properties of the account's Table service. Prints out the details of the Response<T>.

TableServiceProperties myProperties = new TableServiceProperties()
     .setHourMetrics(new TableServiceMetrics()
         .setVersion("1.0")
         .setEnabled(true))
     .setLogging(new TableServiceLogging()
         .setAnalyticsVersion("1.0")
         .setReadLogged(true)
         .setRetentionPolicy(new TableServiceRetentionPolicy()
             .setEnabled(true)
             .setDaysToRetain(5)));

 tableServiceAsyncClient.setPropertiesWithResponse(myProperties)
     .contextWrite(Context.of("key1", "value1", "key2", "value2"))
     .subscribe(response ->
         System.out.printf("Retrieved service properties successfully with status code: %d.",
             response.getStatusCode()));

Parameters:

tableServiceProperties - The TableServiceProperties to set.

Returns:

A Mono containing the Response<T>.

Applies to