public interface DatabaseAdminClient
Modifier and Type | Method and Description |
---|---|
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 |
dropDatabase(String instanceId,
String databaseId)
Drops a Cloud Spanner database.
|
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.api.gax.paging.Page<Database> |
listDatabases(String instanceId,
Options.ListOption... options)
Returns the list of Cloud Spanner database in the given instance.
|
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> |
testDatabaseIAMPermissions(String instanceId,
String databaseId,
Iterable<String> permissions)
Tests for the given permissions on the specified database for the caller.
|
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
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
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.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.Copyright © 2019 Google LLC. All rights reserved.