Enum Class DefaultSqlFormatter

java.lang.Object
java.lang.Enum<DefaultSqlFormatter>
de.calamanari.adl.sql.DefaultSqlFormatter
All Implemented Interfaces:
de.calamanari.adl.cnv.tps.ArgValueFormatter, Serializable, Comparable<DefaultSqlFormatter>, Constable

public enum DefaultSqlFormatter extends Enum<DefaultSqlFormatter> implements de.calamanari.adl.cnv.tps.ArgValueFormatter
The formatters in this enumeration define the default behavior when formatting values for sql.

Important: These formatters usually only come into play when debugging or logging because regularly all values are passed as parameters of PreparedStatements, so there is no formatting required.

See also remarks at QueryParameterApplicator.applyUnsafe(StringBuilder, QueryParameter, int)

Author:
Karl Eilebrecht
  • Enum Constant Details

  • Method Details

    • values

      public static DefaultSqlFormatter[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DefaultSqlFormatter valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • format

      public String format(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Specified by:
      format in interface de.calamanari.adl.cnv.tps.ArgValueFormatter
    • formatSqlBit

      public static String formatSqlBit(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string as a bit-value (0/1) if it is '0', '1', 'TRUE' or 'FALSE'
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      0 or 1
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - if the input does not match
    • formatSqlBoolean

      public static String formatSqlBoolean(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string as a boolean value (TRUE/FALSE) if it is '0', '1', 'TRUE' or 'FALSE'
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      FALSE or TRUE
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - if the input does not match
    • formatSqlInteger

      public static String formatSqlInteger(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string as integer if it is in 32-bit signed integer range
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      int value as string
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - if the input does not match
    • formatSqlSmallInt

      public static String formatSqlSmallInt(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string as integer if it is in 16-bit signed short range
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      short value as string
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - if the input does not match
    • formatSqlTinyInt

      public static String formatSqlTinyInt(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string as integer if it is in 8-bit unsigned byte range
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      byte value as string (0-255)
      Throws:
      de.calamanari.adl.cnv.tps.AdlFormattingException - if the input does not match
    • formatSqlTimestampPlain

      public static String formatSqlTimestampPlain(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it either matches the format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss and represents a valid UTC-time.

      Note: The compromise to support full time stamps was introduced to avoid confusion when specifying FilterColumns, it should be irrelevant for regular fields (by default Audlang deals with date only).

      This plain format is accepted by SQLite.

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form 'yyyy-MM-dd HH:mm:ss'
    • formatSqlTimestampDefaultStyle

      public static String formatSqlTimestampDefaultStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it either matches the format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss and represents a valid UTC-time.

      This "standard" format works with H2 and PostreSql but for example not with SQLite.

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TIMESTAMP '2024-12-12 00:00:00'
    • formatSqlTimestampOracleStyle

      public static String formatSqlTimestampOracleStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it either matches the format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss and represents a valid UTC-time.

      Should also work for PostgreSQL

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TO_TIMESTAMP('2024-12-12 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
    • formatSqlTimestampMySqlStyle

      public static String formatSqlTimestampMySqlStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it either matches the format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss and represents a valid UTC-time.
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TIMESTAMP('2024-12-12 00:00:00')
    • formatSqlTimestampSqlServerStyle

      public static String formatSqlTimestampSqlServerStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it either matches the format yyyy-MM-dd or yyyy-MM-dd HH:mm:ss and represents a valid UTC-time.
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TO_TIMESTAMP('2024-12-12 00:00:00')
    • formatSqlDatePlain

      public static String formatSqlDatePlain(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it matches the format yyyy-MM-dd and represents a valid UTC-time.

      This plain format is accepted by SQLite.

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form 'yyyy-MM-dd'
    • formatSqlDateDefaultStyle

      public static String formatSqlDateDefaultStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it matches the format yyyy-MM-dd and represents a valid UTC-time.

      This "standard" format works with H2 and PostreSql but for example not with SQLite.

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form DATE '2024-12-12'
    • formatSqlDateOracleStyle

      public static String formatSqlDateOracleStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it matches the format yyyy-MM-dd and represents a valid UTC-time.

      Should also work for PostgreSQL

      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TO_DATE('2024-12-12', 'YYYY-MM-DD')
    • formatSqlDateSqlServerStyle

      public static String formatSqlDateSqlServerStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it matches the format yyyy-MM-dd and represents a valid UTC-time.
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form TO_DATE('2024-12-12')
    • formatSqlDateMySqlStyle

      public static String formatSqlDateMySqlStyle(String argName, String argValue, de.calamanari.adl.irl.MatchOperator operator)
      Formats the given string if it matches the format yyyy-MM-dd and represents a valid UTC-time.
      Parameters:
      argName -
      argValue -
      operator -
      Returns:
      stamp of the form DATE('2024-12-12')