Class Table.Builder
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.model.VersionedSchemaObject
-
- org.linuxforhealth.fhir.database.utils.model.Table.Builder
-
- Enclosing class:
- Table
public static class Table.Builder extends VersionedSchemaObject
Builder for table
-
-
Field Summary
-
Fields inherited from class org.linuxforhealth.fhir.database.utils.model.VersionedSchemaObject
migrations, version
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Table.Builder
addBigIntColumn(java.lang.String columnName, boolean nullable)
Table.Builder
addBigIntColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultValue)
Table.Builder
addBlobColumn(java.lang.String columnName, long size, int inlineSize, boolean nullable)
Table.Builder
addCharColumn(java.lang.String columnName, int size, boolean nullable)
Add char (fixed-width) columnTable.Builder
addCharColumn(java.lang.String columnName, int size, boolean nullable, java.lang.String defaultValue)
Add char (fixed-width) column with a default value specifiedTable.Builder
addCheckConstraint(java.lang.String constraintName, java.lang.String constraintExpression)
Table.Builder
addClobColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultVal)
Table.Builder
addDoubleColumn(java.lang.String columnName, boolean nullable)
Table.Builder
addForeignKeyConstraint(java.lang.String constraintName, boolean enforced, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String... columns)
Add a foreign key constraint pointing to the target table.Table.Builder
addForeignKeyConstraint(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String... columns)
Add a foreign key constraint pointing to the target table (with enforcement).Table.Builder
addForeignKeyConstraintAltTarget(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.lang.String... columns)
Adds a foreign key constraint relationship on itself.Table.Builder
addForeignKeyConstraintSelf(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.lang.String... columns)
Adds a foreign key constraint relationship on itself.Table.Builder
addIndex(java.lang.String indexName, java.lang.String... columns)
Add an index to the table using the list of column namesTable.Builder
addIndex(java.lang.String indexName, OrderedColumnDef... columns)
Table.Builder
addIntColumn(java.lang.String columnName, boolean nullable)
Table.Builder
addMigration(Migration... migration)
Add migration steps to perform to upgrade from previous versions of this objectTable.Builder
addPrimaryKey(java.lang.String constraintName, java.lang.String... columns)
Add a primary key constraint to the tableTable.Builder
addPrivilege(java.lang.String groupName, Privilege p)
Table.Builder
addPrivileges(java.util.Collection<GroupPrivilege> gps)
Add the collection of group privileges to this tableTable.Builder
addSmallIntBooleanColumn(java.lang.String columnName, java.lang.Integer defaultValue, boolean nullable)
Variant used by JavaBatch which is BOOLEAN in PostgreSQL but SMALLINT elsewhereTable.Builder
addSmallIntColumn(java.lang.String columnName, java.lang.Integer defaultValue, boolean nullable)
Table.Builder
addTag(java.lang.String tagName, java.lang.String tagValue)
Table.Builder
addTimestampColumn(java.lang.String columnName, boolean nullable)
Table.Builder
addTimestampColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultValue)
Table.Builder
addTimestampColumn(java.lang.String columnName, int numberOfFractionalSecondDigits, boolean nullable)
Table.Builder
addUniqueConstraint(java.lang.String constraintName, java.lang.String... columnName)
Add a unique constraint to the table/columnTable.Builder
addUniqueIndex(java.lang.String indexName, java.lang.String... columns)
Add a unique index to the table using the list of column namesTable.Builder
addUniqueIndex(java.lang.String indexName, java.util.Collection<java.lang.String> indexColumns, java.util.Collection<java.lang.String> includeColumns)
Add a unique index with include columnsTable.Builder
addVarbinaryColumn(java.lang.String columnName, int size, boolean nullable)
Add a VARBINARY(nn) columnTable.Builder
addVarcharColumn(java.lang.String columnName, int size, boolean nullable)
Table.Builder
addWiths(java.util.List<With> withs)
adds with parameters (key-values) to the table definition.Table
build(IDataModel dataModel)
Build the immutable table object based on the current configurationprotected java.util.List<ColumnBase>
buildColumns()
Create the columns for the table based on the definitions that have been addedprotected void
checkColumns(java.lang.String[] columns)
Check each of the columns in the given array are valid column namesprotected void
checkColumns(java.util.Collection<java.lang.String> columns)
Check each of the columns in the given array are valid column namesTable.Builder
setCreate(boolean flag)
Setter for the create flagTable.Builder
setDistributionColumnName(java.lang.String columnName)
Setter for the distributionColumnName valueTable.Builder
setDistributionType(DistributionType dt)
Setter for the distributionTypeTable.Builder
setIdentityColumn(java.lang.String columnName, Generated generated)
Set one of the columns to be the identity column for the tableTable.Builder
setTablespace(Tablespace ts)
Setter for the tablespaceTable.Builder
setVersion(int v)
Set the version-
Methods inherited from class org.linuxforhealth.fhir.database.utils.model.VersionedSchemaObject
getObjectName, getQualifiedName, getSchemaName, getVersion, setVersionValue
-
-
-
-
Method Detail
-
setVersion
public Table.Builder setVersion(int v)
Set the version- Parameters:
v
-- Returns:
-
setTablespace
public Table.Builder setTablespace(Tablespace ts)
Setter for the tablespace- Parameters:
ts
-- Returns:
-
setCreate
public Table.Builder setCreate(boolean flag)
Setter for the create flag- Parameters:
flag
- true is the default for new tables; set to false to avoid creating this table- Returns:
-
setDistributionType
public Table.Builder setDistributionType(DistributionType dt)
Setter for the distributionType- Parameters:
cn
-- Returns:
-
setDistributionColumnName
public Table.Builder setDistributionColumnName(java.lang.String columnName)
Setter for the distributionColumnName value- Parameters:
columnName
-- Returns:
-
addIntColumn
public Table.Builder addIntColumn(java.lang.String columnName, boolean nullable)
-
addSmallIntColumn
public Table.Builder addSmallIntColumn(java.lang.String columnName, java.lang.Integer defaultValue, boolean nullable)
-
addSmallIntBooleanColumn
public Table.Builder addSmallIntBooleanColumn(java.lang.String columnName, java.lang.Integer defaultValue, boolean nullable)
Variant used by JavaBatch which is BOOLEAN in PostgreSQL but SMALLINT elsewhere- Parameters:
columnName
-defaultValue
-nullable
-- Returns:
-
addBigIntColumn
public Table.Builder addBigIntColumn(java.lang.String columnName, boolean nullable)
-
addBigIntColumn
public Table.Builder addBigIntColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultValue)
-
addDoubleColumn
public Table.Builder addDoubleColumn(java.lang.String columnName, boolean nullable)
-
addTimestampColumn
public Table.Builder addTimestampColumn(java.lang.String columnName, boolean nullable)
-
addTimestampColumn
public Table.Builder addTimestampColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultValue)
-
addTimestampColumn
public Table.Builder addTimestampColumn(java.lang.String columnName, int numberOfFractionalSecondDigits, boolean nullable)
-
addVarcharColumn
public Table.Builder addVarcharColumn(java.lang.String columnName, int size, boolean nullable)
-
addVarbinaryColumn
public Table.Builder addVarbinaryColumn(java.lang.String columnName, int size, boolean nullable)
Add a VARBINARY(nn) column- Parameters:
columnName
-size
-nullable
-- Returns:
-
addCharColumn
public Table.Builder addCharColumn(java.lang.String columnName, int size, boolean nullable)
Add char (fixed-width) column- Parameters:
columnName
-size
-nullable
-- Returns:
-
addCharColumn
public Table.Builder addCharColumn(java.lang.String columnName, int size, boolean nullable, java.lang.String defaultValue)
Add char (fixed-width) column with a default value specified- Parameters:
columnName
-size
-nullable
-defaultValue
-- Returns:
-
addBlobColumn
public Table.Builder addBlobColumn(java.lang.String columnName, long size, int inlineSize, boolean nullable)
-
addClobColumn
public Table.Builder addClobColumn(java.lang.String columnName, boolean nullable, java.lang.String defaultVal)
- Parameters:
columnName
-nullable
-defaultVal
- this value is auto-quoted; do not pass the single-quote (') within the string value- Returns:
-
setIdentityColumn
public Table.Builder setIdentityColumn(java.lang.String columnName, Generated generated)
Set one of the columns to be the identity column for the table- Parameters:
constraintName
-columns
-- Returns:
-
addPrimaryKey
public Table.Builder addPrimaryKey(java.lang.String constraintName, java.lang.String... columns)
Add a primary key constraint to the table- Parameters:
constraintName
-columns
-- Returns:
-
addIndex
public Table.Builder addIndex(java.lang.String indexName, java.lang.String... columns)
Add an index to the table using the list of column names- Parameters:
indexName
-columns
-- Returns:
-
addIndex
public Table.Builder addIndex(java.lang.String indexName, OrderedColumnDef... columns)
-
addUniqueIndex
public Table.Builder addUniqueIndex(java.lang.String indexName, java.lang.String... columns)
Add a unique index to the table using the list of column names- Parameters:
indexName
-columns
-- Returns:
-
addUniqueIndex
public Table.Builder addUniqueIndex(java.lang.String indexName, java.util.Collection<java.lang.String> indexColumns, java.util.Collection<java.lang.String> includeColumns)
Add a unique index with include columns- Parameters:
indexName
-indexColumns
-includeColumns
-- Returns:
-
addUniqueConstraint
public Table.Builder addUniqueConstraint(java.lang.String constraintName, java.lang.String... columnName)
Add a unique constraint to the table/column- Parameters:
constraintName
-columnName
- - at least one column- Returns:
-
addCheckConstraint
public Table.Builder addCheckConstraint(java.lang.String constraintName, java.lang.String constraintExpression)
-
addForeignKeyConstraint
public Table.Builder addForeignKeyConstraint(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String... columns)
Add a foreign key constraint pointing to the target table (with enforcement). The list of columns is expected to match the primary key definition on the target.- Parameters:
constraintName
-targetSchema
-targetTable
-columns
-- Returns:
-
addForeignKeyConstraint
public Table.Builder addForeignKeyConstraint(java.lang.String constraintName, boolean enforced, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String... columns)
Add a foreign key constraint pointing to the target table. The list of columns is expected to match the primary key definition on the target- Parameters:
constraintName
-enforced
-targetSchema
-targetTable
-columns
-- Returns:
-
addForeignKeyConstraintSelf
public Table.Builder addForeignKeyConstraintSelf(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.lang.String... columns)
Adds a foreign key constraint relationship on itself. This is intentionally created as a separate method, so there are no mistakes.- Parameters:
constraintName
-targetSchema
-targetTable
-targetColumnName
-columns
-- Returns:
-
addForeignKeyConstraintAltTarget
public Table.Builder addForeignKeyConstraintAltTarget(java.lang.String constraintName, java.lang.String targetSchema, java.lang.String targetTable, java.lang.String targetColumnName, java.lang.String... columns)
Adds a foreign key constraint relationship on itself. This is intentionally created as a separate method, so there are no mistakes.- Parameters:
constraintName
-targetSchema
-targetTable
-targetColumnName
-columns
-- Returns:
-
checkColumns
protected void checkColumns(java.lang.String[] columns)
Check each of the columns in the given array are valid column names- Parameters:
columns
-
-
checkColumns
protected void checkColumns(java.util.Collection<java.lang.String> columns)
Check each of the columns in the given array are valid column names- Parameters:
columns
-
-
build
public Table build(IDataModel dataModel)
Build the immutable table object based on the current configuration- Parameters:
dataModel
-- Returns:
-
buildColumns
protected java.util.List<ColumnBase> buildColumns()
Create the columns for the table based on the definitions that have been added- Returns:
-
addTag
public Table.Builder addTag(java.lang.String tagName, java.lang.String tagValue)
- Parameters:
tagName
-tagValue
-- Returns:
-
addPrivilege
public Table.Builder addPrivilege(java.lang.String groupName, Privilege p)
-
addPrivileges
public Table.Builder addPrivileges(java.util.Collection<GroupPrivilege> gps)
Add the collection of group privileges to this table- Parameters:
gps
-- Returns:
-
addMigration
public Table.Builder addMigration(Migration... migration)
Description copied from class:VersionedSchemaObject
Add migration steps to perform to upgrade from previous versions of this object- Overrides:
addMigration
in classVersionedSchemaObject
- Returns:
-
addWiths
public Table.Builder addWiths(java.util.List<With> withs)
adds with parameters (key-values) to the table definition.- Parameters:
withs
-
-
-