Class SpannerSchemaUtils

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

@ImportRuntimeHints(SpannerSchemaUtilsRuntimeHints.class) public class SpannerSchemaUtils extends Object
Contains functions related to the table schema of entities.
Since:
1.1
  • Constructor Details

    • SpannerSchemaUtils

      public SpannerSchemaUtils(SpannerMappingContext mappingContext, SpannerEntityProcessor spannerEntityProcessor, boolean createInterleavedTableDdlOnDeleteCascade)
      Constructor. Generates create-table DDL statements that cascade deletes for interleaved tables.
      Parameters:
      mappingContext - a mapping context used to obtain persistent entity metadata for generating DDL statements.
      spannerEntityProcessor - an entity processor that is queried for types that it can convert for determining compatible column types when generating DDL statements.
      createInterleavedTableDdlOnDeleteCascade - if true will generate create-table statements that specify cascade on delete for interleaved tables. If false, then the deletes among interleaved tables do not cascade and require manual deletion of all children before parents.
  • Method Details

    • getDropTableDdlString

      public String getDropTableDdlString(Class entityClass)
      Gets the DDL string to drop the table for the given entity in Cloud Spanner.
      Parameters:
      entityClass - the entity type.
      Returns:
      the DDL string.
    • getKey

      public com.google.cloud.spanner.Key getKey(Object object)
      Gets the key for the given object.
      Parameters:
      object - the object to get the key for
      Returns:
      the Spanner Key for the given object.
    • getCreateTableDdlString

      public <T> String getCreateTableDdlString(Class<T> entityClass)
      Gets the DDL string to create the table for the given entity in Cloud Spanner. This is just one of the possible schemas that can support the given entity type. The specific schema is determined by the configured property type converters used by the read and write methods in this SpannerOperations and will be compatible with those methods.
      Type Parameters:
      T - the type of the entity class
      Parameters:
      entityClass - the entity type.
      Returns:
      the DDL string.
    • getCreateTableDdlStringsForInterleavedHierarchy

      public List<String> getCreateTableDdlStringsForInterleavedHierarchy(Class entityClass)
      Gets a list of DDL strings to create the tables rooted at the given entity class. The DDL-create strings are ordered in the list starting with the given root class and are topologically sorted.
      Parameters:
      entityClass - the root class for which to get create strings.
      Returns:
      a list of create strings that are toplogically sorted from parents to children.
    • getDropTableDdlStringsForInterleavedHierarchy

      public List<String> getDropTableDdlStringsForInterleavedHierarchy(Class entityClass)
      Gets the DDL strings to drop the tables of this entity and all of its sub-entities. The list is given in reverse topological sort, since parent tables cannot be dropped before their children tables.
      Parameters:
      entityClass - the root entity whose table to drop.
      Returns:
      the list of drop DDL strings.