Class PlainSchemaAdapter
- java.lang.Object
 - 
- org.linuxforhealth.fhir.database.utils.common.PlainSchemaAdapter
 
 
- 
- All Implemented Interfaces:
 ISchemaAdapter
- Direct Known Subclasses:
 DistributedSchemaAdapter,FhirSchemaAdapter
public class PlainSchemaAdapter extends java.lang.Object implements ISchemaAdapter
Adapter to build the plain version of the FHIR schema. Uses the IDatabaseAdapter to hide the specifics of a particular database flavor (like PostgreSQL, Derby etc). 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected IDatabaseAdapterdatabaseAdapter 
- 
Constructor Summary
Constructors Constructor Description PlainSchemaAdapter(IDatabaseAdapter databaseAdapter)Public constructor 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalterSequenceRestartWith(java.lang.String schemaName, java.lang.String sequenceName, long restartWith, int cache, int incrementBy)Sets/resets the sequence to start with the given value.voidalterTableAddColumn(java.lang.String schemaName, java.lang.String tableName, ColumnBase column)Add a new column to an existing tablevoidalterTableColumnIdentityCache(java.lang.String schemaName, java.lang.String objectName, java.lang.String columnName, int cache)Change the CACHE value of the named identity generated always columnvoidapplyDistributionRules(java.lang.String schemaName, java.lang.String tableName, DistributionType distributionType, java.lang.String distributionColumnName)Apply any distribution rules configured for the named tablebooleancheckCompatibility(java.lang.String adminSchema)checks connectivity to the database and that it is compatiblevoidcreateForeignKeyConstraint(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, DistributionType distributionType, boolean targetIsReference)voidcreateIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionType distributionType)Create an index on the named schema.table objectvoidcreateOrReplaceFunction(java.lang.String schemaName, java.lang.String objectName, java.util.function.Supplier<java.lang.String> supplier)creates or replaces the SQL functionvoidcreateOrReplaceProcedure(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 suppliervoidcreateOrReplaceView(java.lang.String schemaName, java.lang.String objectName, java.lang.String selectClause)Create or replace the viewvoidcreateSchema(java.lang.String schemaName)Create a database schemavoidcreateSequence(java.lang.String schemaName, java.lang.String sequenceName, long startWith, int cache, int incrementBy)voidcreateTable(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, DistributionType distributionType, java.lang.String distributionColumnName)Build the create table DDLvoidcreateTablespace(java.lang.String tablespaceName)Create a new tablespace with the given namevoidcreateTablespace(java.lang.String tablespaceName, int extentSizeKB)Create a new tablespace using the given extent sizevoidcreateUniqueConstraint(java.lang.String constraintName, java.util.List<java.lang.String> columns, java.lang.String schemaName, java.lang.String name)create a unique constraint on a table.voidcreateUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, java.util.List<java.lang.String> includeColumns, DistributionType distributionType, java.lang.String distributionColumnName)Create a unique indexvoidcreateUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionType distributionType, java.lang.String distributionColumnName)Create a unique indexvoidcreateView(java.lang.String schemaName, java.lang.String objectName, java.lang.String selectClause)Create the view as defined by the selectClausevoiddisableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Disable the FK with the given constraint namevoiddistributeFunction(java.lang.String schemaName, java.lang.String functionName, int distributeByParamNumber)For Citus, functions can be distributed by one of their parameters (typically the first)booleandoesForeignKeyConstraintExist(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Check to see if the named foreign key constraint already existsbooleandoesTableExist(java.lang.String schemaName, java.lang.String objectName)Check if the table currently existsvoiddropForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Drop the FK on the table with the given constraint namevoiddropFunction(java.lang.String schemaName, java.lang.String functionName)drops a given functionvoiddropIndex(java.lang.String schemaName, java.lang.String indexName)Drop the named indexvoiddropProcedure(java.lang.String schemaName, java.lang.String procedureName)Drop the given procedurevoiddropSequence(java.lang.String schemaName, java.lang.String sequenceName)voiddropTable(java.lang.String schemaName, java.lang.String name)Drop table from the schemavoiddropTablespace(java.lang.String tablespaceName)Drop an existing tablespace, including all of its contentsvoiddropView(java.lang.String schemaName, java.lang.String objectName)Drop the view from the databasevoidenableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Enable the FK with the given constraint namevoidgrantAllSequenceUsage(java.lang.String schemaName, java.lang.String grantToUser)Grant access to all sequences in the named schemavoidgrantFunctionPrivileges(java.lang.String schemaName, java.lang.String functionName, java.util.Collection<Privilege> privileges, java.lang.String toUser)grants permissions on a given functionvoidgrantObjectPrivileges(java.lang.String schemaName, java.lang.String tableName, java.util.Collection<Privilege> privileges, java.lang.String toUser)Grant the list of privileges on the named object to the user.voidgrantProcedurePrivileges(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 uservoidgrantSchemaUsage(java.lang.String schemaName, java.lang.String grantToUser)Grants USAGE on the given schemaName to the given uservoidgrantSequencePrivileges(java.lang.String schemaName, java.lang.String objectName, java.util.Collection<Privilege> group, java.lang.String toUser)Grant the collection of privileges on the named variable to the uservoidgrantVariablePrivileges(java.lang.String schemaName, java.lang.String variableName, java.util.Collection<Privilege> privileges, java.lang.String toUser)Grant the collection of privileges on the named variable to the userjava.util.List<SchemaInfoObject>listSchemaObjects(java.lang.String schemaName)List the objects present in the given schemavoidrunStatement(IDatabaseStatement statement)Run the given statement against the database represented by this adaptervoidsetIntegrityOff(java.lang.String schemaName, java.lang.String tableName)voidsetIntegrityUnchecked(java.lang.String schemaName, java.lang.String tableName) 
 - 
 
- 
- 
Field Detail
- 
databaseAdapter
protected final IDatabaseAdapter databaseAdapter
 
 - 
 
- 
Constructor Detail
- 
PlainSchemaAdapter
public PlainSchemaAdapter(IDatabaseAdapter databaseAdapter)
Public constructor- Parameters:
 databaseAdapter-
 
 - 
 
- 
Method Detail
- 
createTablespace
public void createTablespace(java.lang.String tablespaceName)
Description copied from interface:ISchemaAdapterCreate a new tablespace with the given name- Specified by:
 createTablespacein interfaceISchemaAdapter
 
- 
createTablespace
public void createTablespace(java.lang.String tablespaceName, int extentSizeKB)Description copied from interface:ISchemaAdapterCreate a new tablespace using the given extent size- Specified by:
 createTablespacein interfaceISchemaAdapter
 
- 
dropTablespace
public void dropTablespace(java.lang.String tablespaceName)
Description copied from interface:ISchemaAdapterDrop an existing tablespace, including all of its contents- Specified by:
 dropTablespacein interfaceISchemaAdapter
 
- 
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, DistributionType distributionType, java.lang.String distributionColumnName)Description copied from interface:ISchemaAdapterBuild the create table DDL- Specified by:
 createTablein interfaceISchemaAdapter
 
- 
applyDistributionRules
public void applyDistributionRules(java.lang.String schemaName, java.lang.String tableName, DistributionType distributionType, java.lang.String distributionColumnName)Description copied from interface:ISchemaAdapterApply any distribution rules configured for the named table- Specified by:
 applyDistributionRulesin interfaceISchemaAdapter
 
- 
alterTableAddColumn
public void alterTableAddColumn(java.lang.String schemaName, java.lang.String tableName, ColumnBase column)Description copied from interface:ISchemaAdapterAdd a new column to an existing table- Specified by:
 alterTableAddColumnin interfaceISchemaAdapter
 
- 
createOrReplaceProcedure
public void createOrReplaceProcedure(java.lang.String schemaName, java.lang.String procedureName, java.util.function.Supplier<java.lang.String> supplier)Description copied from interface:ISchemaAdapterCreate the stored procedure using the DDL text provided by the supplier- Specified by:
 createOrReplaceProcedurein interfaceISchemaAdapter
 
- 
dropProcedure
public void dropProcedure(java.lang.String schemaName, java.lang.String procedureName)Description copied from interface:ISchemaAdapterDrop the given procedure- Specified by:
 dropProcedurein interfaceISchemaAdapter
 
- 
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, DistributionType distributionType, java.lang.String distributionColumnName)Description copied from interface:ISchemaAdapterCreate a unique index- Specified by:
 createUniqueIndexin interfaceISchemaAdapter
 
