Package adql.db

Class DefaultDBTable

java.lang.Object
adql.db.DBIdentifier
adql.db.DefaultDBTable
All Implemented Interfaces:
DBTable, Iterable<DBColumn>

public class DefaultDBTable extends DBIdentifier implements DBTable
Default implementation of DBTable.

WARNING: constructors signature and behavior changed since v2.0! Before v2.0, the constructors expected to have the DB names before the ADQL names and thus, they forced to give a DB table name ; the ADQL table name being optional (if not provided it was set to the DB name). But since v2.0, this logic is inverted: the ADQL name is mandatory (a NullPointerException will be thrown if NULL or empty) while the DB name is optional (DBIdentifier.getDBName() will return the same as DBIdentifier.getADQLName() if no DB name is specified at initialization). Consequently, the ADQL names are expected as first parameters.

  • Field Details

    • dbCatalogName

      protected String dbCatalogName
    • dbSchemaName

      protected String dbSchemaName
    • adqlCatalogName

      protected String adqlCatalogName
    • adqlSchemaName

      protected String adqlSchemaName
    • columns

      protected Map<String,DBColumn> columns
  • Constructor Details

    • DefaultDBTable

      public DefaultDBTable(String adqlName) throws NullPointerException
      Builds a default DBTable with the given ADQL name.

      With this constructor: DB name = ADQL name.

      Note: The ADQL/DB schema and catalog names are set to NULL.

      WARNING: The ADQL table name MUST be NON-qualified (i.e. not prefixed by a schema and/or a catalog)! For instance, t1 is ok, but not schema1.t1 or cat1.schema1.t2 which won't be split but instead, considered as the whole ADQL name.

      Important note: The ADQL table name can be delimited (i.e. surrounded by double quotes). In such case, the surrounded name would be considered as case-sensitive.

      Parameters:
      adqlName - The ADQL name of this table (i.e. name to use in ADQL).
      Throws:
      NullPointerException - If the given ADQL name is NULL or empty.
      Since:
      2.0
    • DefaultDBTable

      public DefaultDBTable(String adqlName, String dbName) throws NullPointerException
      Builds a default DBTable with the given ADQL and DB names.

      Note: The ADQL/DB schema and catalog names are set to NULL.

      WARNING: The ADQL table name MUST NOT be qualified (i.e. prefixed by a schema and/or a catalog)! For instance, t1 is ok, but not schema1.t1 or cat1.schema1.t2 which won't be split but instead, considered as the whole ADQL name.

      Important note: The ADQL table name can be delimited (i.e. surrounded by double quotes). In such case, the surrounded name would be considered as case-sensitive.

      Parameters:
      adqlName - Name used in ADQL queries.
      dbName - Database name. If NULL, DBIdentifier.getDBName() will return the same as DBIdentifier.getADQLName().
      Throws:
      NullPointerException - If the given ADQL name is NULL or empty.
      Since:
      2.0
    • DefaultDBTable

      public DefaultDBTable(String adqlCatName, String adqlSchemaName, String adqlName) throws NullPointerException
      Builds default DBTable with a ADQL catalog, schema and table names.

      WARNING: The ADQL table name MUST NOT be qualified (i.e. prefixed by a schema and/or a catalog)! For instance, t1 is ok, but not schema1.t1 or cat1.schema1.t2 which won't be split but instead, considered as the whole ADQL name.

      Important note: The ADQL table name can be delimited (i.e. surrounded by double quotes). In such case, the surrounded name would be considered as case-sensitive.

      Parameters:
      adqlCatName - ADQL catalog name (it will be also used as DB catalog name).
      adqlSchemaName - ADQL schema name (it will be also used as DB schema name).
      adqlName - ADQL table name (it will be also used as DB table name). MUST NOT be NULL!
      Throws:
      NullPointerException - If the given ADQL name is NULL or empty.
      Since:
      2.0
    • DefaultDBTable

      public DefaultDBTable(String adqlCatName, String dbCatName, String adqlSchemaName, String dbSchemaName, String adqlName, String dbName) throws NullPointerException
      Builds default DBTable with the ADQL and DB names for the catalog, schema and table.

      WARNING: The ADQL table name MUST NOT be qualified (i.e. prefixed by a schema and/or a catalog)! For instance, t1 is ok, but not schema1.t1 or cat1.schema1.t2 which won't be split but instead, considered as the whole ADQL name.

      Important note: The ADQL table name can be delimited (i.e. surrounded by double quotes). In such case, the surrounded name would be considered as case-sensitive.

      Parameters:
      adqlCatName - Catalog name used in ADQL queries.
      dbCatName - Database catalog name. If NULL, it will be set to adqlCatName.
      adqlSchemaName - Schema name used in ADQL queries.
      dbSchemaName - Database schema name. If NULL, it will be set to adqlSchemaName.
      adqlName - Table name used in ADQL queries. MUST NOT be NULL!
      dbName - Database table name. If NULL, it will be set to adqlName.
      Throws:
      NullPointerException - If the given ADQL name is NULL or empty.
  • Method Details

    • getDBSchemaName

      public final String getDBSchemaName()
      Description copied from interface: DBTable
      Gets the DB name of the schema which contains this table.

      Warning! Same rules as DBTable.getDBName().

      Specified by:
      getDBSchemaName in interface DBTable
      Returns:
      DB name of its schema.
    • setDBSchemaName

      public final void setDBSchemaName(String name)
    • getDBCatalogName

      public final String getDBCatalogName()
      Description copied from interface: DBTable
      Gets the DB name of the catalog which contains this table.

      Warning! Same rules as DBTable.getDBName().

      Specified by:
      getDBCatalogName in interface DBTable
      Returns:
      DB name of its catalog.
    • setDBCatalogName

      public final void setDBCatalogName(String name)
    • getADQLSchemaName

      public final String getADQLSchemaName()
      Description copied from interface: DBTable
      Gets the ADQL name of the schema which contains this table.

      Warning! Same rules as DBTable.getADQLName().

      Specified by:
      getADQLSchemaName in interface DBTable
      Returns:
      ADQL name of its schema.
    • setADQLSchemaName

      public void setADQLSchemaName(String name)
    • getADQLCatalogName

      public final String getADQLCatalogName()
      Description copied from interface: DBTable
      Gets the ADQL name of the catalog which contains this table.

      Warning! Same rules as DBTable.getADQLName().

      Specified by:
      getADQLCatalogName in interface DBTable
      Returns:
      ADQL name of its catalog.
    • setADQLCatalogName

      public void setADQLCatalogName(String name)
    • getColumn

      public DBColumn getColumn(String colName, boolean byAdqlName)

      Case sensitive !

      Research optimized for researches by ADQL name.

      Specified by:
      getColumn in interface DBTable
      Parameters:
      colName - Name of the column (may be the ADQL or DB name depending of the second parameter).
      byAdqlName - true means the given name is the ADQL name of the column and that the research must be done on the ADQL name of columns, false means the same thing but with the DB name.
      Returns:
      The corresponding column, or NULL if the specified column had not been found.
      See Also:
    • hasColumn

      public boolean hasColumn(String colName, boolean byAdqlName)
    • iterator

      public Iterator<DBColumn> iterator()
      Specified by:
      iterator in interface Iterable<DBColumn>
    • addColumn

      public void addColumn(DBColumn column)
    • addAllColumns

      public void addAllColumns(Collection<DBColumn> colList)
    • splitTableName

      @Deprecated public static final String[] splitTableName(String table)
      Deprecated.
      Since v2.0, the table name is not any more split automatically.
      Splits the given table name in 3 parts: catalog, schema, table.
      Parameters:
      table - The table name to split.
      Returns:
      A String array of 3 items: [0]=catalog, [1]=schema, [0]=table.
    • joinTableName

      @Deprecated public static final String joinTableName(String[] nameParts)
      Deprecated.
      Since v2.0, the table name is not any more split automatically. So, it is not any more needed to join all its parts.

      Join the last 3 items of the given string array with a dot ('.'). These three parts should be: [0]=catalog name, [1]=schema name, [2]=table name.

      If the array contains less than 3 items, all the given items will be though joined. However, if it contains more than 3 items, only the three last items will be.

      A null item will be written as an empty string (string of length 0 ; "").

      In the case the first and the third items are not null, but the second is null, the final string will contain in the middle two dots. Example: if the array is {"cat", NULL, "table"}, then the joined string will be: "cat..table".

      Parameters:
      nameParts - String items to join.
      Returns:
      A string joining the 3 last string items of the given array, or an empty string if the given array is NULL.
      Since:
      1.3
    • copy

      public DBTable copy(String dbName, String adqlName)
      Description copied from interface: DBTable
      Makes a copy of this instance of DBTable, with the possibility to change the DB and ADQL names.

      IMPORTANT:

      • The given DB and ADQL name may be NULL. If NULL, the copy will contain exactly the same full name (DB and/or ADQL).
      • they may be qualified (that's to say: prefixed by the schema name or by the catalog and schema name). It means that it is possible to change the catalog, schema and table name in the copy.
      • they may be delimited (that's to say: written between double quotes to force case sensitivity).

      For instance:

      • .copy(null, "foo") => a copy with the same full DB name, but with no ADQL catalog and schema name and with an ADQL table name equals to "foo"
      • .copy("schema.table", null) => a copy with the same full ADQL name, but with no DB catalog name, with a DB schema name equals to "schema" and with a DB table name equals to "table"
      Specified by:
      copy in interface DBTable
      Parameters:
      dbName - Its new DB name. It may be qualified and/or delimited. It may also be NULL ; if so, the full DB name won't be different in the copy.
      adqlName - Its new ADQL name. It may be qualified and/or delimited. It may also be NULL ; if so, the full DB name won't be different in the copy.
      Returns:
      A modified copy of this DBTable.