Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous Table clients API changes #21940

Merged
merged 18 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
- `TableClient.submitTransaction(List<TableTransactionAction> transactionalBatch)`
- `TableClient.submitTransactionWithResponse(List<TableTransactionAction> transactionalBatch, Duration timeout, Context context)`
- `deleteEntity()` variants in `TableClient` and `TableAsyncClient` now accept an `ifUnchanged` flag instead of an `eTag` parameter for conditional operations. When said flag is set to `true`, the ETag of a given `TableEntity` will be matched with the ETag of the entity in the Table service.
- Removed `deleteEntity(TableEntity tableEntity)` from both `TableClient` and `TableAsyncClient`.
- Replaced `deleteEntityWithResponse(String partitionKey, String rowKey, String eTag)` with `deleteEntity(TableEntity entity, boolean ifUnchanged)` in `TableAsyncClient`.
- Replaced `deleteEntityWithResponse(String partitionKey, String rowKey, String eTag, Duration timeout, Context context)` with `deleteEntity(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context)` in `TableClient`.
- Replaced `deleteEntityWithResponse(String partitionKey, String rowKey, String eTag)` with `deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged)` in `TableAsyncClient`.
- Replaced `deleteEntityWithResponse(String partitionKey, String rowKey, String eTag, Duration timeout, Context context)` with `deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context)` in `TableClient`.
- Removed remaining public APIs supporting the use of `TableEntity` subclasses from `TableAsyncClient`.
- Removed the following method overloads from `TableClient` and `TableAsyncClient`:
- `upsertEntity(TableEntity entity, TableEntityUpdateMode updateMode)`
- `updateEntity(TableEntity entity, TableEntityUpdateMode updateMode,
boolean ifUnchanged)`
- `getEntity(String partitionKey, String rowKey, List<String> select)`

## 12.0.0-beta.7 (2021-05-15)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,30 +305,6 @@ public Mono<Void> upsertEntity(TableEntity entity) {
return upsertEntityWithResponse(entity, null).flatMap(response -> Mono.justOrEmpty(response.getValue()));
}

