diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml index d89045599..76eece042 100644 --- a/.github/.OwlBot.yaml +++ b/.github/.OwlBot.yaml @@ -25,8 +25,12 @@ deep-copy-regex: dest: "/owl-bot-staging/$1/proto-google-cloud-datastore-$1/src" - source: "/google/datastore/admin/(v.*)/.*-java/proto-google-.*/src" dest: "/owl-bot-staging/$1/proto-google-cloud-datastore-admin-$1/src" +- source: "/google/datastore/(v.*)/.*-java/grpc-google-.*/src" + dest: "/owl-bot-staging/$1/grpc-google-cloud-datastore-$1/src" - source: "/google/datastore/admin/(v.*)/.*-java/grpc-google-.*/src" dest: "/owl-bot-staging/$1/grpc-google-cloud-datastore-admin-$1/src" # Admin & Data APIs share the same wrapper library. +- source: "/google/datastore/(v.*)/.*-java/gapic-google-.*/src" + dest: "/owl-bot-staging/$1/google-cloud-datastore/src" - source: "/google/datastore/admin/(v.*)/.*-java/gapic-google-.*/src" - dest: "/owl-bot-staging/$1/google-cloud-datastore/src" \ No newline at end of file + dest: "/owl-bot-staging/$1/google-cloud-datastore/src" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3a7c9a454..203f9eacc 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,4 @@ version: 2 - updates: - package-ecosystem: "maven" directory: "/" @@ -18,14 +17,3 @@ updates: # it via template in the synthtool repository. ignore: - dependency-name: "*" - - # rules for the `V3-experimental` branch - - package-ecosystem: maven - directory: "/" - schedule: - interval: daily - commit-message: - # Prefix all commit messages with "deps: " - prefix: "deps" - open-pull-requests-limit: 10 - target-branch: "V3-experimental" diff --git a/.gitignore b/.gitignore index 6f5e4424d..241f84417 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ target/ *.iml __pycache__/ -.flattened-pom.xml \ No newline at end of file +.flattened-pom.xml diff --git a/google-cloud-datastore/clirr-ignored-differences.xml b/google-cloud-datastore/clirr-ignored-differences.xml index 1620fd752..0037fa807 100644 --- a/google-cloud-datastore/clirr-ignored-differences.xml +++ b/google-cloud-datastore/clirr-ignored-differences.xml @@ -1,7 +1,50 @@ - + + + com/google/cloud/datastore/ReadOption$QueryAndReadOptions + * + 8001 + + + com/google/cloud/datastore/execution/request/AggregationQueryRequestProtoPreparer + *QueryAndReadOptions* + *QueryConfig* + 7005 + + + + com/google/cloud/datastore/DatastoreException + 5000 + com/google/cloud/grpc/BaseGrpcServiceException + + + + com/google/cloud/datastore/DatastoreException + 5001 + com/google/cloud/http/BaseHttpServiceException + + + com/google/cloud/datastore/Datastore + void close() + 7012 + + + com/google/cloud/datastore/spi/v1/DatastoreRpc + void close() + 7012 + + + com/google/cloud/datastore/Datastore + boolean isClosed() + 7012 + + + com/google/cloud/datastore/spi/v1/DatastoreRpc + boolean isClosed() + 7012 + com/google/cloud/datastore/Datastore com.google.cloud.datastore.QueryResults run(com.google.cloud.datastore.Query, com.google.cloud.datastore.models.ExplainOptions, com.google.cloud.datastore.ReadOption[]) @@ -14,7 +57,7 @@ com/google/cloud/datastore/DatastoreReader - com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.models.ExplainOptions) + com.google.cloud.datastore.AggregationResults runAggregation(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.models.ExplainOptions) 7012 @@ -28,18 +71,6 @@ 7012 - - - com/google/cloud/datastore/ReadOption$QueryConfig - com.google.cloud.datastore.ReadOption$QueryConfig create(com.google.cloud.datastore.Query, java.util.List) - *com.google.datastore.v1.ExplainOptions* - 7005 - - - com/google/cloud/datastore/ReadOption$QueryConfig - com.google.cloud.datastore.ReadOption$QueryConfig create(com.google.cloud.datastore.Query) - 7004 - com/google/cloud/datastore/execution/AggregationQueryExecutor com.google.cloud.datastore.AggregationResults execute(com.google.cloud.datastore.AggregationQuery, com.google.cloud.datastore.ReadOption[]) diff --git a/google-cloud-datastore/pom.xml b/google-cloud-datastore/pom.xml index 8d6b79e8d..2624f863c 100644 --- a/google-cloud-datastore/pom.xml +++ b/google-cloud-datastore/pom.xml @@ -18,6 +18,10 @@ google-cloud-datastore + + com.google.api.grpc + grpc-google-cloud-datastore-v1 + com.google.api.grpc grpc-google-cloud-datastore-admin-v1 @@ -26,6 +30,10 @@ com.google.cloud google-cloud-core-http + + com.google.cloud + google-cloud-core-grpc + com.google.api.grpc proto-google-cloud-datastore-v1 diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java index eb4abd854..c9a01673d 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java @@ -16,6 +16,7 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; import java.util.List; import javax.annotation.concurrent.NotThreadSafe; @@ -42,6 +43,7 @@ * This class too should not be treated as a thread safe class. */ @NotThreadSafe +@InternalExtensionOnly public interface Batch extends DatastoreBatchWriter { interface Response { diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java index 5bd8384a3..791446de5 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java @@ -17,6 +17,7 @@ package com.google.cloud.datastore; import com.google.api.core.BetaApi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.Service; import com.google.cloud.datastore.models.ExplainOptions; import com.google.datastore.v1.TransactionOptions; @@ -24,7 +25,8 @@ import java.util.List; /** An interface for Google Cloud Datastore. */ -public interface Datastore extends Service, DatastoreReaderWriter { +@InternalExtensionOnly +public interface Datastore extends Service, DatastoreReaderWriter, AutoCloseable { /** * Returns a new Datastore transaction. @@ -51,9 +53,9 @@ public interface Datastore extends Service, DatastoreReaderWri * @param the type of the return value */ interface TransactionCallable { + T run(DatastoreReaderWriter readerWriter) throws Exception; } - /** * Invokes the callback's {@link Datastore.TransactionCallable#run} method with a {@link * DatastoreReaderWriter} that is associated with a new transaction. The transaction will be @@ -481,10 +483,7 @@ interface TransactionCallable { * @throws DatastoreException upon failure */ @BetaApi - default QueryResults run( - Query query, ExplainOptions explainOptions, ReadOption... options) { - throw new UnsupportedOperationException("Not implemented."); - } + QueryResults run(Query query, ExplainOptions explainOptions, ReadOption... options); /** * Submits a {@link AggregationQuery} and returns {@link AggregationResults}. {@link ReadOption}s @@ -529,9 +528,7 @@ default QueryResults run( * @throws DatastoreException upon failure * @return {@link AggregationResults} */ - default AggregationResults runAggregation(AggregationQuery query, ReadOption... options) { - throw new UnsupportedOperationException("Not implemented."); - } + AggregationResults runAggregation(AggregationQuery query, ReadOption... options); /** * Submits a {@link AggregationQuery} with specified {@link @@ -557,8 +554,17 @@ default AggregationResults runAggregation(AggregationQuery query, ReadOption... * @return {@link AggregationResults} */ @BetaApi - default AggregationResults runAggregation( - AggregationQuery query, ExplainOptions explainOptions, ReadOption... options) { - throw new UnsupportedOperationException("Not implemented."); - } + AggregationResults runAggregation( + AggregationQuery query, ExplainOptions explainOptions, ReadOption... options); + + /** + * Closes the gRPC channels associated with this instance and frees up their resources. This + * method blocks until all channels are closed. Once this method is called, this Datastore client + * is no longer usable. + */ + @Override + void close() throws Exception; + + /** Returns true if this background resource has been shut down. */ + boolean isClosed(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java index db4bd3179..28d2569b6 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java @@ -16,6 +16,7 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; import java.util.List; import javax.annotation.concurrent.NotThreadSafe; @@ -31,6 +32,7 @@ * This class too should not be treated as a thread safe class. */ @NotThreadSafe +@InternalExtensionOnly public interface DatastoreBatchWriter extends DatastoreWriter { /** diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreException.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreException.java index 512d0a3dc..d258feac8 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreException.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreException.java @@ -16,10 +16,16 @@ package com.google.cloud.datastore; +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.StatusCode; import com.google.cloud.BaseServiceException; import com.google.cloud.RetryHelper.RetryHelperException; import com.google.cloud.http.BaseHttpServiceException; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; +import io.grpc.StatusException; +import io.grpc.StatusRuntimeException; import java.io.IOException; import java.util.Set; @@ -43,6 +49,10 @@ public DatastoreException(int code, String message, String reason) { this(code, message, reason, true, null); } + public DatastoreException(int code, String message, Throwable cause) { + super(code, message, null, true, RETRYABLE_ERRORS, cause); + } + public DatastoreException(int code, String message, String reason, Throwable cause) { super(code, message, reason, true, RETRYABLE_ERRORS, cause); } @@ -64,7 +74,76 @@ public DatastoreException(IOException exception) { */ static DatastoreException translateAndThrow(RetryHelperException ex) { BaseServiceException.translate(ex); - throw new DatastoreException(UNKNOWN_CODE, ex.getMessage(), null, ex.getCause()); + throw transformThrowable(ex); + } + + static BaseServiceException transformThrowable(Throwable t) { + if (t instanceof BaseServiceException) { + return (BaseServiceException) t; + } + if (t.getCause() instanceof BaseServiceException) { + return (BaseServiceException) t.getCause(); + } + if (t instanceof ApiException) { + return asDatastoreException((ApiException) t); + } + if (t.getCause() instanceof ApiException) { + return asDatastoreException((ApiException) t.getCause()); + } + return getDatastoreException(t); + } + + private static DatastoreException getDatastoreException(Throwable t) { + // unwrap a RetryHelperException if that is what is being translated + if (t instanceof RetryHelperException) { + return new DatastoreException(UNKNOWN_CODE, t.getMessage(), null, t.getCause()); + } + return new DatastoreException(UNKNOWN_CODE, t.getMessage(), t); + } + + static DatastoreException asDatastoreException(ApiException apiEx) { + int datastoreStatusCode = 0; + StatusCode statusCode = apiEx.getStatusCode(); + if (statusCode instanceof GrpcStatusCode) { + GrpcStatusCode gsc = (GrpcStatusCode) statusCode; + datastoreStatusCode = + GrpcToDatastoreCodeTranslation.grpcCodeToDatastoreStatusCode(gsc.getTransportCode()); + } + + // If there is a gRPC exception in our cause, pull its error message up to be our + // message otherwise, create a generic error message with the status code. + String statusCodeName = statusCode.getCode().name(); + String statusExceptionMessage = getStatusExceptionMessage(apiEx); + + String message; + if (statusExceptionMessage != null) { + message = statusCodeName + ": " + statusExceptionMessage; + } else { + message = "Error: " + statusCodeName; + } + + String reason = ""; + if (Strings.isNullOrEmpty(apiEx.getReason())) { + if (apiEx.getStatusCode() != null) { + reason = apiEx.getStatusCode().getCode().name(); + } + } + // It'd be better to use ExceptionData and BaseServiceException#(ExceptionData) but, + // BaseHttpServiceException does not pass that through so we're stuck using this for now. + // TODO: When we can break the coupling to BaseHttpServiceException replace this + return new DatastoreException(datastoreStatusCode, message, reason, apiEx); + } + + private static String getStatusExceptionMessage(Exception apiEx) { + if (apiEx.getMessage() != null) { + return apiEx.getMessage(); + } else { + Throwable cause = apiEx.getCause(); + if (cause instanceof StatusRuntimeException || cause instanceof StatusException) { + return cause.getMessage(); + } + return null; + } } /** diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreFactory.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreFactory.java index 1b443066d..54274e7bb 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreFactory.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreFactory.java @@ -16,7 +16,9 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.ServiceFactory; /** An interface for Datastore factories. */ +@InternalExtensionOnly public interface DatastoreFactory extends ServiceFactory {} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java index a3bfb3796..ee0057f02 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java @@ -50,9 +50,12 @@ import java.util.Optional; import java.util.Set; import java.util.concurrent.Callable; +import java.util.logging.Level; +import java.util.logging.Logger; final class DatastoreImpl extends BaseService implements Datastore { + Logger logger = Logger.getLogger(Datastore.class.getName()); private final DatastoreRpc datastoreRpc; private final RetrySettings retrySettings; private static final ExceptionHandler TRANSACTION_EXCEPTION_HANDLER = @@ -92,6 +95,20 @@ public Transaction newTransaction() { return new TransactionImpl(this); } + @Override + public void close() throws Exception { + try { + datastoreRpc.close(); + } catch (Exception e) { + logger.log(Level.WARNING, "Failed to close channels", e); + } + } + + @Override + public boolean isClosed() { + return datastoreRpc.isClosed(); + } + static class ReadWriteTransactionCallable implements Callable { private final Datastore datastore; diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java index 8437c3e22..7e5192b52 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOptions.java @@ -18,16 +18,24 @@ import static com.google.cloud.datastore.Validator.validateNamespace; +import com.google.api.core.BetaApi; +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.rpc.TransportChannelProvider; import com.google.cloud.ServiceDefaults; import com.google.cloud.ServiceOptions; import com.google.cloud.ServiceRpc; import com.google.cloud.TransportOptions; import com.google.cloud.datastore.spi.DatastoreRpcFactory; import com.google.cloud.datastore.spi.v1.DatastoreRpc; +import com.google.cloud.datastore.spi.v1.GrpcDatastoreRpc; import com.google.cloud.datastore.spi.v1.HttpDatastoreRpc; +import com.google.cloud.datastore.v1.DatastoreSettings; +import com.google.cloud.grpc.GrpcTransportOptions; import com.google.cloud.http.HttpTransportOptions; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; +import java.io.IOException; import java.lang.reflect.Method; import java.util.Objects; import java.util.Set; @@ -39,6 +47,11 @@ public class DatastoreOptions extends ServiceOptions SCOPES = ImmutableSet.of(DATASTORE_SCOPE); private static final String DEFAULT_DATABASE_ID = ""; + public static final String PROJECT_ID_ENV_VAR = "DATASTORE_PROJECT_ID"; + public static final String LOCAL_HOST_ENV_VAR = "DATASTORE_EMULATOR_HOST"; + + private transient TransportChannelProvider channelProvider = null; + private transient CredentialsProvider credentialsProvider = null; private final String namespace; private final String databaseId; @@ -59,7 +72,15 @@ public static class DefaultDatastoreRpcFactory implements DatastoreRpcFactory { @Override public ServiceRpc create(DatastoreOptions options) { - return new HttpDatastoreRpc(options); + try { + if (options.getTransportOptions() instanceof GrpcTransportOptions) { + return new GrpcDatastoreRpc(options); + } else { + return new HttpDatastoreRpc(options); + } + } catch (IOException e) { + throw new RuntimeException(e); + } } } @@ -67,13 +88,19 @@ public static class Builder extends ServiceOptions.Builder { + private final TransportOptions TRANSPORT_OPTIONS = getDefaultTransportOptionsBuilder().build(); @Override public DatastoreFactory getDefaultServiceFactory() { @@ -140,7 +236,11 @@ public DatastoreRpcFactory getDefaultRpcFactory() { @Override public TransportOptions getDefaultTransportOptions() { - return getDefaultHttpTransportOptions(); + return TRANSPORT_OPTIONS; + } + + public static HttpTransportOptions.Builder getDefaultTransportOptionsBuilder() { + return HttpTransportOptions.newBuilder(); } } @@ -148,6 +248,10 @@ public static HttpTransportOptions getDefaultHttpTransportOptions() { return HttpTransportOptions.newBuilder().build(); } + public static GrpcTransportOptions getDefaultGrpcTransportOptions() { + return GrpcTransportOptions.newBuilder().build(); + } + /** Returns the default namespace to be used by the datastore service. */ public String getNamespace() { return namespace; diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReader.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReader.java index 8aef7f5c0..c3137a9a7 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReader.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReader.java @@ -17,11 +17,13 @@ package com.google.cloud.datastore; import com.google.api.core.BetaApi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.datastore.models.ExplainOptions; import java.util.Iterator; import java.util.List; /** An interface to represent Google Cloud Datastore read operations. */ +@InternalExtensionOnly public interface DatastoreReader { /** @@ -61,9 +63,7 @@ public interface DatastoreReader { * * @throws DatastoreException upon failure */ - default AggregationResults runAggregation(AggregationQuery query) { - throw new UnsupportedOperationException("Not implemented."); - } + AggregationResults runAggregation(AggregationQuery query); /** * Submits a {@link AggregationQuery} with a specified {@link @@ -72,7 +72,5 @@ default AggregationResults runAggregation(AggregationQuery query) { * @throws DatastoreException upon failure */ @BetaApi - default AggregationResults runAggregation(AggregationQuery query, ExplainOptions explainOptions) { - throw new UnsupportedOperationException("Not implemented."); - } + AggregationResults runAggregation(AggregationQuery query, ExplainOptions explainOptions); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReaderWriter.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReaderWriter.java index a51a5aa77..bc8700c70 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReaderWriter.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreReaderWriter.java @@ -16,5 +16,8 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; + /** An interface that combines both Google Cloud Datastore read and write operations. */ +@InternalExtensionOnly public interface DatastoreReaderWriter extends DatastoreReader, DatastoreWriter {} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java new file mode 100644 index 000000000..7ca92872f --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreUtils.java @@ -0,0 +1,56 @@ +/* + * Copyright 2023 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 + * + * http://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; + +import com.google.api.core.InternalApi; +import com.google.cloud.NoCredentials; +import com.google.common.base.Strings; +import java.net.InetAddress; +import java.net.URL; + +@InternalApi +public class DatastoreUtils { + + public static boolean isEmulator(DatastoreOptions datastoreOptions) { + return isLocalHost(datastoreOptions.getHost()) + || NoCredentials.getInstance().equals(datastoreOptions.getCredentials()); + } + + public static boolean isLocalHost(String host) { + if (Strings.isNullOrEmpty(host)) { + return false; + } + try { + String normalizedHost = "http://" + removeScheme(host); + InetAddress hostAddr = InetAddress.getByName(new URL(normalizedHost).getHost()); + return hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static String removeScheme(String url) { + if (url != null) { + if (url.startsWith("https://")) { + return url.substring("https://".length()); + } else if (url.startsWith("http://")) { + return url.substring("http://".length()); + } + } + return url; + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreWriter.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreWriter.java index 6c1d6fdbc..b414995e6 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreWriter.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreWriter.java @@ -16,9 +16,11 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; import java.util.List; /** An interface to represent Google Cloud Datastore write operations. */ +@InternalExtensionOnly public interface DatastoreWriter { /** diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslation.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslation.java new file mode 100644 index 000000000..1d63fb19a --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslation.java @@ -0,0 +1,93 @@ +/* + * Copyright 2024 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 + * + * http://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; + +import com.google.api.gax.grpc.GrpcStatusCode; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.rpc.Code; +import io.grpc.Status; +import java.util.Map; +import java.util.function.Function; + +final class GrpcToDatastoreCodeTranslation { + /** Mappings between gRPC status codes and their corresponding code numbers. */ + private static final ImmutableList STATUS_CODE_MAPPINGS = + ImmutableList.of( + StatusCodeMapping.of(Code.OK.getNumber(), Status.Code.OK), + StatusCodeMapping.of(Code.DATA_LOSS.getNumber(), Status.Code.DATA_LOSS), + StatusCodeMapping.of(Code.INVALID_ARGUMENT.getNumber(), Status.Code.INVALID_ARGUMENT), + StatusCodeMapping.of(Code.OUT_OF_RANGE.getNumber(), Status.Code.OUT_OF_RANGE), + StatusCodeMapping.of(Code.UNAUTHENTICATED.getNumber(), Status.Code.UNAUTHENTICATED), + StatusCodeMapping.of(Code.PERMISSION_DENIED.getNumber(), Status.Code.PERMISSION_DENIED), + StatusCodeMapping.of(Code.NOT_FOUND.getNumber(), Status.Code.NOT_FOUND), + StatusCodeMapping.of(Code.ALREADY_EXISTS.getNumber(), Status.Code.ALREADY_EXISTS), + StatusCodeMapping.of( + Code.FAILED_PRECONDITION.getNumber(), Status.Code.FAILED_PRECONDITION), + StatusCodeMapping.of(Code.RESOURCE_EXHAUSTED.getNumber(), Status.Code.RESOURCE_EXHAUSTED), + StatusCodeMapping.of(Code.INTERNAL.getNumber(), Status.Code.INTERNAL), + StatusCodeMapping.of(Code.UNIMPLEMENTED.getNumber(), Status.Code.UNIMPLEMENTED), + StatusCodeMapping.of(Code.UNAVAILABLE.getNumber(), Status.Code.UNAVAILABLE), + StatusCodeMapping.of(Code.DEADLINE_EXCEEDED.getNumber(), Status.Code.DEADLINE_EXCEEDED), + StatusCodeMapping.of(Code.ABORTED.getNumber(), Status.Code.ABORTED), + StatusCodeMapping.of(Code.CANCELLED.getNumber(), Status.Code.CANCELLED), + StatusCodeMapping.of(Code.UNKNOWN.getNumber(), Status.Code.UNKNOWN)); + + /** Index our {@link StatusCodeMapping} for constant time lookup by {@link Status.Code} */ + private static final Map GRPC_CODE_INDEX = + STATUS_CODE_MAPPINGS.stream() + .collect( + ImmutableMap.toImmutableMap(StatusCodeMapping::getGrpcCode, Function.identity())); + + static int grpcCodeToDatastoreStatusCode(Status.Code code) { + StatusCodeMapping found = GRPC_CODE_INDEX.get(code); + // theoretically it's possible for gRPC to add a new code we haven't mapped here, if this + // happens fall through to our default of 0 + if (found != null) { + return found.getDatastoreCode(); + } else { + return 0; + } + } + + /** + * Simple tuple class to bind together our corresponding http status code and {@link Status.Code} + * while providing easy access to the correct {@link GrpcStatusCode} where necessary. + */ + private static final class StatusCodeMapping { + + private final int datastoreCode; + + private final Status.Code grpcCode; + + private StatusCodeMapping(int datastoreCode, Status.Code grpcCode) { + this.datastoreCode = datastoreCode; + this.grpcCode = grpcCode; + } + + public int getDatastoreCode() { + return datastoreCode; + } + + public Status.Code getGrpcCode() { + return grpcCode; + } + + static StatusCodeMapping of(int datastoreCode, Status.Code grpcCode) { + return new StatusCodeMapping(datastoreCode, grpcCode); + } + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java index 50433a6a9..ca5b240ad 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java @@ -17,6 +17,7 @@ package com.google.cloud.datastore; import com.google.api.core.BetaApi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.datastore.models.ExplainMetrics; import com.google.datastore.v1.QueryResultBatch; import java.util.Iterator; @@ -31,6 +32,7 @@ * * @param the type of the results value. */ +@InternalExtensionOnly public interface QueryResults extends Iterator { /** Returns the actual class of the result's values. */ @@ -75,7 +77,5 @@ public interface QueryResults extends Iterator { QueryResultBatch.MoreResultsType getMoreResults(); @BetaApi - default Optional getExplainMetrics() { - throw new UnsupportedOperationException("Not implemented."); - } + Optional getExplainMetrics(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RetryAndTraceDatastoreRpcDecorator.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RetryAndTraceDatastoreRpcDecorator.java index c4a85caab..920fb440f 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RetryAndTraceDatastoreRpcDecorator.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RetryAndTraceDatastoreRpcDecorator.java @@ -109,6 +109,16 @@ public RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryReques () -> datastoreRpc.runAggregationQuery(request), SPAN_NAME_RUN_AGGREGATION_QUERY); } + @Override + public void close() throws Exception { + datastoreRpc.close(); + } + + @Override + public boolean isClosed() { + return datastoreRpc.isClosed(); + } + public O invokeRpc(Callable block, String startSpan) { Span span = traceUtil.startSpan(startSpan); try (Scope scope = traceUtil.getTracer().withSpan(span)) { diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java index 30cd05759..5bde80ed6 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java @@ -27,6 +27,7 @@ import com.google.api.core.ApiFunction; import com.google.api.core.InternalApi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.StringEnumType; import com.google.cloud.StringEnumValue; import com.google.cloud.Timestamp; @@ -700,6 +701,7 @@ public String toString() { * * @param the type of result the query returns. */ + @InternalExtensionOnly public interface Builder { /** Sets the namespace for the query. */ diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java index 57525d15d..876a871a2 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java @@ -16,14 +16,14 @@ package com.google.cloud.datastore; -import com.google.cloud.datastore.spi.v1.HttpDatastoreRpc; +import com.google.cloud.datastore.spi.v1.DatastoreRpc; import io.opencensus.trace.EndSpanOptions; import io.opencensus.trace.Span; import io.opencensus.trace.Tracer; import io.opencensus.trace.Tracing; /** - * Helper class for tracing utility. It is used for instrumenting {@link HttpDatastoreRpc} with + * Helper class for tracing utility. It is used for instrumenting {@link DatastoreRpc} with * OpenCensus APIs. * *

