Class StatementUtils

java.lang.Object
org.pgcodekeeper.core.schema.StatementUtils

public final class StatementUtils extends Object
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 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, c1

      Column c1 was moved to last index and method will return true Example:

      original columns : c1, c2, c3
      new columns : c2, c3, c4

      Column c1 was deleted and column c4 was added. Method will return false. Example:

      original columns : c1, c2, c3
      new columns : c1, c4, c2, c3

      Column 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, c3

      Some 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 columns
      oldColumns - old columns
      Returns:
      true if order was changed or order is ignored
      Since:
      5.1.7
    • appendCols

      public static void appendCols(StringBuilder sbSQL, Collection<String> cols, DatabaseType dbType)
      Appends column names to a StringBuilder with proper quoting for the database type.
      Parameters:
      sbSQL - the StringBuilder to append to
      cols - the collection of column names
      dbType - 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 to
      options - the map of options to append
      dbType - 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 to
      collection - the collection of strings to append
      delimiter - the delimiter to use between elements
      needParens - 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/option
      dbType - the DatabaseType variable in package schema what's need us for correct delimiter, because in postgres and microsoft server is different
    • getFullBareName

      public static String getFullBareName(PgStatement st)
      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")