Package com.google.cloud.spanner
Class Database
- java.lang.Object
-
- com.google.cloud.spanner.DatabaseInfo
-
- com.google.cloud.spanner.Database
-
public class Database extends DatabaseInfo
Represents a Cloud Spanner database.Database
adds a layer of service related functionality overDatabaseInfo
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Database.Builder
-
Nested classes/interfaces inherited from class com.google.cloud.spanner.DatabaseInfo
DatabaseInfo.State
-
-
Constructor Summary
Constructors Constructor Description Database(DatabaseId id, DatabaseInfo.State state, DatabaseAdminClient dbClient)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.api.gax.longrunning.OperationFuture<Backup,CreateBackupMetadata>
backup(Backup backup)
Backs up this database to the location specified by theBackup
.void
drop()
Drops this database.boolean
exists()
Returnstrue
if a database with the id of thisDatabase
exists on Cloud Spanner.Iterable<String>
getDdl()
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements.com.google.cloud.Policy
getIAMPolicy()
Returns the IAMPolicy
for this database.com.google.api.gax.paging.Page<com.google.longrunning.Operation>
listDatabaseOperations()
Returns the long-running operations for this database.Database
reload()
Fetches the database's current information.com.google.cloud.Policy
setIAMPolicy(com.google.cloud.Policy policy)
Updates the IAM policy for this database and returns the resulting policy.Iterable<String>
testIAMPermissions(Iterable<String> permissions)
Tests for the given permissions on this database for the caller.com.google.api.gax.longrunning.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.-
Methods inherited from class com.google.cloud.spanner.DatabaseInfo
equals, getCreateTime, getDefaultLeader, getDialect, getEarliestVersionTime, getEncryptionConfig, getId, getProto, getRestoreInfo, getState, getVersionRetentionPeriod, hashCode, toString
-
-
-
-
Constructor Detail
-
Database
public Database(DatabaseId id, DatabaseInfo.State state, DatabaseAdminClient dbClient)
-
-
Method Detail
-
reload
public Database reload() throws SpannerException
Fetches the database's current information.- Throws:
SpannerException
-
updateDdl
public com.google.api.gax.longrunning.OperationFuture<Void,UpdateDatabaseDdlMetadata> updateDdl(Iterable<String> statements, String operationId) throws SpannerException
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:
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_]*.- Throws:
SpannerException
-
drop
public void drop() throws SpannerException
Drops this database.- Throws:
SpannerException
-
exists
public boolean exists()
Returnstrue
if a database with the id of thisDatabase
exists on Cloud Spanner.
-
backup
public com.google.api.gax.longrunning.OperationFuture<Backup,CreateBackupMetadata> backup(Backup backup)
-
getDdl
public Iterable<String> getDdl() throws SpannerException
Returns the schema of a Cloud Spanner database as a list of formatted DDL statements. This method does not show pending schema updates.- Throws:
SpannerException
-
listDatabaseOperations
public com.google.api.gax.paging.Page<com.google.longrunning.Operation> listDatabaseOperations()
Returns the long-running operations for this database.
-
getIAMPolicy
public com.google.cloud.Policy getIAMPolicy()
Returns the IAMPolicy
for this database.
-
setIAMPolicy
public com.google.cloud.Policy setIAMPolicy(com.google.cloud.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. SeePolicy.Builder.setEtag(String)
for information on the recommended read-modify-write cycle.
-
testIAMPermissions
public Iterable<String> testIAMPermissions(Iterable<String> permissions)
Tests for the given permissions on this database for the caller.- Parameters:
permissions
- the permissions to test for. Permissions with wildcards (such as '*', 'spanner.*', 'spanner.instances.*') are not allowed.- Returns:
- the subset of the tested permissions that the caller is allowed.
-
-