Interface DatabaseAdminClient (6.82.0)

public interface DatabaseAdminClient

Client to do admin operations on a Cloud Spanner Database.

Methods

cancelOperation(String name)

public abstract void cancelOperation(String name)

Cancels the specified long-running operation.

Parameter
Name Description
name String

copyBackup(BackupId sourceBackupId, Backup destinationBackup)

public default OperationFuture<Backup,CopyBackupMetadata> copyBackup(BackupId sourceBackupId, Backup destinationBackup)

Creates a copy of backup from an existing backup in Cloud Spanner in the same instance. Any configuration options in the Backup instance will be included in the com.google.spanner.admin.database.v1.CopyBackupRequest.

The expire time of the new backup must be set and be at least 6 hours and at most 366 days after the creation time of the existing backup that is being copied.

Example to create a copy of a backup.


 BackupId sourceBackupId = BackupId.of("source-project", "source-instance", "source-backup-id");
 BackupId destinationBackupId = BackupId.of("destination-project", "destination-instance", "new-backup-id");
 Timestamp expireTime = Timestamp.ofTimeMicroseconds(expireTimeMicros);
 EncryptionConfig encryptionConfig =
         EncryptionConfig.ofKey(
             "projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"));

 Backup destinationBackup = dbAdminClient
     .newBackupBuilder(destinationBackupId)
     .setExpireTime(expireTime)
     .setEncryptionConfig(encryptionConfig)
     .build();

 OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient.copyBackup(sourceBackupId, destinationBackup);
 Backup copiedBackup = op.get();
 
Parameters
Name Description
sourceBackupId BackupId

the backup to be copied

destinationBackup Backup

the new backup to create

Returns
Type Description
OperationFuture<Backup,CopyBackupMetadata>

copyBackup(String instanceId, String sourceBackupId, String destinationBackupId, Timestamp expireTime)

public default OperationFuture<Backup,CopyBackupMetadata> copyBackup(String instanceId, String sourceBackupId, String destinationBackupId, Timestamp expireTime)

Creates a copy of backup from an existing backup in a Cloud Spanner instance.

Example to copy a backup.


 String instanceId                  ="my_instance_id";
 String sourceBackupId              ="source_backup_id";
 String destinationBackupId         ="destination_backup_id";
 Timestamp expireTime               =Timestamp.ofTimeMicroseconds(micros);
 OperationFuture<Backup, CopyBackupMetadata> op = dbAdminClient
     .copyBackup(
         instanceId,
         sourceBackupId,
         destinationBackupId,
         expireTime);
 Backup backup = op.get();
 
Parameters
Name Description
instanceId String

the id of the instance where the source backup is located and where the new backup will be created.

sourceBackupId String

the source backup id.

destinationBackupId String

the id of the backup which will be created. It must conform to the regular expression a-z*[a-z0-9] and be between 2 and 60 characters in length.

expireTime com.google.cloud.Timestamp

the time that the new backup will automatically expire.

Returns
Type Description
OperationFuture<Backup,CopyBackupMetadata>

createBackup(Backup backup)

public abstract OperationFuture<Backup,CreateBackupMetadata> createBackup(Backup backup)

Creates a new backup from a database in a Cloud Spanner. Any configuration options in the Backup instance will be included in the com.google.spanner.admin.database.v1.CreateBackupRequest.

Example to create an encrypted backup.


 BackupId backupId = BackupId.of("project", "instance", "backup-id");
 DatabaseId databaseId = DatabaseId.of("project", "instance", "database-id");
 Timestamp expireTime = Timestamp.ofTimeMicroseconds(expireTimeMicros);
 Timestamp versionTime = Timestamp.ofTimeMicroseconds(versionTimeMicros);
 EncryptionConfig encryptionConfig =
         EncryptionConfig.ofKey(
             "projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"));

 Backup backupToCreate = dbAdminClient
     .newBackupBuilder(backupId)
     .setDatabase(databaseId)
     .setExpireTime(expireTime)
     .setVersionTime(versionTime)
     .setEncryptionConfig(encryptionConfig)
     .build();

 OperationFuture<Backup, CreateBackupMetadata> op = dbAdminClient.createBackup(backupToCreate);
 Backup createdBackup = op.get();
 
Parameter
Name Description
backup Backup

the backup to be created

Returns
Type Description
OperationFuture<Backup,CreateBackupMetadata>
Exceptions
Type Description
SpannerException

