Package de.calamanari.adl.sql
Class SqlFormatUtils
java.lang.Object
de.calamanari.adl.sql.SqlFormatUtils
Some additional utilities for formatting SQL
- Author:
- Karl Eilebrecht
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendIsNullInversion(StringBuilder sb, boolean negation) Appends the inversion of an IS (NOT) NULL check.static voidappendOrderBy(StringBuilder sb, String columnName, de.calamanari.adl.FormatStyle style, int level) Appends the order-by in a formatted waystatic voidappendQualifiedColumnName(StringBuilder sb, String alias, String columnName) Appends the column name qualified by the given alias to the builder.static voidappendSpacedIf(StringBuilder sb, boolean condition, String... values) Same asFormatUtils.appendSpaced(StringBuilder, String...)but only if the condition is truestatic booleanTells whether ...
-
Method Details
-
appendSpacedIf
Same asFormatUtils.appendSpaced(StringBuilder, String...)but only if the condition is true- Parameters:
sb-condition- only append if the condition is truevalues- to append surrounded by space- See Also:
-
endsWithOpenBraceOrAllWhitespace
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 appendingcolumnName- the order-by sql columnstyle-level-
-
appendQualifiedColumnName
Appends the column name qualified by the given alias to the builder.Example: columnName=
C71, alias=TABLE3=>TABLE3.C71- Parameters:
sb-alias-columnName-
-
appendIsNullInversion
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 NULLbecause 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 NULLnegation == false -> IS NOT NULL
- Parameters:
sb-negation- if true output IS NULL, otherwise output IS NOT NULL
-