Skip to content

Commit 0a5a27f

Browse files
authored
Rename setters/getters/builders for core classes to meet proto conventions (#1341)
* Rename setters/getters/builders for core classes to meet proto conventions * Update examples, snippets and READMEs to use renamed core getters/setters/builders
1 parent 76c3a48 commit 0a5a27f

File tree

314 files changed

+5749
-3595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+5749
-3595
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Most `google-cloud` libraries require a project ID. There are multiple ways to
9494
* Supply the project ID when building the service options. For example, to use Datastore from a project with ID "PROJECT_ID", you can write:
9595

9696
```java
97-
Datastore datastore = DatastoreOptions.builder().projectId("PROJECT_ID").build().service();
97+
Datastore datastore = DatastoreOptions.newBuilder().setProjectId("PROJECT_ID").build().getService();
9898
```
9999
* Specify the environment variable `GOOGLE_CLOUD_PROJECT` to be your desired project ID.
100100
* Set the project ID using the [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en). To use the SDK, [download the SDK](https://cloud.google.com/sdk/?hl=en) if you haven't already, and set the project ID from the command line. For example:
@@ -128,18 +128,18 @@ Next, choose a method for authenticating API requests from within your project:
128128
```
129129
* Supply the JSON credentials file when building the service options. For example, this Storage object has the necessary permissions to interact with your Google Cloud Storage data:
130130
```java
131-
Storage storage = StorageOptions.builder()
132-
.authCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
131+
Storage storage = StorageOptions.newBuilder()
132+
.setAuthCredentials(AuthCredentials.createForJson(new FileInputStream("/path/to/my/key.json"))
133133
.build()
134-
.service();
134+
.getService();
135135
```
136136
* If running locally for development/testing, you can use Google Cloud SDK. Download the SDK if you haven't already, then login using the SDK (`gcloud auth login` in command line). Be sure to set your project ID as described above.
137137
* If you already have an OAuth2 access token, you can use it to authenticate (notice that in this case the access token will not be automatically refreshed):
138138
```java
139-
Storage storage = StorageOptions.builder()
140-
.authCredentials(AuthCredentials.createFor("your_access_token"))
139+
Storage storage = StorageOptions.newBuilder()
140+
.setAuthCredentials(AuthCredentials.createFor("your_access_token"))
141141
.build()
142-
.service();
142+
.getService();
143143
```
144144
145145
`google-cloud` looks for credentials in the following order, stopping once it finds credentials:
@@ -175,7 +175,7 @@ import com.google.cloud.bigquery.Table;
175175
import com.google.cloud.bigquery.TableId;
176176
import com.google.cloud.bigquery.TableInfo;
177177
178-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
178+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
179179
TableId tableId = TableId.of("dataset", "table");
180180
Table table = bigquery.getTable(tableId);
181181
if (table == null) {
@@ -216,7 +216,7 @@ import com.google.cloud.compute.Disk;
216216
import com.google.cloud.compute.DiskId;
217217
import com.google.cloud.compute.Snapshot;
218218
219-
Compute compute = ComputeOptions.defaultInstance().service();
219+
Compute compute = ComputeOptions.getDefaultInstance().getService();
220220
DiskId diskId = DiskId.of("us-central1-a", "disk-name");
221221
Disk disk = compute.getDisk(diskId, Compute.DiskOption.fields());
222222
if (disk != null) {
@@ -243,7 +243,7 @@ import com.google.cloud.compute.InstanceInfo;
243243
import com.google.cloud.compute.MachineTypeId;
244244
import com.google.cloud.compute.NetworkId;
245245
246-
Compute compute = ComputeOptions.defaultInstance().service();
246+
Compute compute = ComputeOptions.getDefaultInstance().getService();
247247
ImageId imageId = ImageId.of("debian-cloud", "debian-8-jessie-v20160329");
248248
NetworkId networkId = NetworkId.of("default");
249249
AttachedDisk attachedDisk = AttachedDisk.of(AttachedDisk.CreateDiskConfiguration.of(imageId));
@@ -282,7 +282,7 @@ import com.google.cloud.datastore.Entity;
282282
import com.google.cloud.datastore.Key;
283283
import com.google.cloud.datastore.KeyFactory;
284284
285-
Datastore datastore = DatastoreOptions.defaultInstance().service();
285+
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
286286
KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
287287
Key key = keyFactory.newKey("keyName");
288288
Entity entity = Entity.newBuilder(key)
@@ -303,7 +303,7 @@ import com.google.cloud.datastore.Entity;
303303
import com.google.cloud.datastore.Key;
304304
import com.google.cloud.datastore.KeyFactory;
305305
306-
Datastore datastore = DatastoreOptions.defaultInstance().service();
306+
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
307307
KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
308308
Key key = keyFactory.newKey("keyName");
309309
Entity entity = datastore.get(key);
@@ -336,7 +336,7 @@ import com.google.cloud.dns.DnsOptions;
336336
import com.google.cloud.dns.Zone;
337337
import com.google.cloud.dns.ZoneInfo;
338338
339-
Dns dns = DnsOptions.defaultInstance().service();
339+
Dns dns = DnsOptions.getDefaultInstance().getService();
340340
String zoneName = "my-unique-zone";
341341
String domainName = "someexampledomain.com.";
342342
String description = "This is a google-cloud-dns sample zone.";
@@ -356,7 +356,7 @@ import com.google.cloud.dns.Zone;
356356
import java.util.Iterator;
357357
import java.util.concurrent.TimeUnit;
358358
359-
Dns dns = DnsOptions.defaultInstance().service();
359+
Dns dns = DnsOptions.getDefaultInstance().getService();
360360
String zoneName = "my-unique-zone";
361361
Zone zone = dns.getZone(zoneName);
362362
String ip = "12.13.14.15";
@@ -371,8 +371,8 @@ ChangeRequestInfo.Builder changeBuilder = ChangeRequestInfo.newBuilder().add(toC
371371
Iterator<RecordSet> recordSetIterator = zone.listRecordSets().iterateAll();
372372
while (recordSetIterator.hasNext()) {
373373
RecordSet current = recordSetIterator.next();
374-
if (toCreate.name().equals(current.getName()) &&
375-
toCreate.type().equals(current.getType())) {
374+
if (toCreate.getName().equals(current.getName()) &&
375+
toCreate.getType().equals(current.getType())) {
376376
changeBuilder.delete(current);
377377
}
378378
}
@@ -410,19 +410,19 @@ import com.google.cloud.logging.Payload.StringPayload;
410410
import java.util.Collections;
411411
import java.util.Iterator;
412412
413-
LoggingOptions options = LoggingOptions.defaultInstance();
414-
try(Logging logging = options.service()) {
413+
LoggingOptions options = LoggingOptions.getDefaultInstance();
414+
try(Logging logging = options.getService()) {
415415
416416
LogEntry firstEntry = LogEntry.newBuilder(StringPayload.of("message"))
417417
.setLogName("test-log")
418-
.setResource(MonitoredResource.builder("global")
419-
.addLabel("project_id", options.projectId())
418+
.setResource(MonitoredResource.newBuilder("global")
419+
.addLabel("project_id", options.getProjectId())
420420
.build())
421421
.build();
422422
logging.write(Collections.singleton(firstEntry));
423423
424424
Page<LogEntry> entries = logging.listLogEntries(
425-
EntryListOption.filter("logName=projects/" + options.projectId() + "/logs/test-log"));
425+
EntryListOption.filter("logName=projects/" + options.getProjectId() + "/logs/test-log"));
426426
Iterator<LogEntry> entryIterator = entries.iterateAll();
427427
while (entryIterator.hasNext()) {
428428
System.out.println(entryIterator.next());
@@ -472,7 +472,7 @@ import com.google.cloud.pubsub.PubSubOptions;
472472
import com.google.cloud.pubsub.Subscription;
473473
import com.google.cloud.pubsub.SubscriptionInfo;
474474
475-
try (PubSub pubsub = PubSubOptions.defaultInstance().service()) {
475+
try (PubSub pubsub = PubSubOptions.getDefaultInstance().getService()) {
476476
Subscription subscription =
477477
pubsub.create(SubscriptionInfo.of("test-topic", "test-subscription"));
478478
MessageProcessor callback = new MessageProcessor() {
@@ -506,7 +506,7 @@ import com.google.cloud.resourcemanager.ResourceManagerOptions;
506506
507507
import java.util.Iterator;
508508
509-
ResourceManager resourceManager = ResourceManagerOptions.defaultInstance().service();
509+
ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService();
510510
Project project = resourceManager.get("some-project-id"); // Use an existing project's ID
511511
if (project != null) {
512512
Project newProject = project.toBuilder()
@@ -547,7 +547,7 @@ import com.google.cloud.storage.BlobInfo;
547547
import com.google.cloud.storage.Storage;
548548
import com.google.cloud.storage.StorageOptions;
549549
550-
Storage storage = StorageOptions.defaultInstance().service();
550+
Storage storage = StorageOptions.getDefaultInstance().getService();
551551
BlobId blobId = BlobId.of("bucket", "blob_name");
552552
BlobInfo blobInfo = BlobInfo.newBuiler(blobId).setContentType("text/plain").build();
553553
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
@@ -566,7 +566,7 @@ import com.google.cloud.storage.StorageOptions;
566566
import java.nio.ByteBuffer;
567567
import java.nio.channels.WritableByteChannel;
568568
569-
Storage storage = StorageOptions.defaultInstance().service();
569+
Storage storage = StorageOptions.getDefaultInstance().getService();
570570
BlobId blobId = BlobId.of("bucket", "blob_name");
571571
Blob blob = storage.get(blobId);
572572
if (blob != null) {
@@ -599,7 +599,7 @@ import com.google.cloud.translate.Translate.TranslateOption;
599599
import com.google.cloud.translate.TranslateOptions;
600600
import com.google.cloud.translate.Translation;
601601
602-
Translate translate = TranslateOptions.defaultInstance().service();
602+
Translate translate = TranslateOptions.getDefaultInstance().getService();
603603
604604
Detection detection = translate.detect("Hola");
605605
String detectedLanguage = detection.getLanguage();

TESTING.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Here is an example that uses the `RemoteBigQueryHelper` to create a dataset.
2727
```java
2828
RemoteBigQueryHelper bigqueryHelper =
2929
RemoteBigQueryHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
30-
BigQuery bigquery = bigqueryHelper.getOptions().service();
30+
BigQuery bigquery = bigqueryHelper.getOptions().getService();
3131
String dataset = RemoteBigQueryHelper.generateDatasetName();
3232
bigquery.create(DatasetInfo.newBuilder(dataset).build());
3333
```
@@ -56,7 +56,7 @@ uses the `RemoteComputeHelper` to create an address.
5656
```java
5757
RemoteComputeHelper computeHelper =
5858
RemoteBigQueryHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
59-
Compute compute = computeHelper.options().service();
59+
Compute compute = computeHelper.getOptions().getService();
6060
// Pick a name for the resource with low probability of clashing
6161
String addressName = RemoteComputeHelper.baseResourceName() + "address";
6262
AddressId addressId = RegionAddressId.of(REGION, addressName);
@@ -84,7 +84,7 @@ You can test against a temporary local Datastore by following these steps:
8484

8585
2. Create and use a `Datastore` object with the options given by the `LocalDatastoreHelper` instance. For example:
8686
```java
87-
Datastore localDatastore = helper.getOptions().service();
87+
Datastore localDatastore = helper.getOptions().getService();
8888
```
8989

9090
3. Run your tests.
@@ -99,12 +99,12 @@ You can test against a temporary local Datastore by following these steps:
9999
You can test against a remote Datastore emulator as well. To do this, set the `DatastoreOptions` project endpoint to the hostname of the remote machine, like the example below.
100100

101101
```java
102-
DatastoreOptions options = DatastoreOptions.builder()
103-
.projectId("my-project-id") // must match project ID specified on remote machine
104-
.host("http://<hostname of machine>:<port>")
105-
.authCredentials(AuthCredentials.noAuth())
102+
DatastoreOptions options = DatastoreOptions.newBuilder()
103+
.setProjectId("my-project-id") // must match project ID specified on remote machine
104+
.setHost("http://<hostname of machine>:<port>")
105+
.setAuthCredentials(AuthCredentials.noAuth())
106106
.build();
107-
Datastore localDatastore = options.service();
107+
Datastore localDatastore = options.getService();
108108
```
109109

110110
We recommend that you start the emulator on the remote machine using the [Google Cloud SDK](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/datastore/) from command line, as shown below:
@@ -135,7 +135,7 @@ You can test against an in-memory local DNS by following these steps:
135135
For example:
136136

137137
```java
138-
Dns dns = LocalDnsHelper.getOptions().service();
138+
Dns dns = LocalDnsHelper.getOptions().getService();
139139
```
140140

141141
3. Run your tests.
@@ -164,7 +164,7 @@ uses the `RemoteLoggingHelper` to create a metric.
164164
```java
165165
RemoteLoggingHelper loggingHelper =
166166
RemoteLoggingHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
167-
Logging logging = loggingHelper.getOptions().service();
167+
Logging logging = loggingHelper.getOptions().getService();
168168
// Pick a name for the resource with low probability of clashing
169169
String metricName = RemoteLoggingHelper.formatForTest("test-metric");
170170
MetricInfo metricInfo = MetricInfo.of(name, "logName:syslog");
@@ -190,7 +190,7 @@ and `start` methods. This will bind a port for communication with the local Pub/
190190
2. Create and use a `PubSub` object with the options given by the `LocalPubSubHelper` instance. For
191191
example:
192192
```java
193-
PubSub localPubsub = helper.getOptions().service();
193+
PubSub localPubsub = helper.getOptions().getService();
194194
```
195195

196196
3. Run your tests.
@@ -206,12 +206,12 @@ You can test against a remote Pub/Sub emulator as well. To do this, set the `Pub
206206
endpoint to the hostname of the remote machine, like the example below.
207207

208208
```java
209-
PubSubOptions options = PubSubOptions.builder()
210-
.projectId("my-project-id") // must match project ID specified on remote machine
211-
.host("<hostname of machine>:<port>")
212-
.authCredentials(AuthCredentials.noAuth())
209+
PubSubOptions options = PubSubOptions.newBuilder()
210+
.setProjectId("my-project-id") // must match project ID specified on remote machine
211+
.setHost("<hostname of machine>:<port>")
212+
.setAuthCredentials(AuthCredentials.noAuth())
213213
.build();
214-
PubSub localPubsub= options.service();
214+
PubSub localPubsub = options.getService();
215215
```
216216

217217
### Testing code that uses Resource Manager
@@ -232,7 +232,7 @@ You can test against an in-memory local Resource Manager by following these step
232232
2. In your program, create and use a Resource Manager service object whose host is set to `localhost` at the appropriate port. For example:
233233

234234
```java
235-
ResourceManager resourceManager = LocalResourceManagerHelper.options().service();
235+
ResourceManager resourceManager = LocalResourceManagerHelper.getOptions().getService();
236236
```
237237

238238
3. Run your tests.
@@ -258,7 +258,7 @@ Here is an example that uses the `RemoteStorageHelper` to create a bucket.
258258
```java
259259
RemoteStorageHelper helper =
260260
RemoteStorageHelper.create(PROJECT_ID, new FileInputStream("/path/to/my/JSON/key.json"));
261-
Storage storage = helper.getOptions().service();
261+
Storage storage = helper.getOptions().getService();
262262
String bucket = RemoteStorageHelper.generateBucketName();
263263
storage.create(BucketInfo.of(bucket));
264264
```
@@ -285,7 +285,7 @@ key.
285285
that uses the `RemoteTranslateHelper` to list supported languages.
286286
```java
287287
RemoteTranslateHelper translateHelper = RemoteTranslateHelper.create(PROJECT_ID, API_KEY);
288-
Translate translate = translateHelper.getOptions().service();
288+
Translate translate = translateHelper.getOptions().getService();
289289
List<Language> languages = translate.listSupportedLanguages();
290290
```
291291

google-cloud-bigquery/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ code to create your service object:
8585
import com.google.cloud.bigquery.BigQuery;
8686
import com.google.cloud.bigquery.BigQueryOptions;
8787

88-
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
88+
BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService();
8989
```
9090

9191
For other authentication options, see the

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQuery.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ enum DatasetField implements FieldSelector {
6565
}
6666

6767
@Override
68+
@Deprecated
6869
public String selector() {
70+
return getSelector();
71+
}
72+
73+
@Override
74+
public String getSelector() {
6975
return selector;
7076
}
7177
}
@@ -106,7 +112,13 @@ enum TableField implements FieldSelector {
106112
}
107113

108114
@Override
115+
@Deprecated
109116
public String selector() {
117+
return getSelector();
118+
}
119+
120+
@Override
121+
public String getSelector() {
110122
return selector;
111123
}
112124
}
@@ -137,7 +149,13 @@ enum JobField implements FieldSelector {
137149
}
138150

139151
@Override
152+
@Deprecated
140153
public String selector() {
154+
return getSelector();
155+
}
156+
157+
@Override
158+
public String getSelector() {
141159
return selector;
142160
}
143161
}

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public BigQueryException(int code, String message, BigQueryError error) {
6060
public BigQueryException(IOException exception) {
6161
super(exception, true);
6262
BigQueryError error = null;
63-
if (reason() != null) {
64-
error = new BigQueryError(reason(), location(), getMessage(), debugInfo());
63+
if (getReason() != null) {
64+
error = new BigQueryError(getReason(), getLocation(), getMessage(), getDebugInfo());
6565
}
6666
this.error = error;
6767
}
@@ -84,7 +84,7 @@ public BigQueryError getError() {
8484
}
8585

8686
@Override
87-
protected Set<Error> retryableErrors() {
87+
protected Set<Error> getRetryableErrors() {
8888
return RETRYABLE_ERRORS;
8989
}
9090

0 commit comments

Comments
 (0)