Class SQLUtilities

java.lang.Object
org.apache.sis.util.Static
org.apache.sis.internal.metadata.sql.SQLUtilities

public final class SQLUtilities extends Static
Utilities relative to the SQL language. DO NOT USE This class is for Apache SIS internal usage and may change in any future version.
Since:
0.7
Version:
1.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do not allow instantiation of this class.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    appendIfNotRedundant(StringBuilder buffer, char wildcard)
    Appends the given wildcard character to the given buffer if the buffer does not ends with '%'.
    static String
    escape(String pattern, String escape)
    Returns the given pattern with '_' and '%' characters escaped by the database-specific escape characters.
    static boolean
    filterFalsePositive(String expected, String actual)
    Workaround for what seems to be a Derby 10.11 bug, which seems to behave as if the LIKE pattern had a trailing % wildcard.
    static String
    Returns a simplified form of the URL (truncated before the first ? or ; character), for logging or informative purpose only.
    static Boolean
    Converts the given string to a boolean value, or returns null if the value is unrecognized.
    static void
    toLikePattern(String identifier, int i, int end, boolean allowSuffix, boolean toLower, StringBuilder buffer)
    Returns a SQL LIKE pattern for the given identifier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SQLUtilities

      private SQLUtilities()
      Do not allow instantiation of this class.
  • Method Details

    • getSimplifiedURL

      public static String getSimplifiedURL(DatabaseMetaData metadata) throws SQLException
      Returns a simplified form of the URL (truncated before the first ? or ; character), for logging or informative purpose only.
      Parameters:
      metadata - the metadata of the database.
      Returns:
      a simplified version of database URL.
      Throws:
      SQLException - if an error occurred while fetching the URL.
    • parseBoolean

      public static Boolean parseBoolean(String text) throws SQLException
      Converts the given string to a boolean value, or returns null if the value is unrecognized. This method recognizes "true", "false", "yes", "no", "t", "f", 0 and 1 (case insensitive). An empty string is interpreted as null.
      Parameters:
      text - the characters to convert to a boolean value, or null.
      Returns:
      the given characters as a boolean value, or null if the given text was null or empty.
      Throws:
      SQLDataException - if the given text is non-null and non-empty but not recognized.
      SQLException
      Since:
      0.8
      See Also:
    • escape

      public static String escape(String pattern, String escape)
      Returns the given pattern with '_' and '%' characters escaped by the database-specific escape characters. This method should be invoked for escaping the values of all DatabaseMetaData method arguments with a name ending by "Pattern". Note that not all arguments are pattern; please checks carefully DatabaseMetaData javadoc for each method.
      Example: if a method expects an argument named tableNamePattern, then that argument value should be escaped. But if the argument name is only tableName, then the value should not be escaped.
      Parameters:
      pattern - the pattern to escape, or null if none.
      escape - value of DatabaseMetaData.getSearchStringEscape().
      Returns:
      escaped strings, or the same instance than pattern if there are no characters to escape.
    • toLikePattern

      public static void toLikePattern(String identifier, int i, int end, boolean allowSuffix, boolean toLower, StringBuilder buffer)
      Returns a SQL LIKE pattern for the given identifier. The identifier is optionally returned in all lower cases for allowing case-insensitive searches. Punctuations are replaced by any sequence of characters ('%') and non-ASCII letters or digits are replaced by any single character ('_'). This method avoid to put a '%' symbol as the first character since it prevents some databases to use their index.
      Parameters:
      identifier - the identifier to get as a SQL LIKE pattern.
      i - index of the first character to use in the given identifier.
      end - index after the last character to use in the given identifier.
      allowSuffix - whether to append a final '%' wildcard at the end of the pattern.
      toLower - whether to convert characters to lower case.
      buffer - buffer where to append the SQL LIKE pattern.
    • appendIfNotRedundant

      private static void appendIfNotRedundant(StringBuilder buffer, char wildcard)
      Appends the given wildcard character to the given buffer if the buffer does not ends with '%'.
    • filterFalsePositive

      @Workaround(library="Derby", version="10.11") public static boolean filterFalsePositive(String expected, String actual)
      Workaround for what seems to be a Derby 10.11 bug, which seems to behave as if the LIKE pattern had a trailing % wildcard. This can be verified with the following query on the EPSG database: which returns "NTF (Paris) / Lambert zone I" as expected but also zones II and III.
      Parameters:
      expected - the string to search.
      actual - the string found in the database.
      Returns:
      true if the given string can be accepted.