Class SpannerDatabaseAdminTemplate

java.lang.Object
com.google.cloud.spring.data.spanner.core.admin.SpannerDatabaseAdminTemplate

public class SpannerDatabaseAdminTemplate extends Object
Template for performing many operations to a Spanner database including generating hierarchy schemas and creating and deleting tables.
Since:
1.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    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 the DatabaseId object holding the project, instance, and database IDs used for all operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    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
    Returns true if the given table name exists in the database currently.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 the DatabaseId 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

      public void executeDdlStrings(Iterable<String> ddlStrings, boolean createDatabase)
      Execute the given DDL strings in order and creates the database if it does not exist.
      Parameters:
      ddlStrings - the DDL strings
      createDatabase - if true, then the database is created at the same time as the tables using the DDL strings. if false, then the database must already exist.
    • getInstanceId

      public String getInstanceId()
      Get the instance ID used to perform database operations.
      Returns:
      the instance ID string.
    • getDatabase

      public 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

      public Map<String,String> 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

      public boolean isInterleaved(String ancestor, String descendant)
      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 table
      descendant - 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

      public Map<String,Set<String>> 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

      public Set<String> getTables()
      Return a set of the tables that currently exist in the database.
      Returns:
      a set of table names.
    • tableExists

      public boolean tableExists(String table)
      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.