Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.39.0')
implementation platform('com.google.cloud:libraries-bom:26.42.0')

implementation 'com.google.cloud:google-cloud-spanner'
```
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-spanner:6.67.0'
implementation 'com.google.cloud:google-cloud-spanner:6.69.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.67.0"
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.69.0"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -671,7 +671,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.67.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.69.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,9 @@ public Spanner getSpanner() {
private DdlClient createDdlClient() {
return DdlClient.newBuilder()
.setDatabaseAdminClient(spanner.getDatabaseAdminClient())
.setProjectId(options.getProjectId())
.setInstanceId(options.getInstanceId())
.setDatabaseName(options.getDatabaseName())
.setDatabaseId(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You can call options.getDatabaseId() instead of the separate options.getProjectId() etc. methods.

DatabaseId.of(
options.getProjectId(), options.getInstanceId(), options.getDatabaseName()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.cloud.spanner.ErrorCode;
import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;
import java.util.Collections;
Expand All @@ -36,15 +35,12 @@
*/
class DdlClient {
private final DatabaseAdminClient dbAdminClient;
private final String projectId;
private final String instanceId;
private final String databaseName;
private final DatabaseId databaseId;

static class Builder {
private DatabaseAdminClient dbAdminClient;
private String projectId;
private String instanceId;
private String databaseName;

private DatabaseId databaseId;

private Builder() {}

Expand All @@ -54,33 +50,15 @@ Builder setDatabaseAdminClient(DatabaseAdminClient client) {
return this;
}

Builder setProjectId(String projectId) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(projectId), "Empty projectId is not allowed");
this.projectId = projectId;
return this;
}

Builder setInstanceId(String instanceId) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(instanceId), "Empty instanceId is not allowed");
this.instanceId = instanceId;
return this;
}

Builder setDatabaseName(String name) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(name), "Empty database name is not allowed");
this.databaseName = name;
Builder setDatabaseId(DatabaseId databaseId) {
Preconditions.checkNotNull(databaseId);
this.databaseId = databaseId;
return this;
}

DdlClient build() {
Preconditions.checkState(dbAdminClient != null, "No DatabaseAdminClient specified");
Preconditions.checkState(!Strings.isNullOrEmpty(projectId), "No ProjectId specified");
Preconditions.checkState(!Strings.isNullOrEmpty(instanceId), "No InstanceId specified");
Preconditions.checkArgument(
!Strings.isNullOrEmpty(databaseName), "No database name specified");
Preconditions.checkState(databaseId != null, "No DatabaseId specified");
return new DdlClient(this);
}
}
Expand All @@ -91,16 +69,17 @@ static Builder newBuilder() {

private DdlClient(Builder builder) {
this.dbAdminClient = builder.dbAdminClient;
this.projectId = builder.projectId;
this.instanceId = builder.instanceId;
this.databaseName = builder.databaseName;
this.databaseId = builder.databaseId;
}

OperationFuture<Database, CreateDatabaseMetadata> executeCreateDatabase(
String createStatement, Dialect dialect) {
Preconditions.checkArgument(isCreateDatabaseStatement(createStatement));
return dbAdminClient.createDatabase(
instanceId, createStatement, dialect, Collections.emptyList());
databaseId.getInstanceId().getInstance(),
createStatement,
dialect,
Collections.emptyList());
}

/** Execute a single DDL statement. */
Expand All @@ -115,8 +94,7 @@ OperationFuture<Void, UpdateDatabaseDdlMetadata> executeDdl(
throw SpannerExceptionFactory.newSpannerException(
ErrorCode.INVALID_ARGUMENT, "CREATE DATABASE is not supported in a DDL batch");
}
Database.Builder dbBuilder =
dbAdminClient.newDatabaseBuilder(DatabaseId.of(projectId, instanceId, databaseName));
Database.Builder dbBuilder = dbAdminClient.newDatabaseBuilder(databaseId);
if (protoDescriptors != null) {
dbBuilder.setProtoDescriptors(protoDescriptors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public class DdlClientTests {

private DdlClient createSubject(DatabaseAdminClient client) {
return DdlClient.newBuilder()
.setProjectId(projectId)
.setInstanceId(instanceId)
.setDatabaseName(databaseId)
.setDatabaseId(DatabaseId.of(projectId, instanceId, databaseId))
.setDatabaseAdminClient(client)
.build();
}
Expand Down