Skip to content

Commit

Permalink
Tables regenerated implementation layer (#19009)
Browse files Browse the repository at this point in the history
* Regenerated implementation layer

* Fixed serialization issued cause by auto-rest regeneration.

* Removed unused imports.

* Updated Tables swagger README and regenerated implementation layer.

* Reverted exception change on TablesImpl. Fixed an issue with TablesJacksonSerializer. Re-recorded tests.

* Fixed checkstyle issue.

* Reverted exception change on TablesImpl Javadoc.

* Removed unused exception.
  • Loading branch information
vcolin7 authored Feb 10, 2021
1 parent 86d1553 commit c412a52
Show file tree
Hide file tree
Showing 93 changed files with 2,123 additions and 11,084 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -811,34 +811,21 @@ <T extends TableEntity> Mono<Response<T>> getEntityWithResponse(String partition
queryOptions.setSelect(select);
}

return implementation.getTables().queryEntitiesWithPartitionAndRowKeyWithResponseAsync(tableName, partitionKey,
return implementation.getTables().queryEntityWithPartitionAndRowKeyWithResponseAsync(tableName, partitionKey,
rowKey, timeoutInt, null, queryOptions, context)
.handle((response, sink) -> {
final TableEntityQueryResponse entityQueryResponse = response.getValue();
if (entityQueryResponse == null) {
logger.info("TableEntityQueryResponse is null. Table: {}, partition key: {}, row key: {}.",
tableName, partitionKey, rowKey);
final Map<String, Object> matchingEntity = response.getValue();

sink.complete();
return;
}
final List<Map<String, Object>> matchingEntities = entityQueryResponse.getValue();
if (matchingEntities == null || matchingEntities.isEmpty()) {
if (matchingEntity == null || matchingEntity.isEmpty()) {
logger.info("There was no matching entity. Table: {}, partition key: {}, row key: {}.",
tableName, partitionKey, rowKey);

sink.complete();
return;
}

if (matchingEntities.size() > 1) {
logger.warning("There were multiple matching entities. Table: {}, partition key: {}, row key: {}.",
tableName, partitionKey, rowKey);
}

// Deserialize the first entity.
// TODO: Potentially update logic to deserialize them all.
final TableEntity entity = ModelHelper.createEntity(matchingEntities.get(0));
final TableEntity entity = ModelHelper.createEntity(matchingEntity);
sink.next(new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(),
EntityHelper.convertToSubclass(entity, resultType, logger)));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ public HttpPipeline getHttpPipeline() {
return this.httpPipeline;
}

/** The serializer to serialize an object into a string. */
private final SerializerAdapter serializerAdapter;

/**
* Gets The serializer to serialize an object into a string.
*
* @return the serializerAdapter value.
*/
public SerializerAdapter getSerializerAdapter() {
return this.serializerAdapter;
}

/** The TablesImpl object to access its operations. */
private final TablesImpl tables;

Expand All @@ -74,34 +86,47 @@ public ServicesImpl getServices() {
return this.services;
}

/** Initializes an instance of AzureTable client. */
/**
* Initializes an instance of AzureTable client.
*
* @param url The URL of the service account or table that is the target of the desired operation.
* @param version Specifies the version of the operation to use for this request.
*/
AzureTableImpl(String url, String version) {
this(
new HttpPipelineBuilder()
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
.build(),
url, version);
JacksonAdapter.createDefaultSerializerAdapter(),
url,
version);
}

/**
* Initializes an instance of AzureTable client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param url The URL of the service account or table that is the target of the desired operation.
* @param version Specifies the version of the operation to use for this request.
*/
AzureTableImpl(HttpPipeline httpPipeline, String url, String version) {
this(httpPipeline, url, version, JacksonAdapter.createDefaultSerializerAdapter());
this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), url, version);
}

/**
* Initializes an instance of AzureTable client.
*
* @param httpPipeline The HTTP pipeline to send requests through.
* @param serializerAdapter The serializer to serialize an object into a string.
* @param url The URL of the service account or table that is the target of the desired operation.
* @param version Specifies the version of the operation to use for this request.
*/
AzureTableImpl(HttpPipeline httpPipeline, String url, String version, SerializerAdapter serializerAdapter) {
AzureTableImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String url, String version) {
this.httpPipeline = httpPipeline;
this.serializerAdapter = serializerAdapter;
this.url = url;
this.version = version;
this.tables = new TablesImpl(this, serializerAdapter);
this.services = new ServicesImpl(this, serializerAdapter);
this.tables = new TablesImpl(this);
this.services = new ServicesImpl(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,38 @@
package com.azure.data.tables.implementation;

import com.azure.core.annotation.ServiceClientBuilder;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.HttpPipelineBuilder;
import com.azure.core.http.policy.CookiePolicy;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.http.policy.HttpLoggingPolicy;
import com.azure.core.http.policy.HttpPipelinePolicy;
import com.azure.core.http.policy.HttpPolicyProviders;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.util.Configuration;
import com.azure.core.util.serializer.JacksonAdapter;
import com.azure.core.util.serializer.SerializerAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* A builder for creating a new instance of the AzureTable type.
*/
/** A builder for creating a new instance of the AzureTable type. */
@ServiceClientBuilder(serviceClients = {AzureTableImpl.class})
public final class AzureTableImplBuilder {
private static final String SDK_NAME = "name";

private static final String SDK_VERSION = "version";

private final Map<String, String> properties = new HashMap<>();

/** Create an instance of the AzureTableImplBuilder. */
public AzureTableImplBuilder() {
this.pipelinePolicies = new ArrayList<>();
}

/*
* The URL of the service account or table that is the target of the
* desired operation.
Expand All @@ -27,14 +47,29 @@ public final class AzureTableImplBuilder {
* Sets The URL of the service account or table that is the target of the desired operation.
*
* @param url the url value.
*
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder url(String url) {
this.url = url;
return this;
}

/*
* Specifies the version of the operation to use for this request.
*/
private String version;

/**
* Sets Specifies the version of the operation to use for this request.
*
* @param version the version value.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder version(String version) {
this.version = version;
return this;
}

/*
* The HTTP pipeline to send requests through
*/
Expand All @@ -44,41 +79,108 @@ public AzureTableImplBuilder url(String url) {
* Sets The HTTP pipeline to send requests through.
*
* @param pipeline the pipeline value.
*
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder pipeline(HttpPipeline pipeline) {
this.pipeline = pipeline;
return this;
}

/*
* The serializer to serialize an object into a string
*/
private SerializerAdapter serializerAdapter;

/**
* The version for Tables service.
* Sets The serializer to serialize an object into a string.
*
* @param serializerAdapter the serializerAdapter value.
* @return the AzureTableImplBuilder.
*/
private String version;
public AzureTableImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) {
this.serializerAdapter = serializerAdapter;
return this;
}

/*
* The HTTP client used to send the request.
*/
private HttpClient httpClient;

/**
* Sets the version for Tables service.
* Sets The HTTP client used to send the request.
*
* @param version the service value.
* @param httpClient the httpClient value.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder httpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}

/*
* The configuration store that is used during construction of the service
* client.
*/
private Configuration configuration;

/**
* Sets The configuration store that is used during construction of the service client.
*
* @param configuration the configuration value.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder version(String version) {
this.version = version;
public AzureTableImplBuilder configuration(Configuration configuration) {
this.configuration = configuration;
return this;
}

private SerializerAdapter serializerAdapter;
/*
* The logging configuration for HTTP requests and responses.
*/
private HttpLogOptions httpLogOptions;

/**
* Sets the serializer adapter to use.
* Sets The logging configuration for HTTP requests and responses.
*
* @param serializerAdapter Adapter to serialize with.
* @return The updated object.
* @param httpLogOptions the httpLogOptions value.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder serializerAdapter(SerializerAdapter serializerAdapter) {
this.serializerAdapter = serializerAdapter;
public AzureTableImplBuilder httpLogOptions(HttpLogOptions httpLogOptions) {
this.httpLogOptions = httpLogOptions;
return this;
}

/*
* The retry policy that will attempt to retry failed requests, if
* applicable.
*/
private RetryPolicy retryPolicy;

/**
* Sets The retry policy that will attempt to retry failed requests, if applicable.
*
* @param retryPolicy the retryPolicy value.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder retryPolicy(RetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
return this;
}

/*
* The list of Http pipeline policies to add.
*/
private final List<HttpPipelinePolicy> pipelinePolicies;

/**
* Adds a custom Http pipeline policy.
*
* @param customPolicy The custom Http pipeline policy to add.
* @return the AzureTableImplBuilder.
*/
public AzureTableImplBuilder addPolicy(HttpPipelinePolicy customPolicy) {
pipelinePolicies.add(customPolicy);
return this;
}

Expand All @@ -88,13 +190,41 @@ public AzureTableImplBuilder serializerAdapter(SerializerAdapter serializerAdapt
* @return an instance of AzureTableImpl.
*/
public AzureTableImpl buildClient() {
if (version == null) {
this.version = "2019-02-02";
}
if (pipeline == null) {
this.pipeline =
new HttpPipelineBuilder()
.policies(new UserAgentPolicy(), new RetryPolicy(), new CookiePolicy())
.build();
this.pipeline = createHttpPipeline();
}
if (serializerAdapter == null) {
this.serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter();
}
AzureTableImpl client = new AzureTableImpl(pipeline, serializerAdapter, url, version);
return client;
}

return new AzureTableImpl(pipeline, url, version, serializerAdapter);
private HttpPipeline createHttpPipeline() {
Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration() : configuration;
if (httpLogOptions == null) {
httpLogOptions = new HttpLogOptions();
}
List<HttpPipelinePolicy> policies = new ArrayList<>();
String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
policies.add(
new UserAgentPolicy(httpLogOptions.getApplicationId(), clientName, clientVersion, buildConfiguration));
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? new RetryPolicy() : retryPolicy);
policies.add(new CookiePolicy());
policies.addAll(this.pipelinePolicies);
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
HttpPipeline httpPipeline =
new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.build();
return httpPipeline;
}
}
Loading

0 comments on commit c412a52

Please sign in to comment.