- 
createUniqueIndex
public void createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionType distributionType, java.lang.String distributionColumnName)Description copied from interface:ISchemaAdapterCreate a unique index- Specified by:
 createUniqueIndexin interfaceISchemaAdapter
 
- 
createIndex
public void createIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, DistributionType distributionType)Description copied from interface:ISchemaAdapterCreate an index on the named schema.table object- Specified by:
 createIndexin interfaceISchemaAdapter
 
- 
dropTable
public void dropTable(java.lang.String schemaName, java.lang.String name)Description copied from interface:ISchemaAdapterDrop table from the schema- Specified by:
 dropTablein interfaceISchemaAdapter
 
- 
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, DistributionType distributionType, boolean targetIsReference)- Specified by:
 createForeignKeyConstraintin interfaceISchemaAdapterdistributionType- distribution type of the source table
 
- 
createSequence
public void createSequence(java.lang.String schemaName, java.lang.String sequenceName, long startWith, int cache, int incrementBy)- Specified by:
 createSequencein interfaceISchemaAdapterstartWith- the START WITH value for the sequencecache- the sequence CACHE value
 
- 
dropSequence
public void dropSequence(java.lang.String schemaName, java.lang.String sequenceName)- Specified by:
 dropSequencein interfaceISchemaAdapter
 
