Skip to content

Commit 7fc9367

Browse files
committed
feat(spanner): added code to fetch default project id before setting default
1 parent 786e764 commit 7fc9367

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DatabaseId.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ public static DatabaseId of(String project, String instance, String database) {
9696

9797
/** Creates a {@code DatabaseId} with "default" as project id, given instance and database IDs. */
9898
public static DatabaseId of(String instance, String database) {
99-
return new DatabaseId(new InstanceId("default", instance), database);
99+
String projectId = SpannerOptions.getDefaultProjectId();
100+
if (projectId == null) {
101+
projectId = "default";
102+
}
103+
return new DatabaseId(new InstanceId(projectId, instance), database);
100104
}
101105

102106
/** Creates a {@code DatabaseId} given the instance identity and database id. */

0 commit comments

Comments
 (0)