Class SqlFormat

java.lang.Object
org.apache.empire.commons.SqlFormat

public class SqlFormat extends Object
SqlFormat This class pretty-formats an SQL command. It may be either overwritten or replaced by a custom implementation by setting a formatter that implements the SqlFormatter interface
  • Field Details

    • log

      protected static final org.slf4j.Logger log
  • Constructor Details

    • SqlFormat

      protected SqlFormat(String sqlCmd, Object[] paramValues, DataType[] paramTypes)
      SqlFormat Constructor
      Parameters:
      sqlCmd - the SQL command string
      paramValues - the parameter values
      paramTypes - the parameter types
  • Method Details

    • getFormatter

      public static SqlFormat.SqlFormatter getFormatter()
      Returns the current SLQ Formatter
      Returns:
      the current SLQ Formatter
    • setFormatter

      public static void setFormatter(SqlFormat.SqlFormatter formatter)
      Replace the current SqlFormatter
      Parameters:
      formatter - the SQL formatter
    • format

      public static String format(String sqlCmd, Object[] paramValues, DataType[] paramTypes)
      Formats an sqlCmd using the current SQL formatter
      Parameters:
      sqlCmd - the SQL command
      paramValues - the param values to replace query params '?' (optional)
      paramTypes - the param types for the given param values (optional)
      Returns:
      the formatted SQL
    • format

      public static String format(String sqlCmd, Object[] paramValues)
      Formats an sqlCmd using the current SQL formatter
      Parameters:
      sqlCmd - the SQL command
      paramValues - the param values to replace query params '?' (optional)
      Returns:
      the formatted SQL
    • format

      public static String format(String sqlCmd)
      Formats an sqlCmd using the current SQL formatter
      Parameters:
      sqlCmd - the SQL command
      Returns:
      the formatted SQL
    • build

      public String build()
      Builds the formatted SQL
      Returns:
      the formatted SQL
    • prepareCmd

      protected char[] prepareCmd(String sqlCmd)
    • allowBlock

      protected boolean allowBlock(SqlFormat.KeyWord kw)
    • append

      protected int append(int beg, int end, boolean indent, boolean newLineAfter, int lev)
    • nextParamValue

      protected String nextParamValue()
    • findKeyWord

      protected SqlFormat.KeyWord findKeyWord(int pos)
    • skipLiteral

      protected void skipLiteral()
    • skipParenthesis

      protected void skipParenthesis()
    • findNext

      protected final int findNext(char find, int from)
    • findNext

      protected final int findNext(String s, String find, int from)
    • combineBlanks

      protected final String combineBlanks(String s)