- 
alterSequenceRestartWith
public void alterSequenceRestartWith(java.lang.String schemaName, java.lang.String sequenceName, long restartWith, int cache, int incrementBy)Description copied from interface:ISchemaAdapterSets/resets the sequence to start with the given value.- Specified by:
 alterSequenceRestartWithin interfaceISchemaAdapter
 
- 
grantObjectPrivileges
public void grantObjectPrivileges(java.lang.String schemaName, java.lang.String tableName, java.util.Collection<Privilege> privileges, java.lang.String toUser)Description copied from interface:ISchemaAdapterGrant the list of privileges on the named object to the user. This is a general purpose method which can be used to specify privileges for any object type which doesn't need the object type to be specified in the grant DDL.- Specified by:
 grantObjectPrivilegesin interfaceISchemaAdapter
 
- 
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:ISchemaAdapterGrant the collection of privileges on the named procedure to the user- Specified by:
 grantProcedurePrivilegesin interfaceISchemaAdapter
 
- 
grantVariablePrivileges
public void grantVariablePrivileges(java.lang.String schemaName, java.lang.String variableName, java.util.Collection<Privilege> privileges, java.lang.String toUser)Description copied from interface:ISchemaAdapterGrant the collection of privileges on the named variable to the user- Specified by:
 grantVariablePrivilegesin interfaceISchemaAdapter
 
- 
grantSequencePrivileges
public void grantSequencePrivileges(java.lang.String schemaName, java.lang.String objectName, java.util.Collection<Privilege> group, java.lang.String toUser)Description copied from interface:ISchemaAdapterGrant the collection of privileges on the named variable to the user- Specified by:
 grantSequencePrivilegesin interfaceISchemaAdapter
 
- 
grantSchemaUsage
public void grantSchemaUsage(java.lang.String schemaName, java.lang.String grantToUser)Description copied from interface:ISchemaAdapterGrants USAGE on the given schemaName to the given user- Specified by:
 grantSchemaUsagein interfaceISchemaAdapter
 
- 
grantAllSequenceUsage
public void grantAllSequenceUsage(java.lang.String schemaName, java.lang.String grantToUser)Description copied from interface:ISchemaAdapterGrant access to all sequences in the named schema- Specified by:
 grantAllSequenceUsagein interfaceISchemaAdapter
 
- 
doesTableExist
public boolean doesTableExist(java.lang.String schemaName, java.lang.String objectName)Description copied from interface:ISchemaAdapterCheck if the table currently exists- Specified by:
 doesTableExistin interfaceISchemaAdapter- Returns:
 
 
- 
createSchema
public void createSchema(java.lang.String schemaName)
Description copied from interface:ISchemaAdapterCreate a database schema- Specified by:
 createSchemain interfaceISchemaAdapter
 
- 
createUniqueConstraint
public void createUniqueConstraint(java.lang.String constraintName, java.util.List<java.lang.String> columns, java.lang.String schemaName, java.lang.String name)Description copied from interface:ISchemaAdaptercreate a unique constraint on a table.- Specified by:
 createUniqueConstraintin interfaceISchemaAdapter
 
- 
checkCompatibility
public boolean checkCompatibility(java.lang.String adminSchema)
Description copied from interface:ISchemaAdapterchecks connectivity to the database and that it is compatible- Specified by:
 checkCompatibilityin interfaceISchemaAdapter- Returns:
 
 
