The Cloud Spanner Adapter service allows native drivers of supported database dialects to + * interact directly with Cloud Spanner by wrapping the underlying wire protocol used by the driver + * in a gRPC stream. + * + *
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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * DatabaseName parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
+ * Session session = Session.newBuilder().build();
+ * Session response = adapterClient.createSession(parent, session);
+ * }
+ * }
+ *
+ * Note: close() needs to be called on the AdapterClient object to clean up resources such as + * threads. In the example above, try-with-resources is used, which automatically calls close(). + * + *
| Method | + *Description | + *Method Variants | + *
|---|---|---|
CreateSession |
+ * Creates a new session to be used for requests made by the adapter. A session identifies a specific incarnation of a database resource and is meant to be reused across many `AdaptMessage` calls. |
+ *
+ * Request object method variants only take one parameter, a request object, which must be constructed before the call. + *
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method. + *
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service. + *
|
+ *
AdaptMessage |
+ * Handles a single message from the client and returns the result as a stream. The server will interpret the message frame and respond with message frames to the client. |
+ *
+ * Callable method variants take no parameters and return 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 AdapterSettings 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
+ * AdapterSettings adapterSettings =
+ * AdapterSettings.newBuilder()
+ * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
+ * .build();
+ * AdapterClient adapterClient = AdapterClient.create(adapterSettings);
+ * }
+ *
+ * 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
+ * AdapterSettings adapterSettings = AdapterSettings.newBuilder().setEndpoint(myEndpoint).build();
+ * AdapterClient adapterClient = AdapterClient.create(adapterSettings);
+ * }
+ *
+ * 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
+ * AdapterSettings adapterSettings = AdapterSettings.newHttpJsonBuilder().build();
+ * AdapterClient adapterClient = AdapterClient.create(adapterSettings);
+ * }
+ *
+ * Please refer to the GitHub repository's samples for more quickstart code snippets. + */ +@Generated("by gapic-generator-java") +public class AdapterClient implements BackgroundResource { + private final AdapterSettings settings; + private final AdapterStub stub; + + /** Constructs an instance of AdapterClient with default settings. */ + public static final AdapterClient create() throws IOException { + return create(AdapterSettings.newBuilder().build()); + } + + /** + * Constructs an instance of AdapterClient, 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 AdapterClient create(AdapterSettings settings) throws IOException { + return new AdapterClient(settings); + } + + /** + * Constructs an instance of AdapterClient, using the given stub for making calls. This is for + * advanced usage - prefer using create(AdapterSettings). + */ + public static final AdapterClient create(AdapterStub stub) { + return new AdapterClient(stub); + } + + /** + * Constructs an instance of AdapterClient, 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 AdapterClient(AdapterSettings settings) throws IOException { + this.settings = settings; + this.stub = ((AdapterStubSettings) settings.getStubSettings()).createStub(); + } + + protected AdapterClient(AdapterStub stub) { + this.settings = null; + this.stub = stub; + } + + public final AdapterSettings getSettings() { + return settings; + } + + public AdapterStub getStub() { + return stub; + } + + // AUTO-GENERATED DOCUMENTATION AND METHOD. + /** + * Creates a new session to be used for requests made by the adapter. A session identifies a + * specific incarnation of a database resource and is meant to be reused across many + * `AdaptMessage` calls. + * + *
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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * DatabaseName parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
+ * Session session = Session.newBuilder().build();
+ * Session response = adapterClient.createSession(parent, session);
+ * }
+ * }
+ *
+ * @param parent Required. The database in which the new session is created.
+ * @param session Required. The session to create.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Session createSession(DatabaseName parent, Session session) {
+ CreateSessionRequest request =
+ CreateSessionRequest.newBuilder()
+ .setParent(parent == null ? null : parent.toString())
+ .setSession(session)
+ .build();
+ return createSession(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new session to be used for requests made by the adapter. A session identifies a
+ * specific incarnation of a database resource and is meant to be reused across many
+ * `AdaptMessage` calls.
+ *
+ * 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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * String parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString();
+ * Session session = Session.newBuilder().build();
+ * Session response = adapterClient.createSession(parent, session);
+ * }
+ * }
+ *
+ * @param parent Required. The database in which the new session is created.
+ * @param session Required. The session to create.
+ * @throws com.google.api.gax.rpc.ApiException if the remote call fails
+ */
+ public final Session createSession(String parent, Session session) {
+ CreateSessionRequest request =
+ CreateSessionRequest.newBuilder().setParent(parent).setSession(session).build();
+ return createSession(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new session to be used for requests made by the adapter. A session identifies a
+ * specific incarnation of a database resource and is meant to be reused across many
+ * `AdaptMessage` calls.
+ *
+ * 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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * CreateSessionRequest request =
+ * CreateSessionRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setSession(Session.newBuilder().build())
+ * .build();
+ * Session response = adapterClient.createSession(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 Session createSession(CreateSessionRequest request) {
+ return createSessionCallable().call(request);
+ }
+
+ // AUTO-GENERATED DOCUMENTATION AND METHOD.
+ /**
+ * Creates a new session to be used for requests made by the adapter. A session identifies a
+ * specific incarnation of a database resource and is meant to be reused across many
+ * `AdaptMessage` calls.
+ *
+ * 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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * CreateSessionRequest request =
+ * CreateSessionRequest.newBuilder()
+ * .setParent(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString())
+ * .setSession(Session.newBuilder().build())
+ * .build();
+ * ApiFuture future = adapterClient.createSessionCallable().futureCall(request);
+ * // Do something.
+ * Session response = future.get();
+ * }
+ * }
+ */
+ public final UnaryCallableSample 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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * AdaptMessageRequest request =
+ * AdaptMessageRequest.newBuilder()
+ * .setName(
+ * SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString())
+ * .setProtocol("protocol-989163880")
+ * .setPayload(ByteString.EMPTY)
+ * .putAllAttachments(new HashMap())
+ * .build();
+ * ServerStream stream =
+ * adapterClient.adaptMessageCallable().call(request);
+ * for (AdaptMessageResponse response : stream) {
+ * // Do something when a response is received.
+ * }
+ * }
+ * }
+ */
+ public final ServerStreamingCallableThe default instance has everything set to sensible defaults: + * + *
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 + * [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings) + * of createSession: + * + *
{@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
+ * AdapterSettings.Builder adapterSettingsBuilder = AdapterSettings.newBuilder();
+ * adapterSettingsBuilder
+ * .createSessionSettings()
+ * .setRetrySettings(
+ * adapterSettingsBuilder
+ * .createSessionSettings()
+ * .getRetrySettings()
+ * .toBuilder()
+ * .setInitialRetryDelayDuration(Duration.ofSeconds(1))
+ * .setInitialRpcTimeoutDuration(Duration.ofSeconds(5))
+ * .setMaxAttempts(5)
+ * .setMaxRetryDelayDuration(Duration.ofSeconds(30))
+ * .setMaxRpcTimeoutDuration(Duration.ofSeconds(60))
+ * .setRetryDelayMultiplier(1.3)
+ * .setRpcTimeoutMultiplier(1.5)
+ * .setTotalTimeoutDuration(Duration.ofSeconds(300))
+ * .build());
+ * AdapterSettings adapterSettings = adapterSettingsBuilder.build();
+ * }
+ *
+ * Please refer to the [Client Side Retry
+ * Guide](https://github.com/googleapis/google-cloud-java/blob/main/docs/client_retries.md) for
+ * additional support in setting retries.
+ */
+@Generated("by gapic-generator-java")
+public class AdapterSettings extends ClientSettingsNote: This method does not support applying settings to streaming methods.
+ */
+ public Builder applyToAllUnaryMethods(
+ ApiFunction The interfaces provided are listed below, along with usage samples.
+ *
+ * ======================= AdapterClient =======================
+ *
+ * Service Description: Cloud Spanner Adapter API
+ *
+ * The Cloud Spanner Adapter service allows native drivers of supported database dialects to
+ * interact directly with Cloud Spanner by wrapping the underlying wire protocol used by the driver
+ * in a gRPC stream.
+ *
+ * Sample for AdapterClient:
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+public abstract class AdapterStub implements BackgroundResource {
+
+ public UnaryCallable The default instance has everything set to sensible defaults:
+ *
+ * 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
+ * [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)
+ * of createSession:
+ *
+ * Note: This method does not support applying settings to streaming methods.
+ */
+ public Builder applyToAllUnaryMethods(
+ ApiFunction This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+public class GrpcAdapterCallableFactory implements GrpcStubCallableFactory {
+
+ @Override
+ public This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+public class GrpcAdapterStub extends AdapterStub {
+ private static final MethodDescriptor This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+public class HttpJsonAdapterCallableFactory
+ implements HttpJsonStubCallableFactory This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+public class HttpJsonAdapterStub extends AdapterStub {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor{@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 (AdapterClient adapterClient = AdapterClient.create()) {
+ * DatabaseName parent = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
+ * Session session = Session.newBuilder().build();
+ * Session response = adapterClient.createSession(parent, session);
+ * }
+ * }
+ */
+@Generated("by gapic-generator-java")
+package com.google.spanner.adapter.v1;
+
+import javax.annotation.Generated;
diff --git a/java-spanneradapter/google-cloud-spanneradapter/src/main/java/com/google/spanner/adapter/v1/stub/AdapterStub.java b/java-spanneradapter/google-cloud-spanneradapter/src/main/java/com/google/spanner/adapter/v1/stub/AdapterStub.java
new file mode 100644
index 000000000000..57e752616ef0
--- /dev/null
+++ b/java-spanneradapter/google-cloud-spanneradapter/src/main/java/com/google/spanner/adapter/v1/stub/AdapterStub.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2025 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.spanner.adapter.v1.stub;
+
+import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.spanner.adapter.v1.AdaptMessageRequest;
+import com.google.spanner.adapter.v1.AdaptMessageResponse;
+import com.google.spanner.adapter.v1.CreateSessionRequest;
+import com.google.spanner.adapter.v1.Session;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * Base stub class for the Adapter service API.
+ *
+ *
+ *
+ *
+ * {@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
+ * AdapterStubSettings.Builder adapterSettingsBuilder = AdapterStubSettings.newBuilder();
+ * adapterSettingsBuilder
+ * .createSessionSettings()
+ * .setRetrySettings(
+ * adapterSettingsBuilder
+ * .createSessionSettings()
+ * .getRetrySettings()
+ * .toBuilder()
+ * .setInitialRetryDelayDuration(Duration.ofSeconds(1))
+ * .setInitialRpcTimeoutDuration(Duration.ofSeconds(5))
+ * .setMaxAttempts(5)
+ * .setMaxRetryDelayDuration(Duration.ofSeconds(30))
+ * .setMaxRpcTimeoutDuration(Duration.ofSeconds(60))
+ * .setRetryDelayMultiplier(1.3)
+ * .setRpcTimeoutMultiplier(1.5)
+ * .setTotalTimeoutDuration(Duration.ofSeconds(300))
+ * .build());
+ * AdapterStubSettings adapterSettings = adapterSettingsBuilder.build();
+ * }
+ *
+ * Please refer to the [Client Side Retry
+ * Guide](https://github.com/googleapis/google-cloud-java/blob/main/docs/client_retries.md) for
+ * additional support in setting retries.
+ */
+@Generated("by gapic-generator-java")
+public class AdapterStubSettings extends StubSettings