createBackup(String sourceInstanceId, String backupId, String databaseId, Timestamp expireTime)

public abstract OperationFuture<Backup,CreateBackupMetadata> createBackup(String sourceInstanceId, String backupId, String databaseId, Timestamp expireTime)

Creates a new backup from a database in a Cloud Spanner instance.

Example to create a backup.


 String instance       = my_instance_id;
 String backupId       = my_backup_id;
 String databaseId     = my_database_id;
 Timestamp expireTime  = Timestamp.ofTimeMicroseconds(micros);
 OperationFuture<Backup, CreateBackupMetadata> op = dbAdminClient
     .createBackup(
         instanceId,
         backupId,
         databaseId,
         expireTime);
 Backup backup = op.get();
 
Parameters
Name Description
sourceInstanceId String

the id of the instance where the database to backup is located and where the backup will be created.

backupId String

the id of the backup which will be created. It must conform to the regular expression a-z*[a-z0-9] and be between 2 and 60 characters in length.

databaseId String

the id of the database to backup.

expireTime com.google.cloud.Timestamp

the time that the backup will automatically expire.

Returns
Type Description
OperationFuture<Backup,CreateBackupMetadata>
Exceptions
Type Description
SpannerException

createDatabase(Database database, Iterable<String> statements)

public abstract OperationFuture<Database,CreateDatabaseMetadata> createDatabase(Database database, Iterable<String> statements)

Creates a database in a Cloud Spanner instance. Any configuration options in the Database instance will be included in the CreateDatabaseRequest.

