Class PhysicalDataModel

  • All Implemented Interfaces:
    IDataModel

    public class PhysicalDataModel
    extends Object
    implements IDataModel
    Represents the set of tables and other schema objects that make up the schema we want to build and manage. This is created as code and not in a DDL text file on purpose. Doing so makes it much easier to test.
    • Constructor Detail

      • PhysicalDataModel

        public PhysicalDataModel()
        Default constructor. No federated models
      • PhysicalDataModel

        public PhysicalDataModel​(PhysicalDataModel... federatedModels)
        Constructor supporting federated data models
        Parameters:
        federatedModels -
    • Method Detail

      • addTable

        public void addTable​(Table t)
        Add the table to the list of objects in this model
        Parameters:
        t -
      • addObject

        public void addObject​(IDatabaseObject obj)
        Just a general object we don't need to know the details of
        Parameters:
        obj -
      • collect

        public void collect​(ITaskCollector tc,
                            IDatabaseAdapter target,
                            ITransactionProvider tp,
                            IVersionHistoryService vhs)
        Collect all the database objects we know of, describing their interdependencies so that the task collector implementation can execute them in parallel. This greatly reduces the amount of time it takes to provision a schema.
        Parameters:
        tc - collects and manages the object creation tasks and their dependencies
        target - the target database adapter
        tp -
        vhs -
      • apply

        public void apply​(IDatabaseAdapter target)
        Apply the entire model to the target in order
        Parameters:
        target -
      • applyWithHistory

        public void applyWithHistory​(IDatabaseAdapter target,
                                     IVersionHistoryService vhs)
        Apply all the objects linearly, but using the version history service to determine what's new and what already exists
        Parameters:
        target -
        vhs -
      • applyProcedures

        public void applyProcedures​(IDatabaseAdapter adapter)
        Apply all the procedures in the order in which they were added to the model
        Parameters:
        adapter -
      • applyFunctions

        public void applyFunctions​(IDatabaseAdapter adapter)
        Apply all the functions in the order in which they were added to the model
        Parameters:
        adapter -
      • drop

        public void drop​(IDatabaseAdapter target,
                         String tagGroup,
                         String tag)
        Drop the model from the target database. This is done in reverse order
        Parameters:
        target -
        tagGroup -
        tag -
      • dropForeignKeyConstraints

        public void dropForeignKeyConstraints​(IDatabaseAdapter target,
                                              String tagGroup,
                                              String tag)
        Drop all foreign key constraints on tables in this model. Typically done prior to dropping the actual tables when removing a schema
        Parameters:
        target -
        tagGroup -
        tag -
      • visit

        public void visit​(DataModelVisitor v,
                          String tagGroup,
                          String tag)
        Visit all objects which have the given tagGroup and tag
        Parameters:
        v -
        tagGroup -
        tag -
      • visit

        public void visit​(DataModelVisitor v)
        Visits all objects in the data model
        Parameters:
        v -
      • visitReverse

        public void visitReverse​(DataModelVisitor v)
        Visit all objects in reverse order
        Parameters:
        v -
      • drop

        public void drop​(IDatabaseAdapter target)
        Drop the lot
        Parameters:
        target -
      • getTenantPartitionedTables

        public Collection<Table> getTenantPartitionedTables​(String partitionColumn)
        Return all the tables partitioned by the given column name
        Returns:
      • addTenantPartitions

        public void addTenantPartitions​(IDatabaseAdapter adapter,
                                        String schemaName,
                                        int tenantId,
                                        int extentSizeKB)
        Make sure every tenant-partitioned table has a partition for the given tenantId
        Parameters:
        adapter -
        schemaName -
        tenantId -
        extentSizeKB -
      • addNewTenantPartitions

        public void addNewTenantPartitions​(IDatabaseAdapter adapter,
                                           String schemaName,
                                           int tenantId)
        Ensure that each partitioned table has a partition matching the given tenantId. This method is use to add partitions to new tables added by a schema update (after the tenant was allocated).
        Parameters:
        adapter -
        schemaName -
        tenantId -
      • detachTenantPartitions

        public void detachTenantPartitions​(IDatabaseAdapter adapter,
                                           String schemaName,
                                           int tenantId)
        remove the partition from each of the tenant-based tables
        Parameters:
        adapter -
        schemaName -
        tenantId -
        partitionStagingTable -
      • dropDetachedPartitions

        public void dropDetachedPartitions​(IDatabaseAdapter adapter,
                                           String schemaName,
                                           int tenantId)
        Drop the tables generated by the removeTenantPartitions call
        Parameters:
        adapter -
        schemaName -
        tenantId -
      • addProcedure

        public ProcedureDef addProcedure​(String schemaName,
                                         String objectName,
                                         int version,
                                         Supplier<String> templateProvider,
                                         Collection<IDatabaseObject> dependencies,
                                         Collection<GroupPrivilege> privileges)
        Add a stored procedure definition. The given Supplier will be called upon to provide the DDL body for the procedure at the point in time it is being applied to the database, not when constructing the model.
        Parameters:
        schemaName -
        objectName - the name of the procedure object
        version -
        templateProvider - supplier of the procedure text
        dependencies -
        privileges -
        Returns:
      • searchByTag

        public Collection<IDatabaseObject> searchByTag​(String tagName,
                                                       String tagValue)
        Find all the objects matching the given tag name and value. Think of the tagName as the indexed field, and the tagValue as the matching rows (which are the objects we're trying to locate).
        Parameters:
        tagName -
        tagValue -
        Returns:
      • processTablesInSchema

        public void processTablesInSchema​(String schemaName,
                                          Consumer<Table> c)
        Call the given Consumer for each of the tables found in the schema identified by schemaName
        Parameters:
        schemaName -
        c -
      • processObjectsWithTag

        public void processObjectsWithTag​(String tagName,
                                          String tagValue,
                                          Consumer<IDatabaseObject> c)
        Call the consumer for each object matching the given tag name/value tuple
        Parameters:
        tagName -
        tagValue -
        c -
      • applyGrants

        public void applyGrants​(IDatabaseAdapter target,
                                String groupName,
                                String username)
        Apply the grants for the given group to the user
        Parameters:
        target -
        groupName -
        username -
      • dropTenantTablespace

        public void dropTenantTablespace​(IDatabaseAdapter adapter,
                                         int tenantId)
        Drop the tablespace associated with the given tenant.
        Parameters:
        tenantId -