Package com.ibm.fhir.database.utils.db2
Class Db2Adapter
- java.lang.Object
-
- com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
-
- com.ibm.fhir.database.utils.db2.Db2Adapter
-
- All Implemented Interfaces:
IDatabaseAdapter
,IDatabaseTypeAdapter
public class Db2Adapter extends CommonDatabaseAdapter
Implementation of our database adapter which provides implementation of control functions specific to DB2 for things like schema and partition management
-
-
Field Summary
-
Fields inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
connectionProvider, target
-
-
Constructor Summary
Constructors Constructor Description Db2Adapter()
Db2Adapter(IConnectionProvider cp)
Db2Adapter(IDatabaseTarget tgt)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateRowAccessControl(java.lang.String schemaName, java.lang.String tableName)
ALTER TABLEACTIVATE ROW ACCESS CONTROL void
addNewTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int newTenantId)
Add a new tenant partition to each of the tables in the collection.void
addNewTenantPartitions(java.util.Collection<Table> tables, java.util.Map<java.lang.String,PartitionInfo> partitionInfoMap, int newTenantId, java.lang.String tablespaceName)
Add a new tenant partition to each of the tables in the collection.java.lang.String
blobClause(long size, int inlineSize)
Generate a clause for BLOB (with an inline size if supported)boolean
checkCompatibility(java.lang.String adminSchema)
checks connectivity to the database and that it is compatiblevoid
createArrType(java.lang.String schemaName, java.lang.String typeName, java.lang.String valueType, int arraySize)
Create ARRAY type used for passing values to stored procedures e.g.: CREATE OR REPLACE TYPE.t_str_values_arr AS .t_str_values ARRAY[256] void
createIntVariable(java.lang.String schemaName, java.lang.String variableName)
CREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;void
createOrReplacePermission(java.lang.String schemaName, java.lang.String permissionName, java.lang.String tableName, java.lang.String predicate)
CREATE OR REPLACE PERMISSION ROW_ACCESS ON ptng.patients FOR ROWS WHERE patients.mt_id = ptng.session_tenant ENFORCED FOR ALL ACCESS ENABLE;void
createOrReplaceProcedure(java.lang.String schemaName, java.lang.String procedureName, java.util.function.Supplier<java.lang.String> supplier)
Create the stored procedure using the DDL text provided by the suppliervoid
createRowType(java.lang.String schemaName, java.lang.String typeName, java.util.List<ColumnBase> columns)
Create ROW type used for passing values to stored procedures e.g.:void
createSchema(java.lang.String schemaName)
Create a database schemavoid
createTable(java.lang.String schemaName, java.lang.String name, java.lang.String tenantColumnName, java.util.List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, java.lang.String tablespaceName, java.util.List<With> withs, java.util.List<CheckConstraint> checkConstraints)
Build the create table DDLvoid
createTablespace(java.lang.String tablespaceName)
Create a new tablespace with the given namevoid
createTablespace(java.lang.String tablespaceName, int extentSizeKB)
Create a new tablespace using the given extent sizevoid
createTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int newTenantId, int extentSizeKB)
Create the partitions on each of these tablesvoid
createTenantPartitionsThr(Table t, PartitionInfo pi, int newTenantId, java.lang.String tablespaceName)
Ensure that the given table has all the partitions necessary up to and including the max tenant idvoid
deactivateRowAccessControl(java.lang.String schemaName, java.lang.String tableName)
Deactivate row access control on a table ALTER TABLEDEACTIVATE ROW ACCESS CONTROL void
detachPartition(java.lang.String schemaName, java.lang.String tableName, java.lang.String partitionName, java.lang.String intoTableName)
Detach the partitionvoid
disableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Disable the FK with the given constraint nameboolean
doesTableExist(java.lang.String schemaName, java.lang.String tableName)
Check if the table currently existsvoid
dropDetachedPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int tenantId)
Drop the tables which were created by the detach partition operation (as part of tenant deprovisioning).void
dropProcedure(java.lang.String schemaName, java.lang.String procedureName)
Drop the given procedurevoid
dropTablespace(java.lang.String tablespaceName)
Drop an existing tablespace, including all of its contentsvoid
dropTenantTablespace(int tenantId)
Drop the tablespace associated with the given tenantIdvoid
dropType(java.lang.String schemaName, java.lang.String typeName)
Drop the type object from the schemavoid
enableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Enable the FK with the given constraint namejava.util.List<SchemaInfoObject>
listSchemaObjects(java.lang.String schemaName)
List the objects present in the given schemaprotected void
loadPartitionInfoMap(java.util.Map<java.lang.String,PartitionInfo> partitionInfoMap, java.lang.String tableSchema)
Read partition info from the database catalog.void
removeTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int tenantId)
Detach the partition associated with the tenantId from each of the given tablesvoid
reorgTable(java.lang.String schemaName, java.lang.String tableName)
Reorg the table if the underlying database supports it.void
runStatement(IDatabaseStatement stmt)
Run the statement using the connectionProvider to obtain a new connection.void
setIntegrityOff(java.lang.String schemaName, java.lang.String tableName)
void
setIntegrityUnchecked(java.lang.String schemaName, java.lang.String tableName)
void
setIntVariable(java.lang.String schemaName, java.lang.String variableName, int value)
Build the DML statement for setting a session variableboolean
useSessionVariable()
java.lang.String
varbinaryClause(int size)
Generate a clause for binary data typejava.lang.String
varcharClause(int size)
Generate a clause for VARCHAR-
Methods inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
allocateTenant, alterSequenceRestartWith, alterTableAddColumn, alterTableColumnIdentityCache, buildColumns, buildCreateTableStatement, createForeignKeyConstraint, createIndex, createOrReplaceFunction, createOrReplaceView, createSequence, createUniqueConstraint, createUniqueIndex, createUniqueIndex, createView, deleteTenantMeta, dropForeignKey, dropFunction, dropIndex, dropPermission, dropSequence, dropTable, dropVariable, dropView, findTenantId, getQualifiedName, getTranslator, grantAllSequenceUsage, grantFunctionPrivileges, grantObjectPrivileges, grantProcedurePrivileges, grantSchemaUsage, grantSequencePrivileges, grantVariablePrivileges, prefixTenantColumn, runStatement, runStatement, updateTenantStatus
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.ibm.fhir.database.utils.api.IDatabaseTypeAdapter
clobClause, doubleClause, timestampClause
-
-
-
-
Constructor Detail
-
Db2Adapter
public Db2Adapter(IDatabaseTarget tgt)
Public constructor- Parameters:
tgt
- the target database we want to manage
-
Db2Adapter
public Db2Adapter(IConnectionProvider cp)
-
Db2Adapter
public Db2Adapter()
-
-
Method Detail
-
createTable
public void createTable(java.lang.String schemaName, java.lang.String name, java.lang.String tenantColumnName, java.util.List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, java.lang.String tablespaceName, java.util.List<With> withs, java.util.List<CheckConstraint> checkConstraints)
Description copied from interface:IDatabaseAdapter
Build the create table DDLtenantColumnName
- optional column name to enable multi-tenancy
-
createIntVariable
public void createIntVariable(java.lang.String schemaName, java.lang.String variableName)
Description copied from interface:IDatabaseAdapter
CREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;
-
createOrReplacePermission
public void createOrReplacePermission(java.lang.String schemaName, java.lang.String permissionName, java.lang.String tableName, java.lang.String predicate)
Description copied from interface:IDatabaseAdapter
CREATE OR REPLACE PERMISSION ROW_ACCESS ON ptng.patients FOR ROWS WHERE patients.mt_id = ptng.session_tenant ENFORCED FOR ALL ACCESS ENABLE;
-
activateRowAccessControl
public void activateRowAccessControl(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
ALTER TABLE
ACTIVATE ROW ACCESS CONTROL
-
setIntVariable
public void setIntVariable(java.lang.String schemaName, java.lang.String variableName, int value)
Description copied from interface:IDatabaseAdapter
Build the DML statement for setting a session variable
-
createTenantPartitions
public void createTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int newTenantId, int extentSizeKB)
Description copied from interface:IDatabaseAdapter
Create the partitions on each of these tables
-
addNewTenantPartitions
public void addNewTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int newTenantId)
Description copied from class:CommonDatabaseAdapter
Add a new tenant partition to each of the tables in the collection. Idempotent, so can be run to add partitions for existing tenants to new tables- Specified by:
addNewTenantPartitions
in interfaceIDatabaseAdapter
- Overrides:
addNewTenantPartitions
in classCommonDatabaseAdapter
-
addNewTenantPartitions
public void addNewTenantPartitions(java.util.Collection<Table> tables, java.util.Map<java.lang.String,PartitionInfo> partitionInfoMap, int newTenantId, java.lang.String tablespaceName)
Add a new tenant partition to each of the tables in the collection. Idempotent, so can be run to add partitions for existing tenants to new tables- Parameters:
tables
-partitionInfoMap
-newTenantId
-tablespaceName
-
-
createTenantPartitionsThr
public void createTenantPartitionsThr(Table t, PartitionInfo pi, int newTenantId, java.lang.String tablespaceName)
Ensure that the given table has all the partitions necessary up to and including the max tenant id- Parameters:
t
-pi
-newTenantId
-tablespaceName
-
-
loadPartitionInfoMap
protected void loadPartitionInfoMap(java.util.Map<java.lang.String,PartitionInfo> partitionInfoMap, java.lang.String tableSchema)
Read partition info from the database catalog.- Parameters:
partitionInfoMap
-tableSchema
-
-
deactivateRowAccessControl
public void deactivateRowAccessControl(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
Deactivate row access control on a table ALTER TABLEDEACTIVATE ROW ACCESS CONTROL
-
createRowType
public void createRowType(java.lang.String schemaName, java.lang.String typeName, java.util.List<ColumnBase> columns)
Description copied from interface:IDatabaseAdapter
Create ROW type used for passing values to stored procedures e.g.:CREATE OR REPLACE TYPE
.t_str_values AS ROW (parameter_name_id INTEGER, str_value VARCHAR(511 OCTETS), str_value_lcase VARCHAR(511 OCTETS))
-
createArrType
public void createArrType(java.lang.String schemaName, java.lang.String typeName, java.lang.String valueType, int arraySize)
Description copied from interface:IDatabaseAdapter
Create ARRAY type used for passing values to stored procedures e.g.: CREATE OR REPLACE TYPE.t_str_values_arr AS .t_str_values ARRAY[256]
-
dropType
public void dropType(java.lang.String schemaName, java.lang.String typeName)
Description copied from interface:IDatabaseAdapter
Drop the type object from the schema
-
createOrReplaceProcedure
public void createOrReplaceProcedure(java.lang.String schemaName, java.lang.String procedureName, java.util.function.Supplier<java.lang.String> supplier)
Description copied from interface:IDatabaseAdapter
Create the stored procedure using the DDL text provided by the supplier- Specified by:
createOrReplaceProcedure
in interfaceIDatabaseAdapter
- Overrides:
createOrReplaceProcedure
in classCommonDatabaseAdapter
-
dropProcedure
public void dropProcedure(java.lang.String schemaName, java.lang.String procedureName)
Description copied from interface:IDatabaseAdapter
Drop the given procedure- Specified by:
dropProcedure
in interfaceIDatabaseAdapter
- Overrides:
dropProcedure
in classCommonDatabaseAdapter
-
createTablespace
public void createTablespace(java.lang.String tablespaceName)
Description copied from interface:IDatabaseAdapter
Create a new tablespace with the given name
-
createTablespace
public void createTablespace(java.lang.String tablespaceName, int extentSizeKB)
Description copied from interface:IDatabaseAdapter
Create a new tablespace using the given extent size
-
dropTablespace
public void dropTablespace(java.lang.String tablespaceName)
Description copied from interface:IDatabaseAdapter
Drop an existing tablespace, including all of its contents
-
detachPartition
public void detachPartition(java.lang.String schemaName, java.lang.String tableName, java.lang.String partitionName, java.lang.String intoTableName)
Description copied from interface:IDatabaseAdapter
Detach the partition
-
removeTenantPartitions
public void removeTenantPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int tenantId)
Description copied from interface:IDatabaseAdapter
Detach the partition associated with the tenantId from each of the given tables
-
dropDetachedPartitions
public void dropDetachedPartitions(java.util.Collection<Table> tables, java.lang.String schemaName, int tenantId)
Description copied from interface:IDatabaseAdapter
Drop the tables which were created by the detach partition operation (as part of tenant deprovisioning).
-
doesTableExist
public boolean doesTableExist(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
Check if the table currently exists- Returns:
-
varbinaryClause
public java.lang.String varbinaryClause(int size)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for binary data type- Returns:
-
blobClause
public java.lang.String blobClause(long size, int inlineSize)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for BLOB (with an inline size if supported)- Returns:
-
varcharClause
public java.lang.String varcharClause(int size)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for VARCHAR- Returns:
-
checkCompatibility
public boolean checkCompatibility(java.lang.String adminSchema)
Description copied from interface:IDatabaseAdapter
checks connectivity to the database and that it is compatible- Returns:
-
runStatement
public void runStatement(IDatabaseStatement stmt)
Description copied from class:CommonDatabaseAdapter
Run the statement using the connectionProvider to obtain a new connection. Also, there should be a transaction open on the current thread at this time- Specified by:
runStatement
in interfaceIDatabaseAdapter
- Overrides:
runStatement
in classCommonDatabaseAdapter
-
createSchema
public void createSchema(java.lang.String schemaName)
Description copied from interface:IDatabaseAdapter
Create a database schema
-
useSessionVariable
public boolean useSessionVariable()
- Returns:
- a false, if not used, or true if used with the persistence layer.
-
dropTenantTablespace
public void dropTenantTablespace(int tenantId)
Description copied from interface:IDatabaseAdapter
Drop the tablespace associated with the given tenantId
-
disableForeignKey
public void disableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Description copied from interface:IDatabaseAdapter
Disable the FK with the given constraint name
-
enableForeignKey
public void enableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Description copied from interface:IDatabaseAdapter
Enable the FK with the given constraint name
-
setIntegrityOff
public void setIntegrityOff(java.lang.String schemaName, java.lang.String tableName)
-
setIntegrityUnchecked
public void setIntegrityUnchecked(java.lang.String schemaName, java.lang.String tableName)
-
reorgTable
public void reorgTable(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
Reorg the table if the underlying database supports it. Required after columns are added/removed from a table.- Specified by:
reorgTable
in interfaceIDatabaseAdapter
- Overrides:
reorgTable
in classCommonDatabaseAdapter
-
listSchemaObjects
public java.util.List<SchemaInfoObject> listSchemaObjects(java.lang.String schemaName)
Description copied from interface:IDatabaseAdapter
List the objects present in the given schema- Returns:
-
-