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

Sync-Stack: Tables #33143

Merged
merged 28 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
05e268c
Prepare November 2022 Beta Release for Search
jairmyree Nov 10, 2022
294121f
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java
jairmyree Nov 28, 2022
8714080
Cherry-Pick updates to Changelog and version_client.txt from November…
azure-sdk Nov 11, 2022
548aa95
Autorest regeneration with Sync Stack
jairmyree Nov 29, 2022
e625125
Stashing my sync stack work
jairmyree Jan 3, 2023
b873e7e
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
jairmyree Jan 17, 2023
d01ded6
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-java in…
jairmyree Jan 18, 2023
65b2998
Synchronous implementation of our Clients
jairmyree Jan 23, 2023
8ad09df
Update to CHANGELOG.md
jairmyree Jan 23, 2023
6b1ebf9
Fix PR build issues
jairmyree Jan 23, 2023
373ed43
Fix PR build issues
jairmyree Jan 23, 2023
ed29956
Removed TODOs left behind.
jairmyree Jan 23, 2023
bb77546
Adjusting whitespaces
jairmyree Jan 23, 2023
d87f51d
Removing unnecessary annotation
jairmyree Jan 23, 2023
3638028
Adjustments to how context information:
jairmyree Jan 24, 2023
eab0151
Removed unused import
jairmyree Jan 24, 2023
f324cb6
Fixed issues identified by Spotbugs
jairmyree Jan 24, 2023
582a70e
Bug fixes
jairmyree Jan 24, 2023
6229ca1
Checkstyle fixes
jairmyree Jan 24, 2023
0648b01
Added Asserting Clients
jairmyree Jan 30, 2023
13c067e
Add asserting client to clients used for playback
jairmyree Feb 1, 2023
f92f51e
Replaced method threads with a static Thread Pool
jairmyree Feb 14, 2023
988b026
Tables Refactoring
jairmyree Feb 21, 2023
8d77fc5
Updating to only use threadpool for timeout cases.
jairmyree Feb 23, 2023
b88706a
Additional refactoring
jairmyree Feb 23, 2023
95e7fbb
Removed unused imports
jairmyree Feb 24, 2023
93320f8
Fixed Checkstyle Issues
jairmyree Feb 24, 2023
3e72216
Bug fix for failing Cosmos test
jairmyree Feb 24, 2023
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
1 change: 1 addition & 0 deletions sdk/tables/azure-data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

### Other Changes
- Removed Reactor from synchronous clients

## 12.3.7 (2023-01-11)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,25 @@
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.credential.AzureNamedKeyCredential;
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.ResponseBase;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.IterableStream;
import com.azure.core.util.ServiceVersion;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.serializer.SerializerAdapter;
import com.azure.data.tables.implementation.AzureTableImpl;
import com.azure.data.tables.implementation.AzureTableImplBuilder;
import com.azure.data.tables.implementation.EntityPaged;
import com.azure.data.tables.implementation.ModelHelper;
import com.azure.data.tables.implementation.TableSasGenerator;
import com.azure.data.tables.implementation.TableSasUtils;
import com.azure.data.tables.implementation.TableUtils;
import com.azure.data.tables.implementation.TransactionalBatchImpl;
import com.azure.data.tables.implementation.models.AccessPolicy;
import com.azure.data.tables.implementation.models.OdataMetadataFormat;
import com.azure.data.tables.implementation.models.QueryOptions;
import com.azure.data.tables.implementation.models.ResponseFormat;
Expand All @@ -43,7 +40,6 @@
import com.azure.data.tables.implementation.models.TransactionalBatchSubmitBatchHeaders;
import com.azure.data.tables.models.ListEntitiesOptions;
import com.azure.data.tables.models.TableAccessPolicies;
import com.azure.data.tables.models.TableAccessPolicy;
import com.azure.data.tables.models.TableEntity;
import com.azure.data.tables.models.TableEntityUpdateMode;
import com.azure.data.tables.models.TableItem;
Expand Down Expand Up @@ -238,6 +234,7 @@ public String generateSas(TableSasSignatureValues tableSasSignatureValues) {
return new TableSasGenerator(tableSasSignatureValues, getTableName(), azureNamedKeyCredential).getSas();
}


