Class PostgresAdapter
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.common.CommonDatabaseAdapter
-
- org.linuxforhealth.fhir.database.utils.postgres.PostgresAdapter
-
- All Implemented Interfaces:
IDatabaseAdapter
,IDatabaseTypeAdapter
- Direct Known Subclasses:
CitusAdapter
public class PostgresAdapter extends CommonDatabaseAdapter
A PostgreSql database target
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
PostgresAdapter.MessageKey
-
Field Summary
Fields Modifier and Type Field Description protected static boolean
USE_SCHEMA_PREFIX
-
Fields inherited from class org.linuxforhealth.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
alterTableColumnIdentityCache(java.lang.String schemaName, java.lang.String tableName, java.lang.String columnName, int cache)
Change the CACHE value of the named identity generated always columnjava.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 compatiblejava.lang.String
clobClause()
void
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
createForeignKeyConstraint(java.lang.String constraintName, java.lang.String schemaName, java.lang.String name, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.util.List<java.lang.String> columns, boolean enforced)
void
createIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns)
void
createOrReplaceFunction(java.lang.String schemaName, java.lang.String functionName, java.util.function.Supplier<java.lang.String> supplier)
creates or replaces the SQL functionvoid
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
createSequence(java.lang.String schemaName, java.lang.String sequenceName, long startWith, int cache, int incrementBy)
void
createTable(java.lang.String schemaName, java.lang.String name, java.util.List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, java.lang.String tablespaceName, java.util.List<With> withs, java.util.List<CheckConstraint> checkConstraints, DistributionContext distributionContext)
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
createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, java.util.List<java.lang.String> includeColumns, DistributionContext distributionContext)
Create a unique indexvoid
createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionContext distributionContext)
Create a unique indexvoid
disableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Disable the FK with the given constraint nameboolean
doesForeignKeyConstraintExist(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Does the named foreign key constraint existboolean
doesTableExist(java.lang.String schemaName, java.lang.String tableName)
Check if the table currently existsjava.lang.String
doubleClause()
Generate a clause for double data typevoid
dropForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Drop the FK on the table with the given constraint namevoid
dropIndex(java.lang.String schemaName, java.lang.String indexName)
Drop the named indexvoid
dropPermission(java.lang.String schemaName, java.lang.String permissionName)
Drop permission object from the schemavoid
dropProcedure(java.lang.String schemaName, java.lang.String procedureName)
Drop the given procedurevoid
dropSequence(java.lang.String schemaName, java.lang.String sequenceName)
void
dropTable(java.lang.String schemaName, java.lang.String tableName)
Drop table from the schemavoid
dropTablespace(java.lang.String tablespaceName)
Drop an existing tablespace, including all of its contentsvoid
dropType(java.lang.String schemaName, java.lang.String typeName)
Drop the type object from the schemavoid
dropVariable(java.lang.String schemaName, java.lang.String variableName)
void
dropView(java.lang.String schemaName, java.lang.String viewName)
Drop the view from the databasevoid
enableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Enable the FK with the given constraint namevoid
grantAllSequenceUsage(java.lang.String schemaName, java.lang.String grantToUser)
Grant access to all sequences in the named schemavoid
grantProcedurePrivileges(java.lang.String schemaName, java.lang.String procedureName, java.util.Collection<Privilege> privileges, java.lang.String toUser)
Grant the collection of privileges on the named procedure to the uservoid
grantSchemaUsage(java.lang.String schemaName, java.lang.String grantToUser)
Grants USAGE on the given schemaName to the given userjava.util.List<SchemaInfoObject>
listSchemaObjects(java.lang.String schemaName)
List the objects present in the given schemaprotected java.util.List<OrderedColumnDef>
prefixTenantColumn(java.lang.String tenantColumnName, java.util.List<OrderedColumnDef> columns)
Prefix the tenantColumnName to the list of columns, or do nothing if tenantColumnName is nullvoid
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)
java.lang.String
timestampClause(java.lang.Integer precision)
Generate a clause for TIMESTAMPjava.lang.String
varbinaryClause(int size)
Generate a clause for binary data typejava.lang.String
varcharClause(int size)
Generate a clause for VARCHARvoid
warnOnce(PostgresAdapter.MessageKey messageKey, java.lang.String msg)
Once write each warning message once-
Methods inherited from class org.linuxforhealth.fhir.database.utils.common.CommonDatabaseAdapter
alterSequenceRestartWith, alterTableAddColumn, applyDistributionRules, buildColumns, buildCreateTableStatement, createOrReplaceView, createUniqueConstraint, createView, distributeFunction, dropFunction, getQualifiedName, getTranslator, grantFunctionPrivileges, grantObjectPrivileges, grantSequencePrivileges, grantVariablePrivileges, runStatement, runStatement
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.linuxforhealth.fhir.database.utils.api.IDatabaseAdapter
useSessionVariable
-
Methods inherited from interface org.linuxforhealth.fhir.database.utils.api.IDatabaseTypeAdapter
smallintClause
-
-
-
-
Field Detail
-
USE_SCHEMA_PREFIX
protected static final boolean USE_SCHEMA_PREFIX
- See Also:
- Constant Field Values
-
-
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(PostgresAdapter.MessageKey messageKey, java.lang.String msg)
Once write each warning message once- Parameters:
msg
-
-
createTable
public void createTable(java.lang.String schemaName, java.lang.String name, java.util.List<ColumnBase> columns, PrimaryKeyDef primaryKey, IdentityDef identity, java.lang.String tablespaceName, java.util.List<With> withs, java.util.List<CheckConstraint> checkConstraints, DistributionContext distributionContext)
Description copied from interface:IDatabaseAdapter
Build the create table DDL
-
createUniqueIndex
public void createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, java.util.List<java.lang.String> includeColumns, DistributionContext distributionContext)
Description copied from interface:IDatabaseAdapter
Create a unique index- Specified by:
createUniqueIndex
in interfaceIDatabaseAdapter
- Overrides:
createUniqueIndex
in classCommonDatabaseAdapter
-
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
-
createTablespace
public void createTablespace(java.lang.String tablespaceName)
Description copied from interface:IDatabaseAdapter
Create a new tablespace with the given name
-
dropTablespace
public void dropTablespace(java.lang.String tablespaceName)
Description copied from interface:IDatabaseAdapter
Drop an existing tablespace, including all of its contents
-
createTablespace
public void createTablespace(java.lang.String tablespaceName, int extentSizeKB)
Description copied from interface:IDatabaseAdapter
Create a new tablespace using the given extent size
-
doesTableExist
public boolean doesTableExist(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
Check if the table currently exists- Returns:
-
createSequence
public void createSequence(java.lang.String schemaName, java.lang.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 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:
-
timestampClause
public java.lang.String timestampClause(java.lang.Integer precision)
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for TIMESTAMP- Returns:
-
doubleClause
public java.lang.String doubleClause()
Description copied from interface:IDatabaseTypeAdapter
Generate a clause for double data type- Returns:
-
clobClause
public java.lang.String clobClause()
-
createForeignKeyConstraint
public void createForeignKeyConstraint(java.lang.String constraintName, java.lang.String schemaName, java.lang.String name, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.util.List<java.lang.String> columns, boolean enforced)
- Specified by:
createForeignKeyConstraint
in interfaceIDatabaseAdapter
- Overrides:
createForeignKeyConstraint
in classCommonDatabaseAdapter
-
prefixTenantColumn
protected java.util.List<OrderedColumnDef> prefixTenantColumn(java.lang.String tenantColumnName, java.util.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(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionContext distributionContext)
Description copied from interface:IDatabaseAdapter
Create a unique index- Specified by:
createUniqueIndex
in interfaceIDatabaseAdapter
- Overrides:
createUniqueIndex
in classCommonDatabaseAdapter
-
createIndex
public void createIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns)
- Specified by:
createIndex
in interfaceIDatabaseAdapter
- Overrides:
createIndex
in classCommonDatabaseAdapter
-
checkCompatibility
public boolean checkCompatibility(java.lang.String adminSchema)
Description copied from interface:IDatabaseAdapter
checks connectivity to the database and that it is compatible- Returns:
-
createSchema
public void createSchema(java.lang.String schemaName)
Description copied from interface:IDatabaseAdapter
Create a database 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
-
grantProcedurePrivileges
public void grantProcedurePrivileges(java.lang.String schemaName, java.lang.String procedureName, java.util.Collection<Privilege> privileges, java.lang.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(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
-
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
-
doesForeignKeyConstraintExist
public boolean doesForeignKeyConstraintExist(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Description copied from interface:IDatabaseAdapter
Does the named foreign key constraint exist- Returns:
-
setIntegrityOff
public void setIntegrityOff(java.lang.String schemaName, java.lang.String tableName)
-
setIntegrityUnchecked
public void setIntegrityUnchecked(java.lang.String schemaName, java.lang.String tableName)
-
alterTableColumnIdentityCache
public void alterTableColumnIdentityCache(java.lang.String schemaName, java.lang.String tableName, java.lang.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(java.lang.String schemaName, java.lang.String permissionName)
Description copied from interface:IDatabaseAdapter
Drop permission object from the schema- Specified by:
dropPermission
in interfaceIDatabaseAdapter
- Overrides:
dropPermission
in classCommonDatabaseAdapter
-
dropSequence
public void dropSequence(java.lang.String schemaName, java.lang.String sequenceName)
- Specified by:
dropSequence
in interfaceIDatabaseAdapter
- Overrides:
dropSequence
in classCommonDatabaseAdapter
-
dropVariable
public void dropVariable(java.lang.String schemaName, java.lang.String variableName)
- Specified by:
dropVariable
in interfaceIDatabaseAdapter
- Overrides:
dropVariable
in classCommonDatabaseAdapter
-
createOrReplaceFunction
public void createOrReplaceFunction(java.lang.String schemaName, java.lang.String functionName, java.util.function.Supplier<java.lang.String> supplier)
Description copied from interface:IDatabaseAdapter
creates or replaces the SQL function- Specified by:
createOrReplaceFunction
in interfaceIDatabaseAdapter
- Overrides:
createOrReplaceFunction
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:
-
dropForeignKey
public void dropForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)
Description copied from interface:IDatabaseAdapter
Drop the FK on the table with the given constraint name- Specified by:
dropForeignKey
in interfaceIDatabaseAdapter
- Overrides:
dropForeignKey
in classCommonDatabaseAdapter
-
dropTable
public void dropTable(java.lang.String schemaName, java.lang.String tableName)
Description copied from interface:IDatabaseAdapter
Drop table from the schema- Specified by:
dropTable
in interfaceIDatabaseAdapter
- Overrides:
dropTable
in classCommonDatabaseAdapter
-
dropView
public void dropView(java.lang.String schemaName, java.lang.String viewName)
Description copied from interface:IDatabaseAdapter
Drop the view from the database- Specified by:
dropView
in interfaceIDatabaseAdapter
- Overrides:
dropView
in classCommonDatabaseAdapter
-
dropIndex
public void dropIndex(java.lang.String schemaName, java.lang.String indexName)
Description copied from interface:IDatabaseAdapter
Drop the named index- Specified by:
dropIndex
in interfaceIDatabaseAdapter
- Overrides:
dropIndex
in classCommonDatabaseAdapter
-
grantSchemaUsage
public void grantSchemaUsage(java.lang.String schemaName, java.lang.String grantToUser)
Description copied from interface:IDatabaseAdapter
Grants USAGE on the given schemaName to the given user- Specified by:
grantSchemaUsage
in interfaceIDatabaseAdapter
- Overrides:
grantSchemaUsage
in classCommonDatabaseAdapter
-
grantAllSequenceUsage
public void grantAllSequenceUsage(java.lang.String schemaName, java.lang.String grantToUser)
Description copied from interface:IDatabaseAdapter
Grant access to all sequences in the named schema- Specified by:
grantAllSequenceUsage
in interfaceIDatabaseAdapter
- Overrides:
grantAllSequenceUsage
in classCommonDatabaseAdapter
-
-