@Generated(value="by gapic-generator") @BetaApi public class DatabaseAdminClient extends Object implements BackgroundResource
The Cloud Spanner Database Admin API can be used to create, drop, and list databases. It also enables updating the schema of pre-existing databases.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Database response = databaseAdminClient.getDatabase(name);
}
Note: close() needs to be called on the databaseAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of DatabaseAdminSettings to create(). For example:
To customize credentials:
DatabaseAdminSettings databaseAdminSettings =
DatabaseAdminSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
DatabaseAdminClient databaseAdminClient =
DatabaseAdminClient.create(databaseAdminSettings);
To customize the endpoint:
DatabaseAdminSettings databaseAdminSettings =
DatabaseAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
DatabaseAdminClient databaseAdminClient =
DatabaseAdminClient.create(databaseAdminSettings);
Modifier and Type | Class and Description |
---|---|
static class |
DatabaseAdminClient.ListDatabasesFixedSizeCollection |
static class |
DatabaseAdminClient.ListDatabasesPage |
static class |
DatabaseAdminClient.ListDatabasesPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
DatabaseAdminClient(DatabaseAdminSettings settings)
Constructs an instance of DatabaseAdminClient, using the given settings.
|
protected |
DatabaseAdminClient(DatabaseAdminStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static DatabaseAdminClient |
create()
Constructs an instance of DatabaseAdminClient with default settings.
|
static DatabaseAdminClient |
create(DatabaseAdminSettings settings)
Constructs an instance of DatabaseAdminClient, using the given settings.
|
static DatabaseAdminClient |
create(DatabaseAdminStub stub)
Constructs an instance of DatabaseAdminClient, using the given stub for making calls.
|
OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> |
createDatabaseAsync(com.google.spanner.admin.database.v1.CreateDatabaseRequest request)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> |
createDatabaseAsync(com.google.spanner.admin.database.v1.InstanceName parent,
String createStatement)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> |
createDatabaseAsync(String parent,
String createStatement)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
UnaryCallable<com.google.spanner.admin.database.v1.CreateDatabaseRequest,Operation> |
createDatabaseCallable()
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
OperationCallable<com.google.spanner.admin.database.v1.CreateDatabaseRequest,com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> |
createDatabaseOperationCallable()
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
void |
dropDatabase(com.google.spanner.admin.database.v1.DatabaseName database)
Drops (aka deletes) a Cloud Spanner database.
|
void |
dropDatabase(com.google.spanner.admin.database.v1.DropDatabaseRequest request)
Drops (aka deletes) a Cloud Spanner database.
|
void |
dropDatabase(String database)
Drops (aka deletes) a Cloud Spanner database.
|
UnaryCallable<com.google.spanner.admin.database.v1.DropDatabaseRequest,Empty> |
dropDatabaseCallable()
Drops (aka deletes) a Cloud Spanner database.
|
com.google.spanner.admin.database.v1.Database |
getDatabase(com.google.spanner.admin.database.v1.DatabaseName name)
Gets the state of a Cloud Spanner database.
|
com.google.spanner.admin.database.v1.Database |
getDatabase(com.google.spanner.admin.database.v1.GetDatabaseRequest request)
Gets the state of a Cloud Spanner database.
|
com.google.spanner.admin.database.v1.Database |
getDatabase(String name)
Gets the state of a Cloud Spanner database.
|
UnaryCallable<com.google.spanner.admin.database.v1.GetDatabaseRequest,com.google.spanner.admin.database.v1.Database> |
getDatabaseCallable()
Gets the state of a Cloud Spanner database.
|
com.google.spanner.admin.database.v1.GetDatabaseDdlResponse |
getDatabaseDdl(com.google.spanner.admin.database.v1.DatabaseName database)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
com.google.spanner.admin.database.v1.GetDatabaseDdlResponse |
getDatabaseDdl(com.google.spanner.admin.database.v1.GetDatabaseDdlRequest request)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
com.google.spanner.admin.database.v1.GetDatabaseDdlResponse |
getDatabaseDdl(String database)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
UnaryCallable<com.google.spanner.admin.database.v1.GetDatabaseDdlRequest,com.google.spanner.admin.database.v1.GetDatabaseDdlResponse> |
getDatabaseDdlCallable()
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
com.google.iam.v1.Policy |
getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Gets the access control policy for a database resource.
|
com.google.iam.v1.Policy |
getIamPolicy(String resource)
Gets the access control policy for a database resource.
|
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a database resource.
|
OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
DatabaseAdminSettings |
getSettings() |
DatabaseAdminStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
DatabaseAdminClient.ListDatabasesPagedResponse |
listDatabases(com.google.spanner.admin.database.v1.InstanceName parent)
Lists Cloud Spanner databases.
|
DatabaseAdminClient.ListDatabasesPagedResponse |
listDatabases(com.google.spanner.admin.database.v1.ListDatabasesRequest request)
Lists Cloud Spanner databases.
|
DatabaseAdminClient.ListDatabasesPagedResponse |
listDatabases(String parent)
Lists Cloud Spanner databases.
|
UnaryCallable<com.google.spanner.admin.database.v1.ListDatabasesRequest,com.google.spanner.admin.database.v1.ListDatabasesResponse> |
listDatabasesCallable()
Lists Cloud Spanner databases.
|
UnaryCallable<com.google.spanner.admin.database.v1.ListDatabasesRequest,DatabaseAdminClient.ListDatabasesPagedResponse> |
listDatabasesPagedCallable()
Lists Cloud Spanner databases.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the access control policy on a database resource.
|
com.google.iam.v1.Policy |
setIamPolicy(String resource,
com.google.iam.v1.Policy policy)
Sets the access control policy on a database resource.
|
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
setIamPolicyCallable()
Sets the access control policy on a database resource.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource,
List<String> permissions)
Returns permissions that the caller has on the specified database resource.
|
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that the caller has on the specified database resource.
|
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that the caller has on the specified database resource.
|
OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(com.google.spanner.admin.database.v1.DatabaseName database,
List<String> statements)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(String database,
List<String> statements)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest request)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
UnaryCallable<com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest,Operation> |
updateDatabaseDdlCallable()
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
OperationCallable<com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest,Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> |
updateDatabaseDdlOperationCallable()
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
protected DatabaseAdminClient(DatabaseAdminSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected DatabaseAdminClient(DatabaseAdminStub stub)
public static final DatabaseAdminClient create() throws IOException
IOException
public static final DatabaseAdminClient create(DatabaseAdminSettings settings) throws IOException
IOException
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final DatabaseAdminClient create(DatabaseAdminStub stub)
public final DatabaseAdminSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public DatabaseAdminStub getStub()
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationsClient getOperationsClient()
public final DatabaseAdminClient.ListDatabasesPagedResponse listDatabases(com.google.spanner.admin.database.v1.InstanceName parent)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
for (Database element : databaseAdminClient.listDatabases(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The instance whose databases should be listed. Values are of the form
`projects/<project>/instances/<instance>`.ApiException
- if the remote call failspublic final DatabaseAdminClient.ListDatabasesPagedResponse listDatabases(String parent)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
for (Database element : databaseAdminClient.listDatabases(parent.toString()).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The instance whose databases should be listed. Values are of the form
`projects/<project>/instances/<instance>`.ApiException
- if the remote call failspublic final DatabaseAdminClient.ListDatabasesPagedResponse listDatabases(com.google.spanner.admin.database.v1.ListDatabasesRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListDatabasesRequest request = ListDatabasesRequest.newBuilder()
.setParent(parent.toString())
.build();
for (Database element : databaseAdminClient.listDatabases(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.spanner.admin.database.v1.ListDatabasesRequest,DatabaseAdminClient.ListDatabasesPagedResponse> listDatabasesPagedCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListDatabasesRequest request = ListDatabasesRequest.newBuilder()
.setParent(parent.toString())
.build();
ApiFuture<ListDatabasesPagedResponse> future = databaseAdminClient.listDatabasesPagedCallable().futureCall(request);
// Do something
for (Database element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<com.google.spanner.admin.database.v1.ListDatabasesRequest,com.google.spanner.admin.database.v1.ListDatabasesResponse> listDatabasesCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
ListDatabasesRequest request = ListDatabasesRequest.newBuilder()
.setParent(parent.toString())
.build();
while (true) {
ListDatabasesResponse response = databaseAdminClient.listDatabasesCallable().call(request);
for (Database element : response.getDatabasesList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> createDatabaseAsync(com.google.spanner.admin.database.v1.InstanceName parent, String createStatement)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String createStatement = "";
Database response = databaseAdminClient.createDatabaseAsync(parent, createStatement).get();
}
parent
- Required. The name of the instance that will serve the new database. Values are
of the form `projects/<project>/instances/<instance>`.createStatement
- Required. A `CREATE DATABASE` statement, which specifies the ID of the
new database. The database ID must conform to the regular expression
`[a-z][a-z0-9_\-]*[a-z0-9]` and be between 2 and 30 characters in length. If the
database ID is a reserved word or if it contains a hyphen, the database ID must be enclosed
in backticks (`` ` ``).ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> createDatabaseAsync(String parent, String createStatement)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String createStatement = "";
Database response = databaseAdminClient.createDatabaseAsync(parent.toString(), createStatement).get();
}
parent
- Required. The name of the instance that will serve the new database. Values are
of the form `projects/<project>/instances/<instance>`.createStatement
- Required. A `CREATE DATABASE` statement, which specifies the ID of the
new database. The database ID must conform to the regular expression
`[a-z][a-z0-9_\-]*[a-z0-9]` and be between 2 and 30 characters in length. If the
database ID is a reserved word or if it contains a hyphen, the database ID must be enclosed
in backticks (`` ` ``).ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> createDatabaseAsync(com.google.spanner.admin.database.v1.CreateDatabaseRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String createStatement = "";
CreateDatabaseRequest request = CreateDatabaseRequest.newBuilder()
.setParent(parent.toString())
.setCreateStatement(createStatement)
.build();
Database response = databaseAdminClient.createDatabaseAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.spanner.admin.database.v1.CreateDatabaseRequest,com.google.spanner.admin.database.v1.Database,com.google.spanner.admin.database.v1.CreateDatabaseMetadata> createDatabaseOperationCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String createStatement = "";
CreateDatabaseRequest request = CreateDatabaseRequest.newBuilder()
.setParent(parent.toString())
.setCreateStatement(createStatement)
.build();
OperationFuture<Database, CreateDatabaseMetadata> future = databaseAdminClient.createDatabaseOperationCallable().futureCall(request);
// Do something
Database response = future.get();
}
public final UnaryCallable<com.google.spanner.admin.database.v1.CreateDatabaseRequest,Operation> createDatabaseCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String createStatement = "";
CreateDatabaseRequest request = CreateDatabaseRequest.newBuilder()
.setParent(parent.toString())
.setCreateStatement(createStatement)
.build();
ApiFuture<Operation> future = databaseAdminClient.createDatabaseCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final com.google.spanner.admin.database.v1.Database getDatabase(com.google.spanner.admin.database.v1.DatabaseName name)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Database response = databaseAdminClient.getDatabase(name);
}
name
- Required. The name of the requested database. Values are of the form
`projects/<project>/instances/<instance>/databases/<database>`.ApiException
- if the remote call failspublic final com.google.spanner.admin.database.v1.Database getDatabase(String name)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Database response = databaseAdminClient.getDatabase(name.toString());
}
name
- Required. The name of the requested database. Values are of the form
`projects/<project>/instances/<instance>/databases/<database>`.ApiException
- if the remote call failspublic final com.google.spanner.admin.database.v1.Database getDatabase(com.google.spanner.admin.database.v1.GetDatabaseRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseRequest request = GetDatabaseRequest.newBuilder()
.setName(name.toString())
.build();
Database response = databaseAdminClient.getDatabase(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.spanner.admin.database.v1.GetDatabaseRequest,com.google.spanner.admin.database.v1.Database> getDatabaseCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName name = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseRequest request = GetDatabaseRequest.newBuilder()
.setName(name.toString())
.build();
ApiFuture<Database> future = databaseAdminClient.getDatabaseCallable().futureCall(request);
// Do something
Database response = future.get();
}
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> updateDatabaseDdlAsync(com.google.spanner.admin.database.v1.DatabaseName database, List<String> statements)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
databaseAdminClient.updateDatabaseDdlAsync(database, statements).get();
}
database
- Required. The database to update.statements
- DDL statements to be applied to the database.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> updateDatabaseDdlAsync(String database, List<String> statements)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
databaseAdminClient.updateDatabaseDdlAsync(database.toString(), statements).get();
}
database
- Required. The database to update.statements
- DDL statements to be applied to the database.ApiException
- if the remote call fails@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> updateDatabaseDdlAsync(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
UpdateDatabaseDdlRequest request = UpdateDatabaseDdlRequest.newBuilder()
.setDatabase(database.toString())
.addAllStatements(statements)
.build();
databaseAdminClient.updateDatabaseDdlAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call fails@BetaApi(value="The surface for use by generated code is not stable yet and may change in the future.") public final OperationCallable<com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest,Empty,com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata> updateDatabaseDdlOperationCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
UpdateDatabaseDdlRequest request = UpdateDatabaseDdlRequest.newBuilder()
.setDatabase(database.toString())
.addAllStatements(statements)
.build();
OperationFuture<Empty, UpdateDatabaseDdlMetadata> future = databaseAdminClient.updateDatabaseDdlOperationCallable().futureCall(request);
// Do something
future.get();
}
public final UnaryCallable<com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest,Operation> updateDatabaseDdlCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
UpdateDatabaseDdlRequest request = UpdateDatabaseDdlRequest.newBuilder()
.setDatabase(database.toString())
.addAllStatements(statements)
.build();
ApiFuture<Operation> future = databaseAdminClient.updateDatabaseDdlCallable().futureCall(request);
// Do something
future.get();
}
public final void dropDatabase(com.google.spanner.admin.database.v1.DatabaseName database)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
databaseAdminClient.dropDatabase(database);
}
database
- Required. The database to be dropped.ApiException
- if the remote call failspublic final void dropDatabase(String database)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
databaseAdminClient.dropDatabase(database.toString());
}
database
- Required. The database to be dropped.ApiException
- if the remote call failspublic final void dropDatabase(com.google.spanner.admin.database.v1.DropDatabaseRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
DropDatabaseRequest request = DropDatabaseRequest.newBuilder()
.setDatabase(database.toString())
.build();
databaseAdminClient.dropDatabase(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.spanner.admin.database.v1.DropDatabaseRequest,Empty> dropDatabaseCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
DropDatabaseRequest request = DropDatabaseRequest.newBuilder()
.setDatabase(database.toString())
.build();
ApiFuture<Void> future = databaseAdminClient.dropDatabaseCallable().futureCall(request);
// Do something
future.get();
}
public final com.google.spanner.admin.database.v1.GetDatabaseDdlResponse getDatabaseDdl(com.google.spanner.admin.database.v1.DatabaseName database)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseDdlResponse response = databaseAdminClient.getDatabaseDdl(database);
}
database
- Required. The database whose schema we wish to get.ApiException
- if the remote call failspublic final com.google.spanner.admin.database.v1.GetDatabaseDdlResponse getDatabaseDdl(String database)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseDdlResponse response = databaseAdminClient.getDatabaseDdl(database.toString());
}
database
- Required. The database whose schema we wish to get.ApiException
- if the remote call failspublic final com.google.spanner.admin.database.v1.GetDatabaseDdlResponse getDatabaseDdl(com.google.spanner.admin.database.v1.GetDatabaseDdlRequest request)
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseDdlRequest request = GetDatabaseDdlRequest.newBuilder()
.setDatabase(database.toString())
.build();
GetDatabaseDdlResponse response = databaseAdminClient.getDatabaseDdl(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.spanner.admin.database.v1.GetDatabaseDdlRequest,com.google.spanner.admin.database.v1.GetDatabaseDdlResponse> getDatabaseDdlCallable()
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseDdlRequest request = GetDatabaseDdlRequest.newBuilder()
.setDatabase(database.toString())
.build();
ApiFuture<GetDatabaseDdlResponse> future = databaseAdminClient.getDatabaseDdlCallable().futureCall(request);
// Do something
GetDatabaseDdlResponse response = future.get();
}
public final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
Authorization requires `spanner.databases.setIamPolicy` permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
Policy response = databaseAdminClient.setIamPolicy(formattedResource, policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. `resource` is
usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the
policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
Platform services (such as Projects) might reject them.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Authorization requires `spanner.databases.setIamPolicy` permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
Policy response = databaseAdminClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
Authorization requires `spanner.databases.setIamPolicy` permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.setPolicy(policy)
.build();
ApiFuture<Policy> future = databaseAdminClient.setIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(String resource)
Authorization requires `spanner.databases.getIamPolicy` permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy response = databaseAdminClient.getIamPolicy(formattedResource);
}
resource
- REQUIRED: The resource for which the policy is being requested. `resource` is
usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Authorization requires `spanner.databases.getIamPolicy` permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
Policy response = databaseAdminClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Authorization requires `spanner.databases.getIamPolicy` permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(formattedResource)
.build();
ApiFuture<Policy> future = databaseAdminClient.getIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Attempting this RPC on a non-existent Cloud Spanner database will result in a NOT_FOUND error if the user has `spanner.databases.list` permission on the containing Cloud Spanner instance. Otherwise returns an empty set of permissions.
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = databaseAdminClient.testIamPermissions(formattedResource, permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested.
`resource` is usually specified as a path. For example, a Project resource is specified as
`projects/{project}`.permissions
- The set of permissions to check for the `resource`. Permissions with
wildcards (such as '*' or 'storage.*') are not allowed. For more information see
[IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).ApiException
- if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Attempting this RPC on a non-existent Cloud Spanner database will result in a NOT_FOUND error if the user has `spanner.databases.list` permission on the containing Cloud Spanner instance. Otherwise returns an empty set of permissions.
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
TestIamPermissionsResponse response = databaseAdminClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Attempting this RPC on a non-existent Cloud Spanner database will result in a NOT_FOUND error if the user has `spanner.databases.list` permission on the containing Cloud Spanner instance. Otherwise returns an empty set of permissions.
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(formattedResource)
.addAllPermissions(permissions)
.build();
ApiFuture<TestIamPermissionsResponse> future = databaseAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something
TestIamPermissionsResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.