From 9d77f9e05bccedb6b4dee2f988db7b4e2d266dd4 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Wed, 13 Sep 2023 10:51:04 -0400 Subject: [PATCH 1/3] fix: deprecate `databaseId` on datastore-v1-proto-client DatastoreOptions --- .../datastore/v1/client/DatastoreOptions.java | 33 +++++++++++++++++-- .../v1/client/DatastoreClientTest.java | 2 -- .../datastore/spi/v1/HttpDatastoreRpc.java | 1 - 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/datastore-v1-proto-client/src/main/java/com/google/datastore/v1/client/DatastoreOptions.java b/datastore-v1-proto-client/src/main/java/com/google/datastore/v1/client/DatastoreOptions.java index eefd629ec..687410d78 100644 --- a/datastore-v1-proto-client/src/main/java/com/google/datastore/v1/client/DatastoreOptions.java +++ b/datastore-v1-proto-client/src/main/java/com/google/datastore/v1/client/DatastoreOptions.java @@ -41,7 +41,9 @@ */ public class DatastoreOptions { private final String projectId; - private final String databaseId; + + @Deprecated private final String databaseId; + private final String projectEndpoint; private final String host; private final String localHost; @@ -75,7 +77,9 @@ public static class Builder { "Can set at most one of project endpoint, host, and local host."; private String projectId; - private String databaseId; + + @Deprecated private String databaseId; + private String projectEndpoint; private String host; private String localHost; @@ -107,8 +111,19 @@ public Builder projectId(String projectId) { return this; } - /** Sets the database ID used to access Cloud Datastore. */ + /** + * This field is ignored and will be removed in a future release. Please set the database id on + * the request itself. For example: + * + *
{@code
+     * CommitRequest.newBuilder()
+     *     .setDatabaseId("my-database-id")
+     *     ....
+     *     .build();
+     * }
+ */ @BetaApi + @Deprecated public Builder databaseId(String databaseId) { this.databaseId = databaseId; return this; @@ -188,7 +203,19 @@ public String getProjectId() { return projectId; } + /** + * This field is ignored and will be removed in a future release. Please set the database id on + * the request itself. For example: + * + *
{@code
+   * CommitRequest.newBuilder()
+   *     .setDatabaseId("my-database-id")
+   *     ....
+   *     .build();
+   * }
+ */ @BetaApi + @Deprecated public String getDatabaseId() { return databaseId; } diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java index 3eb7a66de..b8a7bd935 100644 --- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java +++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java @@ -220,11 +220,9 @@ public void setDatabaseId() { DatastoreOptions options = new DatastoreOptions.Builder() .projectId(PROJECT_ID) - .databaseId("test-db") .localHost("localhost:8080") .build(); assertThat(options.getProjectId()).isEqualTo(PROJECT_ID); - assertThat(options.getDatabaseId()).isEqualTo("test-db"); } @Test diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java index cfbbaa7df..fd3cdc658 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java @@ -55,7 +55,6 @@ public HttpDatastoreRpc(DatastoreOptions options) { com.google.datastore.v1.client.DatastoreOptions.Builder clientBuilder = new com.google.datastore.v1.client.DatastoreOptions.Builder() .projectId(options.getProjectId()) - .databaseId(options.getDatabaseId()) .initializer(getHttpRequestInitializer(options, httpTransportOptions)) .transport(transport); String normalizedHost = options.getHost() != null ? options.getHost().toLowerCase() : ""; From da39c4f3d331291d1da1844ad1ed80cf97641013 Mon Sep 17 00:00:00 2001 From: kolea2 Date: Wed, 13 Sep 2023 11:24:19 -0400 Subject: [PATCH 2/3] lint --- .../com/google/datastore/v1/client/DatastoreClientTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java index b8a7bd935..f6ce21410 100644 --- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java +++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java @@ -218,10 +218,7 @@ public void create_LocalHost() { @Test public void setDatabaseId() { DatastoreOptions options = - new DatastoreOptions.Builder() - .projectId(PROJECT_ID) - .localHost("localhost:8080") - .build(); + new DatastoreOptions.Builder().projectId(PROJECT_ID).localHost("localhost:8080").build(); assertThat(options.getProjectId()).isEqualTo(PROJECT_ID); } From 21350126082637c422ae18dd1c4dbb1d7d32ea0a Mon Sep 17 00:00:00 2001 From: kolea2 Date: Thu, 14 Sep 2023 10:45:14 -0400 Subject: [PATCH 3/3] review feedback --- .../google/datastore/v1/client/DatastoreClientTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java index f6ce21410..3fd82ddca 100644 --- a/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java +++ b/datastore-v1-proto-client/src/test/java/com/google/datastore/v1/client/DatastoreClientTest.java @@ -216,10 +216,16 @@ public void create_LocalHost() { } @Test + // TODO: remove this test once deprecated `databaseId` is removed public void setDatabaseId() { DatastoreOptions options = - new DatastoreOptions.Builder().projectId(PROJECT_ID).localHost("localhost:8080").build(); + new DatastoreOptions.Builder() + .projectId(PROJECT_ID) + .databaseId("test-db") + .localHost("localhost:8080") + .build(); assertThat(options.getProjectId()).isEqualTo(PROJECT_ID); + assertThat(options.getDatabaseId()).isEqualTo("test-db"); } @Test