Class PostgresAdapter
- java.lang.Object
-
- com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
-
- com.ibm.fhir.database.utils.postgres.PostgresAdapter
-
- All Implemented Interfaces:
IDatabaseAdapter
,IDatabaseTypeAdapter
public class PostgresAdapter extends CommonDatabaseAdapter
A PostgreSql database target
-
-
Field Summary
-
Fields inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
connectionProvider, target
-
-
Constructor Summary
Constructors Constructor Description PostgresAdapter()
PostgresAdapter(IConnectionProvider cp)
PostgresAdapter(IDatabaseTarget tgt)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateRowAccessControl(String schemaName, String tableName)
ALTER TABLEACTIVATE ROW ACCESS CONTROL void
alterTableColumnIdentityCache(String schemaName, String tableName, String columnName, int cache)
Change the CACHE value of the named identity generated always columnString
blobClause(long size, int inlineSize)
Generate a clause for BLOB (with an inline size if supported)boolean
checkCompatibility(String adminSchema)
checks connectivity to the database and that it is compatibleString
clobClause()
void
createArrType(String schemaName, String typeName, 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
createForeignKeyConstraint(String constraintName, String schemaName, String name, String targetSchema, String targetTable, String targetColumnName, String tenantColumnName, List<String> columns, boolean enforced)
void
createIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns)
void
createIntVariable(String schemaName, String variableName)
CREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;void
createOrReplacePermission(String schemaName, String permissionName, String tableName, 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(String schemaName, String procedureName, Supplier<String> supplier)
Create the stored procedure using the DDL text provided by the suppliervoid
createRowType(String schemaName, String typeName, List<ColumnBase> columns)
Create ROW type used for passing values to stored procedures e.g.:void
createSchema(String schemaName)
Create a database schemavoid
createSequence(String schemaName, String sequenceName, long startWith, int cache, int incrementBy)
void
createTable(String schemaName, String name, String tenantColumnName, List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, String tablespaceName)
Build the create table DDLvoid
createTablespace(String tablespaceName)
Create a new tablespace with the given namevoid
createTablespace(String tablespaceName, int extentSizeKB)
Create a new tablespace using the given extent sizevoid
createTenantPartitions(Collection<Table> tables, String schemaName, int newTenantId, int extentSizeKB)
Create the partitions on each of these tablesvoid
createUniqueIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns)
void
createUniqueIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns, List<String> includeColumns)
void
deactivateRowAccessControl(String schemaName, String tableName)
Deactivate row access control on a table ALTER TABLEDEACTIVATE ROW ACCESS CONTROL void
detachPartition(String schemaName, String tableName, String partitionName, String newTableName)
Detach the partitionvoid
disableForeignKey(String schemaName, String tableName, String constraintName)
Disable the FK with the given constraint nameboolean
doesTableExist(String schemaName, String tableName)
Check if the table currently existsString
doubleClause()
Generate a clause for double data typevoid
dropDetachedPartitions(Collection<Table> tables, String schemaName, int tenantId)
Drop the tables which were created by the detach partition operation (as part of tenant deprovisioning).void
dropPermission(String schemaName, String permissionName)
Drop permission object from the schemavoid
dropProcedure(String schemaName, String procedureName)
Drop the given procedurevoid
dropTablespace(String tablespaceName)
Drop an existing tablespace, including all of its contentsvoid
dropTenantTablespace(int tenantId)
Drop the tablespace associated with the given tenantIdvoid
dropType(String schemaName, String typeName)
Drop the type object from the schemavoid
enableForeignKey(String schemaName, String tableName, String constraintName)
Enable the FK with the given constraint namevoid
grantProcedurePrivileges(String schemaName, String procedureName, Collection<Privilege> privileges, String toUser)
Grant the collection of privileges on the named procedure to the userprotected List<OrderedColumnDef>
prefixTenantColumn(String tenantColumnName, List<OrderedColumnDef> columns)
Prefix the tenantColumnName to the list of columns, or do nothing if tenantColumnName is nullvoid
removeTenantPartitions(Collection<Table> tables, String schemaName, int tenantId)
Detach the partition associated with the tenantId from each of the given tablesvoid
runStatement(IDatabaseStatement stmt)
Run the statement using the connectionProvider to obtain a new connection.void
setIntegrityOff(String schemaName, String tableName)
void
setIntegrityUnchecked(String schemaName, String tableName)
void
setIntVariable(String schemaName, String variableName, int value)
Build the DML statement for setting a session variableString
timestampClause(Integer precision)
Generate a clause for TIMESTAMPString
varbinaryClause(int size)
Generate a clause for binary data typeString
varcharClause(int size)
Generate a clause for VARCHARvoid
warnOnce(com.ibm.fhir.database.utils.postgres.PostgresAdapter.MessageKey messageKey, String msg)
Once write each warning message once-
Methods inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
addNewTenantPartitions, allocateTenant, alterSequenceRestartWith, alterTableAddColumn, buildColumns, buildCreateTableStatement, createOrReplaceFunction, createOrReplaceView, createUniqueConstraint, createView, deleteTenantMeta, dropFunction, dropIndex, dropSequence, dropTable, dropVariable, dropView, findTenantId, getQualifiedName, getTranslator, grantFunctionPrivileges, grantObjectPrivileges, grantSequencePrivileges, grantVariablePrivileges, reorgTable, 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.IDatabaseAdapter
useSessionVariable
-
-
-
-
Constructor Detail
-
PostgresAdapter
public PostgresAdapter(IDatabaseTarget tgt)
Public constructor- Parameters:
tgt
- the target database we want to manage
-
PostgresAdapter
public PostgresAdapter(IConnectionProvider cp)
-
PostgresAdapter
public PostgresAdapter()
-
-
Method Detail
-
warnOnce
public void warnOnce(com.ibm.fhir.database.utils.postgres.PostgresAdapter.MessageKey messageKey, String msg)
Once write each warning message once- Parameters:
msg
-
-
createTable
public void createTable(String schemaName, String name, String tenantColumnName, List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, String tablespaceName)
Description copied from interface:IDatabaseAdapter
Build the create table DDLtenantColumnName
- optional column name to enable multi-tenancy
-
createUniqueIndex
public void createUniqueIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns, List<String> includeColumns)
- Specified by:
createUniqueIndex
in interfaceIDatabaseAdapter
- Overrides:
createUniqueIndex
in classCommonDatabaseAdapter
-
createIntVariable
public void createIntVariable(String schemaName, String variableName)
Description copied from interface:IDatabaseAdapter
CREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;
-
createOrReplacePermission
public void createOrReplacePermission(String schemaName, String permissionName, String tableName, 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(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapter
ALTER TABLE
ACTIVATE ROW ACCESS CONTROL
-
setIntVariable
public void setIntVariable(String schemaName, String variableName, int value)
Description copied from interface:IDatabaseAdapter
Build the DML statement for setting a session variable
-
deactivateRowAccessControl
public void deactivateRowAccessControl(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapter
Deactivate row access control on a table ALTER TABLEDEACTIVATE ROW ACCESS CONTROL
-
createTenantPartitions
public void createTenantPartitions(Collection<Table> tables, String schemaName, int newTenantId, int extentSizeKB)
Description copied from interface:IDatabaseAdapter
Create the partitions on each of these tables
-
createRowType
public void createRowType(String schemaName, String typeName, 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(String schemaName, String typeName, 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(String schemaName, String typeName)
Description copied from interface:IDatabaseAdapter
Drop the type object from the schema
-
createTablespace
public void createTablespace(String tablespaceName)
Description copied from interface:IDatabaseAdapter
Create a new tablespace with the given name
-
dropTablespace
public void dropTablespace(String tablespaceName)
Description copied from interface:IDatabaseAdapter
Drop an existing tablespace, including all of its contents
-
detachPartition
public void detachPartition(String schemaName, String tableName, String partitionName, String newTableName)
Description copied from interface:IDatabaseAdapter
Detach the partition
-
removeTenantPartitions
public void removeTenantPartitions(Collection<Table> tables, String schemaName, int tenantId)
Description copied from interface:IDatabaseAdapter
Detach the partition associated with the tenantId from each of the given tables
-
createTablespace
public void createTablespace(String tablespaceName, int extentSizeKB)
Description copied from interface:IDatabaseAdapter
Create a new tablespace using the given extent size
-
doesTableExist
public boolean doesTableExist(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapter
Check if the table currently exists- Returns:
-
createSequence
public void createSequence(String schemaName, String sequenceName, long startWith, int cache, int incrementBy)
- Specified by:
createSequence
in interfaceIDatabaseAdapter
- Overrides:
createSequence
in classCommonDatabaseAdapter
startWith
- the START WITH value for the sequencecache
- the sequence CACHE value
-
varbinaryClause
public String varbinaryClause(int size)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for binary data type- Returns:
-
blobClause
public 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 String varcharClause(int size)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for VARCHAR- Returns:
-
timestampClause
public String timestampClause(Integer precision)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for TIMESTAMP- Returns:
-
doubleClause
public String doubleClause()
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for double data type- Returns:
-
clobClause
public String clobClause()
-
createForeignKeyConstraint
public void createForeignKeyConstraint(String constraintName, String schemaName, String name, String targetSchema, String targetTable, String targetColumnName, String tenantColumnName, List<String> columns, boolean enforced)
- Specified by:
createForeignKeyConstraint
in interfaceIDatabaseAdapter
- Overrides:
createForeignKeyConstraint
in classCommonDatabaseAdapter
-
prefixTenantColumn
protected List<OrderedColumnDef> prefixTenantColumn(String tenantColumnName, List<OrderedColumnDef> columns)
Description copied from class:CommonDatabaseAdapter
Prefix the tenantColumnName to the list of columns, or do nothing if tenantColumnName is null- Overrides:
prefixTenantColumn
in classCommonDatabaseAdapter
- 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
-
createUniqueIndex
public void createUniqueIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns)
- Specified by:
createUniqueIndex
in interfaceIDatabaseAdapter
- Overrides:
createUniqueIndex
in classCommonDatabaseAdapter
-
createIndex
public void createIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns)
- Specified by:
createIndex
in interfaceIDatabaseAdapter
- Overrides:
createIndex
in classCommonDatabaseAdapter
-
checkCompatibility
public boolean checkCompatibility(String adminSchema)
Description copied from interface:IDatabaseAdapter
checks connectivity to the database and that it is compatible- Returns:
-
createSchema
public void createSchema(String schemaName)
Description copied from interface:IDatabaseAdapter
Create a database schema
-
createOrReplaceProcedure
public void createOrReplaceProcedure(String schemaName, String procedureName, Supplier<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
-
grantProcedurePrivileges
public void grantProcedurePrivileges(String schemaName, String procedureName, Collection<Privilege> privileges, String toUser)
Description copied from interface:IDatabaseAdapter
Grant the collection of privileges on the named procedure to the user- Specified by:
grantProcedurePrivileges
in interfaceIDatabaseAdapter
- Overrides:
grantProcedurePrivileges
in classCommonDatabaseAdapter
-
dropProcedure
public void dropProcedure(String schemaName, String procedureName)
Description copied from interface:IDatabaseAdapter
Drop the given procedure- Specified by:
dropProcedure
in interfaceIDatabaseAdapter
- Overrides:
dropProcedure
in classCommonDatabaseAdapter
-
dropDetachedPartitions
public void dropDetachedPartitions(Collection<Table> tables, 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).
-
dropTenantTablespace
public void dropTenantTablespace(int tenantId)
Description copied from interface:IDatabaseAdapter
Drop the tablespace associated with the given tenantId
-
disableForeignKey
public void disableForeignKey(String schemaName, String tableName, String constraintName)
Description copied from interface:IDatabaseAdapter
Disable the FK with the given constraint name
-
enableForeignKey
public void enableForeignKey(String schemaName, String tableName, String constraintName)
Description copied from interface:IDatabaseAdapter
Enable the FK with the given constraint name
-
alterTableColumnIdentityCache
public void alterTableColumnIdentityCache(String schemaName, String tableName, String columnName, int cache)
Description copied from interface:IDatabaseAdapter
Change the CACHE value of the named identity generated always column- Specified by:
alterTableColumnIdentityCache
in interfaceIDatabaseAdapter
- Overrides:
alterTableColumnIdentityCache
in classCommonDatabaseAdapter
-
dropPermission
public void dropPermission(String schemaName, String permissionName)
Description copied from interface:IDatabaseAdapter
Drop permission object from the schema- Specified by:
dropPermission
in interfaceIDatabaseAdapter
- Overrides:
dropPermission
in classCommonDatabaseAdapter
-
-