TraceUtil instances are created by the {@link TraceUtil#getInstance()} method. diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java index 7b6a67a2d..697e7a6ff 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java @@ -17,6 +17,7 @@ package com.google.cloud.datastore; import com.google.api.core.BetaApi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.datastore.models.ExplainOptions; import com.google.protobuf.ByteString; import java.util.Iterator; @@ -63,6 +64,7 @@ * This class too should not be treated as a thread safe class. */ @NotThreadSafe +@InternalExtensionOnly public interface Transaction extends DatastoreBatchWriter, DatastoreReaderWriter { interface Response { @@ -179,9 +181,7 @@ interface Response { QueryResults run(Query query); @BetaApi - default QueryResults run(Query query, ExplainOptions explainOptions) { - throw new UnsupportedOperationException("Not implemented."); - } + QueryResults run(Query query, ExplainOptions explainOptions); /** * Datastore add operation. This method will also allocate id for any entity with an incomplete diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java index 3c60ef409..315728147 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java @@ -16,6 +16,7 @@ package com.google.cloud.datastore; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.GcpLaunchStage; /** @@ -25,6 +26,7 @@ * @param

the value type. * @param the value type's associated builder. */ +@InternalExtensionOnly public interface ValueBuilder, B extends ValueBuilder> { ValueType getValueType(); diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/aggregation/AggregationBuilder.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/aggregation/AggregationBuilder.java index ce23edcf0..632f44393 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/aggregation/AggregationBuilder.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/aggregation/AggregationBuilder.java @@ -16,6 +16,8 @@ package com.google.cloud.datastore.aggregation; +import com.google.api.core.InternalExtensionOnly; + /** * An interface to represent the builders which build and customize {@link Aggregation} for {@link * com.google.cloud.datastore.AggregationQuery}. @@ -23,6 +25,7 @@ *

Used by {@link * com.google.cloud.datastore.AggregationQuery.Builder#addAggregation(AggregationBuilder)}. */ +@InternalExtensionOnly public interface AggregationBuilder { A build(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/DatastoreRpcFactory.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/DatastoreRpcFactory.java index 0b7f9094b..acb85a61d 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/DatastoreRpcFactory.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/DatastoreRpcFactory.java @@ -16,6 +16,7 @@ package com.google.cloud.datastore.spi; +import com.google.api.core.InternalExtensionOnly; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.spi.ServiceRpcFactory; @@ -23,4 +24,5 @@ * An interface for Datastore RPC factory. Implementation will be loaded via {@link * java.util.ServiceLoader}. */ +@InternalExtensionOnly public interface DatastoreRpcFactory extends ServiceRpcFactory {} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/DatastoreRpc.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/DatastoreRpc.java index 33b8e11ea..518bea983 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/DatastoreRpc.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/DatastoreRpc.java @@ -16,8 +16,11 @@ package com.google.cloud.datastore.spi.v1; +import com.google.api.core.InternalExtensionOnly; +import com.google.api.gax.rpc.HeaderProvider; import com.google.cloud.ServiceRpc; import com.google.cloud.datastore.DatastoreException; +import com.google.cloud.datastore.v1.DatastoreSettings; import com.google.datastore.v1.AllocateIdsRequest; import com.google.datastore.v1.AllocateIdsResponse; import com.google.datastore.v1.BeginTransactionRequest; @@ -36,7 +39,8 @@ import com.google.datastore.v1.RunQueryResponse; /** Provides access to the remote Datastore service. */ -public interface DatastoreRpc extends ServiceRpc { +@InternalExtensionOnly +public interface DatastoreRpc extends ServiceRpc, AutoCloseable { /** * Sends an allocate IDs request. @@ -93,7 +97,23 @@ BeginTransactionResponse beginTransaction(BeginTransactionRequest request) * * @throws DatastoreException upon failure */ - default RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryRequest request) { - throw new UnsupportedOperationException("Not implemented."); + RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryRequest request); + + @Override + void close() throws Exception; + /** Returns true if this background resource has been shut down. */ + boolean isClosed(); + + // This class is needed solely to get access to protected method setInternalHeaderProvider() + class DatastoreSettingsBuilder extends DatastoreSettings.Builder { + DatastoreSettingsBuilder(DatastoreSettings settings) { + super(settings); + } + + @Override + protected DatastoreSettings.Builder setInternalHeaderProvider( + HeaderProvider internalHeaderProvider) { + return super.setInternalHeaderProvider(internalHeaderProvider); + } } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java new file mode 100644 index 000000000..3d9aebc68 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/GrpcDatastoreRpc.java @@ -0,0 +1,189 @@ +/* + * Copyright 2023 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 + * + * http://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.spi.v1; + +import static com.google.cloud.datastore.DatastoreUtils.isEmulator; +import static com.google.cloud.datastore.DatastoreUtils.removeScheme; +import static com.google.cloud.datastore.spi.v1.RpcUtils.retrySettingSetter; +import static java.util.concurrent.TimeUnit.SECONDS; + +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.GaxProperties; +import com.google.api.gax.grpc.GrpcCallContext; +import com.google.api.gax.grpc.GrpcTransportChannel; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.HeaderProvider; +import com.google.api.gax.rpc.NoHeaderProvider; +import com.google.api.gax.rpc.TransportChannel; +import com.google.cloud.ServiceOptions; +import com.google.cloud.datastore.DatastoreException; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.v1.DatastoreSettings; +import com.google.cloud.datastore.v1.stub.DatastoreStubSettings; +import com.google.cloud.datastore.v1.stub.GrpcDatastoreStub; +import com.google.common.base.Strings; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import io.grpc.CallOptions; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import java.io.IOException; +import java.util.Collections; + +@InternalApi +public class GrpcDatastoreRpc implements DatastoreRpc { + + private final GrpcDatastoreStub datastoreStub; + private final ClientContext clientContext; + private boolean closed; + + public GrpcDatastoreRpc(DatastoreOptions datastoreOptions) throws IOException { + try { + clientContext = + isEmulator(datastoreOptions) + ? getClientContextForEmulator(datastoreOptions) + : getClientContext(datastoreOptions); + + DatastoreStubSettings datastoreStubSettings = + DatastoreStubSettings.newBuilder(clientContext) + .applyToAllUnaryMethods(retrySettingSetter(datastoreOptions)) + .build(); + datastoreStub = GrpcDatastoreStub.create(datastoreStubSettings); + } catch (IOException e) { + throw new IOException(e); + } + } + + @Override + public void close() throws Exception { + if (!closed) { + datastoreStub.close(); + for (BackgroundResource resource : clientContext.getBackgroundResources()) { + resource.close(); + } + closed = true; + } + for (BackgroundResource resource : clientContext.getBackgroundResources()) { + resource.awaitTermination(1, SECONDS); + } + } + + @Override + public AllocateIdsResponse allocateIds(AllocateIdsRequest request) { + return datastoreStub.allocateIdsCallable().call(request); + } + + @Override + public BeginTransactionResponse beginTransaction(BeginTransactionRequest request) + throws DatastoreException { + return datastoreStub.beginTransactionCallable().call(request); + } + + @Override + public CommitResponse commit(CommitRequest request) { + return datastoreStub.commitCallable().call(request); + } + + @Override + public LookupResponse lookup(LookupRequest request) { + return datastoreStub.lookupCallable().call(request); + } + + @Override + public ReserveIdsResponse reserveIds(ReserveIdsRequest request) { + return datastoreStub.reserveIdsCallable().call(request); + } + + @Override + public RollbackResponse rollback(RollbackRequest request) { + return datastoreStub.rollbackCallable().call(request); + } + + @Override + public RunQueryResponse runQuery(RunQueryRequest request) { + return datastoreStub.runQueryCallable().call(request); + } + + @Override + public RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryRequest request) { + return datastoreStub.runAggregationQueryCallable().call(request); + } + + @Override + public boolean isClosed() { + return closed && datastoreStub.isShutdown(); + } + + private ClientContext getClientContextForEmulator(DatastoreOptions datastoreOptions) + throws IOException { + ManagedChannel managedChannel = + ManagedChannelBuilder.forTarget(removeScheme(datastoreOptions.getHost())) + .usePlaintext() + .build(); + TransportChannel transportChannel = GrpcTransportChannel.create(managedChannel); + return ClientContext.newBuilder() + .setCredentials(null) + .setTransportChannel(transportChannel) + .setDefaultCallContext(GrpcCallContext.of(managedChannel, CallOptions.DEFAULT)) + .setBackgroundResources(Collections.singletonList(transportChannel)) + .build(); + } + + private ClientContext getClientContext(DatastoreOptions datastoreOptions) throws IOException { + HeaderProvider internalHeaderProvider = + DatastoreSettings.defaultApiClientHeaderProviderBuilder() + .setClientLibToken( + ServiceOptions.getGoogApiClientLibName(), + GaxProperties.getLibraryVersion(datastoreOptions.getClass())) + .setResourceToken(getResourceToken(datastoreOptions)) + .build(); + + DatastoreSettingsBuilder settingsBuilder = + new DatastoreSettingsBuilder(DatastoreSettings.newBuilder().build()); + settingsBuilder.setCredentialsProvider(datastoreOptions.getCredentialsProvider()); + settingsBuilder.setTransportChannelProvider(datastoreOptions.getTransportChannelProvider()); + settingsBuilder.setInternalHeaderProvider(internalHeaderProvider); + settingsBuilder.setHeaderProvider( + datastoreOptions.getMergedHeaderProvider(new NoHeaderProvider())); + return ClientContext.create(settingsBuilder.build()); + } + + private String getResourceToken(DatastoreOptions datastoreOptions) { + StringBuilder builder = new StringBuilder("project_id="); + builder.append(datastoreOptions.getProjectId()); + if (!Strings.isNullOrEmpty(datastoreOptions.getDatabaseId())) { + builder.append("&database_id="); + builder.append(datastoreOptions.getDatabaseId()); + } + return builder.toString(); + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java index fd3cdc658..0bc29af76 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/HttpDatastoreRpc.java @@ -19,6 +19,7 @@ import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpTransport; +import com.google.api.core.InternalApi; import com.google.cloud.datastore.DatastoreException; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.datastore.TraceUtil; @@ -44,6 +45,7 @@ import java.net.InetAddress; import java.net.URL; +@InternalApi public class HttpDatastoreRpc implements DatastoreRpc { private final com.google.datastore.v1.client.Datastore client; @@ -58,6 +60,7 @@ public HttpDatastoreRpc(DatastoreOptions options) { .initializer(getHttpRequestInitializer(options, httpTransportOptions)) .transport(transport); String normalizedHost = options.getHost() != null ? options.getHost().toLowerCase() : ""; + if (isLocalHost(normalizedHost)) { clientBuilder = clientBuilder.localHost(removeScheme(normalizedHost)); } else if (!removeScheme(com.google.datastore.v1.client.DatastoreFactory.DEFAULT_HOST) @@ -211,4 +214,14 @@ public RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryReques throw translate(ex); } } + + @Override + public void close() throws Exception { + throw new UnsupportedOperationException("Not implemented."); + } + + @Override + public boolean isClosed() { + throw new UnsupportedOperationException("Not implemented."); + } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/RpcUtils.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/RpcUtils.java new file mode 100644 index 000000000..dee8d6920 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/spi/v1/RpcUtils.java @@ -0,0 +1,34 @@ +/* + * Copyright 2023 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 + * + * http://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.spi.v1; + +import com.google.api.core.ApiFunction; +import com.google.api.core.InternalApi; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.datastore.DatastoreOptions; + +@InternalApi +public class RpcUtils { + @InternalApi + static ApiFunction, Void> retrySettingSetter( + DatastoreOptions datastoreOptions) { + return builder -> { + builder.setRetrySettings(datastoreOptions.getRetrySettings()); + return null; + }; + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java index 2723325ee..927a6cf23 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java @@ -57,7 +57,7 @@ public class LocalDatastoreHelper extends BaseEmulatorHelper { private static final String GCLOUD_CMD_TEXT = "gcloud beta emulators datastore start"; private static final String GCLOUD_CMD_PORT_FLAG = "--host-port="; private static final String VERSION_PREFIX = "cloud-datastore-emulator "; - private static final String MIN_VERSION = "2.0.2"; + private static final String MIN_VERSION = "2.0.2"; // latest version compatible with java 8 // Downloadable emulator settings private static final String BIN_NAME = "cloud-datastore-emulator/cloud_datastore_emulator"; diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java index 596ce96d8..1471328ff 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java @@ -18,12 +18,14 @@ import com.google.api.core.InternalApi; import com.google.api.gax.retrying.RetrySettings; +import com.google.cloud.TransportOptions; import com.google.cloud.datastore.Datastore; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.datastore.Key; import com.google.cloud.datastore.Query; import com.google.cloud.datastore.QueryResults; import com.google.cloud.datastore.StructuredQuery; +import com.google.cloud.grpc.GrpcTransportOptions; import com.google.cloud.http.HttpTransportOptions; import java.util.UUID; import org.threeten.bp.Duration; @@ -74,21 +76,30 @@ public void deleteNamespace() { /** Creates a {@code RemoteStorageHelper} object. */ public static RemoteDatastoreHelper create() { - return create(""); + return create("", DatastoreOptions.getDefaultHttpTransportOptions()); } - /** Creates a {@code RemoteStorageHelper} object. */ public static RemoteDatastoreHelper create(String databaseId) { - HttpTransportOptions transportOptions = DatastoreOptions.getDefaultHttpTransportOptions(); - transportOptions = - transportOptions.toBuilder().setConnectTimeout(60000).setReadTimeout(60000).build(); - DatastoreOptions datastoreOption = + return create(databaseId, DatastoreOptions.getDefaultHttpTransportOptions()); + } + + public static RemoteDatastoreHelper create(TransportOptions transportOptions) { + return create("", transportOptions); + } + + /** Creates a {@code RemoteStorageHelper} object. */ + public static RemoteDatastoreHelper create(String databaseId, TransportOptions transportOptions) { + DatastoreOptions.Builder builder = DatastoreOptions.newBuilder() .setDatabaseId(databaseId) .setNamespace(UUID.randomUUID().toString()) - .setRetrySettings(retrySettings()) - .setTransportOptions(transportOptions) - .build(); + .setRetrySettings(retrySettings()); + if (transportOptions instanceof GrpcTransportOptions) { + builder = builder.setTransportOptions((GrpcTransportOptions) transportOptions); + } else { + builder = builder.setTransportOptions(transportOptions); + } + DatastoreOptions datastoreOption = builder.build(); return new RemoteDatastoreHelper(datastoreOption); } 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..ad988b32d --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreClient.java @@ -0,0 +1,947 @@ +/* + * Copyright 2023 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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * 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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * 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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * DatastoreSettings datastoreSettings =
+ *     DatastoreSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * DatastoreClient datastoreClient = DatastoreClient.create(datastoreSettings);
+ * }
+ * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * DatastoreSettings datastoreSettings = DatastoreSettings.newHttpJsonBuilder().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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   LookupRequest request =
+   *       LookupRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   LookupRequest request =
+   *       LookupRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunQueryRequest request =
+   *       RunQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunQueryRequest request =
+   *       RunQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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. + /** + * Runs an aggregation query. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunAggregationQueryRequest request =
+   *       RunAggregationQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .setPartitionId(PartitionId.newBuilder().build())
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .build();
+   *   RunAggregationQueryResponse response = datastoreClient.runAggregationQuery(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 RunAggregationQueryResponse runAggregationQuery(RunAggregationQueryRequest request) { + return runAggregationQueryCallable().call(request); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Runs an aggregation query. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RunAggregationQueryRequest request =
+   *       RunAggregationQueryRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .setPartitionId(PartitionId.newBuilder().build())
+   *           .setReadOptions(ReadOptions.newBuilder().build())
+   *           .build();
+   *   ApiFuture future =
+   *       datastoreClient.runAggregationQueryCallable().futureCall(request);
+   *   // Do something.
+   *   RunAggregationQueryResponse response = future.get();
+   * }
+   * }
+ */ + public final UnaryCallable + runAggregationQueryCallable() { + return stub.runAggregationQueryCallable(); + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Begins a new transaction. + * + *

Sample code: + * + *

{@code
+   * // This snippet has been automatically generated and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   BeginTransactionRequest request =
+   *       BeginTransactionRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   BeginTransactionRequest request =
+   *       BeginTransactionRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   CommitRequest request =
+   *       CommitRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   CommitRequest request =
+   *       CommitRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RollbackRequest request =
+   *       RollbackRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   RollbackRequest request =
+   *       RollbackRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   AllocateIdsRequest request =
+   *       AllocateIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * try (DatastoreClient datastoreClient = DatastoreClient.create()) {
+   *   AllocateIdsRequest request =
+   *       AllocateIdsRequest.newBuilder()
+   *           .setProjectId("projectId-894832108")
+   *           .setDatabaseId("databaseId1688905718")
+   *           .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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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 and should be regarded as a code template only.
+   * // It will require modifications to work:
+   * // - It may require correct/in-range values for request initialization.
+   * // - It may require specifying regional endpoints when creating the service client as shown in
+   * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+   * 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..22feacdce --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/DatastoreSettings.java @@ -0,0 +1,294 @@ +/* + * Copyright 2023 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.httpjson.InstantiatingHttpJsonChannelProvider; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * 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 runAggregationQuery. */ + public UnaryCallSettings + runAggregationQuerySettings() { + return ((DatastoreStubSettings) getStubSettings()).runAggregationQuerySettings(); + } + + /** 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 gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return DatastoreStubSettings.defaultGrpcTransportProviderBuilder(); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return DatastoreStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + + 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 gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** 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()); + } + + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(DatastoreStubSettings.newHttpJsonBuilder()); + } + + 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 runAggregationQuery. */ + public UnaryCallSettings.Builder + runAggregationQuerySettings() { + return getStubSettingsBuilder().runAggregationQuerySettings(); + } + + /** 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..02196d36e --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/gapic_metadata.json @@ -0,0 +1,42 @@ +{ + "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"] + }, + "RunAggregationQuery": { + "methods": ["runAggregationQuery", "runAggregationQueryCallable"] + }, + "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..2227971ca --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/package-info.java @@ -0,0 +1,49 @@ +/* + * Copyright 2023 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. + */ + +/** + * A client to Cloud Datastore API + * + *

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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * 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..3b2b170bd --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStub.java @@ -0,0 +1,84 @@ +/* + * Copyright 2023 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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 + runAggregationQueryCallable() { + throw new UnsupportedOperationException("Not implemented: runAggregationQueryCallable()"); + } + + 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..bfc622726 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/DatastoreStubSettings.java @@ -0,0 +1,518 @@ +/* + * Copyright 2023 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.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 and should be regarded as a code template only.
+ * // It will require modifications to work:
+ * // - It may require correct/in-range values for request initialization.
+ * // - It may require specifying regional endpoints when creating the service client as shown in
+ * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
+ * 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 + runAggregationQuerySettings; + 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 runAggregationQuery. */ + public UnaryCallSettings + runAggregationQuerySettings() { + return runAggregationQuerySettings; + } + + /** 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); + } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonDatastoreStub.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 gRPC ChannelProvider for this service. */ + public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { + return InstantiatingGrpcChannelProvider.newBuilder() + .setMaxInboundMessageSize(Integer.MAX_VALUE); + } + + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + + 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 defaultGrpcApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(DatastoreStubSettings.class)) + .setTransportToken( + GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); + } + + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken("gapic", GaxProperties.getLibraryVersion(DatastoreStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return DatastoreStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ + public static Builder newBuilder() { + return Builder.createDefault(); + } + + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + + /** 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(); + runAggregationQuerySettings = settingsBuilder.runAggregationQuerySettings().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 + runAggregationQuerySettings; + 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(); + runAggregationQuerySettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + beginTransactionSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + commitSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + rollbackSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + allocateIdsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + reserveIdsSettings = UnaryCallSettings.newUnaryCallSettingsBuilder(); + + unaryMethodSettingsBuilders = + ImmutableList.>of( + lookupSettings, + runQuerySettings, + runAggregationQuerySettings, + beginTransactionSettings, + commitSettings, + rollbackSettings, + allocateIdsSettings, + reserveIdsSettings); + initDefaults(this); + } + + protected Builder(DatastoreStubSettings settings) { + super(settings); + + lookupSettings = settings.lookupSettings.toBuilder(); + runQuerySettings = settings.runQuerySettings.toBuilder(); + runAggregationQuerySettings = settings.runAggregationQuerySettings.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, + runAggregationQuerySettings, + 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 createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().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 + .runAggregationQuerySettings() + .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 runAggregationQuery. */ + public UnaryCallSettings.Builder + runAggregationQuerySettings() { + return runAggregationQuerySettings; + } + + /** 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..4e640ead2 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreCallableFactory.java @@ -0,0 +1,113 @@ +/* + * Copyright 2023 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..f68e8996b --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/GrpcDatastoreStub.java @@ -0,0 +1,429 @@ +/* + * Copyright 2023 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.RequestParamsBuilder; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.pathtemplate.PathTemplate; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 + runAggregationQueryMethodDescriptor = + MethodDescriptor.newBuilder() + .setType(MethodDescriptor.MethodType.UNARY) + .setFullMethodName("google.datastore.v1.Datastore/RunAggregationQuery") + .setRequestMarshaller( + ProtoUtils.marshaller(RunAggregationQueryRequest.getDefaultInstance())) + .setResponseMarshaller( + ProtoUtils.marshaller(RunAggregationQueryResponse.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 + runAggregationQueryCallable; + 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; + + private static final PathTemplate LOOKUP_0_PATH_TEMPLATE = PathTemplate.create("{project_id=**}"); + private static final PathTemplate LOOKUP_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RUN_QUERY_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RUN_QUERY_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RUN_AGGREGATION_QUERY_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RUN_AGGREGATION_QUERY_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate BEGIN_TRANSACTION_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate BEGIN_TRANSACTION_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate COMMIT_0_PATH_TEMPLATE = PathTemplate.create("{project_id=**}"); + private static final PathTemplate COMMIT_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate ROLLBACK_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate ROLLBACK_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate ALLOCATE_IDS_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate ALLOCATE_IDS_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RESERVE_IDS_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RESERVE_IDS_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + + 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 -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", LOOKUP_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", LOOKUP_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings runQueryTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(runQueryMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", RUN_QUERY_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", RUN_QUERY_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings + runAggregationQueryTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(runAggregationQueryMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + request.getProjectId(), + "project_id", + RUN_AGGREGATION_QUERY_0_PATH_TEMPLATE); + builder.add( + request.getDatabaseId(), + "database_id", + RUN_AGGREGATION_QUERY_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings + beginTransactionTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(beginTransactionMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + request.getProjectId(), "project_id", BEGIN_TRANSACTION_0_PATH_TEMPLATE); + builder.add( + request.getDatabaseId(), + "database_id", + BEGIN_TRANSACTION_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings commitTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(commitMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", COMMIT_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", COMMIT_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings rollbackTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(rollbackMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", ROLLBACK_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", ROLLBACK_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings allocateIdsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(allocateIdsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", ALLOCATE_IDS_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", ALLOCATE_IDS_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + GrpcCallSettings reserveIdsTransportSettings = + GrpcCallSettings.newBuilder() + .setMethodDescriptor(reserveIdsMethodDescriptor) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", RESERVE_IDS_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", RESERVE_IDS_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + + this.lookupCallable = + callableFactory.createUnaryCallable( + lookupTransportSettings, settings.lookupSettings(), clientContext); + this.runQueryCallable = + callableFactory.createUnaryCallable( + runQueryTransportSettings, settings.runQuerySettings(), clientContext); + this.runAggregationQueryCallable = + callableFactory.createUnaryCallable( + runAggregationQueryTransportSettings, + settings.runAggregationQuerySettings(), + 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 + runAggregationQueryCallable() { + return runAggregationQueryCallable; + } + + @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/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreCallableFactory.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreCallableFactory.java new file mode 100644 index 000000000..8639433a7 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2023 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.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +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.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the Datastore service API. + * + *

This class is for advanced usage. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonDatastoreCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreStub.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreStub.java new file mode 100644 index 000000000..c0f1c7766 --- /dev/null +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/v1/stub/HttpJsonDatastoreStub.java @@ -0,0 +1,678 @@ +/* + * Copyright 2023 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.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; +import com.google.api.gax.httpjson.ProtoMessageResponseParser; +import com.google.api.gax.httpjson.ProtoRestSerializer; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.RequestParamsBuilder; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.api.pathtemplate.PathTemplate; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the Datastore service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@Generated("by gapic-generator-java") +@BetaApi +public class HttpJsonDatastoreStub extends DatastoreStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private static final ApiMethodDescriptor lookupMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/Lookup") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:lookup", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(LookupResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + runQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/RunQuery") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:runQuery", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RunQueryResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + runAggregationQueryMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/RunAggregationQuery") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:runAggregationQuery", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RunAggregationQueryResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + beginTransactionMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/BeginTransaction") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:beginTransaction", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(BeginTransactionResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor commitMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/Commit") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:commit", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(CommitResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + rollbackMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/Rollback") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:rollback", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(RollbackResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + allocateIdsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/AllocateIds") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:allocateIds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(AllocateIdsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private static final ApiMethodDescriptor + reserveIdsMethodDescriptor = + ApiMethodDescriptor.newBuilder() + .setFullMethodName("google.datastore.v1.Datastore/ReserveIds") + .setHttpMethod("POST") + .setType(ApiMethodDescriptor.MethodType.UNARY) + .setRequestFormatter( + ProtoMessageRequestFormatter.newBuilder() + .setPath( + "/v1/projects/{projectId}:reserveIds", + request -> { + Map fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putPathParam(fields, "projectId", request.getProjectId()); + return fields; + }) + .setQueryParamsExtractor( + request -> { + Map> fields = new HashMap<>(); + ProtoRestSerializer serializer = + ProtoRestSerializer.create(); + serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); + return fields; + }) + .setRequestBodyExtractor( + request -> + ProtoRestSerializer.create() + .toBody("*", request.toBuilder().clearProjectId().build(), true)) + .build()) + .setResponseParser( + ProtoMessageResponseParser.newBuilder() + .setDefaultInstance(ReserveIdsResponse.getDefaultInstance()) + .setDefaultTypeRegistry(typeRegistry) + .build()) + .build(); + + private final UnaryCallable lookupCallable; + private final UnaryCallable runQueryCallable; + private final UnaryCallable + runAggregationQueryCallable; + 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 HttpJsonStubCallableFactory callableFactory; + + private static final PathTemplate LOOKUP_0_PATH_TEMPLATE = PathTemplate.create("{project_id=**}"); + private static final PathTemplate LOOKUP_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RUN_QUERY_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RUN_QUERY_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RUN_AGGREGATION_QUERY_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RUN_AGGREGATION_QUERY_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate BEGIN_TRANSACTION_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate BEGIN_TRANSACTION_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate COMMIT_0_PATH_TEMPLATE = PathTemplate.create("{project_id=**}"); + private static final PathTemplate COMMIT_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate ROLLBACK_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate ROLLBACK_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate ALLOCATE_IDS_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate ALLOCATE_IDS_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + private static final PathTemplate RESERVE_IDS_0_PATH_TEMPLATE = + PathTemplate.create("{project_id=**}"); + private static final PathTemplate RESERVE_IDS_1_PATH_TEMPLATE = + PathTemplate.create("{database_id=**}"); + + public static final HttpJsonDatastoreStub create(DatastoreStubSettings settings) + throws IOException { + return new HttpJsonDatastoreStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonDatastoreStub create(ClientContext clientContext) throws IOException { + return new HttpJsonDatastoreStub( + DatastoreStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonDatastoreStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonDatastoreStub( + DatastoreStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); + } + + /** + * Constructs an instance of HttpJsonDatastoreStub, 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 HttpJsonDatastoreStub(DatastoreStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonDatastoreCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonDatastoreStub, 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 HttpJsonDatastoreStub( + DatastoreStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + HttpJsonCallSettings lookupTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(lookupMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", LOOKUP_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", LOOKUP_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings runQueryTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(runQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", RUN_QUERY_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", RUN_QUERY_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + runAggregationQueryTransportSettings = + HttpJsonCallSettings + .newBuilder() + .setMethodDescriptor(runAggregationQueryMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + request.getProjectId(), + "project_id", + RUN_AGGREGATION_QUERY_0_PATH_TEMPLATE); + builder.add( + request.getDatabaseId(), + "database_id", + RUN_AGGREGATION_QUERY_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings + beginTransactionTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(beginTransactionMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add( + request.getProjectId(), "project_id", BEGIN_TRANSACTION_0_PATH_TEMPLATE); + builder.add( + request.getDatabaseId(), + "database_id", + BEGIN_TRANSACTION_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings commitTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(commitMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", COMMIT_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", COMMIT_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings rollbackTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(rollbackMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", ROLLBACK_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", ROLLBACK_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings allocateIdsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(allocateIdsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", ALLOCATE_IDS_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", ALLOCATE_IDS_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + HttpJsonCallSettings reserveIdsTransportSettings = + HttpJsonCallSettings.newBuilder() + .setMethodDescriptor(reserveIdsMethodDescriptor) + .setTypeRegistry(typeRegistry) + .setParamsExtractor( + request -> { + RequestParamsBuilder builder = RequestParamsBuilder.create(); + builder.add(request.getProjectId(), "project_id", RESERVE_IDS_0_PATH_TEMPLATE); + builder.add(request.getDatabaseId(), "database_id", RESERVE_IDS_1_PATH_TEMPLATE); + return builder.build(); + }) + .build(); + + this.lookupCallable = + callableFactory.createUnaryCallable( + lookupTransportSettings, settings.lookupSettings(), clientContext); + this.runQueryCallable = + callableFactory.createUnaryCallable( + runQueryTransportSettings, settings.runQuerySettings(), clientContext); + this.runAggregationQueryCallable = + callableFactory.createUnaryCallable( + runAggregationQueryTransportSettings, + settings.runAggregationQuerySettings(), + 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()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + methodDescriptors.add(lookupMethodDescriptor); + methodDescriptors.add(runQueryMethodDescriptor); + methodDescriptors.add(runAggregationQueryMethodDescriptor); + methodDescriptors.add(beginTransactionMethodDescriptor); + methodDescriptors.add(commitMethodDescriptor); + methodDescriptors.add(rollbackMethodDescriptor); + methodDescriptors.add(allocateIdsMethodDescriptor); + methodDescriptors.add(reserveIdsMethodDescriptor); + return methodDescriptors; + } + + @Override + public UnaryCallable lookupCallable() { + return lookupCallable; + } + + @Override + public UnaryCallable runQueryCallable() { + return runQueryCallable; + } + + @Override + public UnaryCallable + runAggregationQueryCallable() { + return runAggregationQueryCallable; + } + + @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/main/resources/META-INF/native-image/com.google.cloud.datastore.v1/reflect-config.json b/google-cloud-datastore/src/main/resources/META-INF/native-image/com.google.cloud.datastore.v1/reflect-config.json new file mode 100644 index 000000000..b0a64366e --- /dev/null +++ b/google-cloud-datastore/src/main/resources/META-INF/native-image/com.google.cloud.datastore.v1/reflect-config.json @@ -0,0 +1,2198 @@ +[ + { + "name": "com.google.api.ClientLibraryDestination", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ClientLibraryOrganization", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ClientLibrarySettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ClientLibrarySettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CommonLanguageSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CommonLanguageSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CppSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CppSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CustomHttpPattern", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.CustomHttpPattern$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.DotnetSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.DotnetSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.FieldBehavior", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.GoSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.GoSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.Http", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.Http$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.HttpRule", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.HttpRule$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.JavaSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.JavaSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.LaunchStage", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.MethodSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.MethodSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.MethodSettings$LongRunning", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.MethodSettings$LongRunning$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.NodeSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.NodeSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.PhpSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.PhpSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.Publishing", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.Publishing$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.PythonSettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.PythonSettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceDescriptor", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceDescriptor$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceDescriptor$History", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceDescriptor$Style", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceReference", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.ResourceReference$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RoutingParameter", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RoutingParameter$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RoutingRule", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RoutingRule$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RubySettings", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.api.RubySettings$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Avg", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Avg$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Count", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Count$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Sum", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Aggregation$Sum$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationQuery$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationResult", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationResult$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationResultBatch", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AggregationResultBatch$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AllocateIdsRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AllocateIdsRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AllocateIdsResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.AllocateIdsResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ArrayValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ArrayValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.BeginTransactionRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.BeginTransactionRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.BeginTransactionResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.BeginTransactionResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CommitRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CommitRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CommitRequest$Mode", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CommitResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CommitResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CompositeFilter", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CompositeFilter$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.CompositeFilter$Operator", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Entity", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Entity$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.EntityResult", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.EntityResult$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.EntityResult$ResultType", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Filter", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Filter$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.GqlQuery", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.GqlQuery$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.GqlQueryParameter", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.GqlQueryParameter$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Key", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Key$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Key$PathElement", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Key$PathElement$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.KindExpression", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.KindExpression$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.LookupRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.LookupRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.LookupResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.LookupResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Mutation", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Mutation$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.MutationResult", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.MutationResult$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PartitionId", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PartitionId$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Projection", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Projection$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyFilter", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyFilter$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyFilter$Operator", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyOrder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyOrder$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyOrder$Direction", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyReference", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.PropertyReference$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Query", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Query$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.QueryResultBatch", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.QueryResultBatch$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.QueryResultBatch$MoreResultsType", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReadOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReadOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReadOptions$ReadConsistency", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReserveIdsRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReserveIdsRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReserveIdsResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.ReserveIdsResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RollbackRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RollbackRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RollbackResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RollbackResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunAggregationQueryRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunAggregationQueryRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunAggregationQueryResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunAggregationQueryResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunQueryRequest", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunQueryRequest$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunQueryResponse", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.RunQueryResponse$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions$ReadOnly", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions$ReadOnly$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions$ReadWrite", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.TransactionOptions$ReadWrite$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.datastore.v1.Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.BoolValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.BoolValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.BytesValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.BytesValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto$ExtensionRange", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto$ExtensionRange$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto$ReservedRange", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$DescriptorProto$ReservedRange$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumDescriptorProto$EnumReservedRange", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumDescriptorProto$EnumReservedRange$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumValueDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumValueDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumValueOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$EnumValueOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ExtensionRangeOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ExtensionRangeOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ExtensionRangeOptions$Declaration", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ExtensionRangeOptions$Declaration$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ExtensionRangeOptions$VerificationState", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Label", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Type", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions$CType", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions$JSType", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions$OptionRetention", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FieldOptions$OptionTargetType", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileDescriptorSet", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileDescriptorSet$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$FileOptions$OptimizeMode", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$GeneratedCodeInfo", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$GeneratedCodeInfo$Annotation", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$GeneratedCodeInfo$Annotation$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$GeneratedCodeInfo$Annotation$Semantic", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$GeneratedCodeInfo$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MessageOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MessageOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MethodDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MethodDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MethodOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MethodOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$MethodOptions$IdempotencyLevel", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$OneofDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$OneofDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$OneofOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$OneofOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ServiceDescriptorProto", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ServiceDescriptorProto$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ServiceOptions", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$ServiceOptions$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$SourceCodeInfo", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$SourceCodeInfo$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$SourceCodeInfo$Location", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$SourceCodeInfo$Location$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$UninterpretedOption", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$UninterpretedOption$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$UninterpretedOption$NamePart", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DescriptorProtos$UninterpretedOption$NamePart$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DoubleValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.DoubleValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Duration", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Duration$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.FloatValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.FloatValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Int32Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Int32Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Int64Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Int64Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.ListValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.ListValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.NullValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.StringValue", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.StringValue$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Struct", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Struct$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Timestamp", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Timestamp$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.UInt32Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.UInt32Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.UInt64Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.UInt64Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Value", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.protobuf.Value$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.type.LatLng", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + }, + { + "name": "com.google.type.LatLng$Builder", + "queryAllDeclaredConstructors": true, + "queryAllPublicConstructors": true, + "queryAllDeclaredMethods": true, + "allPublicMethods": true, + "allDeclaredClasses": true, + "allPublicClasses": true + } +] \ No newline at end of file diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java index 12b99c966..8c52b5519 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreExceptionTest.java @@ -97,7 +97,7 @@ public void testTranslateAndThrow() { cause = new IllegalArgumentException("message"); exceptionMock = createMock(RetryHelper.RetryHelperException.class); expect(exceptionMock.getMessage()).andReturn("message").times(1); - expect(exceptionMock.getCause()).andReturn(cause).times(2); + expect(exceptionMock.getCause()).andReturn(cause).times(4); replay(exceptionMock); try { DatastoreException.translateAndThrow(exceptionMock); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java index a545580e2..e3f48ecc9 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreOptionsTest.java @@ -16,15 +16,22 @@ package com.google.cloud.datastore; +import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import com.google.cloud.TransportOptions; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.ChannelPoolSettings; +import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.cloud.NoCredentials; import com.google.cloud.datastore.spi.DatastoreRpcFactory; import com.google.cloud.datastore.spi.v1.DatastoreRpc; +import com.google.cloud.datastore.v1.DatastoreSettings; +import com.google.cloud.grpc.GrpcTransportOptions; +import com.google.cloud.http.HttpTransportOptions; +import com.google.datastore.v1.client.DatastoreFactory; import org.easymock.EasyMock; import org.junit.Assert; import org.junit.Before; @@ -48,7 +55,9 @@ public void setUp() { .setServiceRpcFactory(datastoreRpcFactory) .setProjectId(PROJECT_ID) .setDatabaseId(DATABASE_ID) + .setCredentials(NoCredentials.getInstance()) .setHost("http://localhost:" + PORT); + EasyMock.expect(datastoreRpcFactory.create(EasyMock.anyObject(DatastoreOptions.class))) .andReturn(datastoreRpc) .anyTimes(); @@ -81,12 +90,115 @@ public void testDatastore() { assertSame(datastoreRpc, options.build().getRpc()); } + @Test + public void testCustomChannelAndCredentials() { + NoCredentialsProvider noCredentialsProvider = NoCredentialsProvider.create(); + InstantiatingGrpcChannelProvider channelProvider = + DatastoreSettings.defaultGrpcTransportProviderBuilder() + .setChannelPoolSettings( + ChannelPoolSettings.builder() + .setInitialChannelCount(10) + .setMaxChannelCount(20) + .build()) + .build(); + DatastoreOptions datastoreOptions = + DatastoreOptions.newBuilder() + .setServiceRpcFactory(datastoreRpcFactory) + .setProjectId(PROJECT_ID) + .setDatabaseId(DATABASE_ID) + .setTransportOptions(GrpcTransportOptions.newBuilder().build()) + .setChannelProvider(channelProvider) + .setCredentialsProvider(noCredentialsProvider) + .setHost("http://localhost:" + PORT) + .build(); + assertEquals(datastoreOptions.getTransportChannelProvider(), channelProvider); + assertEquals(datastoreOptions.getCredentialsProvider(), noCredentialsProvider); + } + + @Test + public void testInvalidConfigForHttp() { + DatastoreOptions.Builder options = + DatastoreOptions.newBuilder() + .setServiceRpcFactory(datastoreRpcFactory) + .setProjectId(PROJECT_ID) + .setDatabaseId(DATABASE_ID) + .setTransportOptions(HttpTransportOptions.newBuilder().build()) + .setChannelProvider( + DatastoreSettings.defaultGrpcTransportProviderBuilder() + .setChannelPoolSettings( + ChannelPoolSettings.builder() + .setInitialChannelCount(10) + .setMaxChannelCount(20) + .build()) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .setHost("http://localhost:" + PORT); + Assert.assertThrows(IllegalArgumentException.class, options::build); + } + + @Test + public void testTransport() { + // default http transport + assertThat(options.build().getTransportOptions()).isInstanceOf(HttpTransportOptions.class); + + // custom grpc transport + DatastoreOptions grpcTransportOptions = + DatastoreOptions.newBuilder() + .setTransportOptions(GrpcTransportOptions.newBuilder().build()) + .setProjectId(PROJECT_ID) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + assertThat(grpcTransportOptions.getTransportOptions()).isInstanceOf(GrpcTransportOptions.class); + assertThat(grpcTransportOptions.getCredentialsProvider()) + .isInstanceOf(NoCredentialsProvider.class); + assertThat(grpcTransportOptions.getTransportChannelProvider()) + .isInstanceOf(InstantiatingGrpcChannelProvider.class); + } + + @Test + public void testHostWithGrpcAndHttp() { + DatastoreOptions grpcTransportOptions = + DatastoreOptions.newBuilder() + .setTransportOptions(GrpcTransportOptions.newBuilder().build()) + .setProjectId(PROJECT_ID) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + assertThat(grpcTransportOptions.getHost()).isEqualTo(DatastoreSettings.getDefaultEndpoint()); + assertThat(grpcTransportOptions.getHost()).isEqualTo("datastore.googleapis.com:443"); + + String customHost = "http://localhost:" + PORT; + DatastoreOptions grpcTransportOptionsCustomHost = + DatastoreOptions.newBuilder() + .setTransportOptions(GrpcTransportOptions.newBuilder().build()) + .setHost(customHost) + .setProjectId(PROJECT_ID) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + assertThat(grpcTransportOptionsCustomHost.getHost()).isEqualTo(customHost); + + DatastoreOptions httpTransportOptions = + DatastoreOptions.newBuilder() + .setProjectId(PROJECT_ID) + .setCredentials(NoCredentials.getInstance()) + .build(); + assertThat(httpTransportOptions.getHost()).isEqualTo(DatastoreFactory.DEFAULT_HOST); + + DatastoreOptions httpTransportOptionsCustomHost = + DatastoreOptions.newBuilder() + .setHost(customHost) + .setProjectId(PROJECT_ID) + .setCredentials(NoCredentials.getInstance()) + .build(); + assertThat(httpTransportOptionsCustomHost.getHost()).isEqualTo(customHost); + } + @Test public void testToBuilder() { DatastoreOptions original = options.setNamespace("ns1").build(); DatastoreOptions copy = original.toBuilder().build(); assertEquals(original.getProjectId(), copy.getProjectId()); assertEquals(original.getNamespace(), copy.getNamespace()); + assertEquals(original.getDatabaseId(), copy.getDatabaseId()); assertEquals(original.getHost(), copy.getHost()); assertEquals(original.getRetrySettings(), copy.getRetrySettings()); assertEquals(original.getCredentials(), copy.getCredentials()); @@ -97,15 +209,4 @@ public void testToBuilder() { assertNotEquals(original, newOptions); assertNotEquals(original.hashCode(), newOptions.hashCode()); } - - @Test - public void testInvalidTransport() { - try { - DatastoreOptions.newBuilder() - .setTransportOptions(EasyMock.createMock(TransportOptions.class)); - Assert.fail(); - } catch (IllegalArgumentException ex) { - assertNotNull(ex.getMessage()); - } - } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java index cd768f986..184712443 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java @@ -77,7 +77,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.TimeoutException; import java.util.function.Predicate; import org.easymock.EasyMock; import org.junit.AfterClass; @@ -92,9 +91,9 @@ @RunWith(JUnit4.class) public class DatastoreTest { - private static LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0); - private static final DatastoreOptions options = helper.getOptions(); - private static final Datastore datastore = options.getService(); + private static final LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0, 9090); + private static DatastoreOptions options = helper.getOptions(); + private static Datastore datastore; private static final String PROJECT_ID = options.getProjectId(); private static final String KIND1 = "kind1"; private static final String KIND2 = "kind2"; @@ -170,6 +169,8 @@ public class DatastoreTest { @BeforeClass public static void beforeClass() throws IOException, InterruptedException { helper.start(); + options = helper.getOptions(); + datastore = options.getService(); } @Before @@ -190,7 +191,8 @@ public void setUp() { } @AfterClass - public static void afterClass() throws IOException, InterruptedException, TimeoutException { + public static void afterClass() throws Exception { + datastore.close(); helper.stop(Duration.ofMinutes(1)); } @@ -648,6 +650,7 @@ private List buildResponsesForQueryPagination() { List responses = new ArrayList<>(); RecordQuery query = Query.newKeyQueryBuilder().build(); RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder(); + requestPb.setProjectId(PROJECT_ID); query.populatePb(requestPb); QueryResultBatch queryResultBatchPb = RunQueryResponse.newBuilder() @@ -757,6 +760,7 @@ private List buildResponsesForQueryPaginationWithLimit() { List responses = new ArrayList<>(); RecordQuery query = Query.newEntityQueryBuilder().build(); RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder(); + requestPb.setProjectId(PROJECT_ID); query.populatePb(requestPb); QueryResultBatch queryResultBatchPb = RunQueryResponse.newBuilder() diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreUtilsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreUtilsTest.java new file mode 100644 index 000000000..9a5855d30 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreUtilsTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2023 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 + * + * http://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; + +import static com.google.cloud.datastore.DatastoreUtils.isLocalHost; +import static com.google.cloud.datastore.DatastoreUtils.removeScheme; +import static com.google.common.truth.Truth.assertThat; + +import org.junit.Test; + +public class DatastoreUtilsTest { + + @Test + public void testIsLocalHost() { + assertThat(isLocalHost(null)).isFalse(); + assertThat(isLocalHost("")).isFalse(); + assertThat(isLocalHost("http://localhost:9090")).isTrue(); + assertThat(isLocalHost("https://localhost:9090")).isTrue(); + assertThat(isLocalHost("10.10.10.10:9090")).isFalse(); + } + + @Test + public void testRemoveScheme() { + assertThat(removeScheme("http://localhost:9090")).isEqualTo("localhost:9090"); + assertThat(removeScheme("https://localhost:9090")).isEqualTo("localhost:9090"); + assertThat(removeScheme("https://localhost:9090")).isEqualTo("localhost:9090"); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslationTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslationTest.java new file mode 100644 index 000000000..3f297989f --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/GrpcToDatastoreCodeTranslationTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 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 + * + * http://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; + +import static com.google.common.truth.Truth.assertThat; + +import io.grpc.Status.Code; +import java.util.EnumMap; +import org.junit.Test; + +public class GrpcToDatastoreCodeTranslationTest { + @Test + public void grpcCodeToDatastoreCode_expectedMapping() { + EnumMap expected = new EnumMap<>(Code.class); + expected.put(Code.OK, com.google.rpc.Code.OK.getNumber()); + expected.put(Code.INVALID_ARGUMENT, com.google.rpc.Code.INVALID_ARGUMENT.getNumber()); + expected.put(Code.OUT_OF_RANGE, com.google.rpc.Code.OUT_OF_RANGE.getNumber()); + expected.put(Code.UNAUTHENTICATED, com.google.rpc.Code.UNAUTHENTICATED.getNumber()); + expected.put(Code.PERMISSION_DENIED, com.google.rpc.Code.PERMISSION_DENIED.getNumber()); + expected.put(Code.NOT_FOUND, com.google.rpc.Code.NOT_FOUND.getNumber()); + expected.put(Code.FAILED_PRECONDITION, com.google.rpc.Code.FAILED_PRECONDITION.getNumber()); + expected.put(Code.ALREADY_EXISTS, com.google.rpc.Code.ALREADY_EXISTS.getNumber()); + expected.put(Code.RESOURCE_EXHAUSTED, com.google.rpc.Code.RESOURCE_EXHAUSTED.getNumber()); + expected.put(Code.INTERNAL, com.google.rpc.Code.INTERNAL.getNumber()); + expected.put(Code.UNIMPLEMENTED, com.google.rpc.Code.UNIMPLEMENTED.getNumber()); + expected.put(Code.UNAVAILABLE, com.google.rpc.Code.UNAVAILABLE.getNumber()); + expected.put(Code.ABORTED, com.google.rpc.Code.ABORTED.getNumber()); + expected.put(Code.CANCELLED, com.google.rpc.Code.CANCELLED.getNumber()); + expected.put(Code.UNKNOWN, com.google.rpc.Code.UNKNOWN.getNumber()); + expected.put(Code.DEADLINE_EXCEEDED, com.google.rpc.Code.DEADLINE_EXCEEDED.getNumber()); + expected.put(Code.DATA_LOSS, com.google.rpc.Code.DATA_LOSS.getNumber()); + + EnumMap actual = new EnumMap<>(Code.class); + for (Code c : Code.values()) { + actual.put(c, GrpcToDatastoreCodeTranslation.grpcCodeToDatastoreStatusCode(c)); + } + + assertThat(actual).isEqualTo(expected); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/AbstractITDatastoreTest.java similarity index 96% rename from google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java rename to google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/AbstractITDatastoreTest.java index 09dcd2116..c25e87f2f 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/AbstractITDatastoreTest.java @@ -16,6 +16,11 @@ package com.google.cloud.datastore.it; +import static com.google.api.gax.rpc.StatusCode.Code.ALREADY_EXISTS; +import static com.google.api.gax.rpc.StatusCode.Code.DEADLINE_EXCEEDED; +import static com.google.api.gax.rpc.StatusCode.Code.FAILED_PRECONDITION; +import static com.google.api.gax.rpc.StatusCode.Code.INVALID_ARGUMENT; +import static com.google.api.gax.rpc.StatusCode.Code.NOT_FOUND; import static com.google.cloud.datastore.aggregation.Aggregation.avg; import static com.google.cloud.datastore.aggregation.Aggregation.count; import static com.google.cloud.datastore.aggregation.Aggregation.sum; @@ -27,8 +32,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import com.google.cloud.Timestamp; import com.google.cloud.Tuple; @@ -74,7 +79,6 @@ import com.google.cloud.datastore.models.ExplainMetrics; import com.google.cloud.datastore.models.ExplainOptions; import com.google.cloud.datastore.models.PlanSummary; -import com.google.cloud.datastore.testing.RemoteDatastoreHelper; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Range; @@ -82,7 +86,6 @@ import com.google.datastore.v1.TransactionOptions; import com.google.datastore.v1.TransactionOptions.ReadOnly; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -96,7 +99,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -106,25 +108,18 @@ import org.threeten.bp.Duration; @RunWith(Parameterized.class) -public class ITDatastoreTest { +public abstract class AbstractITDatastoreTest { + protected static final String CUSTOM_DB_ID = "test-db"; - private static final RemoteDatastoreHelper HELPER = RemoteDatastoreHelper.create(); - private static final DatastoreOptions OPTIONS_1 = HELPER.getOptions(); - private static final Datastore DATASTORE_1 = OPTIONS_1.getService(); - - private static final String CUSTOM_DB_ID = "test-db"; - private static final RemoteDatastoreHelper HELPER2 = RemoteDatastoreHelper.create(CUSTOM_DB_ID); - private static final DatastoreOptions OPTIONS_2 = HELPER2.getOptions(); - private static final Datastore DATASTORE_2 = OPTIONS_2.getService(); - - private final DatastoreOptions options; - private final Datastore datastore; + protected DatastoreOptions options; + protected Datastore datastore; private static String PROJECT_ID; private static String NAMESPACE; private static final String KIND1 = "kind1"; private static final String KIND2 = "kind2"; private static final String KIND3 = "kind3"; + private static final String MARKS_KIND = "Marks"; private static final NullValue NULL_VALUE = NullValue.of(); private static final StringValue STR_VALUE = StringValue.of("str"); private static final BooleanValue BOOL_VALUE = @@ -144,7 +139,6 @@ public class ITDatastoreTest { private static Key KEY3; private static Key KEY4; private static Key KEY5; - private static final String MARKS_KIND = "Marks"; private static FullEntity PARTIAL_ENTITY1; private static FullEntity PARTIAL_ENTITY2; private static FullEntity PARTIAL_ENTITY3; @@ -160,12 +154,21 @@ public class ITDatastoreTest { @Rule public MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3); - @AfterClass - public static void afterClass() { - HELPER.deleteNamespace(); + @Before + public void setUp() { + datastore.put(ENTITY1, ENTITY2); + } + + @After + public void tearDown() { + EntityQuery allEntitiesQuery = Query.newEntityQueryBuilder().build(); + QueryResults allEntities = datastore.run(allEntitiesQuery); + Key[] keysToDelete = + ImmutableList.copyOf(allEntities).stream().map(Entity::getKey).toArray(Key[]::new); + datastore.delete(keysToDelete); } - public ITDatastoreTest( + public AbstractITDatastoreTest( DatastoreOptions options, Datastore datastore, // databaseType is unused as a variable, but used as a parameterized label when running tests @@ -267,26 +270,6 @@ public ITDatastoreTest( .build(); } - @Before - public void setUp() { - datastore.put(ENTITY1, ENTITY2); - } - - @After - public void tearDown() { - EntityQuery allEntitiesQuery = Query.newEntityQueryBuilder().build(); - QueryResults allEntities = datastore.run(allEntitiesQuery); - Key[] keysToDelete = - ImmutableList.copyOf(allEntities).stream().map(Entity::getKey).toArray(Key[]::new); - datastore.delete(keysToDelete); - } - - @Parameterized.Parameters(name = "database: {2}") - public static Iterable data() { - return Arrays.asList( - new Object[][] {{OPTIONS_1, DATASTORE_1, "default"}, {OPTIONS_2, DATASTORE_2, "test-db"}}); - } - private Iterator getStronglyConsistentResults(Query scQuery, Query query) throws InterruptedException { // scQuery is equivalent to query, but with an ancestor filter in it @@ -491,19 +474,11 @@ public void testNewTransactionCommit() { assertEquals(ENTITY3, list.get(2)); assertEquals(3, list.size()); - try { - transaction.commit(); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "FAILED_PRECONDITION", 0); - } + DatastoreException expected = assertThrows(DatastoreException.class, transaction::commit); + assertDatastoreException(expected, FAILED_PRECONDITION.name(), 0); - try { - transaction.rollback(); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "FAILED_PRECONDITION", 0); - } + DatastoreException expected2 = assertThrows(DatastoreException.class, transaction::rollback); + assertDatastoreException(expected2, FAILED_PRECONDITION.name(), 0); } @Test @@ -694,12 +669,8 @@ public void testNewTransactionRollback() { transaction.rollback(); transaction.rollback(); // should be safe to repeat rollback calls - try { - transaction.commit(); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "FAILED_PRECONDITION", 0); - } + DatastoreException expected = assertThrows(DatastoreException.class, transaction::commit); + assertDatastoreException(expected, FAILED_PRECONDITION.name(), 0); List list = datastore.fetch(KEY1, KEY2, KEY3); assertEquals(ENTITY1, list.get(0)); @@ -746,12 +717,8 @@ public void testNewBatch() { assertEquals(PARTIAL_ENTITY3.getNames(), datastore.get(generatedKeys.get(0)).getNames()); assertEquals(PARTIAL_ENTITY3.getKey(), IncompleteKey.newBuilder(generatedKeys.get(0)).build()); - try { - batch.submit(); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "FAILED_PRECONDITION", 0); - } + DatastoreException expected = assertThrows(DatastoreException.class, batch::submit); + assertDatastoreException(expected, FAILED_PRECONDITION.name(), 0); batch = datastore.newBatch(); batch.delete(entity4.getKey(), entity5.getKey(), entity6.getKey()); @@ -1837,12 +1804,11 @@ public void testGetArrayNoDeferredResults() { assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList")); assertEquals(8, entity3.getNames().size()); assertFalse(entity3.contains("bla")); - try { - entity3.getString("str"); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "FAILED_PRECONDITION", 0); - } + + DatastoreException expected = + assertThrows(DatastoreException.class, () -> entity3.getString("str")); + assertDatastoreException(expected, FAILED_PRECONDITION.name(), 0); + assertFalse(result.hasNext()); datastore.delete(ENTITY3.getKey()); } @@ -1854,12 +1820,9 @@ public void testAddEntity() { assertNull(keys.get(1)); assertEquals(2, keys.size()); - try { - datastore.add(ENTITY1); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "ALREADY_EXISTS", 6); - } + DatastoreException expected = + assertThrows(DatastoreException.class, () -> datastore.add(ENTITY1)); + assertDatastoreException(expected, ALREADY_EXISTS.name(), 6); List entities = datastore.add(ENTITY3, PARTIAL_ENTITY1, PARTIAL_ENTITY2); assertEquals(ENTITY3, datastore.get(ENTITY3.getKey())); @@ -1882,12 +1845,10 @@ public void testUpdate() { assertNull(keys.get(1)); assertEquals(2, keys.size()); - try { - datastore.update(ENTITY3); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException(expected, "NOT_FOUND", 5); - } + DatastoreException expected = + assertThrows(DatastoreException.class, () -> datastore.update(ENTITY3)); + assertDatastoreException(expected, NOT_FOUND.name(), 5); + datastore.add(ENTITY3); assertEquals(ENTITY3, datastore.get(ENTITY3.getKey())); Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build(); @@ -1897,6 +1858,12 @@ public void testUpdate() { datastore.delete(ENTITY3.getKey()); } + private void assertDatastoreException( + DatastoreException expected, String reason, int datastoreStatusCode) { + Truth.assertThat(expected.getReason()).isEqualTo(reason); + Truth.assertThat(expected.getCode()).isEqualTo(datastoreStatusCode); + } + @Test public void testPut() { Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build(); @@ -1973,12 +1940,9 @@ public Integer run(DatastoreReaderWriter transaction) { } }; - try { - datastore.runInTransaction(callable2); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException((DatastoreException) expected.getCause(), "DEADLINE_EXCEEDED", 4); - } + DatastoreException expected = + assertThrows(DatastoreException.class, () -> datastore.runInTransaction(callable2)); + assertDatastoreException((DatastoreException) expected.getCause(), DEADLINE_EXCEEDED.name(), 4); } @Test @@ -2027,12 +1991,10 @@ public Integer run(DatastoreReaderWriter transaction) { .setReadOnly(TransactionOptions.ReadOnly.getDefaultInstance()) .build(); - try { - datastore.runInTransaction(callable2, readOnlyOptions); - fail("Expecting a failure"); - } catch (DatastoreException expected) { - assertDatastoreException((DatastoreException) expected.getCause(), "INVALID_ARGUMENT", 3); - } + DatastoreException expected = + assertThrows( + DatastoreException.class, () -> datastore.runInTransaction(callable2, readOnlyOptions)); + assertDatastoreException((DatastoreException) expected.getCause(), INVALID_ARGUMENT.name(), 3); } @Test @@ -2147,10 +2109,4 @@ public void testQueryWithReadTime() throws InterruptedException { datastore.delete(entity1.getKey(), entity2.getKey(), entity3.getKey()); } } - - private void assertDatastoreException( - DatastoreException expected, String reason, int statusCode) { - assertEquals(reason, expected.getReason()); - assertEquals(statusCode, expected.getCode()); - } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreConceptsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreConceptsTest.java index 770065778..1d6b2f838 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreConceptsTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreConceptsTest.java @@ -68,6 +68,7 @@ import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /* @@ -77,7 +78,7 @@ public class ITDatastoreConceptsTest { private static final RemoteDatastoreHelper HELPER = RemoteDatastoreHelper.create(); private static final DatastoreOptions OPTIONS = HELPER.getOptions(); private static final FullEntity TEST_FULL_ENTITY = FullEntity.newBuilder().build(); - private Datastore datastore; + private static Datastore datastore; private KeyFactory keyFactory; private Key taskKey; private Entity testEntity; @@ -87,13 +88,15 @@ public class ITDatastoreConceptsTest { private static final String TASK_CONCEPTS = "TaskConcepts"; - /** - * Initializes Datastore and cleans out any residual values. Also initializes global variables - * used for testing. - */ + /** Initializes Datastore for testing. */ + @BeforeClass + public static void beforeClass() throws Exception { + datastore = OPTIONS.getService(); + } + + /** Cleans out any residual values. Also initializes global variables used for testing. */ @Before public void setUp() { - datastore = OPTIONS.getService(); StructuredQuery query = Query.newKeyQueryBuilder().build(); QueryResults result = datastore.run(query); datastore.delete(Iterators.toArray(result, Key.class)); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestGrpc.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestGrpc.java new file mode 100644 index 000000000..7bb809997 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestGrpc.java @@ -0,0 +1,64 @@ +/* + * Copyright 2024 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 + * + * http://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.it; + +import com.google.cloud.datastore.Datastore; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.testing.RemoteDatastoreHelper; +import com.google.cloud.grpc.GrpcTransportOptions; +import com.google.common.truth.Truth; +import java.util.Arrays; +import org.junit.AfterClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class ITDatastoreTestGrpc extends AbstractITDatastoreTest { + // setup for default db, grpc transport + protected static final RemoteDatastoreHelper HELPER_DEFAULT_GRPC = + RemoteDatastoreHelper.create(GrpcTransportOptions.newBuilder().build()); + private static final DatastoreOptions OPTIONS_DEFAULT_GRPC = HELPER_DEFAULT_GRPC.getOptions(); + private static final Datastore DATASTORE_DEFAULT_GRPC = OPTIONS_DEFAULT_GRPC.getService(); + + // setup for custom db, grpc transport + private static final RemoteDatastoreHelper HELPER_CUSTOM_DB_GRPC = + RemoteDatastoreHelper.create(CUSTOM_DB_ID, GrpcTransportOptions.newBuilder().build()); + private static final DatastoreOptions OPTIONS_CUSTOM_DB_GRPC = HELPER_CUSTOM_DB_GRPC.getOptions(); + private static final Datastore DATASTORE_CUSTOM_DB_GRPC = OPTIONS_CUSTOM_DB_GRPC.getService(); + + public ITDatastoreTestGrpc(DatastoreOptions options, Datastore datastore, String databaseType) { + super(options, datastore, databaseType); + } + + @Parameterized.Parameters(name = "database: {2}") + public static Iterable data() { + return Arrays.asList( + new Object[][] { + {OPTIONS_DEFAULT_GRPC, DATASTORE_DEFAULT_GRPC, "default"}, + {OPTIONS_CUSTOM_DB_GRPC, DATASTORE_CUSTOM_DB_GRPC, CUSTOM_DB_ID}, + }); + } + + @AfterClass + public static void afterClass() throws Exception { + HELPER_DEFAULT_GRPC.deleteNamespace(); + HELPER_CUSTOM_DB_GRPC.deleteNamespace(); + DATASTORE_DEFAULT_GRPC.close(); + DATASTORE_CUSTOM_DB_GRPC.close(); + Truth.assertThat(DATASTORE_DEFAULT_GRPC.isClosed()).isTrue(); + Truth.assertThat(DATASTORE_CUSTOM_DB_GRPC.isClosed()).isTrue(); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestHttp.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestHttp.java new file mode 100644 index 000000000..3546bfcaf --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTestHttp.java @@ -0,0 +1,58 @@ +/* + * Copyright 2024 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 + * + * http://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.it; + +import com.google.cloud.datastore.Datastore; +import com.google.cloud.datastore.DatastoreOptions; +import com.google.cloud.datastore.testing.RemoteDatastoreHelper; +import java.util.Arrays; +import org.junit.AfterClass; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +@RunWith(Parameterized.class) +public class ITDatastoreTestHttp extends AbstractITDatastoreTest { + // setup for default db, http transport + private static final RemoteDatastoreHelper HELPER_DEFAULT_HTTP = RemoteDatastoreHelper.create(); + + private static final DatastoreOptions OPTIONS_DEFAULT_HTTP = HELPER_DEFAULT_HTTP.getOptions(); + private static final Datastore DATASTORE_DEFAULT_HTTP = OPTIONS_DEFAULT_HTTP.getService(); + + // setup for custom db, http transport + private static final RemoteDatastoreHelper HELPER_CUSTOM_DB_HTTP = + RemoteDatastoreHelper.create(CUSTOM_DB_ID); + private static final DatastoreOptions OPTIONS_CUSTOM_DB_HTTP = HELPER_CUSTOM_DB_HTTP.getOptions(); + private static final Datastore DATASTORE_CUSTOM_DB_HTTP = OPTIONS_CUSTOM_DB_HTTP.getService(); + + public ITDatastoreTestHttp(DatastoreOptions options, Datastore datastore, String databaseType) { + super(options, datastore, databaseType); + } + + @Parameterized.Parameters(name = "database: {2}") + public static Iterable data() { + return Arrays.asList( + new Object[][] { + {OPTIONS_DEFAULT_HTTP, DATASTORE_DEFAULT_HTTP, "default"}, + {OPTIONS_CUSTOM_DB_HTTP, DATASTORE_CUSTOM_DB_HTTP, CUSTOM_DB_ID}, + }); + } + + @AfterClass + public static void afterClass() throws Exception { + HELPER_DEFAULT_HTTP.deleteNamespace(); + HELPER_CUSTOM_DB_HTTP.deleteNamespace(); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/MultipleAttemptsRule.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/MultipleAttemptsRule.java index 8472f3131..ce9a226a6 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/MultipleAttemptsRule.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/MultipleAttemptsRule.java @@ -37,7 +37,7 @@ public final class MultipleAttemptsRule implements TestRule { this(attemptCount, 1000L); } - MultipleAttemptsRule(int attemptCount, long initialBackoffMillis) { + public MultipleAttemptsRule(int attemptCount, long initialBackoffMillis) { checkState(attemptCount > 0, "attemptCount must be > 0"); checkState(initialBackoffMillis > 0, "initialBackoffMillis must be > 0"); this.initialBackoffMillis = initialBackoffMillis; diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/StatementExecutor.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/StatementExecutor.java index c8ded3d89..f2209be9c 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/StatementExecutor.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/StatementExecutor.java @@ -80,9 +80,10 @@ private boolean transactionConflict(Exception exception) { } return exception instanceof ExecutionException && exception.getCause().getClass() == DatastoreException.class - && exception - .getMessage() - .contains("contention"); // exception raise coz of optimistic concurrency + && (exception.getMessage().contains("contention") + || exception + .getMessage() + .contains("Conflict")); // exception raise coz of optimistic concurrency } interface Statement { diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/spi/v1/RpcUtilsTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/spi/v1/RpcUtilsTest.java new file mode 100644 index 000000000..76fd00580 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/spi/v1/RpcUtilsTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2023 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 + * + * http://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.spi.v1; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.api.gax.retrying.RetrySettings; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.cloud.datastore.DatastoreOptions; +import org.junit.Test; +import org.threeten.bp.Duration; + +public class RpcUtilsTest { + + @Test + public void testRetrySettingSetter() { + UnaryCallSettings.Builder builder = + UnaryCallSettings.newUnaryCallSettingsBuilder(); + + // datastoreOptions with default retry settings + DatastoreOptions datastoreOptions = + DatastoreOptions.newBuilder().setProjectId("project-id").build(); + RpcUtils.retrySettingSetter(datastoreOptions).apply(builder); + assertThat(builder.getRetrySettings()).isEqualTo(datastoreOptions.getRetrySettings()); + + // datastoreOptions with custom retry settings + RetrySettings customRetrySettings = + RetrySettings.newBuilder() + .setTotalTimeout(Duration.ofMinutes(2)) + .setInitialRpcTimeout(Duration.ofSeconds(5)) + .setMaxRpcTimeout(Duration.ofSeconds(10)) + .setRetryDelayMultiplier(1.5) + .setMaxAttempts(5) + .build(); + DatastoreOptions datastoreOptionsWithCustomRetrySettings = + DatastoreOptions.newBuilder() + .setProjectId("project-id") + .setRetrySettings(customRetrySettings) + .build(); + RpcUtils.retrySettingSetter(datastoreOptionsWithCustomRetrySettings).apply(builder); + assertThat(builder.getRetrySettings()).isEqualTo(customRetrySettings); + } +} diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientHttpJsonTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientHttpJsonTest.java new file mode 100644 index 000000000..fa3a2a4e9 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientHttpJsonTest.java @@ -0,0 +1,538 @@ +/* + * Copyright 2023 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.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.ApiException; +import com.google.api.gax.rpc.ApiExceptionFactory; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.api.gax.rpc.StatusCode; +import com.google.api.gax.rpc.testing.FakeStatusCode; +import com.google.cloud.datastore.v1.stub.HttpJsonDatastoreStub; +import com.google.datastore.v1.AggregationQuery; +import com.google.datastore.v1.AggregationResultBatch; +import com.google.datastore.v1.AllocateIdsResponse; +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.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.ReserveIdsResponse; +import com.google.datastore.v1.RollbackResponse; +import com.google.datastore.v1.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +import com.google.datastore.v1.RunQueryRequest; +import com.google.datastore.v1.RunQueryResponse; +import com.google.protobuf.ByteString; +import com.google.protobuf.Timestamp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +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 DatastoreClientHttpJsonTest { + private static MockHttpService mockService; + private static DatastoreClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonDatastoreStub.getMethodDescriptors(), DatastoreSettings.getDefaultEndpoint()); + DatastoreSettings settings = + DatastoreSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + DatastoreSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = DatastoreClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void lookupTest() throws Exception { + LookupResponse expectedResponse = + LookupResponse.newBuilder() + .addAllFound(new ArrayList()) + .addAllMissing(new ArrayList()) + .addAllDeferred(new ArrayList()) + .setTransaction(ByteString.EMPTY) + .setReadTime(Timestamp.newBuilder().build()) + .build(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + ReadOptions readOptions = ReadOptions.newBuilder().build(); + List keys = new ArrayList<>(); + + LookupResponse actualResponse = client.lookup(projectId, readOptions, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void lookupExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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()) + .setTransaction(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + RunQueryRequest request = + RunQueryRequest.newBuilder() + .setProjectId("projectId-1530") + .setDatabaseId("databaseId1688905718") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + + RunQueryResponse actualResponse = client.runQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RunQueryRequest request = + RunQueryRequest.newBuilder() + .setProjectId("projectId-1530") + .setDatabaseId("databaseId1688905718") + .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 runAggregationQueryTest() throws Exception { + RunAggregationQueryResponse expectedResponse = + RunAggregationQueryResponse.newBuilder() + .setBatch(AggregationResultBatch.newBuilder().build()) + .setQuery(AggregationQuery.newBuilder().build()) + .setTransaction(ByteString.EMPTY) + .build(); + mockService.addResponse(expectedResponse); + + RunAggregationQueryRequest request = + RunAggregationQueryRequest.newBuilder() + .setProjectId("projectId-1530") + .setDatabaseId("databaseId1688905718") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + + RunAggregationQueryResponse actualResponse = client.runAggregationQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void runAggregationQueryExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + RunAggregationQueryRequest request = + RunAggregationQueryRequest.newBuilder() + .setProjectId("projectId-1530") + .setDatabaseId("databaseId1688905718") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + client.runAggregationQuery(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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + + BeginTransactionResponse actualResponse = client.beginTransaction(projectId); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void beginTransactionExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + CommitRequest.Mode mode = CommitRequest.Mode.forNumber(0); + List mutations = new ArrayList<>(); + + CommitResponse actualResponse = client.commit(projectId, mode, mutations); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void commitExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + 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 = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void commitExceptionTest2() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + ByteString transaction = ByteString.EMPTY; + + RollbackResponse actualResponse = client.rollback(projectId, transaction); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void rollbackExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + List keys = new ArrayList<>(); + + AllocateIdsResponse actualResponse = client.allocateIds(projectId, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void allocateIdsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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(); + mockService.addResponse(expectedResponse); + + String projectId = "projectId-1530"; + List keys = new ArrayList<>(); + + ReserveIdsResponse actualResponse = client.reserveIds(projectId, keys); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockService.getRequestPaths(); + Assert.assertEquals(1, actualRequests.size()); + + String apiClientHeaderKey = + mockService + .getRequestHeaders() + .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()) + .iterator() + .next(); + Assert.assertTrue( + GaxHttpJsonProperties.getDefaultApiClientHeaderPattern() + .matcher(apiClientHeaderKey) + .matches()); + } + + @Test + public void reserveIdsExceptionTest() throws Exception { + ApiException exception = + ApiExceptionFactory.createException( + new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false); + mockService.addException(exception); + + try { + String projectId = "projectId-1530"; + 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/DatastoreClientTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java new file mode 100644 index 000000000..663de9fb0 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/DatastoreClientTest.java @@ -0,0 +1,514 @@ +/* + * Copyright 2023 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.AggregationQuery; +import com.google.datastore.v1.AggregationResultBatch; +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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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()) + .setTransaction(ByteString.EMPTY) + .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()) + .setTransaction(ByteString.EMPTY) + .build(); + mockDatastore.addResponse(expectedResponse); + + RunQueryRequest request = + RunQueryRequest.newBuilder() + .setProjectId("projectId-894832108") + .setDatabaseId("databaseId1688905718") + .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.getDatabaseId(), actualRequest.getDatabaseId()); + 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") + .setDatabaseId("databaseId1688905718") + .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 runAggregationQueryTest() throws Exception { + RunAggregationQueryResponse expectedResponse = + RunAggregationQueryResponse.newBuilder() + .setBatch(AggregationResultBatch.newBuilder().build()) + .setQuery(AggregationQuery.newBuilder().build()) + .setTransaction(ByteString.EMPTY) + .build(); + mockDatastore.addResponse(expectedResponse); + + RunAggregationQueryRequest request = + RunAggregationQueryRequest.newBuilder() + .setProjectId("projectId-894832108") + .setDatabaseId("databaseId1688905718") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + + RunAggregationQueryResponse actualResponse = client.runAggregationQuery(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockDatastore.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + RunAggregationQueryRequest actualRequest = ((RunAggregationQueryRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getProjectId(), actualRequest.getProjectId()); + Assert.assertEquals(request.getDatabaseId(), actualRequest.getDatabaseId()); + Assert.assertEquals(request.getPartitionId(), actualRequest.getPartitionId()); + Assert.assertEquals(request.getReadOptions(), actualRequest.getReadOptions()); + Assert.assertEquals(request.getAggregationQuery(), actualRequest.getAggregationQuery()); + Assert.assertEquals(request.getGqlQuery(), actualRequest.getGqlQuery()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void runAggregationQueryExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockDatastore.addException(exception); + + try { + RunAggregationQueryRequest request = + RunAggregationQueryRequest.newBuilder() + .setProjectId("projectId-894832108") + .setDatabaseId("databaseId1688905718") + .setPartitionId(PartitionId.newBuilder().build()) + .setReadOptions(ReadOptions.newBuilder().build()) + .build(); + client.runAggregationQuery(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..d2295784c --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastore.java @@ -0,0 +1,59 @@ +/* + * Copyright 2023 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..3b3d8b937 --- /dev/null +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/v1/MockDatastoreImpl.java @@ -0,0 +1,241 @@ +/* + * Copyright 2023 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.RunAggregationQueryRequest; +import com.google.datastore.v1.RunAggregationQueryResponse; +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 runAggregationQuery( + RunAggregationQueryRequest request, + StreamObserver responseObserver) { + Object response = responses.poll(); + if (response instanceof RunAggregationQueryResponse) { + requests.add(request); + responseObserver.onNext(((RunAggregationQueryResponse) 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 RunAggregationQuery, expected %s or %s", + response == null ? "null" : response.getClass().getName(), + RunAggregationQueryResponse.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/pom.xml b/grpc-google-cloud-datastore-v1/pom.xml new file mode 100644 index 000000000..754197440 --- /dev/null +++ b/grpc-google-cloud-datastore-v1/pom.xml @@ -0,0 +1,81 @@ + + 4.0.0 + com.google.api.grpc + grpc-google-cloud-datastore-v1 + 2.19.2-SNAPSHOT + grpc-google-cloud-datastore-v1 + GRPC library for google-cloud-datastore + + com.google.cloud + google-cloud-datastore-parent + 2.19.2-SNAPSHOT + + + + io.grpc + grpc-api + + + io.grpc + grpc-stub + + + io.grpc + grpc-protobuf + + + com.google.protobuf + protobuf-java + + + com.google.api.grpc + proto-google-cloud-datastore-v1 + + + com.google.guava + guava + + + + + + java9 + + [9,) + + + + javax.annotation + javax.annotation-api + + + + + + + + + org.codehaus.mojo + flatten-maven-plugin + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + true + + + + + org.codehaus.mojo + clirr-maven-plugin + + true + + + + + \ No newline at end of file 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..b3dc940b7 --- /dev/null +++ b/grpc-google-cloud-datastore-v1/src/main/java/com/google/datastore/v1/DatastoreGrpc.java @@ -0,0 +1,1194 @@ +/* + * Copyright 2023 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 java.lang.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.RunAggregationQueryRequest, + com.google.datastore.v1.RunAggregationQueryResponse> + getRunAggregationQueryMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "RunAggregationQuery", + requestType = com.google.datastore.v1.RunAggregationQueryRequest.class, + responseType = com.google.datastore.v1.RunAggregationQueryResponse.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor< + com.google.datastore.v1.RunAggregationQueryRequest, + com.google.datastore.v1.RunAggregationQueryResponse> + getRunAggregationQueryMethod() { + io.grpc.MethodDescriptor< + com.google.datastore.v1.RunAggregationQueryRequest, + com.google.datastore.v1.RunAggregationQueryResponse> + getRunAggregationQueryMethod; + if ((getRunAggregationQueryMethod = DatastoreGrpc.getRunAggregationQueryMethod) == null) { + synchronized (DatastoreGrpc.class) { + if ((getRunAggregationQueryMethod = DatastoreGrpc.getRunAggregationQueryMethod) == null) { + DatastoreGrpc.getRunAggregationQueryMethod = + getRunAggregationQueryMethod = + io.grpc.MethodDescriptor + . + newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName( + generateFullMethodName(SERVICE_NAME, "RunAggregationQuery")) + .setSampledToLocalTracing(true) + .setRequestMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RunAggregationQueryRequest + .getDefaultInstance())) + .setResponseMarshaller( + io.grpc.protobuf.ProtoUtils.marshaller( + com.google.datastore.v1.RunAggregationQueryResponse + .getDefaultInstance())) + .setSchemaDescriptor( + new DatastoreMethodDescriptorSupplier("RunAggregationQuery")) + .build(); + } + } + } + return getRunAggregationQueryMethod; + } + + 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 interface AsyncService { + + /** + * + * + *
+     * Looks up entities by key.
+     * 
+ */ + default void lookup( + com.google.datastore.v1.LookupRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getLookupMethod(), responseObserver); + } + + /** + * + * + *
+     * Queries for entities.
+     * 
+ */ + default void runQuery( + com.google.datastore.v1.RunQueryRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getRunQueryMethod(), responseObserver); + } + + /** + * + * + *
+     * Runs an aggregation query.
+     * 
+ */ + default void runAggregationQuery( + com.google.datastore.v1.RunAggregationQueryRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall( + getRunAggregationQueryMethod(), responseObserver); + } + + /** + * + * + *
+     * Begins a new transaction.
+     * 
+ */ + default 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.
+     * 
+ */ + default void commit( + com.google.datastore.v1.CommitRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getCommitMethod(), responseObserver); + } + + /** + * + * + *
+     * Rolls back a transaction.
+     * 
+ */ + default 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.
+     * 
+ */ + default 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.
+     * 
+ */ + default void reserveIds( + com.google.datastore.v1.ReserveIdsRequest request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getReserveIdsMethod(), responseObserver); + } + } + + /** + * Base class for the server implementation of the service Datastore. + * + *
+   * 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, AsyncService { + + @java.lang.Override + public final io.grpc.ServerServiceDefinition bindService() { + return DatastoreGrpc.bindService(this); + } + } + + /** + * A stub to allow clients to do asynchronous rpc calls to service Datastore. + * + *
+   * 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); + } + + /** + * + * + *
+     * Runs an aggregation query.
+     * 
+ */ + public void runAggregationQuery( + com.google.datastore.v1.RunAggregationQueryRequest request, + io.grpc.stub.StreamObserver + responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getRunAggregationQueryMethod(), 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); + } + } + + /** + * A stub to allow clients to do synchronous rpc calls to service Datastore. + * + *
+   * 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); + } + + /** + * + * + *
+     * Runs an aggregation query.
+     * 
+ */ + public com.google.datastore.v1.RunAggregationQueryResponse runAggregationQuery( + com.google.datastore.v1.RunAggregationQueryRequest request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getRunAggregationQueryMethod(), 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); + } + } + + /** + * A stub to allow clients to do ListenableFuture-style rpc calls to service Datastore. + * + *
+   * 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); + } + + /** + * + * + *
+     * Runs an aggregation query.
+     * 
+ */ + public com.google.common.util.concurrent.ListenableFuture< + com.google.datastore.v1.RunAggregationQueryResponse> + runAggregationQuery(com.google.datastore.v1.RunAggregationQueryRequest request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getRunAggregationQueryMethod(), 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_RUN_AGGREGATION_QUERY = 2; + private static final int METHODID_BEGIN_TRANSACTION = 3; + private static final int METHODID_COMMIT = 4; + private static final int METHODID_ROLLBACK = 5; + private static final int METHODID_ALLOCATE_IDS = 6; + private static final int METHODID_RESERVE_IDS = 7; + + 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 AsyncService serviceImpl; + private final int methodId; + + MethodHandlers(AsyncService 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_RUN_AGGREGATION_QUERY: + serviceImpl.runAggregationQuery( + (com.google.datastore.v1.RunAggregationQueryRequest) 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(); + } + } + } + + public static final io.grpc.ServerServiceDefinition bindService(AsyncService service) { + 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>( + service, METHODID_LOOKUP))) + .addMethod( + getRunQueryMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.RunQueryRequest, + com.google.datastore.v1.RunQueryResponse>(service, METHODID_RUN_QUERY))) + .addMethod( + getRunAggregationQueryMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.RunAggregationQueryRequest, + com.google.datastore.v1.RunAggregationQueryResponse>( + service, METHODID_RUN_AGGREGATION_QUERY))) + .addMethod( + getBeginTransactionMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.BeginTransactionRequest, + com.google.datastore.v1.BeginTransactionResponse>( + service, METHODID_BEGIN_TRANSACTION))) + .addMethod( + getCommitMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.CommitRequest, com.google.datastore.v1.CommitResponse>( + service, METHODID_COMMIT))) + .addMethod( + getRollbackMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.RollbackRequest, + com.google.datastore.v1.RollbackResponse>(service, METHODID_ROLLBACK))) + .addMethod( + getAllocateIdsMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.AllocateIdsRequest, + com.google.datastore.v1.AllocateIdsResponse>(service, METHODID_ALLOCATE_IDS))) + .addMethod( + getReserveIdsMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + com.google.datastore.v1.ReserveIdsRequest, + com.google.datastore.v1.ReserveIdsResponse>(service, METHODID_RESERVE_IDS))) + .build(); + } + + 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 java.lang.String methodName; + + DatastoreMethodDescriptorSupplier(java.lang.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(getRunAggregationQueryMethod()) + .addMethod(getBeginTransactionMethod()) + .addMethod(getCommitMethod()) + .addMethod(getRollbackMethod()) + .addMethod(getAllocateIdsMethod()) + .addMethod(getReserveIdsMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/pom.xml b/pom.xml index eeb20ad87..96bc6d6ce 100644 --- a/pom.xml +++ b/pom.xml @@ -176,6 +176,11 @@ proto-google-cloud-datastore-v1 0.110.2-SNAPSHOT + + com.google.api.grpc + grpc-google-cloud-datastore-v1 + 2.19.2-SNAPSHOT + com.google.cloud.datastore datastore-v1-proto-client @@ -269,6 +274,7 @@ grpc-google-cloud-datastore-admin-v1 proto-google-cloud-datastore-v1 proto-google-cloud-datastore-admin-v1 + grpc-google-cloud-datastore-v1 datastore-v1-proto-client google-cloud-datastore-bom diff --git a/pull-gapic-grpc.sh b/pull-gapic-grpc.sh new file mode 100644 index 000000000..327d7676c --- /dev/null +++ b/pull-gapic-grpc.sh @@ -0,0 +1,42 @@ +# +# Copyright 2023 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. +# + +GENERATED_CODE_DIR=$(pwd)/../googleapis-gen +DATASTORE_DIR=$(pwd) + +echo $GENERATED_CODE_DIR +if [ -d "$GENERATED_CODE_DIR" ]; then + echo "Pulling latest changes in ${GENERATED_CODE_DIR}" + pushd $GENERATED_CODE_DIR || exit + git pull + popd || exit +else + echo "Cloning googleapis-gen" + git clone --depth 1 git@github.com:googleapis/googleapis-gen.git $GENERATED_CODE_DIR +fi + +#Copying the required directories +mkdir -p "$DATASTORE_DIR/grpc-google-cloud-datastore-v1" +cp -r "$GENERATED_CODE_DIR/google/datastore/v1/google-cloud-datastore-v1-java/grpc-google-cloud-datastore-v1-java/." \ +"$DATASTORE_DIR/grpc-google-cloud-datastore-v1/." +cp -r "$GENERATED_CODE_DIR/google/datastore/v1/google-cloud-datastore-v1-java/gapic-google-cloud-datastore-v1-java/." \ +"$DATASTORE_DIR/google-cloud-datastore/." + +#Cleaning up unwanted files +rm grpc-google-cloud-datastore-v1/build.gradle +rm google-cloud-datastore/build.gradle + +echo "Success" diff --git a/versions.txt b/versions.txt index 3d01cfb1c..c5f940aa9 100644 --- a/versions.txt +++ b/versions.txt @@ -7,3 +7,4 @@ proto-google-cloud-datastore-v1:0.110.1:0.110.2-SNAPSHOT datastore-v1-proto-client:2.19.1:2.19.2-SNAPSHOT proto-google-cloud-datastore-admin-v1:2.19.1:2.19.2-SNAPSHOT grpc-google-cloud-datastore-admin-v1:2.19.1:2.19.2-SNAPSHOT +grpc-google-cloud-datastore-v1:2.19.1:2.19.2-SNAPSHOT