Partilhar via


TableClientBuilder Class

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

Implements

public final class TableClientBuilder
implements TokenCredentialTrait<TableClientBuilder>, AzureNamedKeyCredentialTrait<TableClientBuilder>, ConnectionStringTrait<TableClientBuilder>, AzureSasCredentialTrait<TableClientBuilder>, HttpTrait<TableClientBuilder>, ConfigurationTrait<TableClientBuilder>, EndpointTrait<TableClientBuilder>

Provides a fluent builder API to help aid the configuration and instantiation of a TableClient and TableAsyncClient.

Overview

This class provides a fluent builder API to help aid the configuration and instantiation of TableClient and TableAsyncClient objects. After properly authenticating the client, call buildClient() or buildAsyncClient(), respectively, to construct an instance of the desired client.

Getting Started

The minimal configuration options required by TableClientBuilder to build a TableClient or TableAsyncClient are a tableName and endpoint and a form of authentication, which can be set via: connectionString(String connectionString), credential(AzureNamedKeyCredential credential), credential(TokenCredential credential), credential(AzureSasCredential credential), or sasToken(String sasToken)

To build an instance of TableClient or TableAsyncClient call buildClient() or buildAsyncClient(), respectively.

The following example shows how to build a TableClient instance.

TableClient tableClient = new TableClientBuilder()
     .connectionString("connectionString")
     .tableName("tableName")
     .buildClient();

The following example shows how to build a TableAsyncClient instance.

TableAsyncClient tableClient = new TableClientBuilder()
     .connectionString("connectionString")
     .tableName("tableName")
     .buildAsyncClient();

Authenticating via Connection String

To use a connection string to authorize the client, call the builder's connectionString(String connectionString) method with your connection string. When authenticating via a connection string, providing an endpoint is not required.

TableClient tableClient = new TableClientBuilder()
     .connectionString("connectionString")
     .tableName("tableName")
     .buildClient();

Authentication via Shared Key

To use shared key authentication, create an instance of AzureNamedKeyCredential and pass it to the builder's credential(AzureNamedKeyCredential credential) method. Pass the account URL to the builder's endpoint(String endpoint) method.

TableClient tableClient = new TableClientBuilder()
     .credential(new AzureNamedKeyCredential("name", "key"))
     .tableName("tableName")
     .endpoint("endpoint")
     .buildClient();

Authentication via Shared Access Signature (SAS)

when authorizing a client utilizing a Shared Access Signature (SAS), you have the option of using AzureSasCredential or the SAS token directly. To use an AzureSasCredential, pass it to the builder's credential(AzureSasCredential credential) method. When authenticating with a SAS token, pass it to the builder's sasToken(String sasToken) method. Pass the account URL to the builder's endpoint(String endpoint) method.

Using AzureSasCredential:

TableClient tableClient = new TableClientBuilder()
     .credential(new AzureSasCredential("sasToken"))
     .endpoint("endpoint")
     .tableName("tableName")
     .buildClient();

Using SAS token:

TableClient tableClient = new TableClientBuilder()
     .sasToken("sasToken")
     .endpoint("endpoint")
     .tableName("tableName")
     .buildClient();

Authentication via Token Credential

To use token credential authentication, create an instance of a credential class that implements TokenCredential and pass it to the builder's credential(TokenCredential credential) method. Pass the account URL to the builder's endpoint(String endpoint) method.

TableClient tableClient = new TableClientBuilder()
     .endpoint("endpoint")
     .credential(new DefaultAzureCredentialBuilder().build())
     .tableName("tableName")
     .buildClient();

Constructor Summary

Constructor Description
TableClientBuilder()

Creates a builder instance that is able to configure and construct TableClient and TableAsyncClient objects.

Method Summary

Modifier and Type Method and Description
TableClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy)

Adds a HttpPipelinePolicy to apply on each request sent.

TableAsyncClient buildAsyncClient()

Creates a TableAsyncClient based on options set in the builder.

TableClient buildClient()

Creates a TableClient based on options set in the builder.

TableClientBuilder clientOptions(ClientOptions clientOptions)

Allows for setting common properties such as application ID, headers, proxy configuration, etc.

TableClientBuilder configuration(Configuration configuration)

Sets the Configuration object used to retrieve environment configuration values during building of the client.

TableClientBuilder connectionString(String connectionString)

Sets the connection string to connect to the service.

