Class Database (6.62.0)

public class Database extends DatabaseInfo

Represents a Cloud Spanner database. Database adds a layer of service related functionality over DatabaseInfo.

Inheritance

java.lang.Object > DatabaseInfo > Database

Constructors

Database(DatabaseId id, DatabaseInfo.State state, DatabaseAdminClient dbClient)

public Database(DatabaseId id, DatabaseInfo.State state, DatabaseAdminClient dbClient)
Parameters
NameDescription
idDatabaseId
stateDatabaseInfo.State
dbClientDatabaseAdminClient

Methods

backup(Backup backup)

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

Backs up this database to the location specified by the Backup. The given Backup must have an expire time. The backup must belong to the same instance as this database.

Parameter
NameDescription
backupBackup
Returns
TypeDescription
OperationFuture<Backup,CreateBackupMetadata>

drop()

public void drop()

Drops this database.

Exceptions
TypeDescription
SpannerException

exists()

public boolean exists()

Returns true if a database with the id of this Database exists on Cloud Spanner.

Returns
TypeDescription
boolean

getDdl()

public Iterable<String> getDdl()

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

Returns
TypeDescription
Iterable<String>
Exceptions
TypeDescription
SpannerException

getIAMPolicy(int version)

public Policy getIAMPolicy(int version)

Returns the IAM Policy for this database.

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

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

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

Parameter
NameDescription
versionint
Returns
TypeDescription
com.google.cloud.Policy

listDatabaseOperations()

public Page<Operation> listDatabaseOperations()

Returns the long-running operations for this database.

Returns
TypeDescription
Page<Operation>

reload()

public Database reload()

Fetches the database's current information.

Returns
TypeDescription
Database
Exceptions
TypeDescription
SpannerException

setIAMPolicy(Policy policy)

public Policy setIAMPolicy(Policy policy)

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

Parameter
NameDescription
policycom.google.cloud.Policy
Returns
TypeDescription
com.google.cloud.Policy

testIAMPermissions(Iterable<String> permissions)

public Iterable<String> testIAMPermissions(Iterable<String> permissions)

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

Parameter
NameDescription
permissionsIterable<String>

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

Returns
TypeDescription
Iterable<String>

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

toProto()

public Database toProto()
Returns
TypeDescription
Database

updateDdl(Iterable<String> statements, String operationId)

public OperationFuture<Void,UpdateDatabaseDdlMetadata> updateDdl(Iterable<String> statements, String operationId)

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

Parameters
NameDescription
statementsIterable<String>
operationIdString

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

Returns
TypeDescription
OperationFuture<Void,UpdateDatabaseDdlMetadata>
Exceptions
TypeDescription
SpannerException