diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ExtendedSpanner.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ExtendedSpanner.java new file mode 100644 index 00000000000..a1b65ecfefb --- /dev/null +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/ExtendedSpanner.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * 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.spanner; + +public interface ExtendedSpanner extends Spanner { + /** + * Returns a {@code DatabaseClient} for the given database and given client id. It uses a pool of + * sessions to talk to the database. + * + * + *
{@code + * SpannerOptions options = SpannerOptions.newBuilder().build(); + * Spanner spanner = options.getService(); + * final String project = "test-project"; + * final String instance = "test-instance"; + * final String database = "example-db"; + * final String client_id = "client_id" + * DatabaseId db = + * DatabaseId.of(project, instance, database); + * + * DatabaseClient dbClient = spanner.getDatabaseClient(db, client_id); + * }+ * + * + */ + default DatabaseClient getDatabaseClient(DatabaseId db, String clientId) { + throw new UnsupportedOperationException( + "getDatabaseClient with clientId is not supported by this default implementation."); + } +} diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java index 63d501fbe63..c4b11cc859d 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java @@ -59,7 +59,7 @@ import javax.annotation.concurrent.GuardedBy; /** Default implementation of the Cloud Spanner interface. */ -class SpannerImpl extends BaseService
NOTE: This feature is not yet exposed in the public API.
*/
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java
index 6f945938df0..fbc59caa174 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionOptions.java
@@ -21,6 +21,7 @@
import static com.google.cloud.spanner.connection.ConnectionProperties.AUTO_PARTITION_MODE;
import static com.google.cloud.spanner.connection.ConnectionProperties.CHANNEL_PROVIDER;
import static com.google.cloud.spanner.connection.ConnectionProperties.CLIENT_CERTIFICATE;
+import static com.google.cloud.spanner.connection.ConnectionProperties.CLIENT_ID;
import static com.google.cloud.spanner.connection.ConnectionProperties.CLIENT_KEY;
import static com.google.cloud.spanner.connection.ConnectionProperties.CREDENTIALS_PROVIDER;
import static com.google.cloud.spanner.connection.ConnectionProperties.CREDENTIALS_URL;
@@ -539,6 +540,11 @@ public Builder setTracingPrefix(String tracingPrefix) {
return this;
}
+ public Builder setClientId(String clientId) {
+ setConnectionPropertyValue(CLIENT_ID, clientId);
+ return this;
+ }
+
/** @return the {@link ConnectionOptions} */
public ConnectionOptions build() {
Preconditions.checkState(this.uri != null, "Connection URI is required");
@@ -603,7 +609,6 @@ private ConnectionOptions(Builder builder) {
// Create the initial connection state from the parsed properties in the connection URL.
this.initialConnectionState = new ConnectionState(connectionPropertyValues);
-
// Check that at most one of credentials location, encoded credentials, credentials provider and
// OUAuth token has been specified in the connection URI.
Preconditions.checkArgument(
diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java
index 54d3461b787..22f541f3bd2 100644
--- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java
+++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/ConnectionProperties.java
@@ -135,6 +135,14 @@ public class ConnectionProperties {
private static final Boolean[] BOOLEANS = new Boolean[] {Boolean.TRUE, Boolean.FALSE};
+ static final ConnectionProperty