Class DerbyAdapter
- java.lang.Object
-
- com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
-
- com.ibm.fhir.database.utils.derby.DerbyAdapter
-
- All Implemented Interfaces:
IDatabaseAdapter,IDatabaseTypeAdapter
public class DerbyAdapter extends CommonDatabaseAdapter
A Derby database target
-
-
Field Summary
-
Fields inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
connectionProvider, target
-
-
Constructor Summary
Constructors Constructor Description DerbyAdapter()DerbyAdapter(IConnectionProvider cp)DerbyAdapter(IDatabaseTarget tgt)Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivateRowAccessControl(String schemaName, String tableName)ALTER TABLEACTIVATE ROW ACCESS CONTROL voidalterSequenceRestartWith(String schemaName, String sequenceName, long restartWith, int cache, int incrementBy)Sets/resets the sequence to start with the given value.voidalterTableColumnIdentityCache(String schemaName, String tableName, String columnName, int cache)Change the CACHE value of the named identity generated always columnStringblobClause(long size, int inlineSize)Generate a clause for BLOB (with an inline size if supported)booleancheckCompatibility(String adminSchema)checks connectivity to the database and that it is compatiblevoidcreateArrType(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] voidcreateForeignKeyConstraint(String constraintName, String schemaName, String name, String targetSchema, String targetTable, String targetColumnName, String tenantColumnName, List<String> columns, boolean enforced)voidcreateIntVariable(String schemaName, String variableName)CREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;voidcreateOrReplacePermission(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;voidcreateOrReplaceProcedure(String schemaName, String procedureName, Supplier<String> supplier)Create the stored procedure using the DDL text provided by the suppliervoidcreateOrReplaceView(String schemaName, String viewName, String selectClause)Create or replace the viewvoidcreateRowType(String schemaName, String typeName, List<ColumnBase> columns)Create ROW type used for passing values to stored procedures e.g.:voidcreateSchema(String schemaName)Create a database schemavoidcreateSequence(String schemaName, String sequenceName, long startWith, int cache, int incrementBy)voidcreateTable(String schemaName, String name, String tenantColumnName, List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, String tablespaceName, List<With> withs, List<CheckConstraint> checkConstraints)Build the create table DDLvoidcreateTablespace(String tablespaceName)Create a new tablespace with the given namevoidcreateTablespace(String tablespaceName, int extentSizeKB)Create a new tablespace using the given extent sizevoidcreateTenantPartitions(Collection<Table> tables, String schemaName, int newTenantId, int extentSizeKB)Create the partitions on each of these tablesvoidcreateUniqueIndex(String schemaName, String tableName, String indexName, String tenantColumnName, List<OrderedColumnDef> indexColumns, List<String> includeColumns)voiddeactivateRowAccessControl(String schemaName, String tableName)Deactivate row access control on a table ALTER TABLEDEACTIVATE ROW ACCESS CONTROL voiddetachPartition(String schemaName, String tableName, String partitionName, String newTableName)Detach the partitionvoiddisableForeignKey(String schemaName, String tableName, String constraintName)Disable the FK with the given constraint namebooleandoesTableExist(String schemaName, String tableName)Check if the table currently existsvoiddropDetachedPartitions(Collection<Table> tables, String schemaName, int tenantId)Drop the tables which were created by the detach partition operation (as part of tenant deprovisioning).voiddropPermission(String schemaName, String permissionName)Drop permission object from the schemavoiddropProcedure(String schemaName, String procedureName)Drop the given procedurevoiddropSequence(String schemaName, String sequenceName)voiddropTable(String schemaName, String tableName)Drop table from the schemavoiddropTablespace(String tablespaceName)Drop an existing tablespace, including all of its contentsvoiddropTenantTablespace(int tenantId)Drop the tablespace associated with the given tenantIdvoiddropType(String schemaName, String typeName)Drop the type object from the schemavoidenableForeignKey(String schemaName, String tableName, String constraintName)Enable the FK with the given constraint nameList<SchemaInfoObject>listSchemaObjects(String schemaName)List the objects present in the given schemaprotected List<OrderedColumnDef>prefixTenantColumn(String tenantColumnName, List<OrderedColumnDef> columns)Prefix the tenantColumnName to the list of columns, or do nothing if tenantColumnName is nullvoidremoveTenantPartitions(Collection<Table> tables, String schemaName, int tenantId)Detach the partition associated with the tenantId from each of the given tablesvoidrunStatement(IDatabaseStatement stmt)Run the statement using the connectionProvider to obtain a new connection.voidsetIntegrityOff(String schemaName, String tableName)voidsetIntegrityUnchecked(String schemaName, String tableName)voidsetIntVariable(String schemaName, String variableName, int value)Build the DML statement for setting a session variableStringtimestampClause(Integer precision)Generate a clause for TIMESTAMPStringvarbinaryClause(int size)Generate a clause for binary data typeStringvarcharClause(int size)Generate a clause for VARCHARvoidwarnOnce(com.ibm.fhir.database.utils.derby.DerbyAdapter.MessageKey messageKey, String msg)Once write each warning message once-
Methods inherited from class com.ibm.fhir.database.utils.common.CommonDatabaseAdapter
addNewTenantPartitions, allocateTenant, alterTableAddColumn, buildColumns, buildCreateTableStatement, createIndex, createOrReplaceFunction, createUniqueConstraint, createUniqueIndex, createView, deleteTenantMeta, dropForeignKey, dropFunction, dropIndex, dropVariable, dropView, findTenantId, getQualifiedName, getTranslator, grantFunctionPrivileges, grantObjectPrivileges, grantProcedurePrivileges, 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
-
Methods inherited from interface com.ibm.fhir.database.utils.api.IDatabaseTypeAdapter
clobClause, doubleClause
-
-
-
-
Constructor Detail
-
DerbyAdapter
public DerbyAdapter(IDatabaseTarget tgt)
Public constructor- Parameters:
tgt- the target database we want to manage
-
DerbyAdapter
public DerbyAdapter(IConnectionProvider cp)
-
DerbyAdapter
public DerbyAdapter()
-
-
Method Detail
-
warnOnce
public void warnOnce(com.ibm.fhir.database.utils.derby.DerbyAdapter.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, List<With> withs, List<CheckConstraint> checkConstraints)
Description copied from interface:IDatabaseAdapterBuild 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:
createUniqueIndexin interfaceIDatabaseAdapter- Overrides:
createUniqueIndexin classCommonDatabaseAdapter
-
createIntVariable
public void createIntVariable(String schemaName, String variableName)
Description copied from interface:IDatabaseAdapterCREATE VARIABLE ptng.session_tenant INT DEFAULT NULL;
-
createOrReplacePermission
public void createOrReplacePermission(String schemaName, String permissionName, String tableName, String predicate)
Description copied from interface:IDatabaseAdapterCREATE 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:IDatabaseAdapterALTER TABLE
ACTIVATE ROW ACCESS CONTROL
-
setIntVariable
public void setIntVariable(String schemaName, String variableName, int value)
Description copied from interface:IDatabaseAdapterBuild the DML statement for setting a session variable
-
deactivateRowAccessControl
public void deactivateRowAccessControl(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapterDeactivate 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:IDatabaseAdapterCreate the partitions on each of these tables
-
createRowType
public void createRowType(String schemaName, String typeName, List<ColumnBase> columns)
Description copied from interface:IDatabaseAdapterCreate 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:IDatabaseAdapterCreate 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:IDatabaseAdapterDrop the type object from the schema
-
createOrReplaceProcedure
public void createOrReplaceProcedure(String schemaName, String procedureName, Supplier<String> supplier)
Description copied from interface:IDatabaseAdapterCreate the stored procedure using the DDL text provided by the supplier- Specified by:
createOrReplaceProcedurein interfaceIDatabaseAdapter- Overrides:
createOrReplaceProcedurein classCommonDatabaseAdapter
-
dropProcedure
public void dropProcedure(String schemaName, String procedureName)
Description copied from interface:IDatabaseAdapterDrop the given procedure- Specified by:
dropProcedurein interfaceIDatabaseAdapter- Overrides:
dropProcedurein classCommonDatabaseAdapter
-
dropPermission
public void dropPermission(String schemaName, String permissionName)
Description copied from interface:IDatabaseAdapterDrop permission object from the schema- Specified by:
dropPermissionin interfaceIDatabaseAdapter- Overrides:
dropPermissionin classCommonDatabaseAdapter
-
createTablespace
public void createTablespace(String tablespaceName)
Description copied from interface:IDatabaseAdapterCreate a new tablespace with the given name
-
createTablespace
public void createTablespace(String tablespaceName, int extentSizeKB)
Description copied from interface:IDatabaseAdapterCreate a new tablespace using the given extent size
-
dropTablespace
public void dropTablespace(String tablespaceName)
Description copied from interface:IDatabaseAdapterDrop an existing tablespace, including all of its contents
-
dropTable
public void dropTable(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapterDrop table from the schema- Specified by:
dropTablein interfaceIDatabaseAdapter- Overrides:
dropTablein classCommonDatabaseAdapter
-
detachPartition
public void detachPartition(String schemaName, String tableName, String partitionName, String newTableName)
Description copied from interface:IDatabaseAdapterDetach the partition
-
removeTenantPartitions
public void removeTenantPartitions(Collection<Table> tables, String schemaName, int tenantId)
Description copied from interface:IDatabaseAdapterDetach the partition associated with the tenantId from each of the given tables
-
doesTableExist
public boolean doesTableExist(String schemaName, String tableName)
Description copied from interface:IDatabaseAdapterCheck if the table currently exists- Returns:
-
createSequence
public void createSequence(String schemaName, String sequenceName, long startWith, int cache, int incrementBy)
- Specified by:
createSequencein interfaceIDatabaseAdapter- Overrides:
createSequencein classCommonDatabaseAdapterstartWith- the START WITH value for the sequencecache- the sequence CACHE value
-
dropSequence
public void dropSequence(String schemaName, String sequenceName)
- Specified by:
dropSequencein interfaceIDatabaseAdapter- Overrides:
dropSequencein classCommonDatabaseAdapter
-
alterSequenceRestartWith
public void alterSequenceRestartWith(String schemaName, String sequenceName, long restartWith, int cache, int incrementBy)
Description copied from interface:IDatabaseAdapterSets/resets the sequence to start with the given value.- Specified by:
alterSequenceRestartWithin interfaceIDatabaseAdapter- Overrides:
alterSequenceRestartWithin classCommonDatabaseAdapter
-
alterTableColumnIdentityCache
public void alterTableColumnIdentityCache(String schemaName, String tableName, String columnName, int cache)
Description copied from interface:IDatabaseAdapterChange the CACHE value of the named identity generated always column- Specified by:
alterTableColumnIdentityCachein interfaceIDatabaseAdapter- Overrides:
alterTableColumnIdentityCachein classCommonDatabaseAdapter
-
varbinaryClause
public String varbinaryClause(int size)
Description copied from interface:IDatabaseTypeAdapterGenerate a clause for binary data type- Returns:
-
blobClause
public String blobClause(long size, int inlineSize)
Description copied from interface:IDatabaseTypeAdapterGenerate a clause for BLOB (with an inline size if supported)- Returns:
-
varcharClause
public String varcharClause(int size)
Description copied from interface:IDatabaseTypeAdapterGenerate a clause for VARCHAR- Returns:
-
timestampClause
public String timestampClause(Integer precision)
Description copied from interface:IDatabaseTypeAdapterGenerate a clause for TIMESTAMP- Returns:
-
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:
createForeignKeyConstraintin interfaceIDatabaseAdapter- Overrides:
createForeignKeyConstraintin classCommonDatabaseAdapter
-
prefixTenantColumn
protected List<OrderedColumnDef> prefixTenantColumn(String tenantColumnName, List<OrderedColumnDef> columns)
Description copied from class:CommonDatabaseAdapterPrefix the tenantColumnName to the list of columns, or do nothing if tenantColumnName is null- Overrides:
prefixTenantColumnin classCommonDatabaseAdapter- Returns:
-
runStatement
public void runStatement(IDatabaseStatement stmt)
Description copied from class:CommonDatabaseAdapterRun 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:
runStatementin interfaceIDatabaseAdapter- Overrides:
runStatementin classCommonDatabaseAdapter
-
checkCompatibility
public boolean checkCompatibility(String adminSchema)
Description copied from interface:IDatabaseAdapterchecks connectivity to the database and that it is compatible- Returns:
-
createSchema
public void createSchema(String schemaName)
Description copied from interface:IDatabaseAdapterCreate a database schema
-
dropDetachedPartitions
public void dropDetachedPartitions(Collection<Table> tables, String schemaName, int tenantId)
Description copied from interface:IDatabaseAdapterDrop 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:IDatabaseAdapterDrop the tablespace associated with the given tenantId
-
disableForeignKey
public void disableForeignKey(String schemaName, String tableName, String constraintName)
Description copied from interface:IDatabaseAdapterDisable the FK with the given constraint name
-
enableForeignKey
public void enableForeignKey(String schemaName, String tableName, String constraintName)
Description copied from interface:IDatabaseAdapterEnable the FK with the given constraint name
-
createOrReplaceView
public void createOrReplaceView(String schemaName, String viewName, String selectClause)
Description copied from interface:IDatabaseAdapterCreate or replace the view- Specified by:
createOrReplaceViewin interfaceIDatabaseAdapter- Overrides:
createOrReplaceViewin classCommonDatabaseAdapter
-
listSchemaObjects
public List<SchemaInfoObject> listSchemaObjects(String schemaName)
Description copied from interface:IDatabaseAdapterList the objects present in the given schema- Returns:
-
-