Package adql.db

Class DBIdentifier

java.lang.Object
adql.db.DBIdentifier
Direct Known Subclasses:
DBTableAlias, DefaultDBColumn, DefaultDBTable

public abstract class DBIdentifier extends Object
Generic implementation of any kind of ADQL/DB identifier.

It already implements functions getting and setting the ADQL and DB names of the interfaces DBTable and DBColumn. Thus, it guarantees that all DB... identifiers will behave the same way when manipulating their ADQL and DB names.

Since:
2.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    A flag indicating if the ADQL name is case sensitive or not (i.e.
    protected String
    Name (not delimited, not prefixed) to use in ADQL queries.
    protected String
    Name (not delimited, not prefixed) of this identifier in the "database".
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    DBIdentifier(String adqlName)
    Create an identifier with the given ADQL name.
    protected
    DBIdentifier(String adqlName, String dbName)
    Create an identifier with the given ADQL and DB names.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    denormalize(String ident, boolean caseSensitive)
    De-normalize the given string.
    Get the ADQL version of this identifier.
    Get the database version of this identifier.
    boolean
    Tell whether the ADQL version of this identifier is case sensitive or not.
    static boolean
    Tell whether the given identifier is delimited (i.e.
    static String
    Normalize the given identifier.
    void
    Set the ADQL version of this identifier.
    void
    setCaseSensitive(boolean caseSensitive)
    Set the case sensitivity of the ADQL version of this identifier.
    void
    setDBName(String newName)
    Set the database version of this identifier.

    Methods inherited from class java.lang.Object

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

    • adqlName

      protected String adqlName
      Name (not delimited, not prefixed) to use in ADQL queries.

      Important: It must never be NULL.

    • adqlCaseSensitive

      protected boolean adqlCaseSensitive
      A flag indicating if the ADQL name is case sensitive or not (i.e. if it must be delimited or not in an ADQL query).
    • dbName

      protected String dbName
      Name (not delimited, not prefixed) of this identifier in the "database". This name must be used, for example, while translating an ADQL query into SQL.

      Note: It may be NULL. In such case, getDBName() must return adqlName.

  • Constructor Details

  • Method Details

    • getADQLName

      public String getADQLName()
      Get the ADQL version of this identifier.

      This name is neither delimited, nor prefixed. To determine whether it should be delimited in an ADQL query, use isCaseSensitive().

      Note: The returned string is never empty or NULL.

      Returns:
      The name to use in ADQL queries.
    • setADQLName

      public void setADQLName(String newName) throws NullPointerException
      Set the ADQL version of this identifier.

      If the given name is delimited, the surrounding double quotes will be removed and case sensitivity will be set to true (i.e. isCaseSensitive() will return true).

      Note: The given name must not be prefixed.

      WARNING: If the given name is NULL or empty (even after removal of surrounding double quotes, if delimited), this function will immediately throw an exception.

      Parameters:
      newName - New ADQL version of this identifier.
      Throws:
      NullPointerException - If the given name is NULL or empty.
      See Also:
    • isCaseSensitive

      public boolean isCaseSensitive()
      Tell whether the ADQL version of this identifier is case sensitive or not.

      If case sensitive, the ADQL name must be written between double quotes (and all inner double quotes should be doubled).

      Returns:
      true if case sensitive, false otherwise.
    • setCaseSensitive

      public void setCaseSensitive(boolean caseSensitive)
      Set the case sensitivity of the ADQL version of this identifier.

      Setting the case sensitivity to true will force the delimited form of the ADQL name (i.e. it will be written between double quotes).

      Parameters:
      caseSensitive - true to declare the ADQL name as case sensitive, false otherwise.
    • getDBName

      public String getDBName()
      Get the database version of this identifier.

      This name is neither delimited, nor prefixed.

      In an SQL query, this name should be considered as case sensitive.

      Note: The returned string is never empty or NULL.

      Returns:
      The real name of this identifier in the "database".
    • setDBName

      public void setDBName(String newName)
      Set the database version of this identifier.

      If the given name is delimited, the surrounding double quotes will be removed.

      Note 1: The given name should not be prefixed.

      Note 2: If the given name is NULL or empty (even after removal of surrounding double quotes if delimited), getDBName() will return the same as getADQLName().

      Parameters:
      newName - The real name of this identifier in the "database".
      See Also:
    • isDelimited

      public static boolean isDelimited(String ident)
      Tell whether the given identifier is delimited (i.e. within the same pair of double quotes - ").

      The following identifiers ARE delimited:

      • "a"
      • "" (empty string ; but won't be considered as a valid ADQL name)
      • " " (string with spaces ; but won't be considered as a valid ADQL name)
      • "foo.bar"
      • "foo"".""bar" (with escaped double quotes)
      • """" (idem)

      The following identifiers are NOT considered as delimited:

      • "foo (missing ending double quote)
      • foo" (missing leading double quote)
      • "foo"."bar" (not the same pair of double quotes)
      Parameters:
      ident - Identifier that may be delimited.
      Returns:
      true if the given identifier is delimited, false otherwise.
    • normalize

      public static String normalize(String ident)
      Normalize the given identifier.

      This function performs the following operations:

      1. Remove leading and trailing space characters.
      2. If the resulting string is empty, return NULL.
      3. If delimited, remove the leading and trailing double quotes.
      4. If the resulting string without leading and trailing spaces is empty, return NULL.
      5. Return the resulting string.
      Parameters:
      ident - The identifier to normalize.
      Returns:
      The normalized string, or NULL if NULL or empty.
      See Also:
    • denormalize

      public static String denormalize(String ident, boolean caseSensitive)
      De-normalize the given string.

      This function does something only if the given string is declared as case sensitive. In such case, it will surround it by double quotes. All inner double quotes will be escaped by doubling them.

      Note: If the given string is NULL, it will be returned as such (i.e. NULL).

      Parameters:
      ident - The identifier to de-normalize.
      caseSensitive - true if the given identifier is considered as case sensitive, false otherwise.
      Returns:
      The de-normalized identifier.
      See Also: