Class SqlFormatUtils

java.lang.Object
de.calamanari.adl.sql.SqlFormatUtils

public class SqlFormatUtils extends Object
Some additional utilities for formatting SQL
Author:
Karl Eilebrecht
  • Method Details

    • appendSpacedIf

      public static void appendSpacedIf(StringBuilder sb, boolean condition, String... values)
      Same as FormatUtils.appendSpaced(StringBuilder, String...) but only if the condition is true
      Parameters:
      sb -
      condition - only append if the condition is true
      values - to append surrounded by space
      See Also:
      • FormatUtils.space(StringBuilder)
    • endsWithOpenBraceOrAllWhitespace

      public static boolean endsWithOpenBraceOrAllWhitespace(StringBuilder sb)
      Tells whether ...
      • sb is empty
      • sb only consist of whitespace
      • sb ends with an opening brace ([whitespace]
      Parameters:
      sb -
      Returns:
      true if the string ends with an opening brace optionally followed by whitespace or only consists of whitespace/empty
    • appendOrderBy

      public static void appendOrderBy(StringBuilder sb, String columnName, de.calamanari.adl.FormatStyle style, int level)
      Appends the order-by in a formatted way
      Parameters:
      sb - for appending
      columnName - the order-by sql column
      style -
      level -
    • appendQualifiedColumnName

      public static void appendQualifiedColumnName(StringBuilder sb, String alias, String columnName)
      Appends the column name qualified by the given alias to the builder.

      Example: columnName=C71, alias=TABLE3 => TABLE3.C71

      Parameters:
      sb -
      alias -
      columnName -
    • appendIsNullInversion

      public static void appendIsNullInversion(StringBuilder sb, boolean negation)
      Appends the inversion of an IS (NOT) NULL check.

      This is sometimes required when we cannot query IS NULL at all. E.g., in a table there might be a column A that always has a value for any given row in that table. There could even be a NOT-NULL SQL-constraint, and we can still not query A IS NULL because that table is only a lookup table and does not contain all IDs.

      This requires a different query approach which instead queries all rows that are NOT NULL to immediately disqualify them.

      Summary: this method turns an IS NULL into an IS NOT NULL and vice-versa.

      • negation == true -> IS NULL
      • negation == false -> IS NOT NULL
      Parameters:
      sb -
      negation - if true output IS NULL, otherwise output IS NOT NULL