Package adql.db

Class DefaultDBTable

java.lang.Object
adql.db.DefaultDBTable
All Implemented Interfaces:
DBTable, Iterable<DBColumn>
Direct Known Subclasses:
DBTableAlias

public class DefaultDBTable extends Object implements DBTable
Default implementation of DBTable.
Version:
1.4 (08/2015)
Author:
Grégory Mantelet (CDS;ARI)
  • Field Details

    • dbCatalogName

      protected String dbCatalogName
    • dbSchemaName

      protected String dbSchemaName
    • dbName

      protected String dbName
    • adqlCatalogName

      protected String adqlCatalogName
    • adqlSchemaName

      protected String adqlSchemaName
    • adqlName

      protected String adqlName
    • columns

      protected Map<String,DBColumn> columns
  • Constructor Details

    • DefaultDBTable

      public DefaultDBTable(String dbName)

      Builds a default DBTable with the given DB name.

      With this constructor: ADQL name = DB name.

      Note: The table name can be prefixed by a schema and a catalog: t1 or schema1.t1 or cat1.schema1.t2

      Parameters:
      dbName - Database name (it will be also used as ADQL table name).
      See Also:
    • DefaultDBTable

      public DefaultDBTable(String dbName, String adqlName)

      Builds a default DBTable with the given DB and ADQL names.

      Note: The table names can be prefixed by a schema and a catalog: t1 or schema1.t1 or cat1.schema1.t2

      Parameters:
      dbName - Database name.
      adqlName - Name used in ADQL queries.
    • DefaultDBTable

      public DefaultDBTable(String dbCatName, String dbSchemName, String dbName)
      Builds default DBTable with a DB catalog, schema and table names.
      Parameters:
      dbCatName - Database catalog name (it will be also used as ADQL catalog name).
      dbSchemName - Database schema name (it will be also used as ADQL schema name).
      dbName - Database table name (it will be also used as ADQL table name).
      See Also:
    • DefaultDBTable

      public DefaultDBTable(String dbCatName, String adqlCatName, String dbSchemName, String adqlSchemName, String dbName, String adqlName)
      Builds default DBTable with the DB and ADQL names for the catalog, schema and table.
      Parameters:
      dbCatName - Database catalog name.
      adqlCatName - Catalog name used in ADQL queries. If NULL, it will be set to dbCatName.
      dbSchemName - Database schema name.
      adqlSchemName - Schema name used in ADQL queries. If NULL, it will be set to dbSchemName.
      dbName - Database table name.
      adqlName - Table name used in ADQL queries. If NULL, it will be set to dbName.
  • Method Details

    • getDBName

      public final String getDBName()
      Description copied from interface: DBTable
      Gets the name of this table in the "database".
      Specified by:
      getDBName in interface DBTable
      Returns:
      Its DB name.
    • getDBSchemaName

      public final String getDBSchemaName()
      Description copied from interface: DBTable
      Gets the DB name of the schema which contains this table.
      Specified by:
      getDBSchemaName in interface DBTable
      Returns:
      DB name of its schema.
    • getDBCatalogName

      public final String getDBCatalogName()
      Description copied from interface: DBTable
      Gets the DB name of the catalog which contains this table.
      Specified by:
      getDBCatalogName in interface DBTable
      Returns:
      DB name of its catalog.
    • getADQLName

      public final String getADQLName()
      Description copied from interface: DBTable
      Gets the name of this table (without any prefix and double-quotes).
      Specified by:
      getADQLName in interface DBTable
      Returns:
      Its ADQL name.
    • setADQLName

      public void setADQLName(String name)
    • getADQLSchemaName

      public final String getADQLSchemaName()
      Description copied from interface: DBTable
      Gets the ADQL name of the schema which contains this table.
      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.
      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

      public static final String[] splitTableName(String table)
      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

      public static final String joinTableName(String[] nameParts)

      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).
      And 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.
      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", ) => 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. 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. 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.