Class DataDefinitionUtil
- java.lang.Object
-
- com.ibm.fhir.database.utils.common.DataDefinitionUtil
-
public class DataDefinitionUtil extends 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(String value)
Make sure this statement fragment does not contain anything which could be used as part of a SQL injection attack.static String
assertValidName(String name)
Make sure that the given name is valid for use in database statementsstatic void
assertValidNames(String... names)
Assert each of the given names in the list (array) is validstatic String
columnSpecList(IDatabaseTypeAdapter adapter, Collection<ColumnBase> columns)
static String
createIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
Create the DDL for a plain old indexstatic String
createUniqueIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
static String
createUniqueIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, List<String> includeColumns, boolean isUseSchemaPrefix)
static String
getQualifiedName(String schemaName, String objectName)
Return the fully qualified name in the form "SCHEMA.OBJECT" Validates that both schema and object names are validstatic boolean
isValidName(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 String
join(String... things)
Create a comma-separated list of the given stringsstatic String
join(Collection<String> things)
Create a comma-separated list of the items in the collectionstatic String
joinOrderedColumnDefs(Collection<OrderedColumnDef> things)
Join the ordered column definitions
-
-
-
Method Detail
-
createUniqueIndex
public static String createUniqueIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, List<String> includeColumns, boolean isUseSchemaPrefix)
- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-includeColumns
-- Returns:
-
createUniqueIndex
public static String createUniqueIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-isUseSchemaPrefix
-- Returns:
-
createIndex
public static String createIndex(String schemaName, String tableName, String indexName, List<OrderedColumnDef> indexColumns, boolean isUseSchemaPrefix)
Create the DDL for a plain old index- Parameters:
schemaName
-tableName
-indexName
-indexColumns
-isUseSchemaPrefix
-- Returns:
-
join
public static String join(Collection<String> things)
Create a comma-separated list of the items in the collection- Parameters:
things
-- Returns:
-
joinOrderedColumnDefs
public static String joinOrderedColumnDefs(Collection<OrderedColumnDef> things)
Join the ordered column definitions- Parameters:
things
-- Returns:
-
join
public static String join(String... things)
Create a comma-separated list of the given strings- Parameters:
things
-- Returns:
-
isValidName
public static boolean isValidName(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 String assertValidName(String name)
Make sure that the given name is valid for use in database statements- Parameters:
name
-- Returns:
- the name confirmed as valid
- Throws:
IllegalArgumentException
- if the given name is invalid
-
assertValidNames
public static void assertValidNames(String... names)
Assert each of the given names in the list (array) is valid- Parameters:
names
-
-
assertSecure
public static void assertSecure(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:
IllegalArgumentException
- if the value contains risky characters
-
getQualifiedName
public static String getQualifiedName(String schemaName, 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:
IllegalArgumentException
- if either name is not a valid database object name
-
columnSpecList
public static String columnSpecList(IDatabaseTypeAdapter adapter, Collection<ColumnBase> columns)
- Parameters:
adapter
-columns
-- Returns:
-
-