Class Quoting

java.lang.Object
net.sf.jailer.util.Quoting

public class Quoting extends Object
Quotes and un-quotes SQL identifier in a DBMS specific way.
Author:
Ralf Wisser
  • Field Details

    • UCSQL2003KEYWORDS

      public static final HashSet<String> UCSQL2003KEYWORDS
  • Constructor Details

  • Method Details

    • getQuoting

      public static Quoting getQuoting(Session session) throws SQLException
      Gets the Quoting for a given session.
      Parameters:
      session - the database session
      Returns:
      the Quoting instance for the session
      Throws:
      SQLException
    • quote

      public String quote(String identifier)
      Quotes an identifier.
      Parameters:
      identifier - the identifier
      Returns:
      quoted identifier
    • hasCorrectCase

      public boolean hasCorrectCase(String identifier)
      Checks whether an identifier has the correct case to be used unquoted.
      Parameters:
      identifier - the identifier to check
      Returns:
      true if the identifier can be used without quoting
    • isQuoted

      public boolean isQuoted(String identifier)
      Checks if an identifier is quoted.
      Parameters:
      identifier - the identifier
      Returns:
      true if identifier is quoted
    • unquote

      public String unquote(String identifier)
      Remove quotes from identifier.
      Parameters:
      identifier - the identifier
      Returns:
      identifier without quotes
    • staticUnquote

      public static String staticUnquote(String identifier)
      Remove quotes from identifier.
      Parameters:
      identifier - the identifier
      Returns:
      identifier without quotes
    • requote

      public String requote(String identifier)
      Quotes an identifier only if it is already quoted (potentially with a different quoting-string).
      Parameters:
      identifier - the identifier
      Returns:
      quoted identifier
    • requote

      public String requote(String identifier, boolean force)
      Quotes an identifier only if it is already quoted (potentially with a different quoting-string).
      Parameters:
      identifier - the identifier
      Returns:
      quoted identifier
    • unquotedTableName

      public static String unquotedTableName(Table t, ExecutionContext executionContext)
      Gets unquoted qualified table name.
      Parameters:
      t - the table
      Returns:
      unquoted qualified name of t
    • getQuote

      public String getQuote()
      Gets the quote character, null if quoting is not supported.
      Returns:
      the quote character, null if quoting is not supported
    • isPotentialIdentifierQuote

      public static boolean isPotentialIdentifierQuote(char c)
      Checks if a character is a potential identifier quote character.
      Parameters:
      c - the character to check
      Returns:
      true if the character can be used as an identifier quote
    • withIdentifierQuoteString

      public Quoting withIdentifierQuoteString(String identifierQuoteString)
      Creates a new Quoting with a different identifier quote string.
      Parameters:
      identifierQuoteString - the new identifier quote string
      Returns:
      a new Quoting instance using the given quote string
    • normalizeIdentifier

      public static String normalizeIdentifier(String identifier)
      Normalizes an identifier. normalizeIdentifier(a).equals(normalizeIdentifier(b)) iff a and b identify the same thing
      Parameters:
      identifier - the identifier
      Returns:
      normalized identifier
    • normalizeCase

      public String normalizeCase(String identifier)
      Normalizes the case of an unquoted identifier according to the database's case rules.
      Parameters:
      identifier - the identifier to normalize
      Returns:
      the identifier with normalized case, or null if the input is null
    • equalsIgnoreQuotingAndCase

      public static boolean equalsIgnoreQuotingAndCase(String a, String b)
      Compares a String to another String, ignoring case considerations and quoting.
      Parameters:
      a - first String
      b - second String
      Returns:
      true if a equals b
    • equalsWROSearchPattern

      public static boolean equalsWROSearchPattern(String a, String cand1, String cand2)
      Checks whether a SQL LIKE search pattern matches either of two candidates, ignoring quoting and case.
      Parameters:
      a - the search pattern
      cand1 - the first candidate
      cand2 - the second candidate
      Returns:
      true if the pattern matches either candidate
    • equalsWROSearchPattern

      public static boolean equalsWROSearchPattern(String a, String b)
      Checks whether a SQL LIKE search pattern matches a candidate, ignoring quoting and case.
      Parameters:
      a - the search pattern
      b - the candidate
      Returns:
      true if the pattern matches the candidate