TableClientBuilder credential(AzureNamedKeyCredential credential)

Sets the AzureNamedKeyCredential used to authorize requests sent to the service.

TableClientBuilder credential(AzureSasCredential credential)

Sets the AzureSasCredential used to authorize requests sent to the service.

TableClientBuilder credential(TokenCredential credential)

Sets the TokenCredential used to authorize requests sent to the service.

TableClientBuilder enableTenantDiscovery()

Enable tenant discovery when authenticating with the Table Service.

TableClientBuilder endpoint(String endpoint)

Sets the service endpoint.

TableClientBuilder httpClient(HttpClient httpClient)

Sets the HttpClient to use for sending and receiving requests to and from the service.

TableClientBuilder httpLogOptions(HttpLogOptions logOptions)

Sets the HttpLogOptions to use when sending and receiving requests to and from the service.

TableClientBuilder pipeline(HttpPipeline pipeline)

Sets the HttpPipeline to use for the service client.

TableClientBuilder retryOptions(RetryOptions retryOptions)

Sets the RetryOptions for all the requests made through the client.

TableClientBuilder retryPolicy(RetryPolicy retryPolicy)

Sets the request RetryPolicy for all the requests made through the client.

TableClientBuilder sasToken(String sasToken)

Sets the SAS token used to authorize requests sent to the service.

TableClientBuilder serviceVersion(TableServiceVersion version)

Sets the TableServiceVersion that is used when making API requests.

TableClientBuilder tableName(String tableName)

Sets the name of the table.

Methods inherited from java.lang.Object

Constructor Details

TableClientBuilder

public TableClientBuilder()

Creates a builder instance that is able to configure and construct TableClient and TableAsyncClient objects.

Method Details

addPolicy

public TableClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy)

Adds a HttpPipelinePolicy to apply on each request sent.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

Parameters:

pipelinePolicy - A HttpPipelinePolicy.

Returns:

The updated TableClientBuilder.

buildAsyncClient

public TableAsyncClient buildAsyncClient()

Creates a TableAsyncClient based on options set in the builder.

Returns:

A TableAsyncClient created from the configurations in this builder.

buildClient

public TableClient buildClient()

Creates a TableClient based on options set in the builder.

Returns:

A TableClient created from the configurations in this builder.

clientOptions

public TableClientBuilder clientOptions(ClientOptions clientOptions)

Allows for setting common properties such as application ID, headers, proxy configuration, etc. Note that it is recommended that this method be called with an instance of the HttpClientOptions class (a subclass of the ClientOptions base class). The HttpClientOptions subclass provides more configuration options suitable for HTTP clients, which is applicable for any class that implements this HttpTrait interface.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

Parameters:

clientOptions - A configured instance of HttpClientOptions.

Returns:

The updated TableClientBuilder.

configuration

public TableClientBuilder configuration(Configuration configuration)

Sets the Configuration object used to retrieve environment configuration values during building of the client.

The Configuration is a clone of the global configuration store, use NONE to bypass using configuration settings during construction.

Parameters:

configuration - Configuration store used to retrieve environment configuration.

Returns:

The updated TableClientBuilder.

connectionString

public TableClientBuilder connectionString(String connectionString)

Sets the connection string to connect to the service.

Parameters:

connectionString - Connection string of the storage or CosmosDB table API account.

Returns:

The updated TableClientBuilder.

credential

public TableClientBuilder credential(AzureNamedKeyCredential credential)

Sets the AzureNamedKeyCredential used to authorize requests sent to the service. Setting this is mutually exclusive with using credential(AzureSasCredential credential), credential(TokenCredential credential) or sasToken(String sasToken).

Parameters:

credential - AzureNamedKeyCredential used to authorize requests sent to the service.

Returns:

The updated TableClientBuilder.

credential

public TableClientBuilder credential(AzureSasCredential credential)

Sets the AzureSasCredential used to authorize requests sent to the service. Setting this is mutually exclusive with credential(AzureNamedKeyCredential credential), credential(TokenCredential credential) or sasToken(String sasToken).

Parameters:

credential - AzureSasCredential used to authorize requests sent to the service.

Returns:

The updated TableClientBuilder.

credential

public TableClientBuilder credential(TokenCredential credential)

