Skip to content

Commit 96e9e73

Browse files
committed
---
yaml --- r: 9711 b: refs/heads/spanner-gapic-migration c: 3973c4d h: refs/heads/master i: 9709: 47dced6 9707: 62d9952 9703: b1ea3ea 9695: 9698a91
1 parent ded00df commit 96e9e73

30 files changed

Lines changed: 475 additions & 1263 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ refs/tags/v0.34.0: bf31760a31a66acb239322a70dcd03dbe1d0c7ca
8080
refs/tags/v0.35.0: c28951c5f4cc97a1be07900d19df6984115a4bd6
8181
refs/tags/v0.36.0: 6b75c61f73e6827b3ca379bd54f88f750290162f
8282
refs/tags/v0.37.0: db2e142f92601709fdd48db159776f905742e30f
83-
refs/heads/spanner-gapic-migration: bc647b11cd1a0469709419d47b670dd38f699364
83+
refs/heads/spanner-gapic-migration: 3973c4d3896cc3af936a2d1df6b732174dbd8235
8484
refs/tags/v0.38.0: c235ee4df5e1248e1769dae3f86a0d7ab7fd8301
8585
refs/tags/v0.39.0: ab231c9d22475242a43d6d9554aa4a3f736dab01
8686
refs/tags/v0.40.0: a1d5b05206cce7734365f1b910396a2c9d6605ec

