From 82f356ae5505d8931b3ea633e1fa85381c55dac9 Mon Sep 17 00:00:00 2001 From: Patrick Costello Date: Tue, 24 May 2022 23:09:04 -0700 Subject: [PATCH] feat: Expose gapic & grpc clients for Datastore V1. This is generated via the owl tool. Manual changes were made to the grpc pom file, which failed to autogenerate and pom files changes for new dependency on grpc. --- google-cloud-datastore-bom/pom.xml | 5 + google-cloud-datastore/pom.xml | 23 + .../cloud/datastore/v1/DatastoreClient.java | 785 ++++++++++++ .../cloud/datastore/v1/DatastoreSettings.java | 258 ++++ .../cloud/datastore/v1/gapic_metadata.json | 39 + .../cloud/datastore/v1/package-info.java | 44 + .../datastore/v1/stub/DatastoreStub.java | 77 ++ .../v1/stub/DatastoreStubSettings.java | 441 +++++++ .../v1/stub/GrpcDatastoreCallableFactory.java | 113 ++ .../datastore/v1/stub/GrpcDatastoreStub.java | 342 ++++++ .../datastore/v1/DatastoreClientTest.java | 448 +++++++ .../cloud/datastore/v1/MockDatastore.java | 59 + .../cloud/datastore/v1/MockDatastoreImpl.java | 217 ++++ .../clirr-ignored-differences.xml | 10 + grpc-google-cloud-datastore-v1/pom.xml | 89 ++ .../google/datastore/v1/DatastoreGrpc.java | 1053 +++++++++++++++++ pom.xml | 6 + .../java/com/google/datastore/v1/Key.java | 63 + .../proto/google/datastore/v1/entity.proto | 11 + synth.metadata | 1 + versions.txt | 1 + 21 files changed, 4085 insertions(+) create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreClient.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreSettings.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/gapic_metadata.json create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/package-info.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStub.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStubSettings.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreCallableFactory.java create mode 100644 google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreStub.java create mode 100644 google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java create mode 100644 google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastore.java create mode 100644 google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastoreImpl.java create mode 100644 grpc-google-cloud-datastore-v1/clirr-ignored-differences.xml create mode 100644 grpc-google-cloud-datastore-v1/pom.xml create mode 100644 grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java diff --git a/google-cloud-datastore-bom/pom.xml b/google-cloud-datastore-bom/pom.xml index a23405e48..3ac9b398a 100644 --- a/google-cloud-datastore-bom/pom.xml +++ b/google-cloud-datastore-bom/pom.xml @@ -59,6 +59,11 @@ proto-google-cloud-datastore-v1 0.96.2-SNAPSHOT + + com.google.api.grpc + grpc-google-cloud-datastore-v1 + 2.5.1-SNAPSHOT + diff --git a/google-cloud-datastore/pom.xml b/google-cloud-datastore/pom.xml index 9635f1c75..788374ecb 100644 --- a/google-cloud-datastore/pom.xml +++ b/google-cloud-datastore/pom.xml @@ -26,6 +26,10 @@ com.google.api.grpc proto-google-cloud-datastore-v1 + + com.google.api.grpc + grpc-google-cloud-datastore-v1 + com.google.cloud.datastore datastore-v1-proto-client @@ -34,6 +38,14 @@ io.grpc grpc-api + + io.grpc + grpc-protobuf + + + io.grpc + grpc-stub + com.google.api api-common @@ -50,6 +62,10 @@ com.google.api gax + + com.google.api + gax-grpc + com.google.guava guava @@ -100,6 +116,13 @@ easymock test + + + com.google.api + gax-grpc + testlib + test + diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreClient.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreClient.java new file mode 100644 index 000000000..adf1a3563 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreClient.java @@ -0,0 +1,785 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.cloud.datastore.v1.stub.DatastoreStub; +import com.google.cloud.datastore.v1.stub.DatastoreStubSettings; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.Key; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.Mutation; +import com.google.datastore.v1.ReadOptions; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.protobuf.ByteString; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Service Description: Each RPC normalizes the partition IDs of the keys in its input entities, and + * always returns entities with keys with normalized partition IDs. This applies to all keys and + * entities, including those in values, except keys with both an empty path and an empty or unset + * partition ID. Normalization of input keys sets the project ID (if not already set) to the project + * ID from the request. + * + *

This class provides the ability to make remote calls to the backing service through method + * calls that map to API methods. Sample code to get started: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+ *   String projectId = "projectId-894832108";
+ *   ReadOptions readOptions = ReadOptions.newBuilder().build();
+ *   List keys = new ArrayList<>();
+ *   LookupResponse response = datastoreClient.lookup(projectId, readOptions, keys);
+ * }
+ * }
+ * + *

Note: close() needs to be called on the DatastoreClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *

The surface of this class includes several types of Java methods for each of the API's + * methods: + * + *

    + *
  1. A "flattened" method. With this type of method, the fields of the request type have been + * converted into function parameters. It may be the case that not all fields are available as + * parameters, and not every API method will have a flattened method entry point. + *
  2. A "request object" method. This type of method only takes one parameter, a request object, + * which must be constructed before the call. Not every API method will have a request object + * method. + *
  3. A "callable" method. This type of method takes no parameters and returns an immutable API + * callable object, which can be used to initiate calls to the service. + *
+ * + *

See the individual methods for example code. + * + *

Many parameters require resource names to be formatted in a particular way. To assist with + * these names, this class includes a format method for each type of name, and additionally a parse + * method to extract the individual identifiers contained within names that are returned. + * + *

This class can be customized by passing in a custom instance of DatastoreSettings to create(). + * For example: + * + *

To customize credentials: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * DatastoreSettings datastoreSettings =
+ *     DatastoreSettings.newBuilder()
+ *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ *         .build();
+ * DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
+ * }
+ * + *

