Package org.pgcodekeeper.core.schema
Class StatementUtils
java.lang.Object
org.pgcodekeeper.core.schema.StatementUtils
Utility class providing common functionality for database statement operations.
Contains helper methods for column ordering, SQL generation, and option handling
across different database types.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendCollection(StringBuilder sbSQL, Collection<String> collection, String delimiter, boolean needParens) Appends a collection of strings to a StringBuilder with a specified delimiter.static voidappendCols(StringBuilder sbSQL, Collection<String> cols, DatabaseType dbType) Appends column names to a StringBuilder with proper quoting for the database type.static voidappendOptions(StringBuilder sbSQL, Map<String, String> options, DatabaseType dbType) Appends parameters/options at StringBuilder.static voidappendOptionsWithParen(StringBuilder sbSQL, Map<String, String> options, DatabaseType dbType) Appends options to a StringBuilder enclosed in parentheses.static StringGets the full bare name of a statement by concatenating parent names.static booleanisColumnsOrderChanged(List<AbstractColumn> newColumns, List<AbstractColumn> oldColumns) Checks if the order of the table columns has changed.
-
Method Details
-
isColumnsOrderChanged
public static boolean isColumnsOrderChanged(List<AbstractColumn> newColumns, List<AbstractColumn> oldColumns) Checks if the order of the table columns has changed. Example:original columns : c1, c2, c3
new columns : c2, c3, c1Column c1 was moved to last index and method will return true Example:
original columns : c1, c2, c3
new columns : c2, c3, c4Column c1 was deleted and column c4 was added. Method will return false. Example:
original columns : c1, c2, c3
new columns : c1, c4, c2, c3Column c4 was added between old columns: c1 and c2. Method will return true. Example:
original columns : c2, c3, inherit(some table)
new columns : c1, c2, c3Some table is no longer inherited. If table did not have a column c1, we must return true, but we cannot track this right now. Method will return false.
- Parameters:
newColumns- new columnsoldColumns- old columns- Returns:
- true if order was changed or order is ignored
- Since:
- 5.1.7
-
appendCols
Appends column names to a StringBuilder with proper quoting for the database type.- Parameters:
sbSQL- the StringBuilder to append tocols- the collection of column namesdbType- the database type for proper quoting
-
appendOptionsWithParen
public static void appendOptionsWithParen(StringBuilder sbSQL, Map<String, String> options, DatabaseType dbType) Appends options to a StringBuilder enclosed in parentheses.- Parameters:
sbSQL- the StringBuilder to append tooptions- the map of options to appenddbType- the database type for proper formatting
-
appendCollection
public static void appendCollection(StringBuilder sbSQL, Collection<String> collection, String delimiter, boolean needParens) Appends a collection of strings to a StringBuilder with a specified delimiter.- Parameters:
sbSQL- the StringBuilder to append tocollection- the collection of strings to appenddelimiter- the delimiter to use between elementsneedParens- whether to enclose the result in parentheses
-
appendOptions
public static void appendOptions(StringBuilder sbSQL, Map<String, String> options, DatabaseType dbType) Appends parameters/options at StringBuilder. This StringBuilder used in schema package Constraint's classes in the method getDifinition()- Parameters:
sbSQL- the StringBuilder from method getDifinition()options- the Map<String, String> where key is parameter/option and value is value of this parameter/optiondbType- the DatabaseType variable in package schema what's need us for correct delimiter, because in postgres and microsoft server is different
-
getFullBareName
Gets the full bare name of a statement by concatenating parent names. Returns a dot-delimited path from the top-level container down to the statement, excluding the database level.- Parameters:
st- the statement to get the full bare name for- Returns:
- the full bare name path (e.g., "schema.table.column")
-