Skip to content

Commit

Permalink
Merge pull request #1 from jianghaolu/storage-proto
Browse files Browse the repository at this point in the history
Builders for generated clients
  • Loading branch information
jaschrep-msft committed Jun 6, 2019
2 parents 64e8c66 + b55810d commit 782953f
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.blob.implementation;

import com.azure.core.http.HttpPipeline;
import com.azure.core.implementation.RestProxy;

/**
* A builder for creating a new instance of the AzureBlobStorage type.
*/
public final class AzureBlobStorageBuilder {
/*
* The URL of the service account, container, or blob that is the targe of the desired operation.
*/
private String url;

/**
* Sets The URL of the service account, container, or blob that is the targe of the desired operation.
*
* @param url the url value.
* @return the AzureBlobStorageBuilder.
*/
public AzureBlobStorageBuilder 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 AzureBlobStorageBuilder.
*/
public AzureBlobStorageBuilder version(String version) {
this.version = version;
return this;
}

/*
* The HTTP pipeline to send requests through
*/
private HttpPipeline pipeline;

/**
* Sets The HTTP pipeline to send requests through.
*
* @param pipeline the pipeline value.
* @return the AzureBlobStorageBuilder.
*/
public AzureBlobStorageBuilder pipeline(HttpPipeline pipeline) {
this.pipeline = pipeline;
return this;
}

/**
* Builds an instance of AzureBlobStorageImpl with the provided parameters.
*
* @return an instance of AzureBlobStorageImpl.
*/
public AzureBlobStorageImpl build() {
if (version == null) {
this.version = "2018-11-09";
}
if (pipeline == null) {
this.pipeline = RestProxy.createDefaultPipeline();
}
AzureBlobStorageImpl client = new AzureBlobStorageImpl(pipeline);
if (this.url != null) {
client.url(this.url);
}
if (this.version != null) {
client.version(this.version);
}
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String url() {
* @param url the url value.
* @return the service client itself.
*/
public AzureBlobStorageImpl withUrl(String url) {
AzureBlobStorageImpl url(String url) {
this.url = url;
return this;
}
Expand All @@ -57,7 +57,7 @@ public String version() {
* @param version the version value.
* @return the service client itself.
*/
public AzureBlobStorageImpl withVersion(String version) {
AzureBlobStorageImpl version(String version) {
this.version = version;
return this;
}
Expand Down Expand Up @@ -160,7 +160,6 @@ public AzureBlobStorageImpl() {
*/
public AzureBlobStorageImpl(HttpPipeline httpPipeline) {
super(httpPipeline);
this.version = "2018-11-09";
this.services = new ServicesImpl(this);
this.containers = new ContainersImpl(this);
this.blobs = new BlobsImpl(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.file.implementation;

import com.azure.core.http.HttpPipeline;
import com.azure.core.implementation.RestProxy;

/**
* A builder for creating a new instance of the AzureFileStorage type.
*/
public final class AzureFileStorageBuilder {
/*
* 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 AzureFileStorageBuilder.
*/
public AzureFileStorageBuilder version(String version) {
this.version = version;
return this;
}

/*
* The URL of the service account, share, directory or file that is the target of the desired operation.
*/
private String url;

/**
* Sets The URL of the service account, share, directory or file that is the target of the desired operation.
*
* @param url the url value.
* @return the AzureFileStorageBuilder.
*/
public AzureFileStorageBuilder url(String url) {
this.url = url;
return this;
}

/*
* The HTTP pipeline to send requests through
*/
private HttpPipeline pipeline;

/**
* Sets The HTTP pipeline to send requests through.
*
* @param pipeline the pipeline value.
* @return the AzureFileStorageBuilder.
*/
public AzureFileStorageBuilder pipeline(HttpPipeline pipeline) {
this.pipeline = pipeline;
return this;
}

/**
* Builds an instance of AzureFileStorageImpl with the provided parameters.
*
* @return an instance of AzureFileStorageImpl.
*/
public AzureFileStorageImpl build() {
if (version == null) {
this.version = "2018-11-09";
}
if (pipeline == null) {
this.pipeline = RestProxy.createDefaultPipeline();
}
AzureFileStorageImpl client = new AzureFileStorageImpl(pipeline);
if (this.version != null) {
client.version(this.version);
}
if (this.url != null) {
client.url(this.url);
}
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String version() {
* @param version the version value.
* @return the service client itself.
*/
public AzureFileStorageImpl withVersion(String version) {
AzureFileStorageImpl version(String version) {
this.version = version;
return this;
}
Expand All @@ -57,7 +57,7 @@ public String url() {
* @param url the url value.
* @return the service client itself.
*/
public AzureFileStorageImpl withUrl(String url) {
AzureFileStorageImpl url(String url) {
this.url = url;
return this;
}
Expand Down Expand Up @@ -132,7 +132,6 @@ public AzureFileStorageImpl() {
*/
public AzureFileStorageImpl(HttpPipeline httpPipeline) {
super(httpPipeline);
this.version = "2018-11-09";
this.services = new ServicesImpl(this);
this.shares = new SharesImpl(this);
this.directorys = new DirectorysImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.azure.core.ServiceClient;
import com.azure.core.http.HttpPipeline;
import com.azure.storage.queue.implementation.AzureQueueStorageBuilder;
import com.azure.storage.queue.implementation.AzureQueueStorageImpl;

import java.net.URL;
Expand All @@ -14,7 +15,7 @@ public class QueueAsyncClient extends ServiceClient {
private QueueAsyncClient(URL endpoint, HttpPipeline httpPipeline) {
super(httpPipeline);
this.endpoint = endpoint.toString();
this.generateClient = new AzureQueueStorageImpl(httpPipeline).withUrl(this.endpoint);
this.generateClient = new AzureQueueStorageBuilder().pipeline(httpPipeline).url(this.endpoint).build();
this.apiVersion = this.generateClient.version();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.queue.implementation;

import com.azure.core.http.HttpPipeline;
import com.azure.core.implementation.RestProxy;

/**
* A builder for creating a new instance of the AzureQueueStorage type.
*/
public final class AzureQueueStorageBuilder {
/*
* The URL of the service account, queue or message that is the targe of the desired operation.
*/
private String url;

/**
* Sets The URL of the service account, queue or message that is the targe of the desired operation.
*
* @param url the url value.
* @return the AzureQueueStorageBuilder.
*/
public AzureQueueStorageBuilder 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 AzureQueueStorageBuilder.
*/
public AzureQueueStorageBuilder version(String version) {
this.version = version;
return this;
}

/*
* The HTTP pipeline to send requests through
*/
private HttpPipeline pipeline;

/**
* Sets The HTTP pipeline to send requests through.
*
* @param pipeline the pipeline value.
* @return the AzureQueueStorageBuilder.
*/
public AzureQueueStorageBuilder pipeline(HttpPipeline pipeline) {
this.pipeline = pipeline;
return this;
}

/**
* Builds an instance of AzureQueueStorageImpl with the provided parameters.
*
* @return an instance of AzureQueueStorageImpl.
*/
public AzureQueueStorageImpl build() {
if (version == null) {
this.version = "2018-03-28";
}
if (pipeline == null) {
this.pipeline = RestProxy.createDefaultPipeline();
}
AzureQueueStorageImpl client = new AzureQueueStorageImpl(pipeline);
if (this.url != null) {
client.url(this.url);
}
if (this.version != null) {
client.version(this.version);
}
return client;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String url() {
* @param url the url value.
* @return the service client itself.
*/
public AzureQueueStorageImpl withUrl(String url) {
AzureQueueStorageImpl url(String url) {
this.url = url;
return this;
}
Expand All @@ -57,7 +57,7 @@ public String version() {
* @param version the version value.
* @return the service client itself.
*/
public AzureQueueStorageImpl withVersion(String version) {
AzureQueueStorageImpl version(String version) {
this.version = version;
return this;
}
Expand Down Expand Up @@ -132,7 +132,6 @@ public AzureQueueStorageImpl() {
*/
public AzureQueueStorageImpl(HttpPipeline httpPipeline) {
super(httpPipeline);
this.version = "2018-03-28";
this.services = new ServicesImpl(this);
this.queues = new QueuesImpl(this);
this.messages = new MessagesImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.core.http.HttpPipeline;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.ProxyOptions.Type;
import com.azure.storage.blob.implementation.AzureBlobStorageBuilder;
import com.azure.storage.blob.implementation.AzureBlobStorageImpl;
import com.azure.storage.blob.models.BlobsGetPropertiesResponse;
import com.azure.storage.blob.models.BlockLookupList;
Expand All @@ -27,7 +28,7 @@ public class BlobPocTests {

@Test
public void testCreateBlob() {
AzureBlobStorageImpl client = new AzureBlobStorageImpl(HttpPipeline.builder().httpClient(HttpClient.createDefault().proxy(() -> new ProxyOptions(Type.HTTP, new InetSocketAddress("localhost", 8888))))/*,
AzureBlobStorageImpl client = new AzureBlobStorageBuilder().pipeline(HttpPipeline.builder().httpClient(HttpClient.createDefault().proxy(() -> new ProxyOptions(Type.HTTP, new InetSocketAddress("localhost", 8888))))/*,
new HttpPipelinePolicy() {
@Override
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
Expand All @@ -44,7 +45,7 @@ public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineN
}
return next.process();
}
}*/.build()).withUrl("https://" + System.getenv("AZURE_STORAGE_ACCOUNT_NAME") + ".blob.core.windows.net/mycontainer/random223" + System.getenv("AZURE_STORAGE_SAS_TOKEN"));
}*/.build()).url("https://" + System.getenv("AZURE_STORAGE_ACCOUNT_NAME") + ".blob.core.windows.net/mycontainer/random223" + System.getenv("AZURE_STORAGE_SAS_TOKEN")).build();

Random random = new Random();

Expand Down

0 comments on commit 782953f

Please sign in to comment.