Class DataDefinitionUtil
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.common.DataDefinitionUtil
-
public class DataDefinitionUtil extends java.lang.Object
Handles common syntax for generating DDL
-
-
Constructor Summary
Constructors Constructor Description DataDefinitionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertSecure(java.lang.String value)
Make sure this statement fragment does not contain anything which could be used as part of a SQL injection attack.static java.lang.String
assertValidName(java.lang.String name)
Make sure that the given name is valid for use in database statementsstatic void
assertValidNames(java.lang.String... names)
Assert each of the given names in the list (array) is validstatic java.lang.String
columnSpecList(IDatabaseTypeAdapter adapter, java.util.Collection<ColumnBase> columns)
static java.lang.String
createIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
Create the DDL for a plain old indexstatic java.lang.String
createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
static java.lang.String
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, boolean isUseSchemaPrefix)
static java.lang.String
getQualifiedName(java.lang.String schemaName, java.lang.String objectName)
Return the fully qualified name in the form "SCHEMA.OBJECT" Validates that both schema and object names are validstatic boolean
isValidName(java.lang.String name)
Although the variables used to build various DDL/DML statements are all sourced internally within the program, we still check that the strings are safe, just to add that extra layer of protectionstatic java.lang.String
join(java.lang.String... things)
Create a comma-separated list of the given stringsstatic java.lang.String
join(java.util.Collection<java.lang.String> things)
Create a comma-separated list of the items in the collectionstatic java.lang.String
joinOrderedColumnDefs(java.util.Collection<OrderedColumnDef> things)
Join the ordered column definitions
-
-
-
Method Detail
-
createUniqueIndex
public static java.lang.String 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, boolean isUseSchemaPrefix)
- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-includeColumns
-- Returns:
-
createUniqueIndex
public static java.lang.String createUniqueIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-isUseSchemaPrefix
-- Returns:
-
createIndex
public static java.lang.String createIndex(java.lang.String schemaName, java.lang.String tableName, java.lang.String indexName, java.util.List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
Create the DDL for a plain old index- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-isUseSchemaPrefix
-- Returns:
-
join
public static java.lang.String join(java.util.Collection<java.lang.String> things)
Create a comma-separated list of the items in the collection- Parameters:
things
-- Returns:
-
joinOrderedColumnDefs
public static java.lang.String joinOrderedColumnDefs(java.util.Collection<OrderedColumnDef> things)
Join the ordered column definitions- Parameters:
things
-- Returns:
-
join
public static java.lang.String join(java.lang.String... things)
Create a comma-separated list of the given strings- Parameters:
things
-- Returns:
-
isValidName
public static boolean isValidName(java.lang.String name)
Although the variables used to build various DDL/DML statements are all sourced internally within the program, we still check that the strings are safe, just to add that extra layer of protection- Parameters:
name
-- Returns:
-
assertValidName
public static java.lang.String assertValidName(java.lang.String name)
Make sure that the given name is valid for use in database statements- Parameters:
name
-- Returns:
- the name confirmed as valid
- Throws:
java.lang.IllegalArgumentException
- if the given name is invalid
-
assertValidNames
public static void assertValidNames(java.lang.String... names)
Assert each of the given names in the list (array) is valid- Parameters:
names
-
-
assertSecure
public static void assertSecure(java.lang.String value)
Make sure this statement fragment does not contain anything which could be used as part of a SQL injection attack. This is used for more complex DDL construction which may require a predicate to be passed as a string as part of a larger CREATE/ALTER statement. Note: none of the input being dealt with here is external input...so it should be safe already.- Parameters:
value
-- Throws:
java.lang.IllegalArgumentException
- if the value contains risky characters
-
getQualifiedName
public static java.lang.String getQualifiedName(java.lang.String schemaName, java.lang.String objectName)
Return the fully qualified name in the form "SCHEMA.OBJECT" Validates that both schema and object names are valid- Parameters:
schemaName
-objectName
-- Returns:
- the fully qualified name
- Throws:
java.lang.IllegalArgumentException
- if either name is not a valid database object name
-
columnSpecList
public static java.lang.String columnSpecList(IDatabaseTypeAdapter adapter, java.util.Collection<ColumnBase> columns)
- Parameters:
adapter
-columns
-- Returns:
-
-