diff --git a/sdk/tables/azure-data-tables/CHANGELOG.md b/sdk/tables/azure-data-tables/CHANGELOG.md index 3de53a69d815..d6cb39e65768 100644 --- a/sdk/tables/azure-data-tables/CHANGELOG.md +++ b/sdk/tables/azure-data-tables/CHANGELOG.md @@ -15,6 +15,8 @@ - The `getEntity` methods have gained the `select` query option to allow for more efficient existence checks for a table entity. [#15289](https://github.com/Azure/azure-sdk-for-java/issues/15289) - The non-functional `TableClient.listEntities(options, timeout)` method was removed. +- The JavaDoc API documentation has been significantly improved + [#13684](https://github.com/Azure/azure-sdk-for-java/issues/13684) ### Fixed diff --git a/sdk/tables/azure-data-tables/README.md b/sdk/tables/azure-data-tables/README.md index 478225124c1c..530b0ed4f235 100644 --- a/sdk/tables/azure-data-tables/README.md +++ b/sdk/tables/azure-data-tables/README.md @@ -53,7 +53,7 @@ Your Table API account URL, subsequently identified as ` `http(s)://.table.cosmosdb.azure.com`. ### Authenticate the client -Every request made to the Table service must be authorized using a connection string, shared key credential, or shared access signature. The samples below demonstrate the usage of these methods. +Every request made to the Tables service must be authorized using a connection string, shared key credential, or shared access signature. The samples below demonstrate the usage of these methods. Note: Azure Tables doesn't support Azure Active Directory (AAD) authentication. @@ -120,7 +120,7 @@ az storage table generate-sas \ - **Partition Key** - An entity's partition key identifies the partition within the table to which the entity belongs. Entities with the same partition key can be queried more quickly, and inserted/updated in atomic operations. - **Row Key** - An entity's row key is its unique identifier within a partition. -Common uses of the Table service include: +Common uses of the Tables service include: - Storing TBs of structured data capable of serving web scale applications - Storing datasets that don't require complex joins, foreign keys, or stored procedures and can be de-normalized for fast access diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java index 1258c08ca894..6d6469d1a18e 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; -class BuilderHelper { +final class BuilderHelper { private static final Map PROPERTIES = CoreUtils.getProperties("azure-data-tables.properties"); private static final String SDK_NAME = "name"; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index 5d7d0d14fecb..d95dc60b24e6 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -25,6 +25,7 @@ import com.azure.data.tables.implementation.models.ResponseFormat; import com.azure.data.tables.implementation.models.TableEntityQueryResponse; import com.azure.data.tables.implementation.models.TableProperties; +import com.azure.data.tables.implementation.models.TableServiceErrorException; import com.azure.data.tables.models.ListEntitiesOptions; import com.azure.data.tables.models.TableEntity; import com.azure.data.tables.models.UpdateMode; @@ -40,12 +41,18 @@ import static com.azure.core.util.FluxUtil.withContext; /** - * class for the table async client + * Provides an asynchronous service client for accessing a table in the Azure Tables service. + * + * 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 {@link TableClientBuilder#buildAsyncClient()} method on a + * {@link TableClientBuilder} object. */ -@ServiceClient( - builder = TableClientBuilder.class, - isAsync = true) -public class TableAsyncClient { +@ServiceClient(builder = TableClientBuilder.class, isAsync = true) +public final class TableAsyncClient { private static final String DELIMITER_CONTINUATION_TOKEN = ";"; private final ClientLogger logger = new ClientLogger(TableAsyncClient.class); private final String tableName; @@ -55,6 +62,9 @@ public class TableAsyncClient { TableAsyncClient(String tableName, AzureTableImpl implementation) { try { + if (tableName == null || tableName.isEmpty()) { + throw new IllegalArgumentException("'tableName' must be provided to create a TableClient"); + } final URI uri = URI.create(implementation.getUrl()); this.accountName = uri.getHost().split("\\.", 2)[0]; this.tableUrl = uri.resolve("/" + tableName).toString(); @@ -79,45 +89,46 @@ public class TableAsyncClient { } /** - * returns the table name associated with the client + * Gets the name of the table. * - * @return table name + * @return The name of the table. */ public String getTableName() { return tableName; } /** - * returns the account for this table + * Gets the name of the account containing the table. * - * @return returns the account name + * @return The name of the account containing the table. */ public String getAccountName() { return accountName; } /** - * returns Url of this table + * Gets the absolute URL for this table. * - * @return Url + * @return The absolute URL for this table. */ public String getTableUrl() { return tableUrl; } /** - * returns the version + * Gets the REST API version used by this client. * - * @return the version + * @return The REST API version used by this client. */ public TablesServiceVersion getApiVersion() { return TablesServiceVersion.valueOf(implementation.getVersion()); } /** - * creates new table with the name of this client + * Creates the table within the Tables service. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono create() { @@ -125,22 +136,16 @@ public Mono create() { } /** - * creates a new table with the name of this client + * Creates the table within the Tables service. * - * @return void + * @return A reactive result containing the HTTP response. + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createWithResponse() { return withContext(context -> createWithResponse(context)); } - /** - * creates a new table with the name of this client - * - * @param context the context of the query - * - * @return An HTTP response - */ Mono> createWithResponse(Context context) { return implementation.getTables().createWithResponseAsync(new TableProperties().setTableName(tableName), null, ResponseFormat.RETURN_NO_CONTENT, null, context).map(response -> { @@ -150,12 +155,14 @@ Mono> createWithResponse(Context context) { } /** - * insert a TableEntity with the given properties and return that TableEntity. Property map must include rowKey and - * partitionKey + * Inserts an entity into the table. * - * @param entity the entity + * @param entity The entity to insert. * - * @return the created TableEntity + * @return An empty reactive result. + * @throws TableServiceErrorException if an entity with the same partition key and row key already exists within the + * table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createEntity(TableEntity entity) { @@ -163,12 +170,14 @@ public Mono createEntity(TableEntity entity) { } /** - * insert a TableEntity with the given properties and return that TableEntity. Property map must include rowKey and - * partitionKey + * Inserts an entity into the table. * - * @param entity the entity + * @param entity The entity to insert. * - * @return a mono of the response with the TableEntity + * @return A reactive result containing the HTTP response. + * @throws TableServiceErrorException if an entity with the same partition key and row key already exists within the + * table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createEntityWithResponse(TableEntity entity) { @@ -189,11 +198,15 @@ Mono> createEntityWithResponse(TableEntity entity, Context contex } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or merges the entity with the existing entity otherwise. * - * @param entity entity to upsert + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the provided entity's properties will be merged into the existing entity. * - * @return void + * @param entity The entity to upsert. + * + * @return An empty reactive result. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upsertEntity(TableEntity entity) { @@ -201,12 +214,21 @@ public Mono upsertEntity(TableEntity entity) { } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update + * mode otherwise. + * + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the existing entity will be updated according to the specified update mode. * - * @param entity entity to upsert - * @param updateMode type of upsert + * 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. * - * @return void + * @param entity The entity to upsert. + * @param updateMode The type of update to perform if the entity already exits. + * + * @return An empty reactive result. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono upsertEntity(TableEntity entity, UpdateMode updateMode) { @@ -214,12 +236,21 @@ public Mono upsertEntity(TableEntity entity, UpdateMode updateMode) { } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update + * mode otherwise. + * + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the existing entity will be updated according to the specified update mode. * - * @param updateMode type of upsert - * @param entity entity to upsert + * 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. * - * @return a response + * @param entity The entity to upsert. + * @param updateMode The type of update to perform if the entity already exits. + * + * @return A reactive result containing the HTTP response. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> upsertEntityWithResponse(TableEntity entity, UpdateMode updateMode) { @@ -251,13 +282,13 @@ Mono> upsertEntityWithResponse(TableEntity entity, UpdateMode upd } /** - * updates the entity, using UpdateMode.MERGE - * - * merges or fails if the entity doesn't exist. + * Updates an existing entity by merging the provided entity with the existing entity. * - * @param entity the entity to update + * @param entity The entity to update. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateEntity(TableEntity entity) { @@ -265,58 +296,75 @@ public Mono updateEntity(TableEntity entity) { } /** - * updates the entity + * Updates an existing entity using the specified update mode. * - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or fails - * if the entity doesn't exist + * 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. * - * @param entity the entity to update - * @param updateMode which type of mode to execute + * @param entity The entity to update. + * @param updateMode The type of update to perform. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono updateEntity(TableEntity entity, UpdateMode updateMode) { - return updateEntity(entity, false, updateMode); + return updateEntity(entity, updateMode, false); } /** - * updates the entity + * Updates an existing entity using the specified update mode. * - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or fails - * if the entity doesn't exist + * 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. * - * @param updateMode which type of update to execute - * @param entity the entity to update - * @param ifUnchanged if the eTag of the entity must match the entity in the service or not + * @param entity The entity to update. + * @param updateMode The type of update to perform. + * @param 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. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table, + * or if {@code ifUnchanged} is {@code true} and the existing entity's eTag does + * not match that of the provided entity. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono updateEntity(TableEntity entity, boolean ifUnchanged, UpdateMode updateMode) { - return updateEntityWithResponse(entity, ifUnchanged, updateMode).flatMap(response -> + public Mono updateEntity(TableEntity entity, UpdateMode updateMode, boolean ifUnchanged) { + return updateEntityWithResponse(entity, updateMode, ifUnchanged).flatMap(response -> Mono.justOrEmpty(response.getValue())); } /** - * updates the entity + * Updates an existing entity using the specified update mode. * - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or fails - * if the entity doesn't exist + * 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. * - * @param updateMode which type of update to execute - * @param entity the entity to update - * @param ifUnchanged if the eTag of the entity must match the entity in the service or not + * @param entity The entity to update. + * @param updateMode The type of update to perform. + * @param 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. * - * @return a response + * @return A reactive result containing the HTTP response. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table, + * or if {@code ifUnchanged} is {@code true} and the existing entity's eTag does + * not match that of the provided entity. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, - UpdateMode updateMode) { - return withContext(context -> updateEntityWithResponse(entity, ifUnchanged, updateMode, null, context)); + public Mono> updateEntityWithResponse(TableEntity entity, UpdateMode updateMode, + boolean ifUnchanged) { + return withContext(context -> updateEntityWithResponse(entity, updateMode, ifUnchanged, null, context)); } - Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, UpdateMode updateMode, + Mono> updateEntityWithResponse(TableEntity entity, UpdateMode updateMode, boolean ifUnchanged, Duration timeout, Context context) { Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (entity == null) { @@ -366,9 +414,10 @@ Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnch } /** - * deletes the table with the name of this client + * Deletes the table within the Tables service. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no table with this name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono delete() { @@ -376,22 +425,16 @@ public Mono delete() { } /** - * deletes the table with the name of this client + * Deletes the table within the Tables service. * - * @return void + * @return A reactive result containing the response. + * @throws TableServiceErrorException if no table with this name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteWithResponse() { return withContext(context -> deleteWithResponse(context)); } - /** - * deletes the table with the name of this client - * - * @param context the context of the query - * - * @return a table - */ Mono> deleteWithResponse(Context context) { return implementation.getTables().deleteWithResponseAsync(tableName, null, context).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), @@ -400,12 +443,15 @@ Mono> deleteWithResponse(Context context) { } /** - * deletes the given entity + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteEntity(String partitionKey, String rowKey) { @@ -413,13 +459,18 @@ public Mono deleteEntity(String partitionKey, String rowKey) { } /** - * deletes the given entity + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key - * @param eTag the eTag of the entity, the delete will only occur if this matches the entity in the service + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match, + * the delete will not occur and an exception will be thrown. * - * @return void + * @return An empty reactive result. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table, or if {@code eTag} is not {@code null} and the existing entity's eTag + * does not match that of the provided entity. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteEntity(String partitionKey, String rowKey, String eTag) { @@ -427,13 +478,18 @@ public Mono deleteEntity(String partitionKey, String rowKey, String eTag) } /** - * deletes the given entity + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key - * @param eTag the eTag of the entity, the delete will only occur if this matches the entity in the service + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match, + * the delete will not occur and an exception will be thrown. * - * @return a response + * @return A reactive result containing the response. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table, or if {@code eTag} is not {@code null} and the existing entity's eTag + * does not match that of the provided entity. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteEntityWithResponse(String partitionKey, String rowKey, String eTag) { @@ -453,9 +509,9 @@ Mono> deleteEntityWithResponse(String partitionKey, String rowKey } /** - * Queries and returns all entities in the given table + * Lists all entities within the table. * - * @return a paged flux of all the entities in the table + * @return A paged reactive result containing all entities within the table. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listEntities() { @@ -463,11 +519,16 @@ public PagedFlux listEntities() { } /** - * Queries and returns entities in the given table using the odata query options + * Lists entities using the parameters in the provided options. * - * @param options the odata query object + * 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 number of returned entities will be limited to that value. * - * @return a paged flux of all the entities which fit this criteria + * @param options The `filter`, `select`, and `top` OData query options to apply to this operation. + * + * @return A paged reactive result containing matching entities within the table. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listEntities(ListEntitiesOptions options) { @@ -477,12 +538,13 @@ public PagedFlux listEntities(ListEntitiesOptions options) { } /** - * Queries and returns entities in the given table using the odata query options + * Lists all entities within the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return a paged flux of all the entities which fit this criteria + * @return A paged reactive result containing all entities within the table. + * @throws IllegalArgumentException if an instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listEntities(Class resultType) { @@ -490,13 +552,19 @@ public PagedFlux listEntities(Class resultType) { } /** - * Queries and returns entities in the given table using the odata query options + * Lists 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 number of returned entities will be limited to that value. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param options the odata query object - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param options The `filter`, `select`, and `top` OData query options to apply to this operation. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return a paged flux of all the entities which fit this criteria + * @return A paged reactive result containing matching entities within the table. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed, or if + * an instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listEntities(ListEntitiesOptions options, Class resultType) { @@ -615,12 +683,15 @@ public void close() { } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. * - * @return a mono of the table entity + * @return A reactive result containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getEntity(String partitionKey, String rowKey) { @@ -628,14 +699,17 @@ public Mono getEntity(String partitionKey, String rowKey) { } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. * - * @return a mono of the table entity + * @return A reactive result containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if the + * {@code select} OData query option is malformed. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getEntity(String partitionKey, String rowKey, String select) { @@ -643,14 +717,18 @@ public Mono getEntity(String partitionKey, String rowKey, String se } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return a mono of the table entity subclass specified in resultType + * @return A reactive result containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if an + * instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getEntity(String partitionKey, String rowKey, Class resultType) { @@ -658,16 +736,20 @@ public Mono getEntity(String partitionKey, String row } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return a mono of the table entity subclass specified in resultType + * @return A reactive result containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, if the + * {@code select} OData query option is malformed, or if an instance of the + * provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono getEntity(String partitionKey, String rowKey, String select, @@ -676,14 +758,17 @@ public Mono getEntity(String partitionKey, String row } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. * - * @return a mono of the response with the table entity + * @return A reactive result containing the response and entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if the + * {@code select} OData query option is malformed. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getEntityWithResponse(String partitionKey, String rowKey, String select) { @@ -692,16 +777,20 @@ public Mono> getEntityWithResponse(String partitionKey, St } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return a mono of the response with the table entity subclass specified in resultType + * @return A reactive result containing the response and entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, if the + * {@code select} OData query option is malformed, or if an instance of the + * provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> getEntityWithResponse(String partitionKey, String rowKey, diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java index 10765d10f38f..77f63e7bebb8 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java @@ -8,6 +8,7 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; +import com.azure.data.tables.implementation.models.TableServiceErrorException; import com.azure.data.tables.models.ListEntitiesOptions; import com.azure.data.tables.models.TableEntity; import com.azure.data.tables.models.UpdateMode; @@ -15,10 +16,17 @@ import java.time.Duration; /** - * sync client for table operations + * Provides a synchronous service client for accessing a table in the Azure Tables service. + * + * 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 {@link TableClientBuilder#buildClient()} method on a + * {@link TableClientBuilder} object. */ -@ServiceClient( - builder = TableClientBuilder.class) +@ServiceClient(builder = TableClientBuilder.class) public class TableClient { final TableAsyncClient client; @@ -27,43 +35,45 @@ public class TableClient { } /** - * returns the table name associated with the client* + * Gets the name of the table. * - * @return table name + * @return The name of the table. */ public String getTableName() { return this.client.getTableName(); } /** - * returns the account for this table + * Gets the name of the account containing the table. * - * @return a string of the account name + * @return The name of the account containing the table. */ public String getAccountName() { return this.client.getAccountName(); } /** - * returns Url of this table + * Gets the absolute URL for this table. * - * @return Url + * @return The absolute URL for this table. */ public String getTableUrl() { return this.client.getTableUrl(); } /** - * returns the version + * Gets the REST API version used by this client. * - * @return the version + * @return The REST API version used by this client. */ public TablesServiceVersion getApiVersion() { return this.client.getApiVersion(); } /** - * creates new table with the name of this client + * Creates the table within the Tables service. + * + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public void create() { @@ -71,9 +81,11 @@ public void create() { } /** - * creates new table with the name of this client + * Creates the table within the Tables service. * - * @param timeout Duration to wait for operation to complete. + * @param timeout Duration to wait for the operation to complete. + * @throws TableServiceErrorException if a table with the same name already exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public void create(Duration timeout) { @@ -81,11 +93,13 @@ public void create(Duration timeout) { } /** - * creates a new table with the name of this client + * Creates the table within the Tables service. * - * @param timeout Duration to wait for operation to complete. + * @param timeout Duration to wait for the operation to complete. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return The HTTP response. + * @throws TableServiceErrorException if a table with the same name already exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response createWithResponse(Duration timeout, Context context) { @@ -93,46 +107,58 @@ public Response createWithResponse(Duration timeout, Context context) { } /** - * insert a TableEntity with the given properties and return that TableEntity. Property map must include - * rowKey and partitionKey + * Inserts an entity into the table. * - * @param tableEntity the entity to add + * @param entity The entity to insert. + * @throws TableServiceErrorException if an entity with the same partition key and row key already exists within the + * table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) - public void createEntity(TableEntity tableEntity) { - client.createEntity(tableEntity).block(); + public void createEntity(TableEntity entity) { + client.createEntity(entity).block(); } /** - * insert a TableEntity with the given properties and return that TableEntity. Property map must include - * rowKey and partitionKey + * Inserts an entity into the table. * - * @param tableEntity the entity to add - * @param timeout max time for query to execute before erroring out + * @param entity The entity to insert. + * @param timeout Duration to wait for the operation to complete. + * @throws TableServiceErrorException if an entity with the same partition key and row key already exists within the + * table. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public void createEntity(TableEntity tableEntity, Duration timeout) { - createEntityWithResponse(tableEntity, timeout, null).getValue(); + public void createEntity(TableEntity entity, Duration timeout) { + createEntityWithResponse(entity, timeout, null).getValue(); } /** - * insert a TableEntity with the given properties and return that TableEntity. Property map must include - * rowKey and partitionKey + * Inserts an entity into the table. * - * @param tableEntity the entity to add - * @param timeout max time for query to execute before erroring out - * @param context the context of the query - * @return a response + * @param entity The entity to insert. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws TableServiceErrorException if an entity with the same partition key and row key already exists within the + * table. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createEntityWithResponse(TableEntity tableEntity, Duration timeout, Context context) { - return client.createEntityWithResponse(tableEntity, context).block(timeout); + public Response createEntityWithResponse(TableEntity entity, Duration timeout, Context context) { + return client.createEntityWithResponse(entity, context).block(timeout); } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or merges the entity with the existing entity otherwise. * - * @param entity entity to upsert + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the provided entity's properties will be merged into the existing entity. + * + * @param entity The entity to upsert. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public void upsertEntity(TableEntity entity) { @@ -140,10 +166,19 @@ public void upsertEntity(TableEntity entity) { } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update + * mode otherwise. + * + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the existing entity will be updated according to the specified update mode. + * + * 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. * - * @param updateMode type of upsert - * @param entity entity to upsert + * @param entity The entity to upsert. + * @param updateMode The type of update to perform if the entity already exits. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public void upsertEntity(TableEntity entity, UpdateMode updateMode) { @@ -151,11 +186,21 @@ public void upsertEntity(TableEntity entity, UpdateMode updateMode) { } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update + * mode otherwise. * - * @param updateMode type of upsert - * @param entity entity to upsert - * @param timeout max time for query to execute before erroring out + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the existing entity will be updated according to the specified update mode. + * + * 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. + * + * @param entity The entity to upsert. + * @param updateMode The type of update to perform if the entity already exits. + * @param timeout Duration to wait for the operation to complete. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public void upsertEntity(TableEntity entity, UpdateMode updateMode, Duration timeout) { @@ -163,13 +208,23 @@ public void upsertEntity(TableEntity entity, UpdateMode updateMode, Duration tim } /** - * based on Mode it either inserts or merges if exists or inserts or merges if exists + * Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update + * mode otherwise. + * + * If no entity exists within the table having the same partition key and row key as the provided entity, it will + * be inserted. Otherwise, the existing entity will be updated according to the specified update mode. * - * @param updateMode type of upsert - * @param entity entity to upsert - * @param timeout max time for query to execute before erroring out - * @param context the context of the query - * @return a response + * 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. + * + * @param entity The entity to upsert. + * @param updateMode The type of update to perform if the entity already exits. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response upsertEntityWithResponse(TableEntity entity, UpdateMode updateMode, Duration timeout, @@ -178,10 +233,11 @@ public Response upsertEntityWithResponse(TableEntity entity, UpdateMode up } /** - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or - * fails if the entity doesn't exist + * Updates an existing entity by merging the provided entity with the existing entity. * - * @param entity the entity to update + * @param entity The entity to update. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public void updateEntity(TableEntity entity) { @@ -189,11 +245,16 @@ public void updateEntity(TableEntity entity) { } /** - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or - * fails if the entity doesn't exist + * Updates an existing entity using the specified update mode. + * + * 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. * - * @param updateMode which type of update to execute - * @param entity the entity to update + * @param entity The entity to update. + * @param updateMode which type of mode to execute + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) public void updateEntity(TableEntity entity, UpdateMode updateMode) { @@ -201,51 +262,82 @@ public void updateEntity(TableEntity entity, UpdateMode updateMode) { } /** - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or - * fails if the entity doesn't exist + * Updates an existing entity using the specified update mode. + * + * 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. * - * @param updateMode which type of update to execute - * @param entity the entity to update - * @param ifUnchanged if the eTag of the entity must match the entity in the service or not + * @param entity The entity to update. + * @param updateMode The type of update to perform. + * @param 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. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table, + * or if {@code ifUnchanged} is {@code true} and the existing entity's eTag does + * not match that of the provided entity. + * @throws IllegalArgumentException if the provided entity is invalid. */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(TableEntity entity, boolean ifUnchanged, UpdateMode updateMode) { - client.updateEntity(entity, ifUnchanged, updateMode).block(); + public void updateEntity(TableEntity entity, UpdateMode updateMode, boolean ifUnchanged) { + client.updateEntity(entity, updateMode, ifUnchanged).block(); } /** - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or - * fails if the entity doesn't exist + * Updates an existing entity using the specified update mode. * - * @param updateMode which type of update to execute - * @param entity the entity to update - * @param ifUnchanged if the eTag of the entity must match the entity in the service or not - * @param timeout max time for query to execute before erroring out + * 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. + * + * @param entity The entity to update. + * @param updateMode The type of update to perform. + * @param 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. + * @param timeout Duration to wait for the operation to complete. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table, + * or if {@code ifUnchanged} is {@code true} and the existing entity's eTag does + * not match that of the provided entity. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(TableEntity entity, boolean ifUnchanged, UpdateMode updateMode, Duration timeout) { - updateEntityWithResponse(entity, ifUnchanged, updateMode, timeout, null).getValue(); + public void updateEntity(TableEntity entity, UpdateMode updateMode, boolean ifUnchanged, Duration timeout) { + updateEntityWithResponse(entity, updateMode, ifUnchanged, timeout, null).getValue(); } /** - * if UpdateMode is MERGE, merges or fails if the entity doesn't exist. If UpdateMode is REPLACE replaces or - * fails if the entity doesn't exist + * Updates an existing entity using the specified update mode. + * + * 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. * - * @param updateMode which type of update to execute - * @param entity the entity to update - * @param ifUnchanged if the eTag of the entity must match the entity in the service or not - * @param timeout max time for query to execute before erroring out - * @param context the context of the query - * @return a response + * @param entity The entity to update. + * @param updateMode The type of update to perform. + * @param 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. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws TableServiceErrorException if no entity with the same partition key and row key exists within the table, + * or if {@code ifUnchanged} is {@code true} and the existing entity's eTag does + * not match that of the provided entity. + * @throws IllegalArgumentException if the provided entity is invalid. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, UpdateMode updateMode, + public Response updateEntityWithResponse(TableEntity entity, UpdateMode updateMode, boolean ifUnchanged, Duration timeout, Context context) { - return client.updateEntityWithResponse(entity, ifUnchanged, updateMode, timeout, context).block(); + return client.updateEntityWithResponse(entity, updateMode, ifUnchanged, timeout, context).block(); } /** - * deletes the table with the name of this client + * Deletes the table within the Tables service. + * + * @throws TableServiceErrorException if no table with this name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public void delete() { @@ -253,9 +345,11 @@ public void delete() { } /** - * deletes the table with the name of this client + * Deletes the table within the Tables service. * - * @param timeout Duration to wait for operation to complete. + * @param timeout Duration to wait for the operation to complete. + * @throws TableServiceErrorException if no table with this name exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public void delete(Duration timeout) { @@ -263,11 +357,13 @@ public void delete(Duration timeout) { } /** - * deletes the table with the name of this client + * Deletes the table within the Tables service. * - * @param timeout Duration to wait for operation to complete. + * @param timeout Duration to wait for the operation to complete. * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return The HTTP response. + * @throws TableServiceErrorException if no table with this name exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response deleteWithResponse(Duration timeout, Context context) { @@ -275,10 +371,13 @@ public Response deleteWithResponse(Duration timeout, Context context) { } /** - * deletes the entity with the given partition key and row key + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteEntity(String partitionKey, String rowKey) { @@ -286,11 +385,16 @@ public void deleteEntity(String partitionKey, String rowKey) { } /** - * deletes the entity with the given partition key and row key + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key - * @param eTag the eTag of the entity, the delete will only occur if this matches the entity in the service + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match, + * the delete will not occur and an exception will be thrown. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table, or if {@code eTag} is not {@code null} and the existing entity's eTag + * does not match that of the provided entity. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteEntity(String partitionKey, String rowKey, String eTag) { @@ -298,12 +402,18 @@ public void deleteEntity(String partitionKey, String rowKey, String eTag) { } /** - * deletes the given entity + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key - * @param eTag the eTag of the entity, the delete will only occur if this matches the entity in the service - * @param timeout max time for query to execute before erroring out + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match, + * the delete will not occur and an exception will be thrown. + * @param timeout Duration to wait for the operation to complete. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table, or if {@code eTag} is not {@code null} and the existing entity's eTag + * does not match that of the provided entity. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteEntity(String partitionKey, String rowKey, String eTag, Duration timeout) { @@ -311,14 +421,20 @@ public void deleteEntity(String partitionKey, String rowKey, String eTag, Durati } /** - * deletes the given entity + * Deletes an entity from the table. * - * @param partitionKey the partition key - * @param rowKey the row key - * @param eTag the eTag of the entity, the delete will only occur if this matches the entity in the service - * @param timeout max time for query to execute before erroring out - * @param context the context of the query - * @return a response + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param eTag The value to compare with the eTag of the entity in the Tables service. If the values do not match, + * the delete will not occur and an exception will be thrown. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table, or if {@code eTag} is not {@code null} and the existing entity's eTag + * does not match that of the provided entity. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response deleteEntityWithResponse(String partitionKey, String rowKey, String eTag, Duration timeout, @@ -327,9 +443,9 @@ public Response deleteEntityWithResponse(String partitionKey, String rowKe } /** - * Queries and returns all entities in the given table + * Lists all entities within the table. * - * @return a list of all the entities which fit this criteria + * @return A paged iterable containing all entities within the table. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listEntities() { @@ -337,10 +453,16 @@ public PagedIterable listEntities() { } /** - * Queries and returns entities in the given table using the odata QueryOptions + * Lists entities using the parameters in the provided options. * - * @param options the odata query object - * @return a list of all the entities which fit this criteria + * 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 number of returned entities will be limited to that value. + * + * @param options The `filter`, `select`, and `top` OData query options to apply to this operation. + * + * @return A paged iterable containing matching entities within the table. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listEntities(ListEntitiesOptions options) { @@ -348,11 +470,13 @@ public PagedIterable listEntities(ListEntitiesOptions options) { } /** - * Queries and returns all entities in the given table + * Lists all entities within the table. + * + * @param The type of the result value, which must be a subclass of TableEntity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param resultType the type of the result value, which must be a subclass of TableEntity - * @return a list of all the entities which fit this criteria + * @return A paged iterable containing all entities within the table. + * @throws IllegalArgumentException if an instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listEntities(Class resultType) { @@ -360,12 +484,19 @@ public PagedIterable listEntities(Class resultType } /** - * Queries and returns entities in the given table using the odata QueryOptions + * Lists 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 number of returned entities will be limited to that value. + * + * @param The type of the result value, which must be a subclass of TableEntity. + * @param options The `filter`, `select`, and `top` OData query options to apply to this operation. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param options the odata query object - * @param resultType the type of the result value, which must be a subclass of TableEntity - * @return a list of all the entities which fit this criteria + * @return A paged iterable containing matching entities within the table. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed, or if + * an instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listEntities(ListEntitiesOptions options, Class resultType) { @@ -373,11 +504,15 @@ public PagedIterable listEntities(ListEntitiesOptions } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @return the table entity + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public TableEntity getEntity(String partitionKey, String rowKey) { @@ -385,13 +520,17 @@ public TableEntity getEntity(String partitionKey, String rowKey) { } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. + * + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @return the table entity + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if the + * {@code select} OData query option is malformed. */ @ServiceMethod(returns = ReturnType.SINGLE) public TableEntity getEntity(String partitionKey, String rowKey, String select) { @@ -399,14 +538,18 @@ public TableEntity getEntity(String partitionKey, String rowKey, String select) } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return the table entity subclass specified in resultType + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if an + * instance of the provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.SINGLE) public T getEntity(String partitionKey, String rowKey, Class resultType) { @@ -414,16 +557,20 @@ public T getEntity(String partitionKey, String rowKey, C } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param resultType the type of the result value, which must be a subclass of TableEntity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. * - * @return the table entity subclass specified in resultType + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, if the + * {@code select} OData query option is malformed, or if an instance of the + * provided {@code resultType} can't be created. */ @ServiceMethod(returns = ReturnType.SINGLE) public T getEntity(String partitionKey, String rowKey, String select, Class resultType) { @@ -431,14 +578,19 @@ public T getEntity(String partitionKey, String rowKey, S } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. + * + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param timeout Duration to wait for the operation to complete. * - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param timeout max time for query to execute before erroring out - * @return the table entity + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if the + * {@code select} OData query option is malformed. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public TableEntity getEntity(String partitionKey, String rowKey, String select, Duration timeout) { @@ -446,16 +598,22 @@ public TableEntity getEntity(String partitionKey, String rowKey, String select, } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param resultType the type of the result value, which must be a subclass of TableEntity - * @param timeout max time for query to execute before erroring out - * @return the table entity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. + * @param timeout Duration to wait for the operation to complete. + * + * @return The entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, if the + * {@code select} OData query option is malformed, or if an instance of the + * provided {@code resultType} can't be created. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public T getEntity(String partitionKey, String rowKey, String select, Class resultType, @@ -464,17 +622,45 @@ public T getEntity(String partitionKey, String rowKey, S } /** - * gets the entity which fits the given criteria + * Gets a single entity from the table. + * + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return The HTTP response containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, or if the + * {@code select} OData query option is malformed. + * @throws RuntimeException if the provided timeout expires. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getEntityWithResponse(String partitionKey, String rowKey, String select, + Duration timeout, Context context) { + return client.getEntityWithResponse(partitionKey, rowKey, select, TableEntity.class, timeout, context).block(); + } + + /** + * Gets a single entity from the table. * - * @param the type of the result value, which must be a subclass of TableEntity - * @param partitionKey the partition key of the entity - * @param rowKey the row key of the entity - * @param select a select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". - * @param resultType the type of the result value, which must be a subclass of TableEntity - * @param timeout max time for query to execute before erroring out - * @param context the context of the query - * @return a mono of the response with the table entity + * @param The type of the result value, which must be a subclass of TableEntity. + * @param partitionKey The partition key of the entity. + * @param rowKey The partition key of the entity. + * @param select An OData `select` expression to limit the set of properties included in the returned entity. + * @param resultType The type of the result value, which must be a subclass of TableEntity. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * + * @return The HTTP response containing the entity. + * @throws TableServiceErrorException if no entity with the provided partition key and row key exists within the + * table. + * @throws IllegalArgumentException if the provided partition key or row key are {@code null} or empty, if the + * {@code select} OData query option is malformed, or if an instance of the + * provided {@code resultType} can't be created. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) public Response getEntityWithResponse(String partitionKey, String rowKey, String select, @@ -482,5 +668,4 @@ public Response getEntityWithResponse(String partitio Context context) { return client.getEntityWithResponse(partitionKey, rowKey, select, resultType, timeout, context).block(); } - } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java index ba61e24e0ddb..6c7215deb2db 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java @@ -26,7 +26,9 @@ import java.util.Objects; /** - * builds table client + * This class provides a fluent builder API to help aid the configuration and instantiation of {@link TableClient} and + * {@link TableAsyncClient} objects. Call {@link #buildClient()} or {@link #buildAsyncClient()}, respectively, to + * construct an instance of the desired client. */ @ServiceClientBuilder(serviceClients = {TableClient.class, TableAsyncClient.class}) public class TableClientBuilder { @@ -43,11 +45,11 @@ public class TableClientBuilder { private HttpPipeline httpPipeline; private SasTokenCredential sasTokenCredential; private TablesServiceVersion version; - private String accountName; private RequestRetryOptions retryOptions = new RequestRetryOptions(); /** - * Create a new `TableClientBuilder` + * Creates a builder instance that is able to configure and construct {@link TableClient} and + * {@link TableAsyncClient} objects. */ public TableClientBuilder() { policies = new ArrayList<>(); @@ -55,10 +57,37 @@ public TableClientBuilder() { } /** - * Sets the connection string to help build the client + * Creates a {@link TableClient} based on options set in the builder. * - * @param connectionString the connection string to the storage account - * @return the TableClientBuilder + * @return A {@link TableClient} created from the configurations in this builder. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + */ + public TableClient buildClient() { + return new TableClient(buildAsyncClient()); + } + + /** + * Creates a {@link TableAsyncClient} based on options set in the builder. + * + * @return A {@link TableAsyncClient} created from the configurations in this builder. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + */ + public TableAsyncClient buildAsyncClient() { + TablesServiceVersion serviceVersion = version != null ? version : TablesServiceVersion.getLatest(); + + HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline( + (TablesSharedKeyCredential) tokenCredential, tokenCredential, sasTokenCredential, endpoint, retryOptions, + httpLogOptions, httpClient, policies, configuration, logger); + + return new TableAsyncClient(tableName, pipeline, endpoint, serviceVersion, serializerAdapter); + } + + /** + * Sets the connection string to connect to the service. + * + * @param connectionString Connection string of the storage or CosmosDB table API account. + * @return The updated {@code TableClientBuilder}. + * @throws IllegalArgumentException if {@code connectionString} isn't a valid connection string. */ public TableClientBuilder connectionString(String connectionString) { StorageConnectionString storageConnectionString @@ -67,15 +96,12 @@ public TableClientBuilder connectionString(String connectionString) { if (endpoint == null || endpoint.getPrimaryUri() == null) { throw logger .logExceptionAsError(new IllegalArgumentException( - "connectionString missing required settings to derive blob service endpoint.")); + "connectionString missing required settings to derive tables service endpoint.")); } this.endpoint(endpoint.getPrimaryUri()); - if (storageConnectionString.getAccountName() != null) { - this.accountName = storageConnectionString.getAccountName(); - } StorageAuthenticationSettings authSettings = storageConnectionString.getStorageAuthSettings(); if (authSettings.getType() == StorageAuthenticationSettings.Type.ACCOUNT_NAME_KEY) { - this.credential((TokenCredential) new TablesSharedKeyCredential(authSettings.getAccount().getName(), + this.credential(new TablesSharedKeyCredential(authSettings.getAccount().getName(), authSettings.getAccount().getAccessKey())); } else if (authSettings.getType() == StorageAuthenticationSettings.Type.SAS_TOKEN) { this.sasToken(authSettings.getSasToken()); @@ -84,47 +110,11 @@ public TableClientBuilder connectionString(String connectionString) { } /** - * Sets the table name to help build the client - * - * @param tableName name of the table for which the client is created for - * @return the TableClientBuilder - */ - public TableClientBuilder tableName(String tableName) { - this.tableName = tableName; - return this; - } - - /** - * builds a sync tableClient - * - * @return a sync tableClient - */ - public TableClient buildClient() { - return new TableClient(buildAsyncClient()); - } - - /** - * builds an async tableClient + * Sets the service endpoint. * - * @return an aysnc tableClient - */ - public TableAsyncClient buildAsyncClient() { - TablesServiceVersion serviceVersion = version != null ? version : TablesServiceVersion.getLatest(); - - HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline( - (TablesSharedKeyCredential) tokenCredential, tokenCredential, sasTokenCredential, endpoint, retryOptions, - httpLogOptions, httpClient, policies, configuration, logger); - - return new TableAsyncClient(tableName, pipeline, endpoint, serviceVersion, serializerAdapter); - } - - /** - * Sets the endpoint for the Azure Storage Table instance that the client will interact with. - * - * @param endpoint The URL of the Azure Storage Table instance to send service requests to and receive responses - * from. - * @return the updated TableClientBuilder object - * @throws IllegalArgumentException If {@code endpoint} isn't a proper URL + * @param endpoint The URL of the storage or CosmosDB table API account endpoint. + * @return The updated {@code TableClientBuilder}. + * @throws IllegalArgumentException if {@code endpoint} isn't a valid URL. */ public TableClientBuilder endpoint(String endpoint) { try { @@ -137,10 +127,11 @@ public TableClientBuilder endpoint(String endpoint) { } /** - * Sets the HTTP pipeline to use for the service client. + * Sets the {@link HttpPipeline} to use for the service client. If {@code pipeline} is set, all other settings are + * ignored, aside from {@code endpoint}. * - * @param pipeline The HTTP pipeline to use for sending service requests and receiving responses. - * @return The updated TableClientBuilder object. + * @param pipeline {@link HttpPipeline} to use for sending service requests and receiving responses. + * @return The updated {@code TableClientBuilder}. */ public TableClientBuilder pipeline(HttpPipeline pipeline) { if (this.httpPipeline != null && pipeline == null) { @@ -154,8 +145,8 @@ public TableClientBuilder pipeline(HttpPipeline pipeline) { * Sets the SAS token used to authorize requests sent to the service. * * @param sasToken The SAS token to use for authenticating requests. - * @return the updated BlobClientBuilder - * @throws NullPointerException If {@code sasToken} is {@code null}. + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code sasToken} is {@code null}. */ public TableClientBuilder sasToken(String sasToken) { this.sasTokenCredential = new SasTokenCredential(Objects.requireNonNull(sasToken, @@ -165,13 +156,13 @@ public TableClientBuilder sasToken(String sasToken) { } /** - * Sets the configuration store that is used during construction of the service client. - *

+ * Sets the configuration object used to retrieve environment configuration values during building of the client. + * * The default configuration store is a clone of the {@link Configuration#getGlobalConfiguration() global * configuration store}, use {@link Configuration#NONE} to bypass using configuration settings during construction. * - * @param configuration The configuration store used to - * @return The updated TableClientBuilder object. + * @param configuration Configuration store used to retrieve environment configurations. + * @return The updated {@code TableClientBuilder}. */ public TableClientBuilder configuration(Configuration configuration) { this.configuration = configuration; @@ -179,11 +170,11 @@ public TableClientBuilder configuration(Configuration configuration) { } /** - * Sets the {@link TokenCredential} used to authenticate HTTP requests. + * Sets the {@link TokenCredential} used to authorize requests sent to the service. * - * @param credential TokenCredential used to authenticate HTTP requests. - * @return The updated TableClientBuilder object. - * @throws NullPointerException If {@code credential} is {@code null}. + * @param credential {@link TokenCredential} used to authorize requests sent to the service. + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code credential} is {@code null}. */ public TableClientBuilder credential(TokenCredential credential) { this.tokenCredential = Objects.requireNonNull(credential, "credential cannot be null."); @@ -191,26 +182,27 @@ public TableClientBuilder credential(TokenCredential credential) { } /** - * Sets the HTTP client to use for sending and receiving requests to and from the service. + * Sets the {@link HttpClient} to use for sending and receiving requests to and from the service. * - * @param client The HTTP client to use for requests. - * @return The updated TableClientBuilder object. + * @param httpClient The {@link HttpClient} to use for requests. + * @return The updated {@code TableClientBuilder}. */ - public TableClientBuilder httpClient(HttpClient client) { - if (this.httpClient != null && client == null) { + public TableClientBuilder httpClient(HttpClient httpClient) { + if (this.httpClient != null && httpClient == null) { logger.error("'httpClient' is being set to 'null' when it was previously configured."); } - this.httpClient = client; + this.httpClient = httpClient; return this; } /** - * Sets the logging configuration for HTTP requests and responses. + * Sets the logging configuration to use when sending and receiving requests to and from the service. * - *

If logLevel is not provided, default value of {@link HttpLogDetailLevel#NONE} is set.

+ * If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set. * - * @param logOptions The logging configuration to use when sending and receiving HTTP requests/responses. - * @return The updated TableClientBuilder object. + * @param logOptions The logging configuration to use when sending and receiving requests to and from the service. + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code logOptions} is {@code null}. */ public TableClientBuilder httpLogOptions(HttpLogOptions logOptions) { this.httpLogOptions = Objects.requireNonNull(logOptions, "'logOptions' cannot be null."); @@ -218,11 +210,12 @@ public TableClientBuilder httpLogOptions(HttpLogOptions logOptions) { } /** - * Adds a policy to the set of existing policies that are executed after required policies. + * Adds a pipeline policy to apply on each request sent. The policy will be added after the retry policy. If + * the method is called multiple times, all policies will be added and their order preserved. * - * @param pipelinePolicy The retry policy for service requests. - * @return The updated TableClientBuilder object. - * @throws NullPointerException If {@code policy} is {@code null}. + * @param pipelinePolicy A pipeline policy + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code pipelinePolicy} is {@code null}. */ public TableClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { this.policies.add(Objects.requireNonNull(pipelinePolicy, "'pipelinePolicy' cannot be null")); @@ -232,8 +225,14 @@ public TableClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { /** * Sets the {@link TablesServiceVersion} that is used when making API requests. * - * @param version {@link TablesServiceVersion} of the service to be used when making requests. - * @return The updated TableClientBuilder object. + * If a service version is not provided, the service version that will be used will be the latest known service + * version based on the version of the client library being used. If no service version is specified, updating to a + * newer version of the client library will have the result of potentially moving to a newer service version. + * + * Targeting a specific service version may also mean that the service will return an error for newer APIs. + * + * @param version The {@link TablesServiceVersion} of the service to be used when making requests. + * @return The updated {@code TableClientBuilder}. */ public TableClientBuilder serviceVersion(TablesServiceVersion version) { this.version = version; @@ -244,11 +243,23 @@ public TableClientBuilder serviceVersion(TablesServiceVersion version) { * Sets the request retry options for all the requests made through the client. * * @param retryOptions {@link RequestRetryOptions}. - * @return the updated TableServiceClientBuilder object - * @throws NullPointerException If {@code retryOptions} is {@code null}. + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code retryOptions} is {@code null}. */ public TableClientBuilder retryOptions(RequestRetryOptions retryOptions) { this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); return this; } + + /** + * Sets the name of the table. + * + * @param tableName Name of the table. + * @return The updated {@code TableClientBuilder}. + * @throws NullPointerException if {@code tableName} is {@code null}. + */ + public TableClientBuilder tableName(String tableName) { + this.tableName = Objects.requireNonNull(tableName, "'tableName' cannot be null."); + return this; + } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java index c870205ec6f3..ba4dceca5535 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java @@ -38,7 +38,14 @@ import static com.azure.core.util.FluxUtil.withContext; /** - * async client for account operations + * Provides an asynchronous service client for accessing the Azure Tables service. + * + * 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 {@link TableServiceClientBuilder#buildAsyncClient()} method on a + * {@link TableServiceClientBuilder} object. */ @ServiceClient(builder = TableServiceClientBuilder.class, isAsync = true) public class TableServiceAsyncClient { @@ -66,47 +73,50 @@ public class TableServiceAsyncClient { } /** - * returns the account for this service + * Gets the name of the account containing the table. * - * @return returns the account name + * @return The name of the account containing the table. */ public String getAccountName() { return accountName; } /** - * returns Url of this service + * Gets the absolute URL for the Tables service endpoint. * - * @return Url + * @return The absolute URL for the Tables service endpoint. */ public String getServiceUrl() { return implementation.getUrl(); } /** - * returns the version + * Gets the REST API version used by this client. * - * @return the version + * @return The REST API version used by this client. */ public TablesServiceVersion getApiVersion() { return TablesServiceVersion.valueOf(implementation.getVersion()); } /** - * retrieves the async table client for the provided table or creates one if it doesn't exist + * Gets a {@link TableAsyncClient} instance for the provided table in the account. * - * @param tableName the tableName of the table - * @return associated TableAsyncClient + * @param tableName The name of the table. + * @return A {@link TableAsyncClient} instance for the provided table in the account. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. */ public TableAsyncClient getTableClient(String tableName) { return new TableAsyncClient(tableName, implementation); } /** - * creates the table with the given name. If a table with the same name already exists, the operation fails. + * Creates a table within the Tables service. * - * @param tableName the name of the table to create - * @return mono void + * @param tableName The name of the table to create. + * @return An empty reactive result. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createTable(String tableName) { @@ -114,10 +124,12 @@ public Mono createTable(String tableName) { } /** - * creates the table with the given name. If a table with the same name already exists, the operation fails. + * Creates a table within the Tables service. * - * @param tableName the name of the table to create - * @return a response + * @param tableName The name of the table to create. + * @return A reactive result containing the HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createTableWithResponse(String tableName) { @@ -142,10 +154,11 @@ Mono> createTableWithResponse(String tableName, Context context) } /** - * creates the table with the given name if it does not exist, otherwise no action is taken. + * Creates a table within the Tables service if the table does not already exist. * - * @param tableName the name of the table to create - * @return mono void + * @param tableName The name of the table to create. + * @return An empty reactive result. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createTableIfNotExists(String tableName) { @@ -153,10 +166,11 @@ public Mono createTableIfNotExists(String tableName) { } /** - * creates the table with the given name if it does not exist, otherwise no action is taken. + * Creates a table within the Tables service if the table does not already exist. * - * @param tableName the name of the table to create - * @return a response + * @param tableName The name of the table to create. + * @return A reactive result containing the HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createTableIfNotExistsWithResponse(String tableName) { @@ -175,10 +189,12 @@ Mono> createTableIfNotExistsWithResponse(String tableName, Contex } /** - * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * Deletes a table within the Tables service. * - * @param tableName the name of the table to delete - * @return mono void + * @param tableName The name of the table to delete. + * @return An empty reactive result. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if no table with the provided name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono deleteTable(String tableName) { @@ -186,10 +202,12 @@ public Mono deleteTable(String tableName) { } /** - * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * Deletes a table within the Tables service. * - * @param tableName the name of the table to delete - * @return a response + * @param tableName The name of the table to delete. + * @return A reactive result containing the HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if no table with the provided name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> deleteTableWithResponse(String tableName) { @@ -204,9 +222,9 @@ Mono> deleteTableWithResponse(String tableName, Context context) } /** - * query all the tables under the storage account + * Lists all tables within the account. * - * @return a flux of the tables under the storage account + * @return A paged reactive result containing all tables within the account. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listTables() { @@ -214,10 +232,15 @@ public PagedFlux listTables() { } /** - * query all the tables under the storage account and return the tables that fit the query options + * Lists tables using the parameters in the provided options. * - * @param options the odata query object - * @return a flux of the tables that met this criteria + * If the `filter` parameter in the options is set, only tables matching the filter will be returned. If the `top` + * parameter is set, the number of returned tables will be limited to that value. + * + * @param options The `filter` and `top` OData query options to apply to this operation. + * + * @return A paged reactive result containing matching tables within the account. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedFlux listTables(ListTablesOptions options) { @@ -225,14 +248,7 @@ public PagedFlux listTables(ListTablesOptions options) { return new PagedFlux<>( () -> withContext(context -> listTablesFirstPage(context, options)), token -> withContext(context -> listTablesNextPage(token, context, options))); - } //802 - - PagedFlux listTables(ListTablesOptions options, Context context) { - - return new PagedFlux<>( - () -> listTablesFirstPage(context, options), - token -> listTablesNextPage(token, context, options)); - } //802 + } private Mono> listTablesFirstPage(Context context, ListTablesOptions options) { try { @@ -240,7 +256,7 @@ private Mono> listTablesFirstPage(Context context, List } catch (RuntimeException e) { return monoError(logger, e); } - } //1459 + } private Mono> listTablesNextPage(String token, Context context, ListTablesOptions options) { @@ -249,7 +265,7 @@ private Mono> listTablesNextPage(String token, Context } catch (RuntimeException e) { return monoError(logger, e); } - } //1459 + } private Mono> listTables(String nextTableName, Context context, ListTablesOptions options) { @@ -274,8 +290,7 @@ private Mono> listTables(String nextTableName, Context response.getDeserializedHeaders().getXMsContinuationNextTableName())); }); - } //1836 - + } private static class TablePaged implements PagedResponse { private final Response httpResponse; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java index 41a6223f5563..8db5513d0f0b 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java @@ -8,14 +8,23 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; +import com.azure.data.tables.implementation.models.TableServiceErrorException; import com.azure.data.tables.models.ListTablesOptions; import com.azure.data.tables.models.TableItem; +import java.time.Duration; + /** - * client for table service + * Provides a synchronous service client for accessing the Azure Tables service. + * + * 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 {@link TableServiceClientBuilder#buildClient()} method on a + * {@link TableServiceClientBuilder} object. */ -@ServiceClient( - builder = TableServiceClientBuilder.class) +@ServiceClient(builder = TableServiceClientBuilder.class) public class TableServiceClient { private final TableServiceAsyncClient client; @@ -24,46 +33,49 @@ public class TableServiceClient { } /** - * returns the account for this service + * Gets the name of the account containing the table. * - * @return returns the account name + * @return The name of the account containing the table. */ public String getAccountName() { return client.getAccountName(); } /** - * returns Url of this service + * Gets the absolute URL for the Tables service endpoint. * - * @return Url + * @return The absolute URL for the Tables service endpoint. */ public String getServiceUrl() { return client.getServiceUrl(); } /** - * returns the version + * Gets the REST API version used by this client. * - * @return the version + * @return The REST API version used by this client. */ public TablesServiceVersion getApiVersion() { return client.getApiVersion(); } /** - * gets the Table Client for the given table + * Gets a {@link TableClient} instance for the provided table in the account. * - * @param name the name of the table - * @return the Table Client for the table + * @param tableName The name of the table. + * @return A {@link TableClient} instance for the provided table in the account. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. */ - public TableClient getTableClient(String name) { - return new TableClient(client.getTableClient(name)); + public TableClient getTableClient(String tableName) { + return new TableClient(client.getTableClient(tableName)); } /** - * creates the table with the given name. If a table with the same name already exists, the operation fails. + * Creates a table within the Tables service. * - * @param tableName the name of the table to create + * @param tableName The name of the table to create. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if a table with the same name already exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public void createTable(String tableName) { @@ -71,21 +83,40 @@ public void createTable(String tableName) { } /** - * creates the table with the given name. If a table with the same name already exists, the operation fails. + * Creates a table within the Tables service. * - * @param tableName the name of the table to create - * @param context the context of the query - * @return response + * @param tableName The name of the table to create. + * @param timeout Duration to wait for the operation to complete. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if a table with the same name already exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createTableWithResponse(String tableName, Context context) { - return client.createTableWithResponse(tableName, context).block(); + public void createTable(String tableName, Duration timeout) { + client.createTable(tableName).block(timeout); } /** - * creates the table with the given name if it does not exist, otherwise no action is taken. + * Creates a table within the Tables service. * - * @param tableName the name of the table to create + * @param tableName The name of the table to create. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if a table with the same name already exists within the service. + * @throws RuntimeException if the provided timeout expires. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createTableWithResponse(String tableName, Duration timeout, Context context) { + return client.createTableWithResponse(tableName, context).block(timeout); + } + + /** + * Creates a table within the Tables service if the table does not already exist. + * + * @param tableName The name of the table to create. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. */ @ServiceMethod(returns = ReturnType.SINGLE) public void createTableIfNotExists(String tableName) { @@ -93,21 +124,39 @@ public void createTableIfNotExists(String tableName) { } /** - * creates the table with the given name if it does not exist, otherwise no action is taken. + * Creates a table within the Tables service if the table does not already exist. * - * @param tableName the name of the table to create - * @param context the context of the query - * @return response + * @param tableName The name of the table to create. + * @param timeout Duration to wait for the operation to complete. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createTableIfNotExistsWithResponse(String tableName, Context context) { - return client.createTableIfNotExistsWithResponse(tableName, context).block(); + public void createTableIfNotExists(String tableName, Duration timeout) { + client.createTableIfNotExists(tableName).block(timeout); } /** - * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * Creates a table within the Tables service if the table does not already exist. * - * @param tableName the name of the table to be deleted + * @param tableName The name of the table to create. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws RuntimeException if the provided timeout expires. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createTableIfNotExistsWithResponse(String tableName, Duration timeout, Context context) { + return client.createTableIfNotExistsWithResponse(tableName, context).block(timeout); + } + + /** + * Deletes a table within the Tables service. + * + * @param tableName The name of the table to delete. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if no table with the provided name exists within the service. */ @ServiceMethod(returns = ReturnType.SINGLE) public void deleteTable(String tableName) { @@ -115,21 +164,39 @@ public void deleteTable(String tableName) { } /** - * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * Deletes a table within the Tables service. + * + * @param tableName The name of the table to delete. + * @param timeout Duration to wait for the operation to complete. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if no table with the provided name exists within the service. + * @throws RuntimeException if the provided timeout expires. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteTable(String tableName, Duration timeout) { + client.deleteTable(tableName).block(timeout); + } + + /** + * Deletes a table within the Tables service. * - * @param tableName the name of the table to be deleted - * @param context the context of the query - * @return response + * @param tableName The name of the table to delete. + * @param timeout Duration to wait for the operation to complete. + * @param context Additional context that is passed through the HTTP pipeline during the service call. + * @return The HTTP response. + * @throws IllegalArgumentException if {@code tableName} is {@code null} or empty. + * @throws TableServiceErrorException if no table with the provided name exists within the service. + * @throws RuntimeException if the provided timeout expires. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response deleteTableWithResponse(String tableName, Context context) { - return client.deleteTableWithResponse(tableName, context).block(); + public Response deleteTableWithResponse(String tableName, Duration timeout, Context context) { + return client.deleteTableWithResponse(tableName, context).block(timeout); } /** - * query all the tables under the storage account + * Lists all tables within the account. * - * @return a list of tables that meet the query + * @return A paged iterable containing all tables within the account. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listTables() { @@ -137,11 +204,15 @@ public PagedIterable listTables() { } /** - * query all the tables under the storage account given the query options and returns the ones that fit the - * criteria + * 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 number of returned tables will be limited to that value. + * + * @param options The `filter` and `top` OData query options to apply to this operation. * - * @param options the odata query object - * @return a list of tables that meet the query + * @return A paged iterable containing matching tables within the account. + * @throws IllegalArgumentException if one or more of the OData query options in {@code options} is malformed. */ @ServiceMethod(returns = ReturnType.COLLECTION) public PagedIterable listTables(ListTablesOptions options) { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java index 86e19b99d4fc..e5168134a313 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java @@ -6,6 +6,7 @@ import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; +import com.azure.core.http.policy.HttpLogDetailLevel; import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.util.Configuration; @@ -24,14 +25,15 @@ import java.util.Objects; /** - * builds the table service clients + * This class provides a fluent builder API to help aid the configuration and instantiation of + * {@link TableServiceClient} and {@link TableServiceAsyncClient} objects. Call {@link #buildClient()} or + * {@link #buildAsyncClient()}, respectively, to construct an instance of the desired client. */ @ServiceClientBuilder(serviceClients = {TableServiceClient.class, TableServiceAsyncClient.class}) public class TableServiceClientBuilder { private final ClientLogger logger = new ClientLogger(TableServiceClientBuilder.class); private final SerializerAdapter serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); private final List policies; - private String connectionString; private Configuration configuration; private String endpoint; private HttpClient httpClient; @@ -40,11 +42,11 @@ public class TableServiceClientBuilder { private TokenCredential tokenCredential; private HttpPipeline httpPipeline; private SasTokenCredential sasTokenCredential; - private String accountName; private RequestRetryOptions retryOptions = new RequestRetryOptions(); /** - * constructor + * Creates a builder instance that is able to configure and construct {@link TableServiceClient} and + * {@link TableServiceAsyncClient} objects. */ public TableServiceClientBuilder() { policies = new ArrayList<>(); @@ -52,18 +54,18 @@ public TableServiceClientBuilder() { } /** - * builds a sync TableServiceClient + * Creates a {@link TableServiceClient} based on options set in the builder. * - * @return a sync TableServiceClient + * @return A {@link TableServiceClient} created from the configurations in this builder. */ public TableServiceClient buildClient() { return new TableServiceClient(buildAsyncClient()); } /** - * builds an async TableServiceAsyncClient + * Creates a {@link TableServiceAsyncClient} based on options set in the builder. * - * @return TableServiceAsyncClient an aysnc TableServiceAsyncClient + * @return A {@link TableServiceAsyncClient} created from the configurations in this builder. */ public TableServiceAsyncClient buildAsyncClient() { @@ -77,10 +79,11 @@ public TableServiceAsyncClient buildAsyncClient() { } /** - * Sets the connection string to help build the client + * Sets the connection string to connect to the service. * - * @param connectionString the connection string to the storage account - * @return the TableServiceClientBuilder + * @param connectionString Connection string of the storage or CosmosDB table API account. + * @return The updated {@code TableServiceClientBuilder}. + * @throws IllegalArgumentException if {@code connectionString} isn't a valid connection string. */ public TableServiceClientBuilder connectionString(String connectionString) { StorageConnectionString storageConnectionString @@ -89,15 +92,12 @@ public TableServiceClientBuilder connectionString(String connectionString) { if (endpoint == null || endpoint.getPrimaryUri() == null) { throw logger .logExceptionAsError(new IllegalArgumentException( - "connectionString missing required settings to derive blob service endpoint.")); + "connectionString missing required settings to derive tables service endpoint.")); } this.endpoint(endpoint.getPrimaryUri()); - if (storageConnectionString.getAccountName() != null) { - this.accountName = storageConnectionString.getAccountName(); - } StorageAuthenticationSettings authSettings = storageConnectionString.getStorageAuthSettings(); if (authSettings.getType() == StorageAuthenticationSettings.Type.ACCOUNT_NAME_KEY) { - this.credential((TokenCredential) new TablesSharedKeyCredential(authSettings.getAccount().getName(), + this.credential(new TablesSharedKeyCredential(authSettings.getAccount().getName(), authSettings.getAccount().getAccessKey())); } else if (authSettings.getType() == StorageAuthenticationSettings.Type.SAS_TOKEN) { this.sasToken(authSettings.getSasToken()); @@ -106,10 +106,11 @@ public TableServiceClientBuilder connectionString(String connectionString) { } /** - * Sets the table service endpoint + * Sets the service endpoint. * - * @param endpoint URL of the service - * @return the updated TableServiceClientBuilder object + * @param endpoint The URL of the storage or CosmosDB table API account endpoint. + * @return The updated {@code TableServiceClientBuilder}. + * @throws IllegalArgumentException if {@code endpoint} isn't a valid URL. */ public TableServiceClientBuilder endpoint(String endpoint) { try { @@ -122,10 +123,11 @@ public TableServiceClientBuilder endpoint(String endpoint) { } /** - * Sets the HTTP pipeline to use for the service client. + * Sets the {@link HttpPipeline} to use for the service client. If {@code pipeline} is set, all other settings are + * ignored, aside from {@code endpoint}. * - * @param pipeline The HTTP pipeline to use for sending service requests and receiving responses. - * @return The updated TableServiceClientBuilder object. + * @param pipeline {@link HttpPipeline} to use for sending service requests and receiving responses. + * @return The updated {@code TableServiceClientBuilder}. */ public TableServiceClientBuilder pipeline(HttpPipeline pipeline) { if (this.httpPipeline != null && pipeline == null) { @@ -140,8 +142,8 @@ public TableServiceClientBuilder pipeline(HttpPipeline pipeline) { * Sets the SAS token used to authorize requests sent to the service. * * @param sasToken The SAS token to use for authenticating requests. - * @return the updated BlobServiceClientBuilder - * @throws NullPointerException If {@code sasToken} is {@code null}. + * @return The updated {@code TableServiceClientBuilder}. + * @throws NullPointerException if {@code sasToken} is {@code null}. */ public TableServiceClientBuilder sasToken(String sasToken) { this.sasTokenCredential = new SasTokenCredential(Objects.requireNonNull(sasToken, @@ -153,8 +155,11 @@ public TableServiceClientBuilder sasToken(String sasToken) { /** * Sets the configuration object used to retrieve environment configuration values during building of the client. * + * The default configuration store is a clone of the {@link Configuration#getGlobalConfiguration() global + * configuration store}, use {@link Configuration#NONE} to bypass using configuration settings during construction. + * * @param configuration Configuration store used to retrieve environment configurations. - * @return the updated TableServiceClientBuilder object + * @return The updated {@code TableServiceClientBuilder}. */ public TableServiceClientBuilder configuration(Configuration configuration) { this.configuration = configuration; @@ -162,11 +167,11 @@ public TableServiceClientBuilder configuration(Configuration configuration) { } /** - * update credential + * Sets the {@link TokenCredential} used to authorize requests sent to the service. * - * @param credential the tables shared key credential - * @return the updated TableServiceClient builder - * @throws NullPointerException If {@code credential} is {@code null}. + * @param credential {@link TokenCredential} used to authorize requests sent to the service. + * @return The updated {@code TableServiceClientBuilder}. + * @throws NullPointerException if {@code credential} is {@code null}. */ public TableServiceClientBuilder credential(TokenCredential credential) { this.tokenCredential = Objects.requireNonNull(credential, "'credential' cannot be null."); @@ -174,10 +179,10 @@ public TableServiceClientBuilder credential(TokenCredential credential) { } /** - * Sets the {@link HttpClient} to use for sending a receiving requests to and from the service. + * Sets the {@link HttpClient} to use for sending and receiving requests to and from the service. * - * @param httpClient HttpClient to use for requests. - * @return the updated TableServiceClientBuilder object + * @param httpClient The {@link HttpClient} to use for requests. + * @return The updated {@code TableServiceClientBuilder}. */ public TableServiceClientBuilder httpClient(HttpClient httpClient) { if (this.httpClient != null && httpClient == null) { @@ -188,11 +193,13 @@ public TableServiceClientBuilder httpClient(HttpClient httpClient) { } /** - * Sets the {@link HttpLogOptions} for service requests. + * Sets the logging configuration to use when sending and receiving requests to and from the service. + * + * If a {@code logLevel} is not provided, default value of {@link HttpLogDetailLevel#NONE} is set. * - * @param logOptions The logging configuration to use when sending and receiving HTTP requests/responses. - * @return the updated TableServiceClientBuilder object - * @throws NullPointerException If {@code logOptions} is {@code null}. + * @param logOptions The logging configuration to use when sending and receiving requests to and from the service. + * @return The updated {@code TableServiceClientBuilder}. + * @throws NullPointerException if {@code logOptions} is {@code null}. */ public TableServiceClientBuilder httpLogOptions(HttpLogOptions logOptions) { this.httpLogOptions = Objects.requireNonNull(logOptions, "'logOptions' cannot be null."); @@ -203,9 +210,9 @@ public TableServiceClientBuilder httpLogOptions(HttpLogOptions logOptions) { * Adds a pipeline policy to apply on each request sent. The policy will be added after the retry policy. If * the method is called multiple times, all policies will be added and their order preserved. * - * @param pipelinePolicy a pipeline policy - * @return the updated TableServiceClientBuilder object - * @throws NullPointerException If {@code pipelinePolicy} is {@code null}. + * @param pipelinePolicy A pipeline policy + * @return The updated {@code TableServiceClientBuilder}. + * @throws NullPointerException if {@code pipelinePolicy} is {@code null}. */ public TableServiceClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { this.policies.add(Objects.requireNonNull(pipelinePolicy, "'pipelinePolicy' cannot be null")); @@ -213,16 +220,16 @@ public TableServiceClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { } /** - * Sets the TablesServiceVersion that is used when making API requests. - *

+ * Sets the {@link TablesServiceVersion} that is used when making API requests. + * * If a service version is not provided, the service version that will be used will be the latest known service * version based on the version of the client library being used. If no service version is specified, updating to a * newer version of the client library will have the result of potentially moving to a newer service version. - *

+ * * Targeting a specific service version may also mean that the service will return an error for newer APIs. * - * @param version {@link TablesServiceVersion} of the service to be used when making requests. - * @return the updated TableServiceClientBuilder object + * @param version The {@link TablesServiceVersion} of the service to be used when making requests. + * @return The updated {@code TableServiceClientBuilder}. */ public TableServiceClientBuilder serviceVersion(TablesServiceVersion version) { this.version = version; @@ -233,8 +240,8 @@ public TableServiceClientBuilder serviceVersion(TablesServiceVersion version) { * Sets the request retry options for all the requests made through the client. * * @param retryOptions {@link RequestRetryOptions}. - * @return the updated TableServiceClientBuilder object - * @throws NullPointerException If {@code retryOptions} is {@code null}. + * @return The updated {@code TableServiceClientBuilder}. + * @throws NullPointerException if {@code retryOptions} is {@code null}. */ public TableServiceClientBuilder retryOptions(RequestRetryOptions retryOptions) { this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java index 53010be0775a..f24f6cc3b1b1 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java @@ -5,10 +5,14 @@ import com.azure.core.util.ServiceVersion; /** - * The versions of Azure Storage Tables supported by this client library. + * The versions of Tables REST API supported by this client library. */ public enum TablesServiceVersion implements ServiceVersion { + /** + * API version 2019-02-02 + */ V2019_02_02("2019-02-02"); + private final String version; TablesServiceVersion(String version) { @@ -24,9 +28,9 @@ public String getVersion() { } /** - * Gets the latest service version supported by this client library + * Gets the latest REST API version supported by this client library. * - * @return the latest TablesServiceVersion + * @return The latest REST API version supported by this client library. */ public static TablesServiceVersion getLatest() { return V2019_02_02; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredential.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredential.java index 420107d52461..fa89cb4271dc 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredential.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredential.java @@ -18,8 +18,7 @@ import reactor.core.publisher.Mono; /** - * A Class which helps generate the shared key credentials for a given storage account to create a Http requests to - * access Azure Tables + * A SharedKey credential that authorizes requests to the Tables service. */ public class TablesSharedKeyCredential implements TokenCredential { private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKeyLite %s:%s"; @@ -27,10 +26,12 @@ public class TablesSharedKeyCredential implements TokenCredential { private final String accountKey; /** - * Constructor for TableSharedKeyCredential Class + * Initializes a new {@code TablesSharedKeyCredential} that contains an account's name and its primary or secondary + * account key. * - * @param accountName name of the storage account - * @param accountKey key to the storage account + * @param accountName The account name associated with the request. + * @param accountKey The account access key used to authenticate the request. + * @throws NullPointerException if {@code accountName} or {@code accountKey} is {@code null}. */ public TablesSharedKeyCredential(String accountName, String accountKey) { this.accountName = Objects.requireNonNull(accountName, "'accountName' cannot be null."); @@ -116,6 +117,9 @@ private String getCanonicalizedResource(URL requestUrl) { return canonicalizedResource.toString(); } + /** + * {@inheritDoc} + */ @Override public Mono getToken(TokenRequestContext tokenRequestContext) { return null; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredentialPolicy.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredentialPolicy.java index f689b85d043a..97dd79f549c8 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredentialPolicy.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredentialPolicy.java @@ -10,27 +10,27 @@ import reactor.core.publisher.Mono; /** - * This class helps authenticate an Http request for the Tables service + * Policy that adds the SharedKey into the request's Authorization header. */ public final class TablesSharedKeyCredentialPolicy implements HttpPipelinePolicy { private final TablesSharedKeyCredential credential; /** - * constructor for the TablesSharedKeyCredentialPolicy class + * Creates a SharedKey pipeline policy that adds the SharedKey into the request's authorization header. * - * @param credential the credentials of the account + * @param credential The SharedKey credential used to create the policy. */ public TablesSharedKeyCredentialPolicy(TablesSharedKeyCredential credential) { this.credential = credential; } /** - * creates an Http response + * Authorizes a {@link com.azure.core.http.HttpRequest} with the SharedKey credential. * - * @param context the context of the http pipeline - * @param next the next Http pipeline policy - * @return an Http response + * @param context The context of the request. + * @param next The next policy in the pipeline. + * @return A reactive result containing the HTTP response. */ public Mono process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { String authorizationValue = credential.generateAuthorizationHeader(context.getHttpRequest().getUrl(), diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListEntitiesOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListEntitiesOptions.java index a11e4860aae4..99cca0a83b98 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListEntitiesOptions.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListEntitiesOptions.java @@ -6,7 +6,7 @@ import com.azure.core.annotation.Fluent; /** - * helps construct a query + * Options to modify the data returned from the {@code listEntities} family of methods. */ @Fluent public final class ListEntitiesOptions { @@ -15,19 +15,19 @@ public final class ListEntitiesOptions { private String filter; /** - * Get the top property: Maximum number of records to return. + * Gets the value of the `top` OData query option which limits the number of returned entities. * - * @return the top value. + * @return The value of the `top` OData query option. */ public Integer getTop() { return this.top; } /** - * Set the top property: Maximum number of records to return. + * Sets the value of the `top` OData query option which limits the number of returned entities. * - * @param top the top value to set. - * @return the TableEntityQueryOptions object itself. + * @param top The value of the `top` OData query option. + * @return The updated {@code ListEntitiesOptions}. */ public ListEntitiesOptions setTop(Integer top) { this.top = top; @@ -35,21 +35,19 @@ public ListEntitiesOptions setTop(Integer top) { } /** - * Get the select property: Select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * Gets the value of the `select` OData query option which limits the properties returned on each entity. * - * @return the select value. + * @return The value of the `select` OData query option. */ public String getSelect() { return this.select; } /** - * Set the select property: Select expression using OData notation. Limits the columns on each record to just those - * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * Sets the value of the `select` OData query option which limits the properties returned on each entity. * - * @param select the select value to set. - * @return the TableEntityQueryOptions object itself. + * @param select The value of the `select` OData query option. + * @return The updated {@code ListEntitiesOptions}. */ public ListEntitiesOptions setSelect(String select) { this.select = select; @@ -57,19 +55,21 @@ public ListEntitiesOptions setSelect(String select) { } /** - * Get the filter property: OData filter expression. + * Gets the value of the `filter` OData query option which filters the set of returned entities, excluding those + * that do not match the filter expression. * - * @return the filter value. + * @return The value of the `filter` OData query option. */ public String getFilter() { return this.filter; } /** - * Set the filter property: OData filter expression. + * Sets the value of the `filter` OData query option which filters the set of returned entities, excluding those + * that do not match the filter expression. * - * @param filter the filter value to set. - * @return the TableEntityQueryOptions object itself. + * @param filter The value of the `filter` OData query option. + * @return The updated {@code ListEntitiesOptions}. */ public ListEntitiesOptions setFilter(String filter) { this.filter = filter; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListTablesOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListTablesOptions.java index b71e5b99964c..fbbb8dcb87c2 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListTablesOptions.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/ListTablesOptions.java @@ -6,7 +6,7 @@ import com.azure.core.annotation.Fluent; /** - * helps construct a query + * Options to modify the data returned from the {@code listTables} family of methods. */ @Fluent public final class ListTablesOptions { @@ -14,19 +14,19 @@ public final class ListTablesOptions { private String filter; /** - * Get the top property: Maximum number of records to return. + * Gets the value of the `top` OData query option which limits the number of returned entities. * - * @return the top value. + * @return The value of the `top` OData query option. */ public Integer getTop() { return this.top; } /** - * Set the top property: Maximum number of records to return. + * Sets the value of the `top` OData query option which limits the number of returned entities. * - * @param top the top value to set. - * @return the TableQueryOptions object itself. + * @param top The value of the `top` OData query option. + * @return The updated {@code ListTablesOptions}. */ public ListTablesOptions setTop(Integer top) { this.top = top; @@ -34,19 +34,21 @@ public ListTablesOptions setTop(Integer top) { } /** - * Get the filter property: OData filter expression. + * Gets the value of the `filter` OData query option which filters the set of returned entities, excluding those + * that do not match the filter expression. * - * @return the filter value. + * @return The value of the `filter` OData query option. */ public String getFilter() { return this.filter; } /** - * Set the filter property: OData filter expression. + * Sets the value of the `filter` OData query option which filters the set of returned entities, excluding those + * that do not match the filter expression. * - * @param filter the filter value to set. - * @return the TableQueryOptions object itself. + * @param filter The value of the `filter` OData query option. + * @return The updated {@code ListTablesOptions}. */ public ListTablesOptions setFilter(String filter) { this.filter = filter; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java index 876a7ca3d5b2..341076d754d3 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java @@ -14,7 +14,20 @@ import java.util.Objects; /** - * table entity class + * An entity within a table. + * + * A {@code TableEntity} can be used directly when interacting with the Tables service, with methods on the + * {@link com.azure.data.tables.TableClient} and {@link com.azure.data.tables.TableAsyncClient} classes that accept and + * return {@code TableEntity} instances. After creating an instance, call the {@link #addProperty(String, Object)} or + * {@link #addProperties(Map)} methods to add properties to the entity. When retrieving an entity from the service, call + * the {@link #getProperty(String)} or {@link #getProperties()} methods to access the entity's properties. + * + * As an alternative, developers can also create a subclass of {@code TableEntity} and add property getters and setters + * to it. If the properties' types are compatible with the Table service, they will automatically be included in any + * write operations, and will automatically be populated in any read operations. Any properties that expose enum types + * will be converted to string values for write operations, and will be converted back into enum values for read + * operations. See Property Types + * for more information about data types supported by the Tables service. */ @Fluent public class TableEntity { @@ -27,10 +40,10 @@ public class TableEntity { } /** - * Create a new instance. + * Construct a new {@code TableEntity}. * - * @param partitionKey the partition key - * @param rowKey the row key + * @param partitionKey The partition key of the entity. + * @param rowKey The row key of the entity. */ public TableEntity(String partitionKey, String rowKey) { if (partitionKey == null || partitionKey.isEmpty()) { @@ -53,31 +66,40 @@ private TableEntity() { } /** - * Gets a single property from the properties map + * Gets a single property from the entity's properties map. + * + * Only properties that have been added by calling {@link #addProperty(String, Object)} or + * {@link #addProperties(Map)} will be returned from this method. Calling this method on a subclass of + * {@code TableEntity} will not retrieve a property which is being supplied via a getter method on the subclass. * * @param key Key for the property. * @return Value of the property. + * @throws NullPointerException if {@code key} is null. */ public final Object getProperty(String key) { return properties.get(key); } /** - * Gets the map of properties + * Gets the map of the entity's properties. + * + * Only properties that have been added by calling {@link #addProperty(String, Object)} or + * {@link #addProperties(Map)} will be returned from this method. Calling this method on a subclass of + * {@code TableEntity} will not retrieve properties which are being supplied via a getter methods on the subclass. * - * @return map of properties representing this entity + * @return A map of all properties representing this entity, including system properties. */ public final Map getProperties() { return properties; } /** - * Adds a property to the entity. + * Adds a single property to the entity's properties map. * * @param key Key for the property. * @param value Value of the property. * - * @return The updated {@link TableEntity} object. + * @return The updated {@link TableEntity}. * @throws NullPointerException if {@code key} is null. */ public final TableEntity addProperty(String key, Object value) { @@ -87,11 +109,12 @@ public final TableEntity addProperty(String key, Object value) { } /** - * Adds properties to the entity. + * Adds the contents of the provided map to the entity's properties map. * * @param properties The map of properties to add. * - * @return The updated {@link TableEntity} object. + * @return The updated {@link TableEntity}. + * @throws NullPointerException if {@code properties} is null. */ public final TableEntity addProperties(Map properties) { for (Map.Entry entry : properties.entrySet()) { @@ -124,36 +147,42 @@ private void validateProperty(String key, Object value) { } /** - * gets the row key + * Gets the entity's row key. * - * @return the row key for the given entity + * @return The entity's row key. */ public final String getRowKey() { return (String) properties.get(TablesConstants.ROW_KEY); } /** - * gets the partition key + * Gets the entity's partition key. * - * @return the partition key for the given entity + * @return The entity's partition key. */ public final String getPartitionKey() { return (String) properties.get(TablesConstants.PARTITION_KEY); } /** - * gets the Timestamp + * Gets the entity's timestamp. * - * @return the Timestamp for the entity + * The timestamp is automatically populated by the service. New {@code TableEntity} instances will not have a + * timestamp, but a timestamp will be present on any {@code TableEntity} returned from the service. + * + * @return The entity's timestamp. */ public final OffsetDateTime getTimestamp() { return (OffsetDateTime) properties.get(TablesConstants.TIMESTAMP_KEY); } /** - * gets the etag + * Gets the entity's eTag. + * + * The eTag is automatically populated by the service. New {@code TableEntity} instances will not have an eTag, but + * an eTag will be present on any {@code TableEntity} returned from the service. * - * @return the etag for the entity + * @return The entity's eTag. */ public final String getETag() { return (String) properties.get(TablesConstants.ODATA_ETAG_KEY); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableErrorCode.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableErrorCode.java index 0a5288833fc3..fb5a5a0527d4 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableErrorCode.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableErrorCode.java @@ -6,47 +6,48 @@ import com.azure.core.util.ExpandableStringEnum; /** - * Defines values for TableErrorCode. + * Defines values for error codes returned from the Tables service. */ public class TableErrorCode extends ExpandableStringEnum { /** - * Static value ResourceAlreadyExists for TableErrorCode. + * Static value {@code TableAlreadyExists}. */ public static final TableErrorCode TABLE_ALREADY_EXISTS = fromString("TableAlreadyExists"); /** - * Static value ResourceNotFound for TableErrorCode. + * Static value {@code TableNotFound}. */ public static final TableErrorCode TABLE_NOT_FOUND = fromString("TableNotFound"); /** - * Static value InvalidResourceName for TableErrorCode. + * Static value {@code InvalidTableName}. */ public static final TableErrorCode INVALID_TABLE_NAME = fromString("InvalidTableName"); /** - * Static value ResourceAlreadyExists for TableErrorCode. + * Static value {@code EntityAlreadyExists}. */ public static final TableErrorCode ENTITY_ALREADY_EXISTS = fromString("EntityAlreadyExists"); /** - * Static value ResourceNotFound for TableErrorCode. + * Static value {@code EntityNotFound}. */ public static final TableErrorCode ENTITY_NOT_FOUND = fromString("EntityNotFound"); /** - * Static value InvalidResourceName for TableErrorCode. + * Static value {@code InvalidPkOrRkName}. */ public static final TableErrorCode INVALID_PK_OR_RK_NAME = fromString("InvalidPkOrRkName"); /** - * returns an error code from a string - * @param name the name of the error - * @return the associated tableErrorCode + * Returns the {@code TableErrorCode} constant with the provided name, or {@code null} if no {@code TableErrorCode} + * has the provided name. + * + * @param name The name of the error. + * @return The {@code TableErrorCode} value having the provided name. */ public static TableErrorCode fromString(String name) { return fromString(name, TableErrorCode.class); } - } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableItem.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableItem.java index 350d34dd9d7d..33e08c2c8419 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableItem.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableItem.java @@ -6,7 +6,7 @@ import com.azure.data.tables.implementation.models.TableResponseProperties; /** - * class for a table object + * A table within a storage or CosmosDB table API account. */ public class TableItem { private final String name; @@ -31,9 +31,9 @@ public class TableItem { } /** - * returns the name of this table + * Gets the name of the table. * - * @return table name + * @return The name of the table. */ public String getName() { return name; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableStorageException.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableStorageException.java index 99c944d13687..2abde14810f1 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableStorageException.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableStorageException.java @@ -8,22 +8,27 @@ import static com.azure.storage.common.implementation.Constants.HeaderConstants.ERROR_CODE; /** - * exceptions for the Tables SDK + * A {@code TableStorageException} is thrown whenever the Tables service successfully returns an error code that is not + * 200-level. Users can inspect the status code and error code to determine the cause of the error response. The + * exception message may also contain more detailed information depending on the type of error. The user may also + * inspect the raw HTTP response or call {@link #toString()} to get the full payload of the error response if present. */ public class TableStorageException extends HttpResponseException { /** - * Constructs a {@code BlobStorageException}. + * Constructs a {@code TableStorageException}. * - * @param message the exception message or the response content if a message is not available. - * @param response the HTTP response. - * @param value the error code of the exception. + * @param message The exception message or the response content if a message is not available. + * @param response The {@link HttpResponse}. + * @param value The error code of the exception. */ public TableStorageException(String message, HttpResponse response, Object value) { super(message, response, value); } /** + * Gets the error code returned by the service. + * * @return The error code returned by the service. */ public TableErrorCode getErrorCode() { @@ -31,6 +36,8 @@ public TableErrorCode getErrorCode() { } /** + * Gets the message returned by the service. + * * @return The message returned by the service. */ public String getServiceMessage() { @@ -38,7 +45,9 @@ public String getServiceMessage() { } /** - * @return The status code on the response. + * Gets the status code of the response. + * + * @return The status code of the response. */ public int getStatusCode() { return super.getResponse().getStatusCode(); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java index 3f4e9e19ebce..d3a3f875f8a6 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java @@ -3,9 +3,16 @@ package com.azure.data.tables.models; /** - * update type for update and upsert methods + * The type of update operation to perform on an existing entity within a table. */ public enum UpdateMode { + /** + * The provided entity's properties will be merged into the existing entity. + */ MERGE, + + /** + * The provided entity's properties will completely replace those in the existing entity. + */ REPLACE } diff --git a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java index cde9577c3ad6..2e24845cec55 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -8,7 +8,7 @@ import com.azure.data.tables.models.UpdateMode; /** - * async code snippets for the table service + * async code snippets for the Tables service */ public class TableServiceAsyncClientCodeSnippets { @@ -142,7 +142,7 @@ private void update() { //UpdateMode.REPLACE: so the entity will be replaced if it exists or the request fails if not found //ifUnchanged being false means the eTags must not match - return tableAsyncClient.updateEntity(tableEntity, false, UpdateMode.REPLACE); + return tableAsyncClient.updateEntity(tableEntity, UpdateMode.REPLACE, false); }).subscribe( Void -> { }, error -> System.err.println("There was an error updating the Entity. Error: " + error), diff --git a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java index b25d518b3e7e..61fb08eb714e 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -13,7 +13,7 @@ import com.azure.data.tables.models.UpdateMode; /** - * sync code snippets for the table service + * sync code snippets for the Tables service */ public class TableServiceClientCodeSnippets { private final ClientLogger logger = new ClientLogger("TableServiceClientCodeSnippets"); diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java index a884833cb7f7..f1272748ea6c 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java @@ -499,11 +499,11 @@ void updateEntityWithResponseAsync(UpdateMode mode) { // Act & Assert if (mode == UpdateMode.MERGE && tableClient.getTableUrl().contains("cosmos.azure.com")) { // This scenario is currently broken when using the CosmosDB Table API - StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, true, mode)) + StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, mode, true)) .expectError(com.azure.data.tables.implementation.models.TableServiceErrorException.class) .verify(); } else { - StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, true, mode)) + StepVerifier.create(tableClient.updateEntityWithResponse(createdEntity, mode, true)) .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) .expectComplete() .verify(); @@ -532,7 +532,7 @@ void updateEntityWithResponseSubclassAsync() { // Act & Assert tableEntity.setSubclassProperty("UpdatedValue"); - StepVerifier.create(tableClient.updateEntityWithResponse(tableEntity, true, UpdateMode.MERGE)) + StepVerifier.create(tableClient.updateEntityWithResponse(tableEntity, UpdateMode.REPLACE, true)) .assertNext(response -> assertEquals(expectedStatusCode, response.getStatusCode())) .expectComplete() .verify(); diff --git a/sdk/tables/azure-data-tables/src/test/resources/session-records/updateEntityWithResponseSubclassAsync.json b/sdk/tables/azure-data-tables/src/test/resources/session-records/updateEntityWithResponseSubclassAsync.json index d19477e9febe..cbab8f273cfe 100644 --- a/sdk/tables/azure-data-tables/src/test/resources/session-records/updateEntityWithResponseSubclassAsync.json +++ b/sdk/tables/azure-data-tables/src/test/resources/session-records/updateEntityWithResponseSubclassAsync.json @@ -5,7 +5,7 @@ "Headers" : { "x-ms-version" : "2019-02-02", "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.8; Mac OS X; 10.15.6)", - "x-ms-client-request-id" : "2f244f3d-1e59-4190-9f0b-44cd6161756c", + "x-ms-client-request-id" : "c3ce0667-a925-4162-baa1-7c66ea1590f1", "Content-Type" : "application/json" }, "Response" : { @@ -14,23 +14,23 @@ "X-Content-Type-Options" : "nosniff", "retry-after" : "0", "StatusCode" : "204", - "Date" : "Wed, 30 Sep 2020 00:58:05 GMT", + "Date" : "Fri, 02 Oct 2020 00:26:59 GMT", "Cache-Control" : "no-cache", - "DataServiceId" : "https://brsiegelsample.table.core.windows.net/Tables('tablename54368bea')", + "DataServiceId" : "https://brsiegelsample.table.core.windows.net/Tables('tablename40583955')", "Content-Length" : "0", - "x-ms-request-id" : "13411e6a-1002-006c-55c4-9621cb000000", + "x-ms-request-id" : "6815fb1a-9002-002f-2f52-98c797000000", "Preference-Applied" : "return-no-content", - "x-ms-client-request-id" : "2f244f3d-1e59-4190-9f0b-44cd6161756c", - "Location" : "https://brsiegelsample.table.core.windows.net/Tables('tablename54368bea')" + "x-ms-client-request-id" : "c3ce0667-a925-4162-baa1-7c66ea1590f1", + "Location" : "https://brsiegelsample.table.core.windows.net/Tables('tablename40583955')" }, "Exception" : null }, { "Method" : "POST", - "Uri" : "https://REDACTED.table.core.windows.net/tablename54368bea", + "Uri" : "https://REDACTED.table.core.windows.net/tablename40583955", "Headers" : { "x-ms-version" : "2019-02-02", "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.8; Mac OS X; 10.15.6)", - "x-ms-client-request-id" : "916f87fb-6338-4ec0-9c99-364f3e060f11", + "x-ms-client-request-id" : "3a678243-7f32-4683-abbe-9b2c14a5b138", "Content-Type" : "application/json" }, "Response" : { @@ -39,47 +39,47 @@ "X-Content-Type-Options" : "nosniff", "retry-after" : "0", "StatusCode" : "204", - "Date" : "Wed, 30 Sep 2020 00:58:05 GMT", + "Date" : "Fri, 02 Oct 2020 00:26:59 GMT", "Cache-Control" : "no-cache", - "ETag" : "W/datetime'2020-09-30T00%3A58%3A06.5695489Z'", - "DataServiceId" : "https://brsiegelsample.table.core.windows.net/tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')", + "ETag" : "W/datetime'2020-10-02T00%3A26%3A59.7449847Z'", + "DataServiceId" : "https://brsiegelsample.table.core.windows.net/tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')", "Content-Length" : "0", - "x-ms-request-id" : "13411e77-1002-006c-60c4-9621cb000000", + "x-ms-request-id" : "6815fb26-9002-002f-3952-98c797000000", "Preference-Applied" : "return-no-content", - "x-ms-client-request-id" : "916f87fb-6338-4ec0-9c99-364f3e060f11", - "Location" : "https://brsiegelsample.table.core.windows.net/tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')" + "x-ms-client-request-id" : "3a678243-7f32-4683-abbe-9b2c14a5b138", + "Location" : "https://brsiegelsample.table.core.windows.net/tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')" }, "Exception" : null }, { - "Method" : "PATCH", - "Uri" : "https://REDACTED.table.core.windows.net/tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')", + "Method" : "PUT", + "Uri" : "https://REDACTED.table.core.windows.net/tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')", "Headers" : { "x-ms-version" : "2019-02-02", "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.8; Mac OS X; 10.15.6)", - "x-ms-client-request-id" : "34ee8f9a-d9bc-4d02-94a0-a20e32b0df1d", + "x-ms-client-request-id" : "e7c068ae-b479-4f72-90be-693e58ff863a", "Content-Type" : "application/json" }, "Response" : { "x-ms-version" : "2019-02-02", "Server" : "Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0", "Cache-Control" : "no-cache", - "ETag" : "W/datetime'2020-09-30T00%3A58%3A06.6087467Z'", + "ETag" : "W/datetime'2020-10-02T00%3A26%3A59.8027552Z'", "X-Content-Type-Options" : "nosniff", "retry-after" : "0", "Content-Length" : "0", "StatusCode" : "204", - "x-ms-request-id" : "13411e83-1002-006c-69c4-9621cb000000", - "Date" : "Wed, 30 Sep 2020 00:58:05 GMT", - "x-ms-client-request-id" : "34ee8f9a-d9bc-4d02-94a0-a20e32b0df1d" + "x-ms-request-id" : "6815fb29-9002-002f-3c52-98c797000000", + "Date" : "Fri, 02 Oct 2020 00:26:59 GMT", + "x-ms-client-request-id" : "e7c068ae-b479-4f72-90be-693e58ff863a" }, "Exception" : null }, { "Method" : "GET", - "Uri" : "https://REDACTED.table.core.windows.net/tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')?$format=application/json%3Bodata%3Dfullmetadata", + "Uri" : "https://REDACTED.table.core.windows.net/tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')?$format=application/json%3Bodata%3Dfullmetadata", "Headers" : { "x-ms-version" : "2019-02-02", "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.8; Mac OS X; 10.15.6)", - "x-ms-client-request-id" : "f004daa9-3b8a-4eb6-bec8-25ecf55b47ad" + "x-ms-client-request-id" : "4fb56ebf-8153-4cf1-ad39-4879b3ebf60e" }, "Response" : { "Transfer-Encoding" : "chunked", @@ -88,15 +88,15 @@ "X-Content-Type-Options" : "nosniff", "retry-after" : "0", "StatusCode" : "200", - "Date" : "Wed, 30 Sep 2020 00:58:05 GMT", + "Date" : "Fri, 02 Oct 2020 00:26:59 GMT", "Cache-Control" : "no-cache", - "ETag" : "W/datetime'2020-09-30T00%3A58%3A06.6087467Z'", - "x-ms-request-id" : "13411e8b-1002-006c-71c4-9621cb000000", - "Body" : "{\"odata.metadata\":\"https://brsiegelsample.table.core.windows.net/$metadata#tablename54368bea/@Element\",\"odata.type\":\"brsiegelsample.tablename54368bea\",\"odata.id\":\"https://brsiegelsample.table.core.windows.net/tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')\",\"odata.etag\":\"W/\\\"datetime'2020-09-30T00%3A58%3A06.6087467Z'\\\"\",\"odata.editLink\":\"tablename54368bea(PartitionKey='apartitionkey197836',RowKey='arowkey2442208b8')\",\"PartitionKey\":\"apartitionkey197836\",\"RowKey\":\"arowkey2442208b8\",\"Timestamp@odata.type\":\"Edm.DateTime\",\"Timestamp\":\"2020-09-30T00:58:06.6087467Z\",\"SubclassProperty\":\"UpdatedValue\"}", - "x-ms-client-request-id" : "f004daa9-3b8a-4eb6-bec8-25ecf55b47ad", + "ETag" : "W/datetime'2020-10-02T00%3A26%3A59.8027552Z'", + "x-ms-request-id" : "6815fb2b-9002-002f-3e52-98c797000000", + "Body" : "{\"odata.metadata\":\"https://brsiegelsample.table.core.windows.net/$metadata#tablename40583955/@Element\",\"odata.type\":\"brsiegelsample.tablename40583955\",\"odata.id\":\"https://brsiegelsample.table.core.windows.net/tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')\",\"odata.etag\":\"W/\\\"datetime'2020-10-02T00%3A26%3A59.8027552Z'\\\"\",\"odata.editLink\":\"tablename40583955(PartitionKey='apartitionkey81459a',RowKey='arowkey90628af6a')\",\"PartitionKey\":\"apartitionkey81459a\",\"RowKey\":\"arowkey90628af6a\",\"Timestamp@odata.type\":\"Edm.DateTime\",\"Timestamp\":\"2020-10-02T00:26:59.8027552Z\",\"SubclassProperty\":\"UpdatedValue\"}", + "x-ms-client-request-id" : "4fb56ebf-8153-4cf1-ad39-4879b3ebf60e", "Content-Type" : "application/json;odata=fullmetadata;streaming=true;charset=utf-8" }, "Exception" : null } ], - "variables" : [ "tablename54368bea", "apartitionkey197836", "arowkey2442208b8" ] + "variables" : [ "tablename40583955", "apartitionkey81459a", "arowkey90628af6a" ] } \ No newline at end of file