public final class TableServiceClient extends Object
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.
Instances of this client are obtained by calling the TableServiceClientBuilder.buildClient() method on a
TableServiceClientBuilder object.
Samples to construct a sync client
TableServiceClient tableServiceClient = new TableServiceClientBuilder()
.endpoint("https://myvault.azure.net/")
.credential(new AzureNamedKeyCredential("name", "key"))
.buildClient();
TableServiceClientBuilder| Modifier and Type | Method and Description |
|---|---|
TableClient |
createTable(String tableName)
Creates a table within the Tables service.
|
TableClient |
createTableIfNotExists(String tableName)
Creates a table within the Tables service if the table does not already exist.
|
com.azure.core.http.rest.Response<TableClient> |
createTableIfNotExistsWithResponse(String tableName,
Duration timeout,
com.azure.core.util.Context context)
Creates a table within the Tables service if the table does not already exist.
|
com.azure.core.http.rest.Response<TableClient> |
createTableWithResponse(String tableName,
Duration timeout,
com.azure.core.util.Context context)
Creates a table within the Tables service.
|
void |
deleteTable(String tableName)
Deletes a table within the Tables service.
|
com.azure.core.http.rest.Response<Void> |
deleteTableWithResponse(String tableName,
Duration timeout,
com.azure.core.util.Context context)
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.
|
TableServiceProperties |
getProperties()
Gets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin
Resource Sharing) rules.
|
com.azure.core.http.rest.Response<TableServiceProperties> |
getPropertiesWithResponse(Duration timeout,
com.azure.core.util.Context context)
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.
|
TableServiceStatistics |
getStatistics()
Retrieves statistics related to replication for the account's Table service.
|
com.azure.core.http.rest.Response<TableServiceStatistics> |
getStatisticsWithResponse(Duration timeout,
com.azure.core.util.Context context)
Retrieves statistics related to replication for the account's Table service.
|
TableClient |
getTableClient(String tableName)
Gets a
TableClient instance for the table in the account with the provided tableName. |
com.azure.core.http.rest.PagedIterable<TableItem> |
listTables()
Lists all tables within the account.
|
com.azure.core.http.rest.PagedIterable<TableItem> |
listTables(ListTablesOptions options,
Duration timeout,
com.azure.core.util.Context context)
If the
filter parameter in the options is set, only tables matching the filter will be returned. |
void |
setProperties(TableServiceProperties tableServiceProperties)
Sets the properties of the account's Table service, including properties for Analytics and CORS (Cross-Origin
Resource Sharing) rules.
|
com.azure.core.http.rest.Response<Void> |
setPropertiesWithResponse(TableServiceProperties tableServiceProperties,
Duration timeout,
com.azure.core.util.Context context)
Sets the properties of an account's Table service, including properties for Analytics and CORS (Cross-Origin
Resource Sharing) rules.
|
public String getAccountName()
public String getServiceEndpoint()
public TableServiceVersion getServiceVersion()
public String generateAccountSas(TableAccountSasSignatureValues tableAccountSasSignatureValues)
TableAccountSasSignatureValues.
Note: The client must be authenticated via AzureNamedKeyCredential.
See TableAccountSasSignatureValues for more information on how to construct an account SAS.
tableAccountSasSignatureValues - TableAccountSasSignatureValues.String representing the SAS query parameters.IllegalStateException - If this TableClient is not authenticated with an
AzureNamedKeyCredential.public TableClient getTableClient(String tableName)
TableClient instance for the table in the account with the provided tableName.tableName - The name of the table.TableClient instance for the table in the account with the provided tableName.IllegalArgumentException - If tableName is null or empty.public TableClient createTable(String tableName)
Code Samples
Creates a table. Prints out the details of the created table.
TableClient tableClient = tableServiceClient.createTable("myTable");
System.out.printf("Table with name '%s' was created.", tableClient.getTableName());
tableName - The name of the table to create.TableClient for the created table.IllegalArgumentException - If tableName is null or empty.TableServiceException - If a table with the same name already exists within the service.public com.azure.core.http.rest.Response<TableClient> createTableWithResponse(String tableName, 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<TableClient> response = tableServiceClient.createTableWithResponse("myTable", 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().getTableName());
tableName - The name of the table to create.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 TableClient for the created table.IllegalArgumentException - If tableName is null or empty.TableServiceException - If a table with the same name already exists within the service.public TableClient createTableIfNotExists(String tableName)
Code Samples
Creates a table if it does not already exist. Prints out the details of the created table.
TableClient tableClient = tableServiceClient.createTableIfNotExists("myTable");
System.out.printf("Table with name '%s' was created.", tableClient.getTableName());
tableName - The name of the table to create.TableClient for the created table.IllegalArgumentException - If tableName is null or empty.public com.azure.core.http.rest.Response<TableClient> createTableIfNotExistsWithResponse(String tableName, Duration timeout, com.azure.core.util.Context context)
Code Samples
Creates a table if it does not already exist. Prints out the details of the HTTP response
and the created table.
Response<TableClient> response =
tableServiceClient.createTableIfNotExistsWithResponse("myTable", 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().getTableName());
tableName - The name of the table to create.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 TableClient for the created table.IllegalArgumentException - If tableName is null or empty.public void deleteTable(String tableName)
Code Samples
Deletes a table.
String tableName = "myTable";
tableServiceClient.deleteTable(tableName);
System.out.printf("Table with name '%s' was deleted.", tableName);
tableName - The name of the table to delete.IllegalArgumentException - If tableName is null or empty.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> deleteTableWithResponse(String tableName, Duration timeout, com.azure.core.util.Context context)
Code Samples
Deletes a table. Prints out the details of the HTTP response.
String myTableName = "myTable";
Response<Void> response = tableServiceClient.deleteTableWithResponse(myTableName, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Response successful with status code: %d. Table with name '%s' was deleted.",
response.getStatusCode(), myTableName);
tableName - The name of the table to delete.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 tableName is null or empty.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.PagedIterable<TableItem> listTables()
Code Samples
Lists all tables. Prints out the details of the retrieved tables.
PagedIterable<TableItem> tableItems = tableServiceClient.listTables();
tableItems.forEach(tableItem ->
System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));
PagedIterable containing all tables within the account.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.PagedIterable<TableItem> listTables(ListTablesOptions options, Duration timeout, com.azure.core.util.Context context)
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.
ListTablesOptions options = new ListTablesOptions().setFilter("TableName eq 'myTable'");
PagedIterable<TableItem> retrievedTableItems = tableServiceClient.listTables(options, Duration.ofSeconds(5),
new Context("key1", "value1"));
retrievedTableItems.forEach(tableItem ->
System.out.printf("Retrieved table with name '%s'.%n", tableItem.getName()));
options - The filter 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 tables within the account.IllegalArgumentException - If one or more of the OData query options in options is malformed.TableServiceException - If the request is rejected by the service.public TableServiceProperties getProperties()
This operation is only supported on Azure Storage endpoints.
Code Samples
Gets the properties of the account's Table service.
TableServiceProperties properties = tableServiceClient.getProperties();
System.out.print("Retrieved service properties successfully.");
properties of the account's Table service.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<TableServiceProperties> getPropertiesWithResponse(Duration timeout, com.azure.core.util.Context context)
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
HTTP response.
Response<TableServiceProperties> response =
tableServiceClient.getPropertiesWithResponse(Duration.ofSeconds(5), new Context("key1", "value1"));
System.out.printf("Retrieved service properties 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 and the properties of the account's
Table service.TableServiceException - If the request is rejected by the service.public void setProperties(TableServiceProperties tableServiceProperties)
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)));
tableServiceClient.setProperties(properties);
System.out.print("Set service properties successfully.");
tableServiceProperties - The TableServiceProperties to set.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<Void> setPropertiesWithResponse(TableServiceProperties tableServiceProperties, Duration timeout, com.azure.core.util.Context context)
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
HTTP response.
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)));
Response<Void> response = tableServiceClient.setPropertiesWithResponse(myProperties, Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Retrieved service properties successfully with status code: %d.", response.getStatusCode());
tableServiceProperties - The TableServiceProperties to set.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 TableServiceStatistics getStatistics()
This operation is only supported on Azure Storage endpoints.
Code Samples
Gets the replication statistics of the account's Table service.
TableServiceStatistics statistics = tableServiceClient.getStatistics();
System.out.print("Retrieved service statistics successfully.");
Statistics for the account's Table service.TableServiceException - If the request is rejected by the service.public com.azure.core.http.rest.Response<TableServiceStatistics> getStatisticsWithResponse(Duration timeout, com.azure.core.util.Context context)
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
HTTP response.
Response<TableServiceStatistics> response = tableServiceClient.getStatisticsWithResponse(Duration.ofSeconds(5),
new Context("key1", "value1"));
System.out.printf("Retrieved service statistics 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 containing statistics for the
account's Table service.TableServiceException - If the request is rejected by the service.Copyright © 2021 Microsoft Corporation. All rights reserved.