Example to create an encrypted database.


 Database dbInfo =
     dbClient
         .newDatabaseBuilder(DatabaseId.of("my-project", "my-instance", "my-database"))
         .setEncryptionConfig(
             EncryptionConfig.ofKey(
                 "projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"))
         .build();
 Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
     .createDatabase(
         dbInfo,
         Arrays.asList(
             "CREATE TABLE Singers (
"
                 + "  SingerId   INT64 NOT NULL,
"
                 + "  FirstName  STRING(1024),
"
                 + "  LastName   STRING(1024),
"
                 + "  SingerInfo BYTES(MAX)
"
                 + ") PRIMARY KEY (SingerId)",
             "CREATE TABLE Albums (
"
                 + "  SingerId     INT64 NOT NULL,
"
                 + "  AlbumId      INT64 NOT NULL,
"
                 + "  AlbumTitle   STRING(MAX)
"
                 + ") PRIMARY KEY (SingerId, AlbumId),
"
                 + "  INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
 Database db = op.waitFor().getResult();
 

See Also: #createDatabase(String, String, Iterable)

Parameters
Name Description
database Database
statements Iterable<String>
Returns
Type Description
OperationFuture<Database,CreateDatabaseMetadata>
Exceptions
Type Description
SpannerException

createDatabase(String instanceId, String createDatabaseStatement, Dialect dialect, Iterable<String> statements)

public default OperationFuture<Database,CreateDatabaseMetadata> createDatabase(String instanceId, String createDatabaseStatement, Dialect dialect, Iterable<String> statements)

Creates a new database in a Cloud Spanner instance with the given Dialect.

Example to create database.


 String instanceId = "my_instance_id";
 String createDatabaseStatement = "CREATE DATABASE "my-database"";
 Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
     .createDatabase(
         instanceId,
         createDatabaseStatement,
         Dialect.POSTGRESQL
         Collections.emptyList());
 Database db = op.waitFor().getResult();
 
Parameters
Name Description
instanceId String

the id of the instance in which to create the database.

createDatabaseStatement String

the CREATE DATABASE statement for the database. This statement must use the dialect for the new database.

dialect Dialect

the dialect that the new database should use.

statements Iterable<String>

DDL statements to run while creating the database, for example CREATE TABLE MyTable ( ... ). This should not include CREATE DATABASE statement.

Returns
Type Description
OperationFuture<Database,CreateDatabaseMetadata>
Exceptions
Type Description
SpannerException

createDatabase(String instanceId, String databaseId, Iterable<String> statements)

public abstract OperationFuture<Database,CreateDatabaseMetadata> createDatabase(String instanceId, String databaseId, Iterable<String> statements)

Creates a new database in a Cloud Spanner instance.

Example to create database.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
     .createDatabase(
         instanceId,
         databaseId,
         Arrays.asList(
             "CREATE TABLE Singers (
"
                 + "  SingerId   INT64 NOT NULL,
"
                 + "  FirstName  STRING(1024),
"
                 + "  LastName   STRING(1024),
"
                 + "  SingerInfo BYTES(MAX)
"
                 + ") PRIMARY KEY (SingerId)",
             "CREATE TABLE Albums (
"
                 + "  SingerId     INT64 NOT NULL,
"
                 + "  AlbumId      INT64 NOT NULL,
"
                 + "  AlbumTitle   STRING(MAX)
"
                 + ") PRIMARY KEY (SingerId, AlbumId),
"
                 + "  INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
 Database db = op.waitFor().getResult();
 
Parameters
Name Description
instanceId String

the id of the instance in which to create the database.

databaseId String

the id of the database which will be created. It must conform to the regular expression a-z*[a-z0-9] and be between 2 and 30 characters in length

statements Iterable<String>

DDL statements to run while creating the database, for example CREATE TABLE MyTable ( ... ). This should not include CREATE DATABASE statement.

Returns
Type Description
OperationFuture<Database,CreateDatabaseMetadata>
Exceptions
Type Description
SpannerException

deleteBackup(String instanceId, String backupId)

public abstract void deleteBackup(String instanceId, String backupId)

Deletes a pending or completed backup.

Parameters
Name Description
instanceId String

Required. The instance where the backup exists.

backupId String

Required. The id of the backup to delete.

dropDatabase(String instanceId, String databaseId)

public abstract void dropDatabase(String instanceId, String databaseId)

Drops a Cloud Spanner database.

Example to drop a Cloud Spanner database.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 dbAdminClient.dropDatabase(instanceId, databaseId);
 
Parameters
Name Description
instanceId String
databaseId String
Exceptions
Type Description
SpannerException

getBackup(String instanceId, String backupId)

public abstract Backup getBackup(String instanceId, String backupId)

Gets the current state of a Cloud Spanner database backup.

Example to get a backup.


 String instanceId = my_instance_id;
 String backupId   = my_backup_id;
 Backup backup = dbAdminClient.getBackup(instanceId, backupId);
 
Parameters
Name Description
instanceId String
backupId String
Returns
Type Description
Backup
Exceptions
Type Description
SpannerException

getBackupIAMPolicy(String instanceId, String backupId)

public abstract Policy getBackupIAMPolicy(String instanceId, String backupId)

Returns the IAM policy for the given backup.

Parameters
Name Description
instanceId String
backupId String
Returns
Type Description
com.google.cloud.Policy

getDatabase(String instanceId, String databaseId)

public abstract Database getDatabase(String instanceId, String databaseId)

Gets the current state of a Cloud Spanner database.

Example to getDatabase.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 Database db = dbAdminClient.getDatabase(instanceId, databaseId);
 
Parameters
Name Description
instanceId String
databaseId String
Returns
Type Description
Database
Exceptions
Type Description
SpannerException

getDatabaseDdl(String instanceId, String databaseId)

public abstract List<String> getDatabaseDdl(String instanceId, String databaseId)

Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates.

Example to get the schema of a Cloud Spanner database.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 List<String> statementsInDb = dbAdminClient.getDatabaseDdl(instanceId, databaseId);
 
Parameters
Name Description
instanceId String
databaseId String
Returns
Type Description
List<String>

getDatabaseDdlResponse(String instanceId, String databaseId)

public abstract GetDatabaseDdlResponse getDatabaseDdlResponse(String instanceId, String databaseId)

Returns the GetDatabaseDdlResponse object of a Cloud Spanner database.

Example to get GetDatabaseDdlResponse object of a Cloud Spanner database.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 GetDatabaseDdlResponse response = dbAdminClient.getDatabaseDdl(instanceId, databaseId);
 
Parameters
Name Description
instanceId String

the id of the instance where the database was created.

databaseId String

the id of the database.

Returns
Type Description
GetDatabaseDdlResponse

GetDatabaseDdlResponse object

getDatabaseIAMPolicy(String instanceId, String databaseId, int version)

public abstract Policy getDatabaseIAMPolicy(String instanceId, String databaseId, int version)

Returns the IAM policy for the given database.

Version specifies the format used to create the policy, valid values are 0, 1, and 3. Requests specifying an invalid value will be rejected. Requests for policies with any conditional role bindings must specify version 3. Policies with no conditional role bindings may specify any valid value or leave the field unset.

The policy in the response might use the policy version that you specified, or it might use a lower policy version. For example, if you specify version 3, but the policy has no conditional role bindings, the response uses version 1.

To learn which resources support conditions in their IAM policies, see the See Also: IAM documentation.

Parameters
Name Description
instanceId String
databaseId String
version int
Returns
Type Description
com.google.cloud.Policy

getOperation(String name)

public abstract Operation getOperation(String name)

Gets the specified long-running operation.

Parameter
Name Description
name String
Returns
Type Description
Operation

listBackupOperations(String instanceId, Options.ListOption[] options)

public abstract Page<Operation> listBackupOperations(String instanceId, Options.ListOption[] options)

Lists long-running backup operations on the specified instance.

Parameters
Name Description
instanceId String
options ListOption[]
Returns
Type Description
Page<Operation>

listBackups(String instanceId, Options.ListOption[] options)

public abstract Page<Backup> listBackups(String instanceId, Options.ListOption[] options)

Returns the list of Cloud Spanner backups in the given instance.

Example to get the list of Cloud Spanner backups in the given instance.


 String instanceId = my_instance_id;
 Page<Backup> page = dbAdminClient.listBackups(instanceId, Options.pageSize(1));
 List<Backup> backups = new ArrayList<>();
 while (page != null) {
   Backup backup = Iterables.getOnlyElement(page.getValues());
   dbs.add(backup);
   page = page.getNextPage();
 }
 
Parameters
Name Description
instanceId String
options ListOption[]
Returns
Type Description
Page<Backup>

listDatabaseOperations(String instanceId, Options.ListOption[] options)

public abstract Page<Operation> listDatabaseOperations(String instanceId, Options.ListOption[] options)

Lists long-running database operations on the specified instance.

Parameters
Name Description
instanceId String
options ListOption[]
Returns
Type Description
Page<Operation>

listDatabaseRoles(String instanceId, String databaseId, Options.ListOption[] options)

public abstract Page<DatabaseRole> listDatabaseRoles(String instanceId, String databaseId, Options.ListOption[] options)

Lists database roles on the specified database.

Parameters
Name Description
instanceId String
databaseId String
options ListOption[]
Returns
Type Description
Page<DatabaseRole>

listDatabases(String instanceId, Options.ListOption[] options)

public abstract Page<Database> listDatabases(String instanceId, Options.ListOption[] options)

Returns the list of Cloud Spanner database in the given instance.

Example to get the list of Cloud Spanner database in the given instance.


 String instanceId = my_instance_id;
 Page<Database> page = dbAdminClient.listDatabases(instanceId, Options.pageSize(1));
 List<Database> dbs = new ArrayList<>();
 while (page != null) {
   Database db = Iterables.getOnlyElement(page.getValues());
   dbs.add(db);
   page = page.getNextPage();
 }
 
Parameters
Name Description
instanceId String
options ListOption[]
Returns
Type Description
Page<Database>

newBackupBuilder(BackupId id)

public abstract Backup.Builder newBackupBuilder(BackupId id)

Returns a builder for a Backup object with the given id.

Parameter
Name Description
id BackupId
Returns
Type Description
Backup.Builder

newDatabaseBuilder(DatabaseId id)

public abstract Database.Builder newDatabaseBuilder(DatabaseId id)

Returns a builder for a Database object with the given id.

Parameter
Name Description
id DatabaseId
Returns
Type Description
Database.Builder

newRestoreBuilder(BackupId source, DatabaseId destination)

public abstract Restore.Builder newRestoreBuilder(BackupId source, DatabaseId destination)

Returns a builder for a Restore object with the given source and destination

Parameters
Name Description
source BackupId
destination DatabaseId
Returns
Type Description
Restore.Builder

restoreDatabase(Restore restore)

public abstract OperationFuture<Database,RestoreDatabaseMetadata> restoreDatabase(Restore restore)

Restore a database from a backup. The database that is restored will be created and may not already exist.

Example to restore an encrypted database.


 final Restore restore = dbAdminClient
     .newRestoreBuilder(
         BackupId.of("my-project", "my-instance", "my-backup"),
         DatabaseId.of("my-project", "my-instance", "my-database")
     )
     .setEncryptionConfig(EncryptionConfig.ofKey(
         "projects/my-project/locations/some-location/keyRings/my-keyring/cryptoKeys/my-key"))
     .build();

 final OperationFuture<Database, RestoreDatabaseMetadata> op = dbAdminClient
     .restoreDatabase(restore);

 Database database = op.get();
 
Parameter
Name Description
restore Restore

a Restore instance with the backup source and destination database

Returns
Type Description
OperationFuture<Database,RestoreDatabaseMetadata>
Exceptions
Type Description
SpannerException

restoreDatabase(String backupInstanceId, String backupId, String restoreInstanceId, String restoreDatabaseId)

public abstract OperationFuture<Database,RestoreDatabaseMetadata> restoreDatabase(String backupInstanceId, String backupId, String restoreInstanceId, String restoreDatabaseId)

Restore a database from a backup. The database that is restored will be created and may not already exist.

Example to restore a database.


 String backupInstanceId   = my_instance_id;
 String backupId           = my_backup_id;
 String restoreInstanceId  = my_db_instance_id;
 String restoreDatabaseId  = my_database_id;
 OperationFuture<Database, RestoreDatabaseMetadata> op = dbAdminClient
     .restoreDatabase(
         backupInstanceId,
         backupId,
         restoreInstanceId,
         restoreDatabaseId);
 Database database = op.get();
 
Parameters
Name Description
backupInstanceId String

the id of the instance where the backup is located.

backupId String

the id of the backup to restore.

restoreInstanceId String

the id of the instance where the database should be created. This may be a different instance than where the backup is stored.

restoreDatabaseId String

the id of the database to restore to.

Returns
Type Description
OperationFuture<Database,RestoreDatabaseMetadata>
Exceptions
Type Description
SpannerException

setBackupIAMPolicy(String instanceId, String backupId, Policy policy)

public abstract Policy setBackupIAMPolicy(String instanceId, String backupId, Policy policy)

Updates the IAM policy for the given backup and returns the resulting policy. It is highly recommended to first get the current policy and base the updated policy on the returned policy. See Policy.Builder#setEtag(String) for information on the recommended read-modify-write cycle.

Parameters
Name Description
instanceId String
backupId String
policy com.google.cloud.Policy
Returns
Type Description
com.google.cloud.Policy

setDatabaseIAMPolicy(String instanceId, String databaseId, Policy policy)

public abstract Policy setDatabaseIAMPolicy(String instanceId, String databaseId, Policy policy)

Updates the IAM policy for the given database and returns the resulting policy. It is highly recommended to first get the current policy and base the updated policy on the returned policy. See Policy.Builder#setEtag(String) for information on the recommended read-modify-write cycle.

Parameters
Name Description
instanceId String
databaseId String
policy com.google.cloud.Policy
Returns
Type Description
com.google.cloud.Policy

testBackupIAMPermissions(String instanceId, String backupId, Iterable<String> permissions)

public abstract Iterable<String> testBackupIAMPermissions(String instanceId, String backupId, Iterable<String> permissions)

Tests for the given permissions on the specified backup for the caller.

Parameters
Name Description
instanceId String

the id of the instance where the backup to test is located.

backupId String

the id of the backup to test.

permissions Iterable<String>

the permissions to test for. Permissions with wildcards (such as '', 'spanner.', 'spanner.instances.*') are not allowed.

Returns
Type Description
Iterable<String>

the subset of the tested permissions that the caller is allowed.

testDatabaseIAMPermissions(String instanceId, String databaseId, Iterable<String> permissions)

public abstract Iterable<String> testDatabaseIAMPermissions(String instanceId, String databaseId, Iterable<String> permissions)

Tests for the given permissions on the specified database for the caller.

Parameters
Name Description
instanceId String

the id of the instance where the database to test is located.

databaseId String

the id of the database to test.

permissions Iterable<String>

the permissions to test for. Permissions with wildcards (such as '', 'spanner.', 'spanner.instances.*') are not allowed.

Returns
Type Description
Iterable<String>

the subset of the tested permissions that the caller is allowed.

updateBackup(String instanceId, String backupId, Timestamp expireTime)

public abstract Backup updateBackup(String instanceId, String backupId, Timestamp expireTime)

Updates the expire time of a backup.

Parameters
Name Description
instanceId String

Required. The instance of the backup to update.

backupId String

Required. The backup id of the backup to update.

expireTime com.google.cloud.Timestamp

Required. The new expire time of the backup to set to.

Returns
Type Description
Backup

the updated Backup object.

updateDatabase(Database database, DatabaseInfo.DatabaseField[] fieldsToUpdate)

public abstract OperationFuture<Database,UpdateDatabaseMetadata> updateDatabase(Database database, DatabaseInfo.DatabaseField[] fieldsToUpdate)

Updates a Cloud Spanner database. The returned Operation can be used to track the progress of the update. Throws SpannerException if the Cloud Spanner database does not exist.

Until completion of the returned operation:

  • Cancelling the operation is best effort and may or may not succeed.
  • All other attempts to modify the database are rejected.
  • Reading the database via the API continues to give the pre-request field values.

Upon completion of the returned operation:

  • The database's new fields are readable via the API.

Example of updating a database.


 String projectId = my_project_id;
 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 Database databaseToUpdate = databaseAdminClient.newDatabaseBuilder(
         DatabaseId.of(projectId, instanceId, databaseId))
      .enableDropProtection().build();
 OperationFuture<Database, UpdateDatabaseMetadata> op = databaseAdminClient.updateDatabase(
           databaseToUpdate, DatabaseField.DROP_PROTECTION);
 Database updateDatabase = op.get(5, TimeUnit.MINUTES);
 
Parameters
Name Description
database Database

The database to update to. The current field values of the database will be updated to the values specified in this parameter.

fieldsToUpdate DatabaseField[]

The fields that should be updated. Only these fields will have their values updated to the values specified in {@param database}, even if there are other fields specified in {@param database}.

Returns
Type Description
OperationFuture<Database,UpdateDatabaseMetadata>
Exceptions
Type Description
SpannerException

updateDatabaseDdl(Database database, Iterable<String> statements, String operationId)

public abstract OperationFuture<Void,UpdateDatabaseDdlMetadata> updateDatabaseDdl(Database database, Iterable<String> statements, String operationId)

Updates a database in a Cloud Spanner instance. Any proto descriptors that have been set for the com.google.cloud.spanner.Database instance will be included in the com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest.

If an operation already exists with the given operation id, the operation will be resumed and the returned future will complete when the original operation finishes. See more information in com.google.cloud.spanner.spi.v1.GapicSpannerRpc#updateDatabaseDdl(com.google.cloud.spanner.Database, Iterable, String)

Example to update the database DDL with proto descriptors.


 Database dbInfo =
         dbClient
            .newDatabaseBuilder(DatabaseId.of("my_project_id", "my_instance_id", "my_database_id"))
            .setProtoDescriptors("com/google/cloud/spanner/descriptors.pb")
            .build();
 dbAdminClient.updateDatabaseDdl(dbInfo,
     Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
     null).waitFor();
 
Parameters
Name Description
database Database

Database object to set configuration options such as proto_descriptors.

statements Iterable<String>

DDL statements to run while updating the database.

operationId String

Operation id assigned to this operation. If null, system will autogenerate one. This must be unique within a database abd must be a valid identifier a-zA-Z*.

Returns
Type Description
OperationFuture<Void,UpdateDatabaseDdlMetadata>
Exceptions
Type Description
SpannerException

updateDatabaseDdl(String instanceId, String databaseId, Iterable<String> statements, String operationId)

public abstract OperationFuture<Void,UpdateDatabaseDdlMetadata> updateDatabaseDdl(String instanceId, String databaseId, Iterable<String> statements, String operationId)

Enqueues the given DDL statements to be applied, in order but not necessarily all at once, to the database schema at some point (or points) in the future. The server checks that the statements are executable (syntactically valid, name tables that exist, etc.) before enqueueing them, but they may still fail upon later execution (e.g., if a statement from another batch of statements is applied first and it conflicts in some way, or if there is some data-related problem like a NULL value in a column to which NOT NULL would be added). If a statement fails, all subsequent statements in the batch are automatically cancelled.

If an operation already exists with the given operation id, the operation will be resumed and the returned future will complete when the original operation finishes. See more information in com.google.cloud.spanner.spi.v1.GapicSpannerRpc#updateDatabaseDdl(com.google.cloud.spanner.Database, Iterable, String)

Example to update the database DDL.


 String instanceId = my_instance_id;
 String databaseId = my_database_id;
 dbAdminClient.updateDatabaseDdl(instanceId,
     databaseId,
     Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
     null).waitFor();
 
Parameters
Name Description
instanceId String
databaseId String
statements Iterable<String>
operationId String

Operation id assigned to this operation. If null, system will autogenerate one. This must be unique within a database abd must be a valid identifier a-zA-Z*.

Returns
Type Description
OperationFuture<Void,UpdateDatabaseDdlMetadata>
Exceptions
Type Description
SpannerException