@Generated(value="by gapic-generator") @BetaApi public class DatabaseAdminClient extends Object implements com.google.api.gax.core.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.
|
com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> |
createDatabaseAsync(CreateDatabaseRequest request)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> |
createDatabaseAsync(InstanceName parent,
String createStatement)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> |
createDatabaseAsync(String parent,
String createStatement)
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
com.google.api.gax.rpc.UnaryCallable<CreateDatabaseRequest,com.google.longrunning.Operation> |
createDatabaseCallable()
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
com.google.api.gax.rpc.OperationCallable<CreateDatabaseRequest,Database,CreateDatabaseMetadata> |
createDatabaseOperationCallable()
Creates a new Cloud Spanner database and starts to prepare it for serving.
|
void |
dropDatabase(DatabaseName database)
Drops (aka deletes) a Cloud Spanner database.
|
void |
dropDatabase(DropDatabaseRequest request)
Drops (aka deletes) a Cloud Spanner database.
|
void |
dropDatabase(String database)
Drops (aka deletes) a Cloud Spanner database.
|
com.google.api.gax.rpc.UnaryCallable<DropDatabaseRequest,Empty> |
dropDatabaseCallable()
Drops (aka deletes) a Cloud Spanner database.
|
Database |
getDatabase(DatabaseName name)
Gets the state of a Cloud Spanner database.
|
Database |
getDatabase(GetDatabaseRequest request)
Gets the state of a Cloud Spanner database.
|
Database |
getDatabase(String name)
Gets the state of a Cloud Spanner database.
|
com.google.api.gax.rpc.UnaryCallable<GetDatabaseRequest,Database> |
getDatabaseCallable()
Gets the state of a Cloud Spanner database.
|
GetDatabaseDdlResponse |
getDatabaseDdl(DatabaseName database)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
GetDatabaseDdlResponse |
getDatabaseDdl(GetDatabaseDdlRequest request)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
GetDatabaseDdlResponse |
getDatabaseDdl(String database)
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.
|
com.google.api.gax.rpc.UnaryCallable<GetDatabaseDdlRequest,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(com.google.api.resourcenames.ResourceName resource)
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.
|
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Gets the access control policy for a database resource.
|
com.google.longrunning.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(InstanceName parent)
Lists Cloud Spanner databases.
|
DatabaseAdminClient.ListDatabasesPagedResponse |
listDatabases(ListDatabasesRequest request)
Lists Cloud Spanner databases.
|
DatabaseAdminClient.ListDatabasesPagedResponse |
listDatabases(String parent)
Lists Cloud Spanner databases.
|
com.google.api.gax.rpc.UnaryCallable<ListDatabasesRequest,ListDatabasesResponse> |
listDatabasesCallable()
Lists Cloud Spanner databases.
|
com.google.api.gax.rpc.UnaryCallable<ListDatabasesRequest,DatabaseAdminClient.ListDatabasesPagedResponse> |
listDatabasesPagedCallable()
Lists Cloud Spanner databases.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.api.resourcenames.ResourceName resource,
com.google.iam.v1.Policy policy)
Sets the access control policy on a database resource.
|
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.
|
com.google.api.gax.rpc.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(com.google.api.resourcenames.ResourceName resource,
List<String> permissions)
Returns permissions that the caller has on the specified database resource.
|
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.
|
com.google.api.gax.rpc.UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that the caller has on the specified database resource.
|
com.google.api.gax.longrunning.OperationFuture<Empty,UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(DatabaseName database,
List<String> statements)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
com.google.api.gax.longrunning.OperationFuture<Empty,UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(String database,
List<String> statements)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
com.google.api.gax.longrunning.OperationFuture<Empty,UpdateDatabaseDdlMetadata> |
updateDatabaseDdlAsync(UpdateDatabaseDdlRequest request)
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
com.google.api.gax.rpc.UnaryCallable<UpdateDatabaseDdlRequest,com.google.longrunning.Operation> |
updateDatabaseDdlCallable()
Updates the schema of a Cloud Spanner database by creating/altering/dropping tables, columns,
indexes, etc.
|
com.google.api.gax.rpc.OperationCallable<UpdateDatabaseDdlRequest,Empty,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 com.google.longrunning.OperationsClient getOperationsClient()
@BetaApi(value="The surface for long-running operations is not stable yet and may change in the future.") public final com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> createDatabaseAsync(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 (`` ` ``).com.google.api.gax.rpc.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 com.google.api.gax.longrunning.OperationFuture<Database,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 (`` ` ``).com.google.api.gax.rpc.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 com.google.api.gax.longrunning.OperationFuture<Database,CreateDatabaseMetadata> createDatabaseAsync(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.com.google.api.gax.rpc.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 com.google.api.gax.rpc.OperationCallable<CreateDatabaseRequest,Database,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 com.google.api.gax.rpc.UnaryCallable<CreateDatabaseRequest,com.google.longrunning.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 Database getDatabase(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>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final 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>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final Database getDatabase(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetDatabaseRequest,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 com.google.api.gax.longrunning.OperationFuture<Empty,UpdateDatabaseDdlMetadata> updateDatabaseDdlAsync(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
- Required. DDL statements to be applied to the database.com.google.api.gax.rpc.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 com.google.api.gax.longrunning.OperationFuture<Empty,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
- Required. DDL statements to be applied to the database.com.google.api.gax.rpc.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 com.google.api.gax.longrunning.OperationFuture<Empty,UpdateDatabaseDdlMetadata> updateDatabaseDdlAsync(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.com.google.api.gax.rpc.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 com.google.api.gax.rpc.OperationCallable<UpdateDatabaseDdlRequest,Empty,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 com.google.api.gax.rpc.UnaryCallable<UpdateDatabaseDdlRequest,com.google.longrunning.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(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.com.google.api.gax.rpc.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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final void dropDatabase(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<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 GetDatabaseDdlResponse getDatabaseDdl(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final 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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final GetDatabaseDdlResponse getDatabaseDdl(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetDatabaseDdlRequest,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(com.google.api.resourcenames.ResourceName 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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
Policy response = databaseAdminClient.setIamPolicy(resource, policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic 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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
Policy response = databaseAdminClient.setIamPolicy(resource.toString(), policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.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.com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.setPolicy(policy)
.build();
Policy response = databaseAdminClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy policy = Policy.newBuilder().build();
SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.setPolicy(policy)
.build();
ApiFuture<Policy> future = databaseAdminClient.setIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(com.google.api.resourcenames.ResourceName resource)
Authorization requires `spanner.databases.getIamPolicy` permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
Sample code:
try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy response = databaseAdminClient.getIamPolicy(resource);
}
resource
- REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.com.google.api.gax.rpc.ApiException
- if the remote call failspublic 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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Policy response = databaseAdminClient.getIamPolicy(resource.toString());
}
resource
- REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.build();
Policy response = databaseAdminClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
.setResource(resource.toString())
.build();
ApiFuture<Policy> future = databaseAdminClient.getIamPolicyCallable().futureCall(request);
// Do something
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.api.resourcenames.ResourceName 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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = databaseAdminClient.testIamPermissions(resource, permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.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).com.google.api.gax.rpc.ApiException
- if the remote call failspublic 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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response = databaseAdminClient.testIamPermissions(resource.toString(), permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.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).com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(resource.toString())
.build();
TestIamPermissionsResponse response = databaseAdminClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.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()) {
ResourceName resource = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
.setResource(resource.toString())
.build();
ApiFuture<TestIamPermissionsResponse> future = databaseAdminClient.testIamPermissionsCallable().futureCall(request);
// Do something
TestIamPermissionsResponse response = future.get();
}
public final DatabaseAdminClient.ListDatabasesPagedResponse listDatabases(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>`.com.google.api.gax.rpc.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>`.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final DatabaseAdminClient.ListDatabasesPagedResponse listDatabases(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.com.google.api.gax.rpc.ApiException
- if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<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 com.google.api.gax.rpc.UnaryCallable<ListDatabasesRequest,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;
}
}
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isShutdown()
isShutdown
in interface com.google.api.gax.core.BackgroundResource
public boolean isTerminated()
isTerminated
in interface com.google.api.gax.core.BackgroundResource
public void shutdownNow()
shutdownNow
in interface com.google.api.gax.core.BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface com.google.api.gax.core.BackgroundResource
InterruptedException
Copyright © 2019 Google LLC. All rights reserved.