Class SpannerDatabaseAdminTemplate
java.lang.Object
com.google.cloud.spring.data.spanner.core.admin.SpannerDatabaseAdminTemplate
Template for performing many operations to a Spanner database including generating hierarchy
schemas and creating and deleting tables.
- Since:
- 1.1
-
Constructor Summary
ConstructorDescriptionSpannerDatabaseAdminTemplate
(com.google.cloud.spanner.DatabaseAdminClient databaseAdminClient, Supplier<com.google.cloud.spanner.DatabaseClient> databaseClientProvider, Supplier<com.google.cloud.spanner.DatabaseId> databaseIdProvider) Constructor that takes in the database admin client used to perform operations and theDatabaseId
object holding the project, instance, and database IDs used for all operations. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if the configured database ID refers to an existing database.void
executeDdlStrings
(Iterable<String> ddlStrings, boolean createDatabase) Execute the given DDL strings in order and creates the database if it does not exist.Return a map where key is the table name and the value is the parent table name.Get the database ID used to perform database operations.Get the instance ID used to perform database operations.Return a map of parent and child table relationships in the database at the moment.Return a set of the tables that currently exist in the database.boolean
isInterleaved
(String ancestor, String descendant) Return true if the given table names are interleaved as ancestor and descendant.boolean
tableExists
(String table) Returns true if the given table name exists in the database currently.
-
Constructor Details
-
SpannerDatabaseAdminTemplate
public SpannerDatabaseAdminTemplate(com.google.cloud.spanner.DatabaseAdminClient databaseAdminClient, Supplier<com.google.cloud.spanner.DatabaseClient> databaseClientProvider, Supplier<com.google.cloud.spanner.DatabaseId> databaseIdProvider) Constructor that takes in the database admin client used to perform operations and theDatabaseId
object holding the project, instance, and database IDs used for all operations. While operations can be optionally performed for a database that does not yet exist, the project and instance IDs must already exist for Spanner.- Parameters:
databaseAdminClient
- the client used to create databases and execute DDL statements.databaseClientProvider
- the client used to access schema information tables.databaseIdProvider
- the combination of Cloud Spanner Instance Id and Database Id. While databases can be created automatically by this template, instances determine billing and are not created automatically.
-
-
Method Details
-
executeDdlStrings
Execute the given DDL strings in order and creates the database if it does not exist.- Parameters:
ddlStrings
- the DDL stringscreateDatabase
- iftrue
, then the database is created at the same time as the tables using the DDL strings. iffalse
, then the database must already exist.
-
getInstanceId
Get the instance ID used to perform database operations.- Returns:
- the instance ID string.
-
getDatabase
Get the database ID used to perform database operations.- Returns:
- the database ID string.
-
databaseExists
public boolean databaseExists()Returns true if the configured database ID refers to an existing database. False otherwise.- Returns:
- true if the database exists, and false if it does not.
-
getChildParentTablesMap
Return a map where key is the table name and the value is the parent table name. If the table name in the key has no parent then the value is null.- Returns:
- the map of the table names.
-
isInterleaved
Return true if the given table names are interleaved as ancestor and descendant. These may be separated by more than one generation.- Parameters:
ancestor
- the name of the ancestor tabledescendant
- the name of the descendant table. this may be a direct child or further down in the family tree.- Returns:
- true the descendant is indeed a descendant table. false otherwise.
-
getParentChildTablesMap
Return a map of parent and child table relationships in the database at the moment.- Returns:
- a map where the keys are parent table names, and the value is a set of that parent's children.
-
getTables
Return a set of the tables that currently exist in the database.- Returns:
- a set of table names.
-
tableExists
Returns true if the given table name exists in the database currently.- Parameters:
table
- the name of the table.- Returns:
- true if the table exists, false otherwise.
-