- 
createOrReplaceFunction
public void createOrReplaceFunction(java.lang.String schemaName, java.lang.String objectName, java.util.function.Supplier<java.lang.String> supplier)Description copied from interface:ISchemaAdaptercreates or replaces the SQL function- Specified by:
 createOrReplaceFunctionin interfaceISchemaAdapter
 
- 
distributeFunction
public void distributeFunction(java.lang.String schemaName, java.lang.String functionName, int distributeByParamNumber)Description copied from interface:ISchemaAdapterFor Citus, functions can be distributed by one of their parameters (typically the first)- Specified by:
 distributeFunctionin interfaceISchemaAdapter
 
- 
dropFunction
public void dropFunction(java.lang.String schemaName, java.lang.String functionName)Description copied from interface:ISchemaAdapterdrops a given function- Specified by:
 dropFunctionin interfaceISchemaAdapter
 
- 
grantFunctionPrivileges
public void grantFunctionPrivileges(java.lang.String schemaName, java.lang.String functionName, java.util.Collection<Privilege> privileges, java.lang.String toUser)Description copied from interface:ISchemaAdaptergrants permissions on a given function- Specified by:
 grantFunctionPrivilegesin interfaceISchemaAdapter
 
- 
disableForeignKey
public void disableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Description copied from interface:ISchemaAdapterDisable the FK with the given constraint name- Specified by:
 disableForeignKeyin interfaceISchemaAdapter
 
- 
dropForeignKey
public void dropForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Description copied from interface:ISchemaAdapterDrop the FK on the table with the given constraint name- Specified by:
 dropForeignKeyin interfaceISchemaAdapter
 
- 
enableForeignKey
public void enableForeignKey(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Description copied from interface:ISchemaAdapterEnable the FK with the given constraint name- Specified by:
 enableForeignKeyin interfaceISchemaAdapter
 
- 
doesForeignKeyConstraintExist
public boolean doesForeignKeyConstraintExist(java.lang.String schemaName, java.lang.String tableName, java.lang.String constraintName)Description copied from interface:ISchemaAdapterCheck to see if the named foreign key constraint already exists- Specified by:
 doesForeignKeyConstraintExistin interfaceISchemaAdapter- Returns:
 
 
- 
setIntegrityOff
public void setIntegrityOff(java.lang.String schemaName, java.lang.String tableName)- Specified by:
 setIntegrityOffin interfaceISchemaAdapter
 
- 
setIntegrityUnchecked
public void setIntegrityUnchecked(java.lang.String schemaName, java.lang.String tableName)- Specified by:
 setIntegrityUncheckedin interfaceISchemaAdapter
 
- 
alterTableColumnIdentityCache
public void alterTableColumnIdentityCache(java.lang.String schemaName, java.lang.String objectName, java.lang.String columnName, int cache)Description copied from interface:ISchemaAdapterChange the CACHE value of the named identity generated always column- Specified by:
 alterTableColumnIdentityCachein interfaceISchemaAdapter
 
- 
dropIndex
public void dropIndex(java.lang.String schemaName, java.lang.String indexName)Description copied from interface:ISchemaAdapterDrop the named index- Specified by:
 dropIndexin interfaceISchemaAdapter
 
- 
createView
public void createView(java.lang.String schemaName, java.lang.String objectName, java.lang.String selectClause)Description copied from interface:ISchemaAdapterCreate the view as defined by the selectClause- Specified by:
 createViewin interfaceISchemaAdapter
 
- 
dropView
public void dropView(java.lang.String schemaName, java.lang.String objectName)Description copied from interface:ISchemaAdapterDrop the view from the database- Specified by:
 dropViewin interfaceISchemaAdapter
 
- 
createOrReplaceView
public void createOrReplaceView(java.lang.String schemaName, java.lang.String objectName, java.lang.String selectClause)Description copied from interface:ISchemaAdapterCreate or replace the view- Specified by:
 createOrReplaceViewin interfaceISchemaAdapter
 
- 
listSchemaObjects
public java.util.List<SchemaInfoObject> listSchemaObjects(java.lang.String schemaName)
Description copied from interface:ISchemaAdapterList the objects present in the given schema- Specified by:
 listSchemaObjectsin interfaceISchemaAdapter- Returns:
 
 
- 
runStatement
public void runStatement(IDatabaseStatement statement)
Description copied from interface:ISchemaAdapterRun the given statement against the database represented by this adapter- Specified by:
 runStatementin interfaceISchemaAdapter
 
 - 
 
 -