/**
* 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 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.
* @throws TableServiceException If the request is rejected by the service.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> upsertEntity(TableEntity entity, TableEntityUpdateMode updateMode) {
return upsertEntityWithResponse(entity, updateMode).flatMap(response -> Mono.justOrEmpty(response.getValue()));
}

/**
* Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update
* mode otherwise.
Expand Down Expand Up @@ -418,32 +394,8 @@ public Mono<Void> updateEntity(TableEntity entity) {
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateEntity(TableEntity entity, TableEntityUpdateMode updateMode) {
return updateEntity(entity, updateMode, false);
}

/**
* 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 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 An empty reactive result.
*
* @throws IllegalArgumentException If the provided entity is invalid.
* @throws TableServiceException 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.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<Void> updateEntity(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged) {
return updateEntityWithResponse(entity, updateMode, ifUnchanged).flatMap(response ->
Mono.justOrEmpty(response.getValue()));
return updateEntityWithResponse(entity, updateMode, false)
.flatMap(response -> Mono.justOrEmpty(response.getValue()));
}

/**
Expand Down Expand Up @@ -644,46 +596,6 @@ public PagedFlux<TableEntity> listEntities(ListEntitiesOptions options) {
token -> withContext(context -> listEntitiesNextPage(token, context, options, TableEntity.class)));
}

/**
* Lists all entities within the table.
*
* @param <T> 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 reactive result containing all entities within the table.
*
* @throws IllegalArgumentException If an instance of the provided {@code resultType} can't be created.
* @throws TableServiceException If the request is rejected by the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public <T extends TableEntity> PagedFlux<T> listEntities(Class<T> resultType) {
return listEntities(new ListEntitiesOptions(), resultType);
}

/**
* 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 <T> 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 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.
* @throws TableServiceException If the request is rejected by the service.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public <T extends TableEntity> PagedFlux<T> listEntities(ListEntitiesOptions options, Class<T> resultType) {
return new PagedFlux<>(
() -> withContext(context -> listEntitiesFirstPage(context, options, resultType)),
token -> withContext(context -> listEntitiesNextPage(token, context, options, resultType)));
}

/**
* Lists entities using the parameters in the provided options.
*
Expand Down Expand Up @@ -842,68 +754,6 @@ public Mono<TableEntity> getEntity(String partitionKey, String rowKey) {
return getEntityWithResponse(partitionKey, rowKey, null).flatMap(FluxUtil::toMono);
}

/**
* 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 A list of properties to select on the entity.
*
* @return A reactive result containing the entity.
*
* @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 TableServiceException If no entity with the provided partition key and row key exists within the
* table.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<TableEntity> getEntity(String partitionKey, String rowKey, List<String> select) {
return getEntityWithResponse(partitionKey, rowKey, select).flatMap(FluxUtil::toMono);
}

/**
* Gets a single entity from the table.
*
* @param <T> 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 reactive result containing the entity.
*
* @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.
* @throws TableServiceException If no entity with the provided partition key and row key exists within the
* table.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T extends TableEntity> Mono<T> getEntity(String partitionKey, String rowKey, Class<T> resultType) {
return getEntityWithResponse(partitionKey, rowKey, null, resultType).flatMap(FluxUtil::toMono);
}

/**
* Gets a single entity from the table.
*
* @param <T> 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 reactive result containing the entity.
*
* @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 TableServiceException If no entity with the provided partition key and row key exists within the
* table.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T extends TableEntity> Mono<T> getEntity(String partitionKey, String rowKey, List<String> select,
Class<T> resultType) {
return getEntityWithResponse(partitionKey, rowKey, select, resultType).flatMap(FluxUtil::toMono);
}

/**
* Gets a single entity from the table.
*
Expand All @@ -923,29 +773,6 @@ public Mono<Response<TableEntity>> getEntityWithResponse(String partitionKey, St
return withContext(context -> getEntityWithResponse(partitionKey, rowKey, select, TableEntity.class, context));
}

/**
* Gets a single entity from the table.
*
* @param <T> 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 reactive result containing the response and entity.
*
* @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 TableServiceException If no entity with the provided partition key and row key exists within the
* table.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public <T extends TableEntity> Mono<Response<T>> getEntityWithResponse(String partitionKey, String rowKey,
List<String> select, Class<T> resultType) {
return withContext(context -> getEntityWithResponse(partitionKey, rowKey, select, resultType, context));
}

<T extends TableEntity> Mono<Response<T>> getEntityWithResponse(String partitionKey, String rowKey,
List<String> select, Class<T> resultType,
Context context) {
Expand Down Expand Up @@ -1105,7 +932,7 @@ private AccessPolicy toAccessPolicy(TableAccessPolicy tableAccessPolicy) {
* fail.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public synchronized Mono<TableTransactionResult> submitTransaction(List<TableTransactionAction> transactionActions) {
public Mono<TableTransactionResult> submitTransaction(List<TableTransactionAction> transactionActions) {
return submitTransactionWithResponse(transactionActions)
.flatMap(response -> Mono.justOrEmpty(response.getValue()));
}
Expand All @@ -1129,7 +956,7 @@ public synchronized Mono<TableTransactionResult> submitTransaction(List<TableTra
* fail.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public synchronized Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableTransactionAction> transactionActions) {
public Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableTransactionAction> transactionActions) {
return withContext(context -> submitTransactionWithResponse(transactionActions, context));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,6 @@ public void upsertEntity(TableEntity entity) {
client.upsertEntity(entity).block();
}

/**
* 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 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.
* @throws TableServiceException If the request is rejected by the service.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void upsertEntity(TableEntity entity, TableEntityUpdateMode updateMode) {
client.upsertEntity(entity, updateMode).block();
}

/**
* Inserts an entity into the table if it does not exist, or updates the existing entity using the specified update
* mode otherwise.
Expand Down Expand Up @@ -235,28 +213,6 @@ public void updateEntity(TableEntity entity, TableEntityUpdateMode updateMode) {
client.updateEntity(entity, updateMode).block();
}

/**
* 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 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 IllegalArgumentException If the provided entity is invalid.
* @throws TableServiceException 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.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public void updateEntity(TableEntity entity, TableEntityUpdateMode updateMode, boolean ifUnchanged) {
client.updateEntity(entity, updateMode, ifUnchanged).block();
}

/**
* Updates an existing entity using the specified update mode.
*
Expand Down Expand Up @@ -409,25 +365,6 @@ public TableEntity getEntity(String partitionKey, String rowKey) {
return client.getEntity(partitionKey, rowKey).block();
}

/**
* 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 A list of properties to select on the entity.
*
* @return The entity.
*
* @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 TableServiceException If no entity with the provided partition key and row key exists within the
* table.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public TableEntity getEntity(String partitionKey, String rowKey, List<String> select) {
return client.getEntity(partitionKey, rowKey, select).block();
}

/**
* Gets a single entity from the table.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ private void upsert() {
System.out.println("Table Entity: " + tableEntity);
tableEntity.getProperties().put("Price", "5");

//default is for UpdateMode is UpdateMode.MERGE, which means it merges if exists; inserts if not
//ifUnchanged being true means the eTags must match to upsert
// The default TableEntityUpdateMode for this operation is MERGE, which means it merges the entities if one
// already exists or inserts it if it does not.
return tableAsyncClient.upsertEntity(tableEntity);
}).subscribe(
Void -> { },
Expand All @@ -143,10 +143,9 @@ private void update() {
System.out.println("Table Entity: " + tableEntity);
tableEntity.getProperties().put("Price", "5");

// Using TableEntityUpdateMode.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, TableEntityUpdateMode.REPLACE, false);
// The default TableEntityUpdateMode for this operation is REPLACE, which means the entity will be
// replaced if it exists or the request will fail if not found.
return tableAsyncClient.updateEntity(tableEntity, TableEntityUpdateMode.REPLACE);
}).subscribe(
Void -> { },
error -> System.err.println("There was an error updating the Entity. Error: " + error),
Expand Down
Loading