To customize the endpoint: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * DatastoreSettings datastoreSettings =
+ *     DatastoreSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
+ * }
+ * + *

Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@Generated("by gapic-generator-java") +public class DatastoreClient implements BackgroundResource { + private final DatastoreSettings settings; + private final DatastoreStub stub; + + /** Constructs an instance of DatastoreClient with default settings. */ + public static final DatastoreClient create() throws IOException { + return create(DatastoreSettings.newBuilder().build()); + } + + /** + * Constructs an instance of DatastoreClient, using the given settings. The channels are created + * based on the settings passed in, or defaults for any settings that are not set. + */ + public static final DatastoreClient create(DatastoreSettings settings) throws IOException { + return new DatastoreClient(settings); + } + + /** + * Constructs an instance of DatastoreClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(DatastoreSettings). + */ + public static final DatastoreClient create(DatastoreStub stub) { + return new DatastoreClient(stub); + } + + /** + * Constructs an instance of DatastoreClient, using the given settings. This is protected so that + * it is easy to make a subclass, but otherwise, the static factory methods should be preferred. + */ + protected DatastoreClient(DatastoreSettings settings) throws IOException { + this.settings = settings; + this.stub = ((DatastoreStubSettings) settings.getStubSettings()).createStub(); + } + + protected DatastoreClient(DatastoreStub stub) { + this.settings = null; + this.stub = stub; + } + + public final DatastoreSettings getSettings() { + return settings; + } + + public DatastoreStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Looks up entities by key. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   ReadOptions readOptions = ReadOptions.newBuilder().build();
+   *   List keys = new ArrayList<>();
+   *   LookupResponse response = datastoreClient.lookup(projectId, readOptions, keys);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param readOptions The options for this lookup request. + * @param keys Required. Keys of entities to look up. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LookupResponse lookup(String projectId, ReadOptions readOptions, List keys) { + LookupRequest request = + LookupRequest.newBuilder() + .setProjectId(projectId) + .setReadOptions(readOptions) + .addAllKeys(keys) + .build(); + return lookup(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Looks up entities by key. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   LookupRequest request =
+   *       LookupRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   LookupResponse response = datastoreClient.lookup(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final LookupResponse lookup(LookupRequest request) { + return lookupCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Looks up entities by key. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   LookupRequest request =
+   *       LookupRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   ApiFuture future = datastoreClient.lookupCallable().futureCall(request);
+   *   // Do something.
+   *   LookupResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable lookupCallable() { + return stub.lookupCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Queries for entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunQueryRequest request =
+   *       RunQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setPartitionId(PartitionId.newBuilder().build())
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .build();
+   *   RunQueryResponse response = datastoreClient.runQuery(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final RunQueryResponse runQuery(RunQueryRequest request) { + return runQueryCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Queries for entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunQueryRequest request =
+   *       RunQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setPartitionId(PartitionId.newBuilder().build())
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future = datastoreClient.runQueryCallable().futureCall(request);
+   *   // Do something.
+   *   RunQueryResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable runQueryCallable() { + return stub.runQueryCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Begins a new transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   BeginTransactionResponse response = datastoreClient.beginTransaction(projectId);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BeginTransactionResponse beginTransaction(String projectId) { + BeginTransactionRequest request = + BeginTransactionRequest.newBuilder().setProjectId(projectId).build(); + return beginTransaction(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Begins a new transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   BeginTransactionRequest request =
+   *       BeginTransactionRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setTransactionOptions(TransactionOptions.newBuilder().build())
+   *           .build();
+   *   BeginTransactionResponse response = datastoreClient.beginTransaction(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final BeginTransactionResponse beginTransaction(BeginTransactionRequest request) { + return beginTransactionCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Begins a new transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   BeginTransactionRequest request =
+   *       BeginTransactionRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setTransactionOptions(TransactionOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       datastoreClient.beginTransactionCallable().futureCall(request);
+   *   // Do something.
+   *   BeginTransactionResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + beginTransactionCallable() { + return stub.beginTransactionCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Commits a transaction, optionally creating, deleting or modifying some entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0);
+   *   List mutations = new ArrayList<>();
+   *   CommitResponse response = datastoreClient.commit(projectId, mode, mutations);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param mode The type of commit to perform. Defaults to `TRANSACTIONAL`. + * @param mutations The mutations to perform. + *

When mode is `TRANSACTIONAL`, mutations affecting a single entity are applied in order. + * The following sequences of mutations affecting a single entity are not permitted in a + * single `Commit` request: + *

- `insert` followed by `insert` - `update` followed by `insert` - `upsert` followed by + * `insert` - `delete` followed by `update` + *

When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single entity. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final CommitResponse commit( + String projectId, CommitRequest.Mode mode, List mutations) { + CommitRequest request = + CommitRequest.newBuilder() + .setProjectId(projectId) + .setMode(mode) + .addAllMutations(mutations) + .build(); + return commit(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Commits a transaction, optionally creating, deleting or modifying some entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0);
+   *   ByteString transaction = ByteString.EMPTY;
+   *   List mutations = new ArrayList<>();
+   *   CommitResponse response = datastoreClient.commit(projectId, mode, transaction, mutations);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param mode The type of commit to perform. Defaults to `TRANSACTIONAL`. + * @param transaction The identifier of the transaction associated with the commit. A transaction + * identifier is returned by a call to + * [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]. + * @param mutations The mutations to perform. + *

When mode is `TRANSACTIONAL`, mutations affecting a single entity are applied in order. + * The following sequences of mutations affecting a single entity are not permitted in a + * single `Commit` request: + *

- `insert` followed by `insert` - `update` followed by `insert` - `upsert` followed by + * `insert` - `delete` followed by `update` + *

When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single entity. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final CommitResponse commit( + String projectId, CommitRequest.Mode mode, ByteString transaction, List mutations) { + CommitRequest request = + CommitRequest.newBuilder() + .setProjectId(projectId) + .setMode(mode) + .setTransaction(transaction) + .addAllMutations(mutations) + .build(); + return commit(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Commits a transaction, optionally creating, deleting or modifying some entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   CommitRequest request =
+   *       CommitRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .addAllMutations(new ArrayList())
+   *           .build();
+   *   CommitResponse response = datastoreClient.commit(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final CommitResponse commit(CommitRequest request) { + return commitCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Commits a transaction, optionally creating, deleting or modifying some entities. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   CommitRequest request =
+   *       CommitRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .addAllMutations(new ArrayList())
+   *           .build();
+   *   ApiFuture future = datastoreClient.commitCallable().futureCall(request);
+   *   // Do something.
+   *   CommitResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable commitCallable() { + return stub.commitCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Rolls back a transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   ByteString transaction = ByteString.EMPTY;
+   *   RollbackResponse response = datastoreClient.rollback(projectId, transaction);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param transaction Required. The transaction identifier, returned by a call to + * [Datastore.BeginTransaction][google.datastore.v1.Datastore.BeginTransaction]. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final RollbackResponse rollback(String projectId, ByteString transaction) { + RollbackRequest request = + RollbackRequest.newBuilder().setProjectId(projectId).setTransaction(transaction).build(); + return rollback(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Rolls back a transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RollbackRequest request =
+   *       RollbackRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setTransaction(ByteString.EMPTY)
+   *           .build();
+   *   RollbackResponse response = datastoreClient.rollback(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final RollbackResponse rollback(RollbackRequest request) { + return rollbackCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Rolls back a transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RollbackRequest request =
+   *       RollbackRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setTransaction(ByteString.EMPTY)
+   *           .build();
+   *   ApiFuture future = datastoreClient.rollbackCallable().futureCall(request);
+   *   // Do something.
+   *   RollbackResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable rollbackCallable() { + return stub.rollbackCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Allocates IDs for the given keys, which is useful for referencing an entity before it is + * inserted. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   List keys = new ArrayList<>();
+   *   AllocateIdsResponse response = datastoreClient.allocateIds(projectId, keys);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param keys Required. A list of keys with incomplete key paths for which to allocate IDs. No + * key may be reserved/read-only. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AllocateIdsResponse allocateIds(String projectId, List keys) { + AllocateIdsRequest request = + AllocateIdsRequest.newBuilder().setProjectId(projectId).addAllKeys(keys).build(); + return allocateIds(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Allocates IDs for the given keys, which is useful for referencing an entity before it is + * inserted. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   AllocateIdsRequest request =
+   *       AllocateIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   AllocateIdsResponse response = datastoreClient.allocateIds(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final AllocateIdsResponse allocateIds(AllocateIdsRequest request) { + return allocateIdsCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Allocates IDs for the given keys, which is useful for referencing an entity before it is + * inserted. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   AllocateIdsRequest request =
+   *       AllocateIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       datastoreClient.allocateIdsCallable().futureCall(request);
+   *   // Do something.
+   *   AllocateIdsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable allocateIdsCallable() { + return stub.allocateIdsCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   String projectId = "projectId-894832108";
+   *   List keys = new ArrayList<>();
+   *   ReserveIdsResponse response = datastoreClient.reserveIds(projectId, keys);
+   * }
+   * }
+ * + * @param projectId Required. The ID of the project against which to make the request. + * @param keys Required. A list of keys with complete key paths whose numeric IDs should not be + * auto-allocated. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ReserveIdsResponse reserveIds(String projectId, List keys) { + ReserveIdsRequest request = + ReserveIdsRequest.newBuilder().setProjectId(projectId).addAllKeys(keys).build(); + return reserveIds(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   ReserveIdsRequest request =
+   *       ReserveIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   ReserveIdsResponse response = datastoreClient.reserveIds(request);
+   * }
+   * }
+ * + * @param request The request object containing all of the parameters for the API call. + * @throws com.google.api.gax.rpc.ApiException if the remote call fails + */ + public final ReserveIdsResponse reserveIds(ReserveIdsRequest request) { + return reserveIdsCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Prevents the supplied keys' IDs from being auto-allocated by Cloud Datastore. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated for illustrative purposes only.
+   * // It may require modifications to work in your environment.
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   ReserveIdsRequest request =
+   *       ReserveIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .addAllKeys(new ArrayList())
+   *           .build();
+   *   ApiFuture future =
+   *       datastoreClient.reserveIdsCallable().futureCall(request);
+   *   // Do something.
+   *   ReserveIdsResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable reserveIdsCallable() { + return stub.reserveIdsCallable(); + } + + @Override + public final void close() { + stub.close(); + } + + @Override + public void shutdown() { + stub.shutdown(); + } + + @Override + public boolean isShutdown() { + return stub.isShutdown(); + } + + @Override + public boolean isTerminated() { + return stub.isTerminated(); + } + + @Override + public void shutdownNow() { + stub.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return stub.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreSettings.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreSettings.java new file mode 100644 index 000000000..df96f8893 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreSettings.java @@ -0,0 +1,258 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.datastore.v1.stub.DatastoreStubSettings; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link DatastoreClient}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (datastore.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of lookup to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * DatastoreSettings.Builder datastoreSettingsBuilder = DatastoreSettings.newBuilder();
+ * datastoreSettingsBuilder
+ *     .lookupSettings()
+ *     .setRetrySettings(
+ *         datastoreSettingsBuilder
+ *             .lookupSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * DatastoreSettings datastoreSettings = datastoreSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class DatastoreSettings extends ClientSettings { + + /** Returns the object with the settings used for calls to lookup. */ + public UnaryCallSettings lookupSettings() { + return ((DatastoreStubSettings) getStubSettings()).lookupSettings(); + } + + /** Returns the object with the settings used for calls to runQuery. */ + public UnaryCallSettings runQuerySettings() { + return ((DatastoreStubSettings) getStubSettings()).runQuerySettings(); + } + + /** Returns the object with the settings used for calls to beginTransaction. */ + public UnaryCallSettings + beginTransactionSettings() { + return ((DatastoreStubSettings) getStubSettings()).beginTransactionSettings(); + } + + /** Returns the object with the settings used for calls to commit. */ + public UnaryCallSettings commitSettings() { + return ((DatastoreStubSettings) getStubSettings()).commitSettings(); + } + + /** Returns the object with the settings used for calls to rollback. */ + public UnaryCallSettings rollbackSettings() { + return ((DatastoreStubSettings) getStubSettings()).rollbackSettings(); + } + + /** Returns the object with the settings used for calls to allocateIds. */ + public UnaryCallSettings allocateIdsSettings() { + return ((DatastoreStubSettings) getStubSettings()).allocateIdsSettings(); + } + + /** Returns the object with the settings used for calls to reserveIds. */ + public UnaryCallSettings reserveIdsSettings() { + return ((DatastoreStubSettings) getStubSettings()).reserveIdsSettings(); + } + + public static final DatastoreSettings create(DatastoreStubSettings stub) throws IOException { + return new DatastoreSettings.Builder(stub.toBuilder()).build(); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return DatastoreStubSettings.defaultExecutorProviderBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return DatastoreStubSettings.getDefaultEndpoint(); + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DatastoreStubSettings.getDefaultServiceScopes(); + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return DatastoreStubSettings.defaultCredentialsProviderBuilder(); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return DatastoreStubSettings.defaultGrpcTransportProviderBuilder(); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return DatastoreStubSettings.defaultTransportChannelProvider(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return DatastoreStubSettings.defaultApiClientHeaderProviderBuilder(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected DatastoreSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + } + + /** Builder for DatastoreSettings. */ + public static class Builder extends ClientSettings.Builder { + + protected Builder() throws IOException { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(DatastoreStubSettings.newBuilder(clientContext)); + } + + protected Builder(DatastoreSettings settings) { + super(settings.getStubSettings().toBuilder()); + } + + protected Builder(DatastoreStubSettings.Builder stubSettings) { + super(stubSettings); + } + + private static Builder createDefault() { + return new Builder(DatastoreStubSettings.newBuilder()); + } + + public DatastoreStubSettings.Builder getStubSettingsBuilder() { + return ((DatastoreStubSettings.Builder) getStubSettings()); + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods( + getStubSettingsBuilder().unaryMethodSettingsBuilders(), settingsUpdater); + return this; + } + + /** Returns the builder for the settings used for calls to lookup. */ + public UnaryCallSettings.Builder lookupSettings() { + return getStubSettingsBuilder().lookupSettings(); + } + + /** Returns the builder for the settings used for calls to runQuery. */ + public UnaryCallSettings.Builder runQuerySettings() { + return getStubSettingsBuilder().runQuerySettings(); + } + + /** Returns the builder for the settings used for calls to beginTransaction. */ + public UnaryCallSettings.Builder + beginTransactionSettings() { + return getStubSettingsBuilder().beginTransactionSettings(); + } + + /** Returns the builder for the settings used for calls to commit. */ + public UnaryCallSettings.Builder commitSettings() { + return getStubSettingsBuilder().commitSettings(); + } + + /** Returns the builder for the settings used for calls to rollback. */ + public UnaryCallSettings.Builder rollbackSettings() { + return getStubSettingsBuilder().rollbackSettings(); + } + + /** Returns the builder for the settings used for calls to allocateIds. */ + public UnaryCallSettings.Builder + allocateIdsSettings() { + return getStubSettingsBuilder().allocateIdsSettings(); + } + + /** Returns the builder for the settings used for calls to reserveIds. */ + public UnaryCallSettings.Builder reserveIdsSettings() { + return getStubSettingsBuilder().reserveIdsSettings(); + } + + @Override + public DatastoreSettings build() throws IOException { + return new DatastoreSettings(this); + } + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/gapic_metadata.json b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/gapic_metadata.json new file mode 100644 index 000000000..d6253d5d1 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/gapic_metadata.json @@ -0,0 +1,39 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "java", + "protoPackage": "google.datastore.v1", + "libraryPackage": "com.google.cloud.datastore.v1", + "services": { + "Datastore": { + "clients": { + "grpc": { + "libraryClient": "DatastoreClient", + "rpcs": { + "AllocateIds": { + "methods": ["allocateIds", "allocateIds", "allocateIdsCallable"] + }, + "BeginTransaction": { + "methods": ["beginTransaction", "beginTransaction", "beginTransactionCallable"] + }, + "Commit": { + "methods": ["commit", "commit", "commit", "commitCallable"] + }, + "Lookup": { + "methods": ["lookup", "lookup", "lookupCallable"] + }, + "ReserveIds": { + "methods": ["reserveIds", "reserveIds", "reserveIdsCallable"] + }, + "Rollback": { + "methods": ["rollback", "rollback", "rollbackCallable"] + }, + "RunQuery": { + "methods": ["runQuery", "runQueryCallable"] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/package-info.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/package-info.java new file mode 100644 index 000000000..aca2577c0 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/package-info.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The interfaces provided are listed below, along with usage samples. + * + *

======================= DatastoreClient ======================= + * + *

Service Description: Each RPC normalizes the partition IDs of the keys in its input entities, + * and always returns entities with keys with normalized partition IDs. This applies to all keys and + * entities, including those in values, except keys with both an empty path and an empty or unset + * partition ID. Normalization of input keys sets the project ID (if not already set) to the project + * ID from the request. + * + *

Sample for DatastoreClient: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+ *   String projectId = "projectId-894832108";
+ *   ReadOptions readOptions = ReadOptions.newBuilder().build();
+ *   List keys = new ArrayList<>();
+ *   LookupResponse response = datastoreClient.lookup(projectId, readOptions, keys);
+ * }
+ * }
+ */ +@Generated("by gapic-generator-java") +package com.google.cloud.datastore.v1; + +import javax.annotation.Generated; diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStub.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStub.java new file mode 100644 index 000000000..45df467de --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStub.java @@ -0,0 +1,77 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Base stub class for the Datastore service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +public abstract class DatastoreStub implements BackgroundResource { + + public UnaryCallable lookupCallable() { + throw new UnsupportedOperationException("Not implemented: lookupCallable()"); + } + + public UnaryCallable runQueryCallable() { + throw new UnsupportedOperationException("Not implemented: runQueryCallable()"); + } + + public UnaryCallable + beginTransactionCallable() { + throw new UnsupportedOperationException("Not implemented: beginTransactionCallable()"); + } + + public UnaryCallable commitCallable() { + throw new UnsupportedOperationException("Not implemented: commitCallable()"); + } + + public UnaryCallable rollbackCallable() { + throw new UnsupportedOperationException("Not implemented: rollbackCallable()"); + } + + public UnaryCallable allocateIdsCallable() { + throw new UnsupportedOperationException("Not implemented: allocateIdsCallable()"); + } + + public UnaryCallable reserveIdsCallable() { + throw new UnsupportedOperationException("Not implemented: reserveIdsCallable()"); + } + + @Override + public abstract void close(); +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStubSettings.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStubSettings.java new file mode 100644 index 000000000..13a1f390a --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStubSettings.java @@ -0,0 +1,441 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1.stub; + +import com.google.api.core.ApiFunction; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.core.GoogleCredentialsProvider; +import com.google.api.gax.core.InstantiatingExecutorProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.StubSettings; +import com.google.api.gax.rpc.TransportChannelProvider; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import java.io.IOException; +import java.util.List; +import javax.annotation.Generated; +import org.threeten.bp.Duration; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * Settings class to configure an instance of {@link DatastoreStub}. + * + *

The default instance has everything set to sensible defaults: + * + *

    + *
  • The default service address (datastore.googleapis.com) and default port (443) are used. + *
  • Credentials are acquired automatically through Application Default Credentials. + *
  • Retries are configured for idempotent methods but not for non-idempotent methods. + *
+ * + *

The builder of this class is recursive, so contained classes are themselves builders. When + * build() is called, the tree of builders is called to create the complete settings object. + * + *

For example, to set the total timeout of lookup to 30 seconds: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * DatastoreStubSettings.Builder datastoreSettingsBuilder = DatastoreStubSettings.newBuilder();
+ * datastoreSettingsBuilder
+ *     .lookupSettings()
+ *     .setRetrySettings(
+ *         datastoreSettingsBuilder
+ *             .lookupSettings()
+ *             .getRetrySettings()
+ *             .toBuilder()
+ *             .setTotalTimeout(Duration.ofSeconds(30))
+ *             .build());
+ * DatastoreStubSettings datastoreSettings = datastoreSettingsBuilder.build();
+ * }
+ */ +@Generated("by gapic-generator-java") +public class DatastoreStubSettings extends StubSettings { + /** The default scopes of the service. */ + private static final ImmutableList DEFAULT_SERVICE_SCOPES = + ImmutableList.builder() + .add("https://www.googleapis.com/auth/cloud-platform") + .add("https://www.googleapis.com/auth/datastore") + .build(); + + private final UnaryCallSettings lookupSettings; + private final UnaryCallSettings runQuerySettings; + private final UnaryCallSettings + beginTransactionSettings; + private final UnaryCallSettings commitSettings; + private final UnaryCallSettings rollbackSettings; + private final UnaryCallSettings allocateIdsSettings; + private final UnaryCallSettings reserveIdsSettings; + + /** Returns the object with the settings used for calls to lookup. */ + public UnaryCallSettings lookupSettings() { + return lookupSettings; + } + + /** Returns the object with the settings used for calls to runQuery. */ + public UnaryCallSettings runQuerySettings() { + return runQuerySettings; + } + + /** Returns the object with the settings used for calls to beginTransaction. */ + public UnaryCallSettings + beginTransactionSettings() { + return beginTransactionSettings; + } + + /** Returns the object with the settings used for calls to commit. */ + public UnaryCallSettings commitSettings() { + return commitSettings; + } + + /** Returns the object with the settings used for calls to rollback. */ + public UnaryCallSettings rollbackSettings() { + return rollbackSettings; + } + + /** Returns the object with the settings used for calls to allocateIds. */ + public UnaryCallSettings allocateIdsSettings() { + return allocateIdsSettings; + } + + /** Returns the object with the settings used for calls to reserveIds. */ + public UnaryCallSettings reserveIdsSettings() { + return reserveIdsSettings; + } + + public DatastoreStub createStub() throws IOException { + if (getTransportChannelProvider() + .getTransportName() + .equals(GrpcTransportChannel.getGrpcTransportName())) { + return GrpcDatastoreStub.create(this); + } + throw new UnsupportedOperationException( + String.format( + "Transport not supported: %s", getTransportChannelProvider().getTransportName())); + } + + /** Returns a builder for the default ExecutorProvider for this service. */ + public static InstantiatingExecutorProvider.Builder defaultExecutorProviderBuilder() { + return InstantiatingExecutorProvider.newBuilder(); + } + + /** Returns the default service endpoint. */ + public static String getDefaultEndpoint() { + return "datastore.googleapis.com:443"; + } + + /** Returns the default mTLS service endpoint. */ + public static String getDefaultMtlsEndpoint() { + return "datastore.mtls.googleapis.com:443"; + } + + /** Returns the default service scopes. */ + public static List getDefaultServiceScopes() { + return DEFAULT_SERVICE_SCOPES; + } + + /** Returns a builder for the default credentials for this service. */ + public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilder() { + return GoogleCredentialsProvider.newBuilder() + .setScopesToApply(DEFAULT_SERVICE_SCOPES) + .setUseJwtAccessWithScope(true); + } + + /** Returns a builder for the default ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + public static TransportChannelProvider defaultTransportChannelProvider() { + return defaultGrpcTransportProviderBuilder().build(); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(DatastoreStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new builder for this class. */ + public static Builder newBuilder(ClientContext clientContext) { + return new Builder(clientContext); + } + + /** Returns a builder containing all the values of this settings class. */ + public Builder toBuilder() { + return new Builder(this); + } + + protected DatastoreStubSettings(Builder settingsBuilder) throws IOException { + super(settingsBuilder); + + lookupSettings = settingsBuilder.lookupSettings().build(); + runQuerySettings = settingsBuilder.runQuerySettings().build(); + beginTransactionSettings = settingsBuilder.beginTransactionSettings().build(); + commitSettings = settingsBuilder.commitSettings().build(); + rollbackSettings = settingsBuilder.rollbackSettings().build(); + allocateIdsSettings = settingsBuilder.allocateIdsSettings().build(); + reserveIdsSettings = settingsBuilder.reserveIdsSettings().build(); + } + + /** Builder for DatastoreStubSettings. */ + public static class Builder extends StubSettings.Builder { + private final ImmutableList> unaryMethodSettingsBuilders; + private final UnaryCallSettings.Builder lookupSettings; + private final UnaryCallSettings.Builder runQuerySettings; + private final UnaryCallSettings.Builder + beginTransactionSettings; + private final UnaryCallSettings.Builder commitSettings; + private final UnaryCallSettings.Builder rollbackSettings; + private final UnaryCallSettings.Builder + allocateIdsSettings; + private final UnaryCallSettings.Builder + reserveIdsSettings; + private static final ImmutableMap> + RETRYABLE_CODE_DEFINITIONS; + + static { + ImmutableMap.Builder> definitions = + ImmutableMap.builder(); + definitions.put( + "retry_policy_0_codes", + ImmutableSet.copyOf( + Lists.newArrayList( + StatusCode.Code.UNAVAILABLE, StatusCode.Code.DEADLINE_EXCEEDED))); + definitions.put( + "no_retry_1_codes", ImmutableSet.copyOf(Lists.newArrayList())); + RETRYABLE_CODE_DEFINITIONS = definitions.build(); + } + + private static final ImmutableMap RETRY_PARAM_DEFINITIONS; + + static { + ImmutableMap.Builder definitions = ImmutableMap.builder(); + RetrySettings settings = null; + settings = + RetrySettings.newBuilder() + .setInitialRetryDelay(Duration.ofMillis(100L)) + .setRetryDelayMultiplier(1.3) + .setMaxRetryDelay(Duration.ofMillis(60000L)) + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(60000L)) + .build(); + definitions.put("retry_policy_0_params", settings); + settings = + RetrySettings.newBuilder() + .setInitialRpcTimeout(Duration.ofMillis(60000L)) + .setRpcTimeoutMultiplier(1.0) + .setMaxRpcTimeout(Duration.ofMillis(60000L)) + .setTotalTimeout(Duration.ofMillis(60000L)) + .build(); + definitions.put("no_retry_1_params", settings); + RETRY_PARAM_DEFINITIONS = definitions.build(); + } + + protected Builder() { + this(((ClientContext) null)); + } + + protected Builder(ClientContext clientContext) { + super(clientContext); + + lookupSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + runQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + beginTransactionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + commitSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + rollbackSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + allocateIdsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + reserveIdsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + lookupSettings, + runQuerySettings, + beginTransactionSettings, + commitSettings, + rollbackSettings, + allocateIdsSettings, + reserveIdsSettings); + initDefaults(this); + } + + protected Builder(DatastoreStubSettings settings) { + super(settings); + + lookupSettings = settings.lookupSettings.toBuilder(); + runQuerySettings = settings.runQuerySettings.toBuilder(); + beginTransactionSettings = settings.beginTransactionSettings.toBuilder(); + commitSettings = settings.commitSettings.toBuilder(); + rollbackSettings = settings.rollbackSettings.toBuilder(); + allocateIdsSettings = settings.allocateIdsSettings.toBuilder(); + reserveIdsSettings = settings.reserveIdsSettings.toBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + lookupSettings, + runQuerySettings, + beginTransactionSettings, + commitSettings, + rollbackSettings, + allocateIdsSettings, + reserveIdsSettings); + } + + private static Builder createDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultTransportChannelProvider()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + + private static Builder initDefaults(Builder builder) { + builder + .lookupSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); + + builder + .runQuerySettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); + + builder + .beginTransactionSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .commitSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .rollbackSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .allocateIdsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")); + + builder + .reserveIdsSettings() + .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("retry_policy_0_codes")) + .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("retry_policy_0_params")); + + return builder; + } + + /** + * Applies the given settings updater function to all of the unary API methods in this service. + * + *

Note: This method does not support applying settings to streaming methods. + */ + public Builder applyToAllUnaryMethods( + ApiFunction, Void> settingsUpdater) { + super.applyToAllUnaryMethods(unaryMethodSettingsBuilders, settingsUpdater); + return this; + } + + public ImmutableList> unaryMethodSettingsBuilders() { + return unaryMethodSettingsBuilders; + } + + /** Returns the builder for the settings used for calls to lookup. */ + public UnaryCallSettings.Builder lookupSettings() { + return lookupSettings; + } + + /** Returns the builder for the settings used for calls to runQuery. */ + public UnaryCallSettings.Builder runQuerySettings() { + return runQuerySettings; + } + + /** Returns the builder for the settings used for calls to beginTransaction. */ + public UnaryCallSettings.Builder + beginTransactionSettings() { + return beginTransactionSettings; + } + + /** Returns the builder for the settings used for calls to commit. */ + public UnaryCallSettings.Builder commitSettings() { + return commitSettings; + } + + /** Returns the builder for the settings used for calls to rollback. */ + public UnaryCallSettings.Builder rollbackSettings() { + return rollbackSettings; + } + + /** Returns the builder for the settings used for calls to allocateIds. */ + public UnaryCallSettings.Builder + allocateIdsSettings() { + return allocateIdsSettings; + } + + /** Returns the builder for the settings used for calls to reserveIds. */ + public UnaryCallSettings.Builder reserveIdsSettings() { + return reserveIdsSettings; + } + + @Override + public DatastoreStubSettings build() throws IOException { + return new DatastoreStubSettings(this); + } + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreCallableFactory.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreCallableFactory.java new file mode 100644 index 000000000..1376c614f --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreCallableFactory.java @@ -0,0 +1,113 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1.stub; + +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcCallableFactory; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.BidiStreamingCallable; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.ClientStreamingCallable; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.StreamingCallSettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import com.google.longrunning.stub.OperationsStub; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC callable factory implementation for the Datastore service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +public class GrpcDatastoreCallableFactory implements GrpcStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + GrpcCallSettings grpcCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createUnaryCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + GrpcCallSettings grpcCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createPagedCallable(grpcCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + GrpcCallSettings grpcCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBatchingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + OperationCallable createOperationCallable( + GrpcCallSettings grpcCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + return GrpcCallableFactory.createOperationCallable( + grpcCallSettings, callSettings, clientContext, operationsStub); + } + + @Override + public + BidiStreamingCallable createBidiStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createBidiStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + GrpcCallSettings grpcCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createServerStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } + + @Override + public + ClientStreamingCallable createClientStreamingCallable( + GrpcCallSettings grpcCallSettings, + StreamingCallSettings callSettings, + ClientContext clientContext) { + return GrpcCallableFactory.createClientStreamingCallable( + grpcCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreStub.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreStub.java new file mode 100644 index 000000000..f81bfb109 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreStub.java @@ -0,0 +1,342 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1.stub; + +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.grpc.GrpcCallSettings; +import com.google.api.gax.grpc.GrpcStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.common.collect.ImmutableMap; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.longrunning.stub.GrpcOperationsStub; +import io.grpc.MethodDescriptor; +import io.grpc.protobuf.ProtoUtils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * gRPC stub implementation for the Datastore service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +public class GrpcDatastoreStub extends DatastoreStub { + private static final MethodDescriptor lookupMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/Lookup") + .setRequestMarshaller(ProtoUtils.marshaller(LookupRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(LookupResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + runQueryMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/RunQuery") + .setRequestMarshaller(ProtoUtils.marshaller(RunQueryRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RunQueryResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + beginTransactionMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/BeginTransaction") + .setRequestMarshaller( + ProtoUtils.marshaller(BeginTransactionRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(BeginTransactionResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor commitMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/Commit") + .setRequestMarshaller(ProtoUtils.marshaller(CommitRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(CommitResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + rollbackMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/Rollback") + .setRequestMarshaller(ProtoUtils.marshaller(RollbackRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(RollbackResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + allocateIdsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/AllocateIds") + .setRequestMarshaller(ProtoUtils.marshaller(AllocateIdsRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(AllocateIdsResponse.getDefaultInstance())) + .build(); + + private static final MethodDescriptor + reserveIdsMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/ReserveIds") + .setRequestMarshaller(ProtoUtils.marshaller(ReserveIdsRequest.getDefaultInstance())) + .setResponseMarshaller(ProtoUtils.marshaller(ReserveIdsResponse.getDefaultInstance())) + .build(); + + private final UnaryCallable lookupCallable; + private final UnaryCallable runQueryCallable; + private final UnaryCallable + beginTransactionCallable; + private final UnaryCallable commitCallable; + private final UnaryCallable rollbackCallable; + private final UnaryCallable allocateIdsCallable; + private final UnaryCallable reserveIdsCallable; + + private final BackgroundResource backgroundResources; + private final GrpcOperationsStub operationsStub; + private final GrpcStubCallableFactory callableFactory; + + public static final GrpcDatastoreStub create(DatastoreStubSettings settings) throws IOException { + return new GrpcDatastoreStub(settings, ClientContext.create(settings)); + } + + public static final GrpcDatastoreStub create(ClientContext clientContext) throws IOException { + return new GrpcDatastoreStub(DatastoreStubSettings.newBuilder().build(), clientContext); + } + + public static final GrpcDatastoreStub create( + ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { + return new GrpcDatastoreStub( + DatastoreStubSettings.newBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of GrpcDatastoreStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDatastoreStub(DatastoreStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new GrpcDatastoreCallableFactory()); + } + + /** + * Constructs an instance of GrpcDatastoreStub, using the given settings. This is protected so + * that it is easy to make a subclass, but otherwise, the static factory methods should be + * preferred. + */ + protected GrpcDatastoreStub( + DatastoreStubSettings settings, + ClientContext clientContext, + GrpcStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); + + GrpcCallSettings lookupTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(lookupMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings runQueryTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(runQueryMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings + beginTransactionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(beginTransactionMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings commitTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(commitMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings rollbackTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(rollbackMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings allocateIdsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(allocateIdsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + GrpcCallSettings reserveIdsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(reserveIdsMethodDescriptor) + .setParamsExtractor( + request -> { + ImmutableMap.Builder params = ImmutableMap.builder(); + params.put("project_id", String.valueOf(request.getProjectId())); + return params.build(); + }) + .build(); + + this.lookupCallable = + callableFactory.createUnaryCallable( + lookupTransportSettings, settings.lookupSettings(), clientContext); + this.runQueryCallable = + callableFactory.createUnaryCallable( + runQueryTransportSettings, settings.runQuerySettings(), clientContext); + this.beginTransactionCallable = + callableFactory.createUnaryCallable( + beginTransactionTransportSettings, settings.beginTransactionSettings(), clientContext); + this.commitCallable = + callableFactory.createUnaryCallable( + commitTransportSettings, settings.commitSettings(), clientContext); + this.rollbackCallable = + callableFactory.createUnaryCallable( + rollbackTransportSettings, settings.rollbackSettings(), clientContext); + this.allocateIdsCallable = + callableFactory.createUnaryCallable( + allocateIdsTransportSettings, settings.allocateIdsSettings(), clientContext); + this.reserveIdsCallable = + callableFactory.createUnaryCallable( + reserveIdsTransportSettings, settings.reserveIdsSettings(), clientContext); + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + public GrpcOperationsStub getOperationsStub() { + return operationsStub; + } + + @Override + public UnaryCallable lookupCallable() { + return lookupCallable; + } + + @Override + public UnaryCallable runQueryCallable() { + return runQueryCallable; + } + + @Override + public UnaryCallable + beginTransactionCallable() { + return beginTransactionCallable; + } + + @Override + public UnaryCallable commitCallable() { + return commitCallable; + } + + @Override + public UnaryCallable rollbackCallable() { + return rollbackCallable; + } + + @Override + public UnaryCallable allocateIdsCallable() { + return allocateIdsCallable; + } + + @Override + public UnaryCallable reserveIdsCallable() { + return reserveIdsCallable; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java new file mode 100644 index 000000000..c0e086537 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java @@ -0,0 +1,448 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.EntityResult; +import com.google.datastore.v1.Key; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.Mutation; +import com.google.datastore.v1.MutationResult; +import com.google.datastore.v1.PartitionId; +import com.google.datastore.v1.Query; +import com.google.datastore.v1.QueryResultBatch; +import com.google.datastore.v1.ReadOptions; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.ByteString; +import com.google.protobuf.Timestamp; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class DatastoreClientTest { + private static MockDatastore mockDatastore; + private static MockServiceHelper mockServiceHelper; + private LocalChannelProvider channelProvider; + private DatastoreClient client; + + @BeforeClass + public static void startStaticServer() { + mockDatastore = new MockDatastore(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockDatastore)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + DatastoreSettings settings = + DatastoreSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = DatastoreClient.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void lookupTest() throws Exception { + LookupResponse expectedResponse = + LookupResponse.newBuilder() + .addAllFound(new ArrayList()) + .addAllMissing(new ArrayList()) + .addAllDeferred(new ArrayList()) + .setReadTime(Timestamp.newBuilder().build()) + .build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + ReadOptions readOptions = ReadOptions.newBuilder().build(); + List keys = new ArrayList<>(); + + LookupResponse actualResponse = client.lookup(projectId, readOptions, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + LookupRequest actualRequest = ((LookupRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(readOptions, actualRequest.getReadOptions()); + Assert.assertEquals(keys, actualRequest.getKeysList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void lookupExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + ReadOptions readOptions = ReadOptions.newBuilder().build(); + List keys = new ArrayList<>(); + client.lookup(projectId, readOptions, keys); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void runQueryTest() throws Exception { + RunQueryResponse expectedResponse = + RunQueryResponse.newBuilder() + .setBatch(QueryResultBatch.newBuilder().build()) + .setQuery(Query.newBuilder().build()) + .build(); + mockDatastore.addResponse(expectedResponse); + + RunQueryRequest request = + RunQueryRequest.newBuilder() + .setProjectId("projectId-894832108") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + + RunQueryResponse actualResponse = client.runQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RunQueryRequest actualRequest = ((RunQueryRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getProjectId(), actualRequest.getProjectId()); + Assert.assertEquals(request.getPartitionId(), actualRequest.getPartitionId()); + Assert.assertEquals(request.getReadOptions(), actualRequest.getReadOptions()); + Assert.assertEquals(request.getQuery(), actualRequest.getQuery()); + Assert.assertEquals(request.getGqlQuery(), actualRequest.getGqlQuery()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void runQueryExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + RunQueryRequest request = + RunQueryRequest.newBuilder() + .setProjectId("projectId-894832108") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + client.runQuery(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void beginTransactionTest() throws Exception { + BeginTransactionResponse expectedResponse = + BeginTransactionResponse.newBuilder().setTransaction(ByteString.EMPTY).build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + + BeginTransactionResponse actualResponse = client.beginTransaction(projectId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + BeginTransactionRequest actualRequest = ((BeginTransactionRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void beginTransactionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + client.beginTransaction(projectId); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void commitTest() throws Exception { + CommitResponse expectedResponse = + CommitResponse.newBuilder() + .addAllMutationResults(new ArrayList()) + .setIndexUpdates(-1425228195) + .setCommitTime(Timestamp.newBuilder().build()) + .build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); + List mutations = new ArrayList<>(); + + CommitResponse actualResponse = client.commit(projectId, mode, mutations); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(mode, actualRequest.getMode()); + Assert.assertEquals(mutations, actualRequest.getMutationsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void commitExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); + List mutations = new ArrayList<>(); + client.commit(projectId, mode, mutations); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void commitTest2() throws Exception { + CommitResponse expectedResponse = + CommitResponse.newBuilder() + .addAllMutationResults(new ArrayList()) + .setIndexUpdates(-1425228195) + .setCommitTime(Timestamp.newBuilder().build()) + .build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); + ByteString transaction = ByteString.EMPTY; + List mutations = new ArrayList<>(); + + CommitResponse actualResponse = client.commit(projectId, mode, transaction, mutations); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(mode, actualRequest.getMode()); + Assert.assertEquals(transaction, actualRequest.getTransaction()); + Assert.assertEquals(mutations, actualRequest.getMutationsList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void commitExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); + ByteString transaction = ByteString.EMPTY; + List mutations = new ArrayList<>(); + client.commit(projectId, mode, transaction, mutations); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void rollbackTest() throws Exception { + RollbackResponse expectedResponse = RollbackResponse.newBuilder().build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + ByteString transaction = ByteString.EMPTY; + + RollbackResponse actualResponse = client.rollback(projectId, transaction); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RollbackRequest actualRequest = ((RollbackRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(transaction, actualRequest.getTransaction()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void rollbackExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + ByteString transaction = ByteString.EMPTY; + client.rollback(projectId, transaction); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void allocateIdsTest() throws Exception { + AllocateIdsResponse expectedResponse = + AllocateIdsResponse.newBuilder().addAllKeys(new ArrayList()).build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + List keys = new ArrayList<>(); + + AllocateIdsResponse actualResponse = client.allocateIds(projectId, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + AllocateIdsRequest actualRequest = ((AllocateIdsRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(keys, actualRequest.getKeysList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void allocateIdsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + List keys = new ArrayList<>(); + client.allocateIds(projectId, keys); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void reserveIdsTest() throws Exception { + ReserveIdsResponse expectedResponse = ReserveIdsResponse.newBuilder().build(); + mockDatastore.addResponse(expectedResponse); + + String projectId = "projectId-894832108"; + List keys = new ArrayList<>(); + + ReserveIdsResponse actualResponse = client.reserveIds(projectId, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ReserveIdsRequest actualRequest = ((ReserveIdsRequest) actualRequests.get(0)); + + Assert.assertEquals(projectId, actualRequest.getProjectId()); + Assert.assertEquals(keys, actualRequest.getKeysList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void reserveIdsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + String projectId = "projectId-894832108"; + List keys = new ArrayList<>(); + client.reserveIds(projectId, keys); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastore.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastore.java new file mode 100644 index 000000000..c1fc8412a --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastore.java @@ -0,0 +1,59 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockDatastore implements MockGrpcService { + private final MockDatastoreImpl serviceImpl; + + public MockDatastore() { + serviceImpl = new MockDatastoreImpl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastoreImpl.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastoreImpl.java new file mode 100644 index 000000000..77d412354 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastoreImpl.java @@ -0,0 +1,217 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.datastore.v1; + +import com.google.api.core.BetaApi; +import com.google.datastore.v1.AllocateIdsRequest; +import com.google.datastore.v1.AllocateIdsResponse; +import com.google.datastore.v1.BeginTransactionRequest; +import com.google.datastore.v1.BeginTransactionResponse; +import com.google.datastore.v1.CommitRequest; +import com.google.datastore.v1.CommitResponse; +import com.google.datastore.v1.DatastoreGrpc.DatastoreImplBase; +import com.google.datastore.v1.LookupRequest; +import com.google.datastore.v1.LookupResponse; +import com.google.datastore.v1.ReserveIdsRequest; +import com.google.datastore.v1.ReserveIdsResponse; +import com.google.datastore.v1.RollbackRequest; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.protobuf.AbstractMessage; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockDatastoreImpl extends DatastoreImplBase { + private List requests; + private Queue responses; + + public MockDatastoreImpl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void lookup(LookupRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof LookupResponse) { + requests.add(request); + responseObserver.onNext(((LookupResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Lookup, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + LookupResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void runQuery(RunQueryRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RunQueryResponse) { + requests.add(request); + responseObserver.onNext(((RunQueryResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method RunQuery, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RunQueryResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void beginTransaction( + BeginTransactionRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof BeginTransactionResponse) { + requests.add(request); + responseObserver.onNext(((BeginTransactionResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method BeginTransaction, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + BeginTransactionResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void commit(CommitRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof CommitResponse) { + requests.add(request); + responseObserver.onNext(((CommitResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Commit, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + CommitResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void rollback(RollbackRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RollbackResponse) { + requests.add(request); + responseObserver.onNext(((RollbackResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method Rollback, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RollbackResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void allocateIds( + AllocateIdsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof AllocateIdsResponse) { + requests.add(request); + responseObserver.onNext(((AllocateIdsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method AllocateIds, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + AllocateIdsResponse.class.getName(), + Exception.class.getName()))); + } + } + + @Override + public void reserveIds( + ReserveIdsRequest request, StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof ReserveIdsResponse) { + requests.add(request); + responseObserver.onNext(((ReserveIdsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError( + new IllegalArgumentException( + String.format( + "Unrecognized response type %s for method ReserveIds, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + ReserveIdsResponse.class.getName(), + Exception.class.getName()))); + } + } +} diff --git a/grpc-google-cloud-datastore-v1/clirr-ignored-differences.xml b/grpc-google-cloud-datastore-v1/clirr-ignored-differences.xml new file mode 100644 index 000000000..79b0aaf9d --- /dev/null +++ b/grpc-google-cloud-datastore-v1/clirr-ignored-differences.xml @@ -0,0 +1,10 @@ + + + + + + 6001 + com/google/datastore/v1/*Grpc + METHOD_* + + \ No newline at end of file diff --git a/grpc-google-cloud-datastore-v1/pom.xml b/grpc-google-cloud-datastore-v1/pom.xml new file mode 100644 index 000000000..7b744be1a --- /dev/null +++ b/grpc-google-cloud-datastore-v1/pom.xml @@ -0,0 +1,89 @@ + + 4.0.0 + com.google.api.grpc + grpc-google-cloud-datastore-v1 + 2.5.1-SNAPSHOT + grpc-google-cloud-datastore-v1 + GRPC library for grpc-google-cloud-datastore-v1 + + com.google.cloud + google-cloud-datastore-parent + 2.5.1-SNAPSHOT + + + + io.grpc + grpc-stub + compile + + + io.grpc + grpc-protobuf + compile + + + com.google.api.grpc + proto-google-cloud-datastore-v1 + compile + + + io.grpc + grpc-api + + + com.google.protobuf + protobuf-java + + + com.google.guava + guava + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + protected + true + none + true + + + ${project.javadoc.protobufBaseURL} + ../../../../proto-google-cloud-datastore-v1/target/site/apidocs/ + + + + + + + + + + org.codehaus.mojo + flatten-maven-plugin + + + + + + + java9 + + [9,) + + + + javax.annotation + javax.annotation-api + + + + + + diff --git a/grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java b/grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java new file mode 100644 index 000000000..cdd95c194 --- /dev/null +++ b/grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java @@ -0,0 +1,1053 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.datastore.v1; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + * + * + *
+ * Each RPC normalizes the partition IDs of the keys in its input entities,
+ * and always returns entities with keys with normalized partition IDs.
+ * This applies to all keys and entities, including those in values, except keys
+ * with both an empty path and an empty or unset partition ID. Normalization of
+ * input keys sets the project ID (if not already set) to the project ID from
+ * the request.
+ * 
+ */ +@javax.annotation.Generated( + value = "by gRPC proto compiler", + comments = "Source: google/datastore/v1/datastore.proto") +@io.grpc.stub.annotations.GrpcGenerated +public final class DatastoreGrpc { + + private DatastoreGrpc() {} + + public static final String SERVICE_NAME = "google.datastore.v1.Datastore"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.LookupRequest, com.google.datastore.v1.LookupResponse> + getLookupMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "Lookup", + requestType = com.google.datastore.v1.LookupRequest.class, + responseType = com.google.datastore.v1.LookupResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.LookupRequest, com.google.datastore.v1.LookupResponse> + getLookupMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.LookupRequest, com.google.datastore.v1.LookupResponse> + getLookupMethod; + if ((getLookupMethod = DatastoreGrpc.getLookupMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getLookupMethod = DatastoreGrpc.getLookupMethod) == null) { + DatastoreGrpc.getLookupMethod = + getLookupMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Lookup")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.LookupRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.LookupResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("Lookup")) + .build(); + } + } + } + return getLookupMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.RunQueryRequest, com.google.datastore.v1.RunQueryResponse> + getRunQueryMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "RunQuery", + requestType = com.google.datastore.v1.RunQueryRequest.class, + responseType = com.google.datastore.v1.RunQueryResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.RunQueryRequest, com.google.datastore.v1.RunQueryResponse> + getRunQueryMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.RunQueryRequest, com.google.datastore.v1.RunQueryResponse> + getRunQueryMethod; + if ((getRunQueryMethod = DatastoreGrpc.getRunQueryMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getRunQueryMethod = DatastoreGrpc.getRunQueryMethod) == null) { + DatastoreGrpc.getRunQueryMethod = + getRunQueryMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "RunQuery")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RunQueryRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RunQueryResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("RunQuery")) + .build(); + } + } + } + return getRunQueryMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.BeginTransactionRequest, + com.google.datastore.v1.BeginTransactionResponse> + getBeginTransactionMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "BeginTransaction", + requestType = com.google.datastore.v1.BeginTransactionRequest.class, + responseType = com.google.datastore.v1.BeginTransactionResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.BeginTransactionRequest, + com.google.datastore.v1.BeginTransactionResponse> + getBeginTransactionMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.BeginTransactionRequest, + com.google.datastore.v1.BeginTransactionResponse> + getBeginTransactionMethod; + if ((getBeginTransactionMethod = DatastoreGrpc.getBeginTransactionMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getBeginTransactionMethod = DatastoreGrpc.getBeginTransactionMethod) == null) { + DatastoreGrpc.getBeginTransactionMethod = + getBeginTransactionMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "BeginTransaction")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.BeginTransactionRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.BeginTransactionResponse + .getDefaultInstance())) + .setSchemaDescriptor( + new DatastoreMethodDescriptorSupplier("BeginTransaction")) + .build(); + } + } + } + return getBeginTransactionMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.CommitRequest, com.google.datastore.v1.CommitResponse> + getCommitMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "Commit", + requestType = com.google.datastore.v1.CommitRequest.class, + responseType = com.google.datastore.v1.CommitResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.CommitRequest, com.google.datastore.v1.CommitResponse> + getCommitMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.CommitRequest, com.google.datastore.v1.CommitResponse> + getCommitMethod; + if ((getCommitMethod = DatastoreGrpc.getCommitMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getCommitMethod = DatastoreGrpc.getCommitMethod) == null) { + DatastoreGrpc.getCommitMethod = + getCommitMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Commit")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.CommitRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.CommitResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("Commit")) + .build(); + } + } + } + return getCommitMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.RollbackRequest, com.google.datastore.v1.RollbackResponse> + getRollbackMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "Rollback", + requestType = com.google.datastore.v1.RollbackRequest.class, + responseType = com.google.datastore.v1.RollbackResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.RollbackRequest, com.google.datastore.v1.RollbackResponse> + getRollbackMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.RollbackRequest, com.google.datastore.v1.RollbackResponse> + getRollbackMethod; + if ((getRollbackMethod = DatastoreGrpc.getRollbackMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getRollbackMethod = DatastoreGrpc.getRollbackMethod) == null) { + DatastoreGrpc.getRollbackMethod = + getRollbackMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "Rollback")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RollbackRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RollbackResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("Rollback")) + .build(); + } + } + } + return getRollbackMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.AllocateIdsRequest, com.google.datastore.v1.AllocateIdsResponse> + getAllocateIdsMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "AllocateIds", + requestType = com.google.datastore.v1.AllocateIdsRequest.class, + responseType = com.google.datastore.v1.AllocateIdsResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.AllocateIdsRequest, com.google.datastore.v1.AllocateIdsResponse> + getAllocateIdsMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.AllocateIdsRequest, com.google.datastore.v1.AllocateIdsResponse> + getAllocateIdsMethod; + if ((getAllocateIdsMethod = DatastoreGrpc.getAllocateIdsMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getAllocateIdsMethod = DatastoreGrpc.getAllocateIdsMethod) == null) { + DatastoreGrpc.getAllocateIdsMethod = + getAllocateIdsMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "AllocateIds")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.AllocateIdsRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.AllocateIdsResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("AllocateIds")) + .build(); + } + } + } + return getAllocateIdsMethod; + } + + private static volatile io.grpc.MethodDescriptor< + com.google.datastore.v1.ReserveIdsRequest, com.google.datastore.v1.ReserveIdsResponse> + getReserveIdsMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "ReserveIds", + requestType = com.google.datastore.v1.ReserveIdsRequest.class, + responseType = com.google.datastore.v1.ReserveIdsResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.ReserveIdsRequest, com.google.datastore.v1.ReserveIdsResponse> + getReserveIdsMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.ReserveIdsRequest, com.google.datastore.v1.ReserveIdsResponse> + getReserveIdsMethod; + if ((getReserveIdsMethod = DatastoreGrpc.getReserveIdsMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getReserveIdsMethod = DatastoreGrpc.getReserveIdsMethod) == null) { + DatastoreGrpc.getReserveIdsMethod = + getReserveIdsMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "ReserveIds")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.ReserveIdsRequest.getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.ReserveIdsResponse.getDefaultInstance())) + .setSchemaDescriptor(new DatastoreMethodDescriptorSupplier("ReserveIds")) + .build(); + } + } + } + return getReserveIdsMethod; + } + + /** Creates a new async stub that supports all call types for the service */ + public static DatastoreStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public DatastoreStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreStub(channel, callOptions); + } + }; + return DatastoreStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static DatastoreBlockingStub newBlockingStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public DatastoreBlockingStub newStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreBlockingStub(channel, callOptions); + } + }; + return DatastoreBlockingStub.newStub(factory, channel); + } + + /** Creates a new ListenableFuture-style stub that supports unary calls on the service */ + public static DatastoreFutureStub newFutureStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @java.lang.Override + public DatastoreFutureStub newStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreFutureStub(channel, callOptions); + } + }; + return DatastoreFutureStub.newStub(factory, channel); + } + + /** + * + * + *
+   * Each RPC normalizes the partition IDs of the keys in its input entities,
+   * and always returns entities with keys with normalized partition IDs.
+   * This applies to all keys and entities, including those in values, except keys
+   * with both an empty path and an empty or unset partition ID. Normalization of
+   * input keys sets the project ID (if not already set) to the project ID from
+   * the request.
+   * 
+ */ + public abstract static class DatastoreImplBase implements io.grpc.BindableService { + + /** + * + * + *
+     * Looks up entities by key.
+     * 
+ */ + public void lookup( + com.google.datastore.v1.LookupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getLookupMethod(), responseObserver); + } + + /** + * + * + *
+     * Queries for entities.
+     * 
+ */ + public void runQuery( + com.google.datastore.v1.RunQueryRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRunQueryMethod(), responseObserver); + } + + /** + * + * + *
+     * Begins a new transaction.
+     * 
+ */ + public void beginTransaction( + com.google.datastore.v1.BeginTransactionRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getBeginTransactionMethod(), responseObserver); + } + + /** + * + * + *
+     * Commits a transaction, optionally creating, deleting or modifying some
+     * entities.
+     * 
+ */ + public void commit( + com.google.datastore.v1.CommitRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getCommitMethod(), responseObserver); + } + + /** + * + * + *
+     * Rolls back a transaction.
+     * 
+ */ + public void rollback( + com.google.datastore.v1.RollbackRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRollbackMethod(), responseObserver); + } + + /** + * + * + *
+     * Allocates IDs for the given keys, which is useful for referencing an entity
+     * before it is inserted.
+     * 
+ */ + public void allocateIds( + com.google.datastore.v1.AllocateIdsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getAllocateIdsMethod(), responseObserver); + } + + /** + * + * + *
+     * Prevents the supplied keys' IDs from being auto-allocated by Cloud
+     * Datastore.
+     * 
+ */ + public void reserveIds( + com.google.datastore.v1.ReserveIdsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getReserveIdsMethod(), responseObserver); + } + + @java.lang.Override + public final io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getLookupMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.LookupRequest, + com.google.datastore.v1.LookupResponse>(this, METHODID_LOOKUP))) + .addMethod( + getRunQueryMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.RunQueryRequest, + com.google.datastore.v1.RunQueryResponse>(this, METHODID_RUN_QUERY))) + .addMethod( + getBeginTransactionMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.BeginTransactionRequest, + com.google.datastore.v1.BeginTransactionResponse>( + this, METHODID_BEGIN_TRANSACTION))) + .addMethod( + getCommitMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.CommitRequest, + com.google.datastore.v1.CommitResponse>(this, METHODID_COMMIT))) + .addMethod( + getRollbackMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.RollbackRequest, + com.google.datastore.v1.RollbackResponse>(this, METHODID_ROLLBACK))) + .addMethod( + getAllocateIdsMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.AllocateIdsRequest, + com.google.datastore.v1.AllocateIdsResponse>(this, METHODID_ALLOCATE_IDS))) + .addMethod( + getReserveIdsMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.ReserveIdsRequest, + com.google.datastore.v1.ReserveIdsResponse>(this, METHODID_RESERVE_IDS))) + .build(); + } + } + + /** + * + * + *
+   * Each RPC normalizes the partition IDs of the keys in its input entities,
+   * and always returns entities with keys with normalized partition IDs.
+   * This applies to all keys and entities, including those in values, except keys
+   * with both an empty path and an empty or unset partition ID. Normalization of
+   * input keys sets the project ID (if not already set) to the project ID from
+   * the request.
+   * 
+ */ + public static final class DatastoreStub extends io.grpc.stub.AbstractAsyncStub { + private DatastoreStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected DatastoreStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreStub(channel, callOptions); + } + + /** + * + * + *
+     * Looks up entities by key.
+     * 
+ */ + public void lookup( + com.google.datastore.v1.LookupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getLookupMethod(), getCallOptions()), request, responseObserver); + } + + /** + * + * + *
+     * Queries for entities.
+     * 
+ */ + public void runQuery( + com.google.datastore.v1.RunQueryRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getRunQueryMethod(), getCallOptions()), request, responseObserver); + } + + /** + * + * + *
+     * Begins a new transaction.
+     * 
+ */ + public void beginTransaction( + com.google.datastore.v1.BeginTransactionRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getBeginTransactionMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Commits a transaction, optionally creating, deleting or modifying some
+     * entities.
+     * 
+ */ + public void commit( + com.google.datastore.v1.CommitRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getCommitMethod(), getCallOptions()), request, responseObserver); + } + + /** + * + * + *
+     * Rolls back a transaction.
+     * 
+ */ + public void rollback( + com.google.datastore.v1.RollbackRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getRollbackMethod(), getCallOptions()), request, responseObserver); + } + + /** + * + * + *
+     * Allocates IDs for the given keys, which is useful for referencing an entity
+     * before it is inserted.
+     * 
+ */ + public void allocateIds( + com.google.datastore.v1.AllocateIdsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getAllocateIdsMethod(), getCallOptions()), + request, + responseObserver); + } + + /** + * + * + *
+     * Prevents the supplied keys' IDs from being auto-allocated by Cloud
+     * Datastore.
+     * 
+ */ + public void reserveIds( + com.google.datastore.v1.ReserveIdsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getReserveIdsMethod(), getCallOptions()), request, responseObserver); + } + } + + /** + * + * + *
+   * Each RPC normalizes the partition IDs of the keys in its input entities,
+   * and always returns entities with keys with normalized partition IDs.
+   * This applies to all keys and entities, including those in values, except keys
+   * with both an empty path and an empty or unset partition ID. Normalization of
+   * input keys sets the project ID (if not already set) to the project ID from
+   * the request.
+   * 
+ */ + public static final class DatastoreBlockingStub + extends io.grpc.stub.AbstractBlockingStub { + private DatastoreBlockingStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected DatastoreBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreBlockingStub(channel, callOptions); + } + + /** + * + * + *
+     * Looks up entities by key.
+     * 
+ */ + public com.google.datastore.v1.LookupResponse lookup( + com.google.datastore.v1.LookupRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getLookupMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Queries for entities.
+     * 
+ */ + public com.google.datastore.v1.RunQueryResponse runQuery( + com.google.datastore.v1.RunQueryRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getRunQueryMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Begins a new transaction.
+     * 
+ */ + public com.google.datastore.v1.BeginTransactionResponse beginTransaction( + com.google.datastore.v1.BeginTransactionRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getBeginTransactionMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Commits a transaction, optionally creating, deleting or modifying some
+     * entities.
+     * 
+ */ + public com.google.datastore.v1.CommitResponse commit( + com.google.datastore.v1.CommitRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getCommitMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Rolls back a transaction.
+     * 
+ */ + public com.google.datastore.v1.RollbackResponse rollback( + com.google.datastore.v1.RollbackRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getRollbackMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Allocates IDs for the given keys, which is useful for referencing an entity
+     * before it is inserted.
+     * 
+ */ + public com.google.datastore.v1.AllocateIdsResponse allocateIds( + com.google.datastore.v1.AllocateIdsRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getAllocateIdsMethod(), getCallOptions(), request); + } + + /** + * + * + *
+     * Prevents the supplied keys' IDs from being auto-allocated by Cloud
+     * Datastore.
+     * 
+ */ + public com.google.datastore.v1.ReserveIdsResponse reserveIds( + com.google.datastore.v1.ReserveIdsRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getReserveIdsMethod(), getCallOptions(), request); + } + } + + /** + * + * + *
+   * Each RPC normalizes the partition IDs of the keys in its input entities,
+   * and always returns entities with keys with normalized partition IDs.
+   * This applies to all keys and entities, including those in values, except keys
+   * with both an empty path and an empty or unset partition ID. Normalization of
+   * input keys sets the project ID (if not already set) to the project ID from
+   * the request.
+   * 
+ */ + public static final class DatastoreFutureStub + extends io.grpc.stub.AbstractFutureStub { + private DatastoreFutureStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected DatastoreFutureStub build(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new DatastoreFutureStub(channel, callOptions); + } + + /** + * + * + *
+     * Looks up entities by key.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.LookupResponse> + lookup(com.google.datastore.v1.LookupRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getLookupMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Queries for entities.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.RunQueryResponse> + runQuery(com.google.datastore.v1.RunQueryRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getRunQueryMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Begins a new transaction.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.BeginTransactionResponse> + beginTransaction(com.google.datastore.v1.BeginTransactionRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getBeginTransactionMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Commits a transaction, optionally creating, deleting or modifying some
+     * entities.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.CommitResponse> + commit(com.google.datastore.v1.CommitRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getCommitMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Rolls back a transaction.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.RollbackResponse> + rollback(com.google.datastore.v1.RollbackRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getRollbackMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Allocates IDs for the given keys, which is useful for referencing an entity
+     * before it is inserted.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.AllocateIdsResponse> + allocateIds(com.google.datastore.v1.AllocateIdsRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getAllocateIdsMethod(), getCallOptions()), request); + } + + /** + * + * + *
+     * Prevents the supplied keys' IDs from being auto-allocated by Cloud
+     * Datastore.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.ReserveIdsResponse> + reserveIds(com.google.datastore.v1.ReserveIdsRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getReserveIdsMethod(), getCallOptions()), request); + } + } + + private static final int METHODID_LOOKUP = 0; + private static final int METHODID_RUN_QUERY = 1; + private static final int METHODID_BEGIN_TRANSACTION = 2; + private static final int METHODID_COMMIT = 3; + private static final int METHODID_ROLLBACK = 4; + private static final int METHODID_ALLOCATE_IDS = 5; + private static final int METHODID_RESERVE_IDS = 6; + + private static final class MethodHandlers + implements io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final DatastoreImplBase serviceImpl; + private final int methodId; + + MethodHandlers(DatastoreImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_LOOKUP: + serviceImpl.lookup( + (com.google.datastore.v1.LookupRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_RUN_QUERY: + serviceImpl.runQuery( + (com.google.datastore.v1.RunQueryRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_BEGIN_TRANSACTION: + serviceImpl.beginTransaction( + (com.google.datastore.v1.BeginTransactionRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_COMMIT: + serviceImpl.commit( + (com.google.datastore.v1.CommitRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_ROLLBACK: + serviceImpl.rollback( + (com.google.datastore.v1.RollbackRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_ALLOCATE_IDS: + serviceImpl.allocateIds( + (com.google.datastore.v1.AllocateIdsRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + case METHODID_RESERVE_IDS: + serviceImpl.reserveIds( + (com.google.datastore.v1.ReserveIdsRequest) request, + (io.grpc.stub.StreamObserver) + responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + private abstract static class DatastoreBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, + io.grpc.protobuf.ProtoServiceDescriptorSupplier { + DatastoreBaseDescriptorSupplier() {} + + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return com.google.datastore.v1.DatastoreProto.getDescriptor(); + } + + @java.lang.Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("Datastore"); + } + } + + private static final class DatastoreFileDescriptorSupplier + extends DatastoreBaseDescriptorSupplier { + DatastoreFileDescriptorSupplier() {} + } + + private static final class DatastoreMethodDescriptorSupplier + extends DatastoreBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final String methodName; + + DatastoreMethodDescriptorSupplier(String methodName) { + this.methodName = methodName; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (DatastoreGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = + result = + io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new DatastoreFileDescriptorSupplier()) + .addMethod(getLookupMethod()) + .addMethod(getRunQueryMethod()) + .addMethod(getBeginTransactionMethod()) + .addMethod(getCommitMethod()) + .addMethod(getRollbackMethod()) + .addMethod(getAllocateIdsMethod()) + .addMethod(getReserveIdsMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/pom.xml b/pom.xml index 73853572c..90c445cd9 100644 --- a/pom.xml +++ b/pom.xml @@ -166,6 +166,11 @@ proto-google-cloud-datastore-v1 0.96.2-SNAPSHOT + + com.google.api.grpc + grpc-google-cloud-datastore-v1 + 2.5.1-SNAPSHOT + com.google.cloud.datastore datastore-v1-proto-client @@ -257,6 +262,7 @@ google-cloud-datastore proto-google-cloud-datastore-v1 + grpc-google-cloud-datastore-v1 datastore-v1-proto-client google-cloud-datastore-bom diff --git a/proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/Key.java b/proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/Key.java index f992eec2b..54a39945f 100644 --- a/proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/Key.java +++ b/proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/Key.java @@ -151,6 +151,9 @@ public interface PathElementOrBuilder * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -166,6 +169,9 @@ public interface PathElementOrBuilder * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -211,6 +217,9 @@ public interface PathElementOrBuilder * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -226,6 +235,9 @@ public interface PathElementOrBuilder * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -241,6 +253,9 @@ public interface PathElementOrBuilder * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -418,6 +433,9 @@ public IdTypeCase getIdTypeCase() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -444,6 +462,9 @@ public java.lang.String getKind() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -511,6 +532,9 @@ public long getId() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -528,6 +552,9 @@ public boolean hasName() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -558,6 +585,9 @@ public java.lang.String getName() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -989,6 +1019,9 @@ public Builder clearIdType() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -1014,6 +1047,9 @@ public java.lang.String getKind() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -1039,6 +1075,9 @@ public com.google.protobuf.ByteString getKindBytes() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -1063,6 +1102,9 @@ public Builder setKind(java.lang.String value) { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -1083,6 +1125,9 @@ public Builder clearKind() { * A kind matching regex `__.*__` is reserved/read-only. * A kind must not contain more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string kind = 1; @@ -1186,6 +1231,9 @@ public Builder clearId() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -1204,6 +1252,9 @@ public boolean hasName() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -1235,6 +1286,9 @@ public java.lang.String getName() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -1266,6 +1320,9 @@ public com.google.protobuf.ByteString getNameBytes() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -1290,6 +1347,9 @@ public Builder setName(java.lang.String value) { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; @@ -1312,6 +1372,9 @@ public Builder clearName() { * A name matching regex `__.*__` is reserved/read-only. * A name must not be more than 1500 bytes when UTF-8 encoded. * Cannot be `""`. + * Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + * encoded as `__bytes<X>__` where `<X>` is the base-64 encoding of the + * bytes. * * * string name = 3; diff --git a/proto-google-cloud-datastore-v1/src/main/proto/google/datastore/v1/entity.proto b/proto-google-cloud-datastore-v1/src/main/proto/google/datastore/v1/entity.proto index befbcd7b6..55d7b64fe 100644 --- a/proto-google-cloud-datastore-v1/src/main/proto/google/datastore/v1/entity.proto +++ b/proto-google-cloud-datastore-v1/src/main/proto/google/datastore/v1/entity.proto @@ -66,22 +66,33 @@ message Key { // If neither is set, the element is incomplete. message PathElement { // The kind of the entity. + // // A kind matching regex `__.*__` is reserved/read-only. // A kind must not contain more than 1500 bytes when UTF-8 encoded. // Cannot be `""`. + // + // Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + // encoded as `__bytes__` where `` is the base-64 encoding of the + // bytes. string kind = 1; // The type of ID. oneof id_type { // The auto-allocated ID of the entity. + // // Never equal to zero. Values less than zero are discouraged and may not // be supported in the future. int64 id = 2; // The name of the entity. + // // A name matching regex `__.*__` is reserved/read-only. // A name must not be more than 1500 bytes when UTF-8 encoded. // Cannot be `""`. + // + // Must be valid UTF-8 bytes. Legacy values that are not valid UTF-8 are + // encoded as `__bytes__` where `` is the base-64 encoding of the + // bytes. string name = 3; } } diff --git a/synth.metadata b/synth.metadata index b2f526b6c..578ad3558 100644 --- a/synth.metadata +++ b/synth.metadata @@ -106,6 +106,7 @@ "codecov.yaml", "java.header", "license-checks.xml", + "grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java", "proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/AllocateIdsRequest.java", "proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/AllocateIdsRequestOrBuilder.java", "proto-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/AllocateIdsResponse.java", diff --git a/versions.txt b/versions.txt index 5896f28c0..270608ebd 100644 --- a/versions.txt +++ b/versions.txt @@ -5,3 +5,4 @@ google-cloud-datastore:2.5.1:2.5.2-SNAPSHOT google-cloud-datastore-bom:2.5.1:2.5.2-SNAPSHOT proto-google-cloud-datastore-v1:0.96.1:0.96.2-SNAPSHOT datastore-v1-proto-client:2.5.1:2.5.2-SNAPSHOT +grpc-google-cloud-datastore-v1:2.5.2:2.5.2-SNAPSHOT