branches/spanner-gapic-migration/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/DatasetInfo.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,20 @@ public DatasetId getDatasetId() {
318318
/**
319319
* Returns the dataset's access control configuration.
320320
*
321+
* <p>Update the ACLs for a dataset.
322+
* <pre> {@code
323+
* Dataset dataset = bigquery.getDataset(DatasetId.of("my_dataset"));
324+
* List<Acl> beforeAcls = dataset.getAcl();
325+
*
326+
* // Make a copy of the ACLs so that they can be modified.
327+
* ArrayList<Acl> acls = new ArrayList<>(beforeAcls);
328+
* acls.add(Acl.of(new Acl.User("[email protected]"), Acl.Role.READER));
329+
* Dataset.Builder builder = dataset.toBuilder();
330+
* builder.setAcl(acls);
331+
*
332+
* bigquery.update(builder.build()); // API request.
333+
* }</pre>
334+
*
321335
* @see <a href="https://cloud.google.com/bigquery/access-control">Access Control</a>
322336
*/
323337
public List<Acl> getAcl() {
@@ -341,6 +355,18 @@ public Long getCreationTime() {
341355
* will be deleted automatically. If a table's expirationTime is modified or removed before the
342356
* table expires, or if you provide an explicit expirationTime when creating a table, that value
343357
* takes precedence over the default expiration time indicated by this property.
358+
*
359+
* <p>Update the default table expiration time for a dataset.
360+
* <pre> {@code
361+
* Dataset dataset = bigquery.getDataset(DatasetId.of("my_dataset"));
362+
* Long beforeExpiration = dataset.getDefaultTableLifetime();
363+
*
364+
* Long oneDayMilliseconds = 24 * 60 * 60 * 1000L;
365+
* Dataset.Builder builder = dataset.toBuilder();
366+
* builder.setDefaultTableLifetime(oneDayMilliseconds);
367+
* bigquery.update(builder.build()); // API request.
368+
* }</pre>
369+
*
344370
*/
345371
public Long getDefaultTableLifetime() {
346372
return defaultTableLifetime;

branches/spanner-gapic-migration/google-cloud-bom/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@
170170
<testing.version>0.46.1-alpha-SNAPSHOT</testing.version><!-- {x-version-update:google-cloud-testing:current} -->
171171

172172
<api-common.version>1.5.0</api-common.version>
173-
<gax.version>1.26.0</gax.version>
174-
<gax-grpc.version>1.26.0</gax-grpc.version>
175-
<gax-httpjson.version>0.43.0</gax-httpjson.version>
173+
<gax.version>1.25.0</gax.version>
174+
<gax-grpc.version>1.25.0</gax-grpc.version>
175+
<gax-httpjson.version>0.42.0</gax-httpjson.version>
176176
<generated-proto-beta.version>0.11.0</generated-proto-beta.version>
177177
<generated-proto-ga.version>1.10.0</generated-proto-ga.version>
178178
</properties>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* EDITING INSTRUCTIONS
19+
* This file is referenced in DatasetInfo’s javadoc. Any change to this file should be reflected in
20+
* DatasetInfo’s javadoc. Use utilities/add_snipptets_to_file.py to copy.
21+
*/
22+
23+
package com.google.cloud.examples.bigquery.snippets;
24+
25+
import com.google.api.gax.paging.Page;
26+
import com.google.cloud.bigquery.*;
27+
import com.google.cloud.bigquery.DatasetInfo.Builder;
28+
29+
import java.util.ArrayList;
30+
import java.util.List;
31+
32+
/**
33+
* This class contains a number of snippets for the {@link DatasetInfo} interface.
34+
*/
35+
public class DatasetInfoSnippets {
36+
37+
private final BigQuery bigquery;
38+
39+
public DatasetInfoSnippets(BigQuery bigquery) {
40+
this.bigquery = bigquery;
41+
}
42+
43+
/**
44+
* Update the ACLs for a dataset.
45+
*/
46+
// [TARGET getAcl()]
47+
// [VARIABLE bigquery.getDataset(DatasetId.of("my_dataset"))]
48+
public List<Acl> updateDatasetAccess(Dataset dataset) {
49+
// [START bigquery_update_dataset_access]
50+
List<Acl> beforeAcls = dataset.getAcl();
51+
52+
// Make a copy of the ACLs so that they can be modified.
53+
ArrayList<Acl> acls = new ArrayList<>(beforeAcls);
54+
acls.add(Acl.of(new Acl.User("[email protected]"), Acl.Role.READER));
55+
Dataset.Builder builder = dataset.toBuilder();
56+
builder.setAcl(acls);
57+
58+
bigquery.update(builder.build()); // API request.
59+
// [END bigquery_update_dataset_access]
60+
61+
return beforeAcls;
62+
}
63+
64+
/**
65+
* Update the default table expiration time for a dataset.
66+
*/
67+
// [TARGET getDefaultTableLifetime()]
68+
// [VARIABLE bigquery.getDataset(DatasetId.of("my_dataset"))]
69+
public Long updateDatasetExpiration(Dataset dataset) {
70+
// [START bigquery_update_dataset_expiration]
71+
Long beforeExpiration = dataset.getDefaultTableLifetime();
72+
73+
Long oneDayMilliseconds = 24 * 60 * 60 * 1000L;
74+
Dataset.Builder builder = dataset.toBuilder();
75+
builder.setDefaultTableLifetime(oneDayMilliseconds);
76+
bigquery.update(builder.build()); // API request.
77+
// [END bigquery_update_dataset_expiration]
78+
79+
return beforeExpiration;
80+
}
81+
}

branches/spanner-gapic-migration/google-cloud-examples/src/main/java/com/google/cloud/examples/spanner/snippets/DatabaseAdminClientSnippets.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@
2222

2323
package com.google.cloud.examples.spanner.snippets;
2424

25-
import com.google.api.gax.longrunning.OperationFuture;
2625
import com.google.api.gax.paging.Page;
2726
import com.google.common.collect.Iterables;
2827
import com.google.cloud.spanner.DatabaseAdminClient;
2928
import com.google.cloud.spanner.Options;
3029
import com.google.cloud.spanner.Database;
31-
import com.google.cloud.spanner.SpannerExceptionFactory;
30+
import com.google.cloud.spanner.Operation;
3231
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
3332

3433
import java.util.ArrayList;
3534
import java.util.Arrays;
3635
import java.util.List;
37-
import java.util.concurrent.ExecutionException;
3836

3937
/**
4038
* This class contains snippets for {@link DatabaseAdminClient} interface.
@@ -55,7 +53,7 @@ public DatabaseAdminClientSnippets(DatabaseAdminClient dbAdminClient) {
5553
// [VARIABLE my_database_id]
5654
public Database createDatabase(String instanceId, String databaseId) {
5755
// [START createDatabase]
58-
OperationFuture<Database, CreateDatabaseMetadata> op = dbAdminClient
56+
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
5957
.createDatabase(
6058
instanceId,
6159
databaseId,
@@ -72,13 +70,9 @@ public Database createDatabase(String instanceId, String databaseId) {
7270
+ " AlbumTitle STRING(MAX)\n"
7371
+ ") PRIMARY KEY (SingerId, AlbumId),\n"
7472
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
75-
try {
76-
return op.get();
77-
// [END createDatabase]
78-
} catch (ExecutionException | InterruptedException e) {
79-
// DO error handing
80-
}
81-
return null;
73+
Database db = op.waitFor().getResult();
74+
// [END createDatabase]
75+
return db;
8276
}
8377

8478
/**
@@ -102,14 +96,10 @@ public Database getDatabase(String instanceId, String databaseId) {
10296
// [VARIABLE my_database_id]
10397
public void updateDatabaseDdl(String instanceId, String databaseId) {
10498
// [START updateDatabaseDdl]
105-
try {
106-
dbAdminClient.updateDatabaseDdl(instanceId,
99+
dbAdminClient.updateDatabaseDdl(instanceId,
107100
databaseId,
108101
Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
109-
null).get();
110-
} catch (ExecutionException | InterruptedException e) {
111-
// DO error handling
112-
}
102+
null).waitFor();
113103
// [END updateDatabaseDdl]
114104
}
115105

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.examples.bigquery.snippets;
18+
19+
import com.google.cloud.bigquery.*;
20+
import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption;
21+
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
22+
import org.junit.AfterClass;
23+
import org.junit.BeforeClass;
24+
import org.junit.Rule;
25+
import org.junit.Test;
26+
import org.junit.rules.Timeout;
27+
28+
import java.io.ByteArrayOutputStream;
29+
import java.io.PrintStream;
30+
import java.util.List;
31+
import java.util.concurrent.ExecutionException;
32+
33+
import static org.junit.Assert.*;
34+
35+
public class ITDatasetInfoSnippets {
36+
37+
private static final String DATASET = RemoteBigQueryHelper.generateDatasetName();
38+
39+
private static BigQuery bigquery;
40+
private static DatasetInfoSnippets datasetInfoSnippets;
41+
private static ByteArrayOutputStream bout;
42+
private static PrintStream out;
43+
44+
@Rule public Timeout globalTimeout = Timeout.seconds(300);
45+
46+
@BeforeClass
47+
public static void beforeClass() {
48+
bigquery = RemoteBigQueryHelper.create().getOptions().getService();
49+
datasetInfoSnippets = new DatasetInfoSnippets(bigquery);
50+
bigquery.create(DatasetInfo.newBuilder(DATASET).build());
51+
bout = new ByteArrayOutputStream();
52+
out = new PrintStream(bout);
53+
System.setOut(out);
54+
}
55+
56+
@AfterClass
57+
public static void afterClass() throws ExecutionException, InterruptedException {
58+
bigquery.delete(DATASET, DatasetDeleteOption.deleteContents());
59+
System.setOut(null);
60+
}
61+
62+
@Test
63+
public void testUpdateDatasetAccess() throws InterruptedException {
64+
Dataset dataset = bigquery.getDataset(DATASET);
65+
List<Acl> beforeAcls = datasetInfoSnippets.updateDatasetAccess(dataset);
66+
dataset = bigquery.getDataset(DATASET);
67+
List<Acl> afterAcls = dataset.getAcl();
68+
assertEquals(beforeAcls.size() + 1, afterAcls.size());
69+
}
70+
71+
@Test
72+
public void testUpdateDatasetExpiration() throws InterruptedException {
73+
Dataset dataset = bigquery.getDataset(DATASET);
74+
Long beforeExpiration = datasetInfoSnippets.updateDatasetExpiration(dataset);
75+
dataset = bigquery.getDataset(DATASET);
76+
Long afterExpiration = dataset.getDefaultTableLifetime();
77+
assertNotEquals(beforeExpiration, afterExpiration);
78+
}
79+
}

branches/spanner-gapic-migration/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.google.cloud.spanner.SpannerImpl.MultiUseReadOnlyTransaction;
2424
import com.google.cloud.spanner.SpannerImpl.SessionImpl;
2525
import com.google.cloud.spanner.spi.v1.SpannerRpc;
26-
import com.google.cloud.spanner.spi.v1.GapicSpannerRpc;
2726
import com.google.common.base.Preconditions;
2827
import com.google.common.collect.ImmutableList;
2928
import com.google.protobuf.Struct;
@@ -69,7 +68,7 @@ private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransa
6968
super(
7069
checkNotNull(session),
7170
checkNotNull(bound),
72-
checkNotNull(spanner).getOptions().getGapicSpannerRpc(),
71+
checkNotNull(spanner).getOptions().getSpannerRpcV1(),
7372
spanner.getOptions().getPrefetchChunks());
7473
this.sessionName = session.getName();
7574
this.options = session.getOptions();
@@ -82,7 +81,7 @@ private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransa
8281
checkNotNull(session),
8382
checkNotNull(batchTransactionId).getTransactionId(),
8483
batchTransactionId.getTimestamp(),
85-
checkNotNull(spanner).getOptions().getGapicSpannerRpc(),
84+
checkNotNull(spanner).getOptions().getSpannerRpcV1(),
8685
spanner.getOptions().getPrefetchChunks());
8786
this.sessionName = session.getName();
8887
this.options = session.getOptions();

branches/spanner-gapic-migration/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Database.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
2020

21-
import com.google.api.gax.longrunning.OperationFuture;
2221
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
2322

2423
/**
@@ -52,7 +51,7 @@ public Database reload() throws SpannerException {
5251
* one. This must be unique within a database abd must be a valid identifier
5352
* [a-zA-Z][a-zA-Z0-9_]*.
5453
*/
55-
public OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDdl(
54+
public Operation<Void, UpdateDatabaseDdlMetadata> updateDdl(
5655
Iterable<String> statements, String operationId) throws SpannerException {
5756
return dbClient.updateDatabaseDdl(instance(), database(), statements, operationId);
5857
}

branches/spanner-gapic-migration/google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseAdminClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.cloud.spanner;
1818

19-
import com.google.api.gax.longrunning.OperationFuture;
2019
import com.google.api.gax.paging.Page;
2120
import com.google.cloud.spanner.Options.ListOption;
2221
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
@@ -59,7 +58,7 @@ public interface DatabaseAdminClient {
5958
* @param statements DDL statements to run while creating the database, for example {@code CREATE
6059
* TABLE MyTable ( ... )}. This should not include {@code CREATE DATABASE} statement.
6160
*/
62-
OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
61+
Operation<Database, CreateDatabaseMetadata> createDatabase(
6362
String instanceId, String databaseId, Iterable<String> statements) throws SpannerException;
6463

6564
/**
@@ -98,7 +97,7 @@ OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
9897
* one. This must be unique within a database abd must be a valid identifier
9998
* [a-zA-Z][a-zA-Z0-9_]*.
10099
*/
101-
OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
100+
Operation<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
102101
String instanceId,
103102
String databaseId,
104103
Iterable<String> statements,

branches/spanner-gapic-migration/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Instance.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.cloud.spanner;
1818

19-
import com.google.api.gax.longrunning.OperationFuture;
2019
import com.google.api.gax.paging.Page;
2120
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
2221
import com.google.spanner.admin.instance.v1.UpdateInstanceMetadata;
@@ -105,7 +104,7 @@ public void delete() {
105104
instanceClient.deleteInstance(instanceId());
106105
}
107106

108-
public OperationFuture<Instance, UpdateInstanceMetadata> update(
107+
public Operation<Instance, UpdateInstanceMetadata> update(
109108
InstanceInfo.InstanceField... fieldsToUpdate) {
110109
return instanceClient.updateInstance(this, fieldsToUpdate);
111110
}
@@ -126,7 +125,7 @@ public Database getDatabase(String databaseId) {
126125
* @param statements DDL statements to run while creating the database, for example {@code CREATE
127126
* TABLE MyTable ( ... )}. This should not include {@code CREATE DATABASE} statement.
128127
*/
129-
public OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
128+
public Operation<Database, CreateDatabaseMetadata> createDatabase(
130129
String databaseId, Iterable<String> statements) throws SpannerException {
131130
return dbClient.createDatabase(instanceId(), databaseId, statements);
132131
}

0 commit comments

Comments
 (0)