Sets the TokenCredential used to authorize requests sent to the service. Refer to the Azure SDK for Java identity and authentication documentation for more details on proper usage of the TokenCredential type. Setting this is mutually exclusive with using credential(AzureNamedKeyCredential credential), credential(AzureSasCredential credential) or sasToken(String sasToken).

Parameters:

credential - TokenCredential used to authorize requests sent to the service.

Returns:

The updated TableClientBuilder.

enableTenantDiscovery

public TableClientBuilder enableTenantDiscovery()

Enable tenant discovery when authenticating with the Table Service. This functionality is disabled by default and only available for Storage endpoints using service version V2020_12_06.

Enable this if there is a chance for your application and the Storage account it communicates with to reside in different tenants. If this is enabled, clients created using this builder will make an unauthorized initial service request that will be met with a 401 response containing an authentication challenge, which will be subsequently used to retrieve an access token to authorize all further requests with.

Returns:

The updated TableClientBuilder.

endpoint

public TableClientBuilder endpoint(String endpoint)

Sets the service endpoint.

Parameters:

endpoint - The URL of the storage or CosmosDB table API account endpoint.

Returns:

The updated TableClientBuilder.

httpClient

public TableClientBuilder httpClient(HttpClient httpClient)

Sets the HttpClient to use for sending and receiving requests to and from the service.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

Parameters:

httpClient - The HttpClient to use for requests.

Returns:

The updated TableClientBuilder.

httpLogOptions

public TableClientBuilder httpLogOptions(HttpLogOptions logOptions)

Sets the HttpLogOptions to use when sending and receiving requests to and from the service. If a logLevel is not provided, default value of HttpLogDetailLevel#NONE is set.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

Parameters:

logOptions - The HttpLogOptions to use when sending and receiving requests to and from the service.

Returns:

The updated TableClientBuilder.

pipeline

public TableClientBuilder pipeline(HttpPipeline pipeline)

Sets the HttpPipeline to use for the service client.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

The endpoint(String endpoint) is not ignored when pipeline is set.

Parameters:

pipeline - HttpPipeline to use for sending service requests and receiving responses.

Returns:

The updated TableClientBuilder.

retryOptions

public TableClientBuilder retryOptions(RetryOptions retryOptions)

Sets the RetryOptions for all the requests made through the client.

Note: It is important to understand the precedence order of the HttpTrait APIs. In particular, if a HttpPipeline is specified, this takes precedence over all other APIs in the trait, and they will be ignored. If no HttpPipeline is specified, a HTTP pipeline will be constructed internally based on the settings provided to this trait. Additionally, there may be other APIs in types that implement this trait that are also ignored if an HttpPipeline is specified, so please be sure to refer to the documentation of types that implement this trait to understand the full set of implications.

Setting this is mutually exclusive with using retryPolicy(RetryPolicy retryPolicy).

Parameters:

retryOptions - The RetryOptions to use for all the requests made through the client.

Returns:

The updated TableClientBuilder object.

retryPolicy

public TableClientBuilder retryPolicy(RetryPolicy retryPolicy)

Sets the request RetryPolicy for all the requests made through the client. The default RetryPolicy will be used in the pipeline, if not provided. Setting this is mutually exclusive with using retryOptions(RetryOptions retryOptions).

Parameters:

retryPolicy - RetryPolicy.

Returns:

The updated TableClientBuilder.

sasToken

public TableClientBuilder sasToken(String sasToken)

Sets the SAS token used to authorize requests sent to the service. Setting this is mutually exclusive with credential(AzureNamedKeyCredential credential), credential(AzureSasCredential credential) or credential(TokenCredential credential).

Parameters:

sasToken - The SAS token to use for authenticating requests.

Returns:

The updated TableClientBuilder.

serviceVersion

public TableClientBuilder serviceVersion(TableServiceVersion version)

Sets the TableServiceVersion that is used when making API requests.

If a TableServiceVersion is not provided, the TableServiceVersion that will be used will be the latest known TableServiceVersion based on the version of the client library being used. If no TableServiceVersion is specified, updating to a newer version of the client library will have the result of potentially moving to a newer TableServiceVersion.

Targeting a specific TableServiceVersion may also mean that the service will return an error for newer APIs.

Parameters:

version - The TableServiceVersion of the service to be used when making requests.

Returns:

The updated TableClientBuilder.

tableName

public TableClientBuilder tableName(String tableName)

Sets the name of the table.

Parameters:

tableName - Name of the table.

Returns:

The updated TableClientBuilder.

Applies to