Class PhysicalDataModel
- java.lang.Object
-
- com.ibm.fhir.database.utils.model.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 Summary
Constructors Constructor Description PhysicalDataModel()
Default constructor.PhysicalDataModel(PhysicalDataModel... federatedModels)
Constructor supporting federated data models
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FunctionDef
addFunction(String schemaName, String objectName, int version, Supplier<String> templateProvider, Collection<IDatabaseObject> dependencies, Collection<GroupPrivilege> privileges)
adds the function to the model.void
addNewTenantPartitions(IDatabaseAdapter adapter, String schemaName, int tenantId)
Ensure that each partitioned table has a partition matching the given tenantId.void
addObject(IDatabaseObject obj)
Just a general object we don't need to know the details ofProcedureDef
addProcedure(String schemaName, String objectName, int version, Supplier<String> templateProvider, Collection<IDatabaseObject> dependencies, Collection<GroupPrivilege> privileges)
Add a stored procedure definition.void
addTable(Table t)
Add the table to the list of objects in this modelvoid
addTenantPartitions(IDatabaseAdapter adapter, String schemaName, int tenantId, int extentSizeKB)
Make sure every tenant-partitioned table has a partition for the given tenantIdvoid
apply(IDatabaseAdapter target)
Apply the entire model to the target in ordervoid
applyFunctions(IDatabaseAdapter adapter)
Apply all the functions in the order in which they were added to the modelvoid
applyGrants(IDatabaseAdapter target, String groupName, String username)
Apply the grants for the given group to the uservoid
applyProcedures(IDatabaseAdapter adapter)
Apply all the procedures in the order in which they were added to the modelvoid
applyWithHistory(IDatabaseAdapter target, IVersionHistoryService vhs)
Apply all the objects linearly, but using the version history service to determine what's new and what already existsvoid
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.void
detachTenantPartitions(IDatabaseAdapter adapter, String schemaName, int tenantId)
remove the partition from each of the tenant-based tablesvoid
drop(IDatabaseAdapter target)
Drop the lotvoid
drop(IDatabaseAdapter target, String tagGroup, String tag)
Drop the model from the target database.void
dropDetachedPartitions(IDatabaseAdapter adapter, String schemaName, int tenantId)
Drop the tables generated by the removeTenantPartitions callvoid
dropTenantTablespace(IDatabaseAdapter adapter, int tenantId)
Drop the tablespace associated with the given tenant.Table
findTable(String schemaName, String tableName)
Look up the table definitionCollection<Table>
getTenantPartitionedTables(String partitionColumn)
Return all the tables partitioned by the given column namevoid
processObjectsWithTag(String tagName, String tagValue, Consumer<IDatabaseObject> c)
Call the consumer for each object matching the given tag name/value tuplevoid
processTablesInSchema(String schemaName, Consumer<Table> c)
Call the givenConsumer
for each of the tables found in the schema identified by schemaNameCollection<IDatabaseObject>
searchByTag(String tagName, String tagValue)
Find all the objects matching the given tag name and value.void
visit(DataModelVisitor v)
Visit all objects in creation ordervoid
visitReverse(DataModelVisitor v)
Visit all objects in reverse order
-
-
-
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 dependenciestarget
- the target database adaptertp
-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
-
-
visit
public void visit(DataModelVisitor v)
Visit all objects in creation order- 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 givenSupplier
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 objectversion
-templateProvider
- supplier of the procedure textdependencies
-privileges
-- Returns:
-
addFunction
public FunctionDef addFunction(String schemaName, String objectName, int version, Supplier<String> templateProvider, Collection<IDatabaseObject> dependencies, Collection<GroupPrivilege> privileges)
adds the function to the model.- Parameters:
schemaName
-objectName
-version
-templateProvider
-dependencies
-privileges
-- Returns:
-
findTable
public Table findTable(String schemaName, String tableName)
Description copied from interface:IDataModel
Look up the table definition- Specified by:
findTable
in interfaceIDataModel
- 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 givenConsumer
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
-
-
-