public interface DatabaseAdminClient
Modifier and Type | Method and Description |
---|---|
void |
cancelOperation(String name)
Cancels the specified long-running operation.
|
com.google.api.gax.longrunning.OperationFuture<Backup,CreateBackupMetadata> |
createBackup(String sourceInstanceId,
String backupId,
String databaseId,
com.google.cloud.Timestamp expireTime)
Creates a new backup from a database in a Cloud Spanner instance.
|
com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> |
createDatabase(String instanceId,
String databaseId,
Iterable<String> statements)
Creates a new database in a Cloud Spanner instance.
|
void |
deleteBackup(String instanceId,
String backupId)
Deletes a pending or completed backup.
|
void |
dropDatabase(String instanceId,
String databaseId)
Drops a Cloud Spanner database.
|
Backup |
getBackup(String instanceId,
String backupId)
Gets the current state of a Cloud Spanner database backup.
|
com.google.cloud.Policy |
getBackupIAMPolicy(String instanceId,
String backupId)
Returns the IAM policy for the given backup.
|
Database |
getDatabase(String instanceId,
String databaseId)
Gets the current state of a Cloud Spanner database.
|
List<String> |
getDatabaseDdl(String instanceId,
String databaseId)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
com.google.cloud.Policy |
getDatabaseIAMPolicy(String instanceId,
String databaseId)
Returns the IAM policy for the given database.
|
com.google.longrunning.Operation |
getOperation(String name)
Gets the specified long-running operation.
|
com.google.api.gax.paging.Page<com.google.longrunning.Operation> |
listBackupOperations(String instanceId,
Options.ListOption... options)
Lists long-running backup operations on the specified instance.
|
com.google.api.gax.paging.Page<Backup> |
listBackups(String instanceId,
Options.ListOption... options)
Returns the list of Cloud Spanner backups in the given instance.
|
com.google.api.gax.paging.Page<com.google.longrunning.Operation> |
listDatabaseOperations(String instanceId,
Options.ListOption... options)
Lists long-running database operations on the specified instance.
|
com.google.api.gax.paging.Page<Database> |
listDatabases(String instanceId,
Options.ListOption... options)
Returns the list of Cloud Spanner database in the given instance.
|
Backup.Builder |
newBackupBuilder(BackupId id)
Returns a builder for a
Backup object with the given id. |
com.google.api.gax.longrunning.OperationFuture<Database,RestoreDatabaseMetadata> |
restoreDatabase(String backupInstanceId,
String backupId,
String restoreInstanceId,
String restoreDatabaseId)
Restore a database from a backup.
|
com.google.cloud.Policy |
setBackupIAMPolicy(String instanceId,
String backupId,
com.google.cloud.Policy policy)
Updates the IAM policy for the given backup and returns the resulting policy.
|
com.google.cloud.Policy |
setDatabaseIAMPolicy(String instanceId,
String databaseId,
com.google.cloud.Policy policy)
Updates the IAM policy for the given database and returns the resulting policy.
|
Iterable<String> |
testBackupIAMPermissions(String instanceId,
String backupId,
Iterable<String> permissions)
Tests for the given permissions on the specified backup for the caller.
|
Iterable<String> |
testDatabaseIAMPermissions(String instanceId,
String databaseId,
Iterable<String> permissions)
Tests for the given permissions on the specified database for the caller.
|
Backup |
updateBackup(String instanceId,
String backupId,
com.google.cloud.Timestamp expireTime)
Updates the expire time of a backup.
|
com.google.api.gax.longrunning.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.
|
com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> createDatabase(String instanceId, String databaseId, Iterable<String> statements) throws SpannerException
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 (\n"
+ " SingerId INT64 NOT NULL,\n"
+ " FirstName STRING(1024),\n"
+ " LastName STRING(1024),\n"
+ " SingerInfo BYTES(MAX)\n"
+ ") PRIMARY KEY (SingerId)",
"CREATE TABLE Albums (\n"
+ " SingerId INT64 NOT NULL,\n"
+ " AlbumId INT64 NOT NULL,\n"
+ " AlbumTitle STRING(MAX)\n"
+ ") PRIMARY KEY (SingerId, AlbumId),\n"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
Database db = op.waitFor().getResult();
instanceId
- the id of the instance in which to create the database.databaseId
- the id of the database which will be created. It must conform to the regular
expression [a-z][a-z0-9_\-]*[a-z0-9] and be between 2 and 30 characters in lengthstatements
- DDL statements to run while creating the database, for example CREATE
TABLE MyTable ( ... )
. This should not include CREATE DATABASE
statement.SpannerException
Backup.Builder newBackupBuilder(BackupId id)
Backup
object with the given id.com.google.api.gax.longrunning.OperationFuture<Backup,CreateBackupMetadata> createBackup(String sourceInstanceId, String backupId, String databaseId, com.google.cloud.Timestamp expireTime) throws SpannerException
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();
instanceId
- the id of the instance where the database to backup is located and where the
backup will be created.backupId
- the id of the backup which will be created. It must conform to the regular
expression [a-z][a-z0-9_\-]*[a-z0-9] and be between 2 and 60 characters in length.databaseId
- the id of the database to backup.expireTime
- the time that the backup will automatically expire.SpannerException
com.google.api.gax.longrunning.OperationFuture<Database,RestoreDatabaseMetadata> restoreDatabase(String backupInstanceId, String backupId, String restoreInstanceId, String restoreDatabaseId) throws SpannerException
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<Backup, RestoreDatabaseMetadata> op = dbAdminClient
.restoreDatabase(
backupInstanceId,
backupId,
restoreInstanceId,
restoreDatabaseId);
Database database = op.get();
backupInstanceId
- the id of the instance where the backup is located.backupId
- the id of the backup to restore.restoreInstanceId
- the id of the instance where the database should be created. This may
be a different instance than where the backup is stored.restoreDatabaseId
- the id of the database to restore to.SpannerException
com.google.api.gax.paging.Page<com.google.longrunning.Operation> listDatabaseOperations(String instanceId, Options.ListOption... options)
com.google.api.gax.paging.Page<com.google.longrunning.Operation> listBackupOperations(String instanceId, Options.ListOption... options)
Database getDatabase(String instanceId, String databaseId) throws SpannerException
Example to getDatabase.
String instanceId = my_instance_id;
String databaseId = my_database_id;
Database db = dbAdminClient.getDatabase(instanceId, databaseId);
SpannerException
Backup getBackup(String instanceId, String backupId) throws SpannerException
Example to get a backup.
String instanceId = my_instance_id;
String backupId = my_backup_id;
Backup backup = dbAdminClient.getBackup(instanceId, backupId);
SpannerException
com.google.api.gax.longrunning.OperationFuture<Void,UpdateDatabaseDdlMetadata> updateDatabaseDdl(String instanceId, String databaseId, Iterable<String> statements, @Nullable String operationId) throws SpannerException
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();
operationId
- 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][a-zA-Z0-9_]*.SpannerException
void dropDatabase(String instanceId, String databaseId) throws SpannerException
Example to drop a Cloud Spanner database.
String instanceId = my_instance_id;
String databaseId = my_database_id;
dbAdminClient.dropDatabase(instanceId, databaseId);
SpannerException
List<String> getDatabaseDdl(String instanceId, String databaseId)
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);
com.google.api.gax.paging.Page<Database> listDatabases(String instanceId, Options.ListOption... options)
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();
}
com.google.api.gax.paging.Page<Backup> listBackups(String instanceId, Options.ListOption... options)
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();
}
Backup updateBackup(String instanceId, String backupId, com.google.cloud.Timestamp expireTime)
instanceId
- Required. The instance of the backup to update.backupId
- Required. The backup id of the backup to update.expireTime
- Required. The new expire time of the backup to set to.void deleteBackup(String instanceId, String backupId)
instanceId
- Required. The instance where the backup exists.backupId
- Required. The id of the backup to delete.void cancelOperation(String name)
com.google.longrunning.Operation getOperation(String name)
com.google.cloud.Policy getDatabaseIAMPolicy(String instanceId, String databaseId)
com.google.cloud.Policy setDatabaseIAMPolicy(String instanceId, String databaseId, com.google.cloud.Policy policy)
Policy.Builder#setEtag(String)
for information on the recommended read-modify-write
cycle.Iterable<String> testDatabaseIAMPermissions(String instanceId, String databaseId, Iterable<String> permissions)
instanceId
- the id of the instance where the database to test is located.databaseId
- the id of the database to test.permissions
- the permissions to test for. Permissions with wildcards (such as '*',
'spanner.*', 'spanner.instances.*') are not allowed.com.google.cloud.Policy getBackupIAMPolicy(String instanceId, String backupId)
com.google.cloud.Policy setBackupIAMPolicy(String instanceId, String backupId, com.google.cloud.Policy policy)
Policy.Builder#setEtag(String)
for information on the recommended read-modify-write
cycle.Iterable<String> testBackupIAMPermissions(String instanceId, String backupId, Iterable<String> permissions)
instanceId
- the id of the instance where the backup to test is located.backupId
- the id of the backup to test.permissions
- the permissions to test for. Permissions with wildcards (such as '*',
'spanner.*', 'spanner.instances.*') are not allowed.Copyright © 2020 Google LLC. All rights reserved.