/**
* Creates the table within the Tables service.
*
Expand Down Expand Up @@ -287,7 +284,7 @@ public Mono<Response<TableItem>> createTableWithResponse() {
}

Mono<Response<TableItem>> createTableWithResponse(Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);
final TableProperties properties = new TableProperties().setTableName(tableName);

try {
Expand Down Expand Up @@ -349,7 +346,7 @@ public Mono<Response<Void>> deleteTableWithResponse() {
}

Mono<Response<Void>> deleteTableWithResponse(Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);

try {
return tablesImplementation.getTables().deleteWithResponseAsync(tableName, null, context)
Expand Down Expand Up @@ -432,7 +429,7 @@ public Mono<Response<Void>> createEntityWithResponse(TableEntity entity) {
}

Mono<Response<Void>> createEntityWithResponse(TableEntity entity, Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);

if (entity == null) {
return monoError(logger, new IllegalArgumentException("'entity' cannot be null."));
Expand Down Expand Up @@ -532,14 +529,14 @@ public Mono<Response<Void>> upsertEntityWithResponse(TableEntity entity, TableEn

Mono<Response<Void>> upsertEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode,
Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);

if (entity == null) {
return monoError(logger, new IllegalArgumentException("'entity' cannot be null."));
}

String partitionKey = escapeSingleQuotes(entity.getPartitionKey());
String rowKey = escapeSingleQuotes(entity.getRowKey());
String partitionKey = TableUtils.escapeSingleQuotes(entity.getPartitionKey());
String rowKey = TableUtils.escapeSingleQuotes(entity.getRowKey());

EntityHelper.setPropertiesFromGetters(entity, logger);

Expand Down Expand Up @@ -699,14 +696,14 @@ public Mono<Response<Void>> updateEntityWithResponse(TableEntity entity, TableEn

Mono<Response<Void>> updateEntityWithResponse(TableEntity entity, TableEntityUpdateMode updateMode,
boolean ifUnchanged, Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);

if (entity == null) {
return monoError(logger, new IllegalArgumentException("'entity' cannot be null."));
}

String partitionKey = escapeSingleQuotes(entity.getPartitionKey());
String rowKey = escapeSingleQuotes(entity.getRowKey());
String partitionKey = TableUtils.escapeSingleQuotes(entity.getPartitionKey());
String rowKey = TableUtils.escapeSingleQuotes(entity.getRowKey());
String eTag = ifUnchanged ? entity.getETag() : "*";

EntityHelper.setPropertiesFromGetters(entity, logger);
Expand Down Expand Up @@ -839,7 +836,7 @@ public Mono<Response<Void>> deleteEntityWithResponse(TableEntity entity, boolean

Mono<Response<Void>> deleteEntityWithResponse(String partitionKey, String rowKey, String eTag, boolean ifUnchanged,
Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);
eTag = ifUnchanged ? eTag : "*";

if (isNullOrEmpty(partitionKey) || isNullOrEmpty(rowKey)) {
Expand All @@ -848,7 +845,7 @@ Mono<Response<Void>> deleteEntityWithResponse(String partitionKey, String rowKey

try {
return tablesImplementation.getTables().deleteEntityWithResponseAsync(tableName,
escapeSingleQuotes(partitionKey), escapeSingleQuotes(rowKey), eTag, null, null, null, context)
TableUtils.escapeSingleQuotes(partitionKey), TableUtils.escapeSingleQuotes(rowKey), eTag, null, null, null, context)
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
.map(response -> (Response<Void>) new SimpleResponse<Void>(response, null))
.onErrorResume(TableServiceException.class, e -> swallowExceptionForStatusCode(404, e, logger));
Expand Down Expand Up @@ -967,7 +964,7 @@ private <T extends TableEntity> Mono<PagedResponse<T>> listEntitiesNextPage(Stri
private <T extends TableEntity> Mono<PagedResponse<T>> listEntities(String nextPartitionKey, String nextRowKey,
Context context, ListEntitiesOptions options,
Class<T> resultType) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);
String select = null;

if (options.getSelect() != null) {
Expand Down Expand Up @@ -1011,53 +1008,6 @@ private <T extends TableEntity> Mono<PagedResponse<T>> listEntities(String nextP
}
}

private static class EntityPaged<T extends TableEntity> implements PagedResponse<T> {
private final Response<TableEntityQueryResponse> httpResponse;
private final IterableStream<T> entityStream;
private final String continuationToken;

EntityPaged(Response<TableEntityQueryResponse> httpResponse, List<T> entityList,
String nextPartitionKey, String nextRowKey) {
if (nextPartitionKey == null || nextRowKey == null) {
this.continuationToken = null;
} else {
this.continuationToken = String.join(DELIMITER_CONTINUATION_TOKEN, nextPartitionKey, nextRowKey);
}

this.httpResponse = httpResponse;
this.entityStream = IterableStream.of(entityList);
}

@Override
public int getStatusCode() {
return httpResponse.getStatusCode();
}

@Override
public HttpHeaders getHeaders() {
return httpResponse.getHeaders();
}

@Override
public HttpRequest getRequest() {
return httpResponse.getRequest();
}

@Override
public IterableStream<T> getElements() {
return entityStream;
}

@Override
public String getContinuationToken() {
return continuationToken;
}

@Override
public void close() {
}
}

/**
* Gets a single {@link TableEntity entity} from the table.
*
Expand Down Expand Up @@ -1156,7 +1106,7 @@ <T extends TableEntity> Mono<Response<T>> getEntityWithResponse(String partition

try {
return tablesImplementation.getTables().queryEntityWithPartitionAndRowKeyWithResponseAsync(tableName,
escapeSingleQuotes(partitionKey), escapeSingleQuotes(rowKey), null, null, queryOptions, context)
TableUtils.escapeSingleQuotes(partitionKey), TableUtils.escapeSingleQuotes(rowKey), null, null, queryOptions, context)
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
.handle((response, sink) -> {
final Map<String, Object> matchingEntity = response.getValue();
Expand Down Expand Up @@ -1248,41 +1198,21 @@ public Mono<Response<TableAccessPolicies>> getAccessPoliciesWithResponse() {
}

Mono<Response<TableAccessPolicies>> getAccessPoliciesWithResponse(Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);

try {
return tablesImplementation.getTables()
.getAccessPolicyWithResponseAsync(tableName, null, null, context)
.onErrorMap(TableUtils::mapThrowableToTableServiceException)
.map(response -> new SimpleResponse<>(response,
new TableAccessPolicies(response.getValue() == null ? null : response.getValue().stream()
.map(this::toTableSignedIdentifier)
.map(TableUtils::toTableSignedIdentifier)
.collect(Collectors.toList()))));
} catch (RuntimeException e) {
return monoError(logger, e);
}
}

private TableSignedIdentifier toTableSignedIdentifier(SignedIdentifier signedIdentifier) {
if (signedIdentifier == null) {
return null;
}

return new TableSignedIdentifier(signedIdentifier.getId())
.setAccessPolicy(toTableAccessPolicy(signedIdentifier.getAccessPolicy()));
}

private TableAccessPolicy toTableAccessPolicy(AccessPolicy accessPolicy) {
if (accessPolicy == null) {
return null;
}

return new TableAccessPolicy()
.setExpiresOn(accessPolicy.getExpiry())
.setStartsOn(accessPolicy.getStart())
.setPermissions(accessPolicy.getPermission());
}

/**
* Sets stored {@link TableAccessPolicies access policies} for the table that may be used with Shared Access
* Signatures.
Expand Down Expand Up @@ -1368,7 +1298,7 @@ public Mono<Response<Void>> setAccessPoliciesWithResponse(List<TableSignedIdenti

Mono<Response<Void>> setAccessPoliciesWithResponse(List<TableSignedIdentifier> tableSignedIdentifiers,
Context context) {
context = context == null ? Context.NONE : context;
context = TableUtils.setContext(context);
List<SignedIdentifier> signedIdentifiers = null;

/*
Expand All @@ -1380,7 +1310,7 @@ OffsetDateTime.now will only give back milliseconds (more precise fields are zer
if (tableSignedIdentifiers != null) {
signedIdentifiers = tableSignedIdentifiers.stream()
.map(tableSignedIdentifier -> {
SignedIdentifier signedIdentifier = toSignedIdentifier(tableSignedIdentifier);
SignedIdentifier signedIdentifier = TableUtils.toSignedIdentifier(tableSignedIdentifier);

if (signedIdentifier != null) {
if (signedIdentifier.getAccessPolicy() != null
Expand Down Expand Up @@ -1415,27 +1345,6 @@ OffsetDateTime.now will only give back milliseconds (more precise fields are zer
}
}

private SignedIdentifier toSignedIdentifier(TableSignedIdentifier tableSignedIdentifier) {
if (tableSignedIdentifier == null) {
return null;
}

return new SignedIdentifier()
.setId(tableSignedIdentifier.getId())
.setAccessPolicy(toAccessPolicy(tableSignedIdentifier.getAccessPolicy()));
}

private AccessPolicy toAccessPolicy(TableAccessPolicy tableAccessPolicy) {
if (tableAccessPolicy == null) {
return null;
}

return new AccessPolicy()
.setExpiry(tableAccessPolicy.getExpiresOn())
.setStart(tableAccessPolicy.getStartsOn())
.setPermission(tableAccessPolicy.getPermissions());
}

/**
* Executes all {@link TableTransactionAction actions} within the list inside a transaction. When the call
* completes, either all {@link TableTransactionAction actions} in the transaction will succeed, or if a failure
Expand Down Expand Up @@ -1617,7 +1526,7 @@ public Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List
}

Mono<Response<TableTransactionResult>> submitTransactionWithResponse(List<TableTransactionAction> transactionActions, Context context) {
Context finalContext = context == null ? Context.NONE : context;
Context finalContext = TableUtils.setContext(context);

if (transactionActions.isEmpty()) {
return monoError(logger,
Expand Down Expand Up @@ -1750,14 +1659,4 @@ private Mono<Response<List<TableTransactionActionResponse>>> parseResponse(Trans
return Mono.just(new SimpleResponse<>(response, Arrays.asList(response.getValue())));
}
}

// Single quotes in OData queries should be escaped by using two consecutive single quotes characters.
// Source: http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_URLSyntax.
private String escapeSingleQuotes(String input) {
if (input == null) {
return null;
}

return input.replace("'", "''");
}
}
Loading