public class TAPTable extends java.lang.Object implements DBTable
Represent a table as described by the IVOA standard in the TAP protocol definition.
This object representation has exactly the same fields as the column of the table TAP_SCHEMA.tables.
But it also provides a way to add other data. For instance, if information not listed in the standard
may be stored here, they can be using the function setOtherData(Object)
. This object can be
a single value (integer, string, ...), but also a Map
, List
, etc...
Important note:
A TAPTable
object MUST always have a DB name. That's why, getDBName()
returns
what getADQLName()
returns when no DB name is set. After creation, it is possible to set
the DB name with setDBName(String)
.
This DB name MUST be UNqualified and without double quotes. If a NULL or empty value is provided,
getDBName()
returns what getADQLName()
returns.
Modifier and Type | Class and Description |
---|---|
static class |
TAPTable.TableType
Different types of table according to the TAP protocol.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,TAPColumn> |
columns
List of columns composing this table.
|
protected java.util.ArrayList<TAPForeignKey> |
foreignKeys
List of all foreign keys linking this table to others.
|
protected java.lang.Object |
otherData
Let add some information in addition of the ones of the TAP protocol.
|
Constructor and Description |
---|
TAPTable(java.lang.String tableName)
Build a
TAPTable instance with the given ADQL name. |
TAPTable(java.lang.String tableName,
TAPTable.TableType tableType)
Build a
TAPTable instance with the given ADQL name and table type. |
TAPTable(java.lang.String tableName,
TAPTable.TableType tableType,
java.lang.String description,
java.lang.String utype)
Build a
TAPTable instance with the given ADQL name, table type, description and UType. |
Modifier and Type | Method and Description |
---|---|
TAPColumn |
addColumn(java.lang.String columnName)
Build a
TAPColumn object whose the ADQL and DB name will the given one. |
TAPColumn |
addColumn(java.lang.String columnName,
DBType datatype,
java.lang.String description,
java.lang.String unit,
java.lang.String ucd,
java.lang.String utype)
Build a
TAPColumn object whose the ADQL and DB name will the given one. |
TAPColumn |
addColumn(java.lang.String columnName,
DBType datatype,
java.lang.String description,
java.lang.String unit,
java.lang.String ucd,
java.lang.String utype,
boolean principal,
boolean indexed,
boolean std)
Build a
TAPColumn object whose the ADQL and DB name will the given one. |
void |
addColumn(TAPColumn newColumn)
Add a column to this table.
|
TAPForeignKey |
addForeignKey(java.lang.String keyId,
TAPTable targetTable,
java.util.Map<java.lang.String,java.lang.String> columns)
Build a foreign key using the ID, the target table and the given list of columns.
|
TAPForeignKey |
addForeignKey(java.lang.String keyId,
TAPTable targetTable,
java.util.Map<java.lang.String,java.lang.String> columns,
java.lang.String description,
java.lang.String utype)
Build a foreign key using the ID, the target table, the given list of columns, the given description and the given UType.
|
void |
addForeignKey(TAPForeignKey key)
Add the given foreign key to this table.
|
DBTable |
copy(java.lang.String dbName,
java.lang.String adqlName)
Makes a copy of this instance of
DBTable , with the possibility to change the DB and ADQL names. |
protected void |
deleteColumnRelations(TAPColumn col)
Delete all foreign keys having the given column in the sources or the targets list.
|
protected void |
deleteRelations(TAPForeignKey key)
Delete the link between all columns of the given foreign key
and this foreign key.
|
java.lang.String |
getADQLCatalogName()
Gets the ADQL name of the catalog which contains this table.
|
java.lang.String |
getADQLName()
Gets the name of this table (without any prefix and double-quotes).
|
java.lang.String |
getADQLSchemaName()
Gets the ADQL name of the schema which contains this table.
|
TAPColumn |
getColumn(java.lang.String columnName)
Search a column inside this table having the given ADQL name.
|
DBColumn |
getColumn(java.lang.String colName,
boolean byAdqlName)
Gets the definition of the specified column if it exists in this table.
|
java.util.Iterator<TAPColumn> |
getColumns()
Get the list of all columns contained in this table.
|
java.lang.String |
getDBCatalogName()
Gets the DB name of the catalog which contains this table.
|
java.lang.String |
getDBName()
Gets the name of this table in the "database".
|
java.lang.String |
getDBSchemaName()
Gets the DB name of the schema which contains this table.
|
java.lang.String |
getDescription()
Get the description of this table.
|
java.util.Iterator<TAPForeignKey> |
getForeignKeys()
Get the list of all foreign keys associated whose the source is this table.
|
java.lang.String |
getFullName()
Get the qualified name of this table.
|
int |
getIndex()
Get the ordering index of this table inside its schema.
|
java.lang.String |
getName()
Deprecated.
Does not do anything special: just call
getADQLName() . |
int |
getNbColumns()
Get the number of columns composing this table.
|
int |
getNbForeignKeys()
Get the number of all foreign keys whose the source is this table
|
java.lang.Object |
getOtherData()
Get the other (piece of) information associated with this table.
|
java.lang.String |
getRawName()
Get the full ADQL name of this table, as it has been provided at initialization.
|
TAPSchema |
getSchema()
Get the schema that owns this table.
|
java.lang.String |
getTitle()
Get the title of this table.
|
TAPTable.TableType |
getType()
Get the type of this table.
|
java.lang.String |
getUtype()
Get the UType associating this table with a data-model.
|
boolean |
hasColumn(java.lang.String columnName)
Tell whether this table contains a column with the given ADQL name.
|
boolean |
hasColumn(java.lang.String colName,
boolean byAdqlName)
Tell whether this table contains a column with the given ADQL or DB name.
|
boolean |
isEmpty()
Tell whether this table contains no column.
|
boolean |
isInitiallyQualified()
Deprecated.
To get name of the table as it should be used:
getRawName() .
To get just the table name (with no prefix and surrounding double quotes): getADQLName() . |
java.util.Iterator<DBColumn> |
iterator() |
void |
removeAllColumns()
Remove all columns composing this table.
|
void |
removeAllForeignKeys()
Remove all the foreign keys whose the source is this table.
|
TAPColumn |
removeColumn(java.lang.String columnName)
Remove the specified column.
|
boolean |
removeForeignKey(TAPForeignKey keyToRemove)
Remove the given foreign key from this table.
|
void |
setDBName(java.lang.String name)
Change the name that this table MUST have in the database (i.e.
|
void |
setDescription(java.lang.String description)
Set the description of this table.
|
void |
setIndex(int tableIndex)
Set the ordering index of this table inside its schema.
|
void |
setInitiallyQualifed(boolean mustBeQualified)
Deprecated.
To get name of the table as it should be used:
getRawName() .
To get just the table name (with no prefix and surrounding double quotes): getADQLName() . |
void |
setOtherData(java.lang.Object data)
Set the other (piece of) information associated with this table.
|
protected void |
setSchema(TAPSchema schema)
Set the schema in which this schema is.
|
void |
setTitle(java.lang.String title)
Set the title of this table.
|
void |
setType(TAPTable.TableType type)
Set the type of this table.
|
void |
setUtype(java.lang.String utype)
Set the UType associating this table with a data-model.
|
java.lang.String |
toString() |
protected final java.util.Map<java.lang.String,TAPColumn> columns
protected final java.util.ArrayList<TAPForeignKey> foreignKeys
protected java.lang.Object otherData
Integer
, a String
, a Map
, a List
, ...
Its content is totally free and never used or checked.public TAPTable(java.lang.String tableName) throws java.lang.NullPointerException
Build a TAPTable
instance with the given ADQL name.
Note 1:
The DB name is set by default to NULL so that getDBName()
returns exactly what getADQLName()
returns.
To set a specific DB name, you MUST call setDBName(String)
.
Note 2: The table type is set by default to "table".
Important notes on the given ADQL name:
getADQLName()
but will be still here when using getRawName()
. To work, the schema name must be exactly the same
as what the function TAPSchema.getRawName()
of the set schema returns.
getADQLName()
but will
still appear in the result of getRawName()
.
tableName
- Name that this table MUST have in ADQL queries.
CAN'T be NULL ; this name can never be changed after initialization.java.lang.NullPointerException
- If the given name is null
,
or if the given string is empty after simplification
(i.e. without the surrounding double quotes).public TAPTable(java.lang.String tableName, TAPTable.TableType tableType) throws java.lang.NullPointerException
Build a TAPTable
instance with the given ADQL name and table type.
Note 1:
The DB name is set by default to NULL so that getDBName()
returns exactly what getADQLName()
returns.
To set a specific DB name, you MUST call setDBName(String)
.
Note 2: The table type is set by default to "table".
Important notes on the given ADQL name:
getADQLName()
but will be still here when using getRawName()
. To work, the schema name must be exactly the same
as what the function TAPSchema.getRawName()
of the set schema returns.
getADQLName()
but will
still appear in the result of getRawName()
.
tableName
- Name that this table MUST have in ADQL queries.
CAN'T be NULL ; this name can never be changed after initialization.tableType
- Type of this table. If NULL, "table" will be the type of this table.java.lang.NullPointerException
- If the given name is null
,
or if the given string is empty after simplification
(i.e. without the surrounding double quotes).setType(TableType)
public TAPTable(java.lang.String tableName, TAPTable.TableType tableType, java.lang.String description, java.lang.String utype) throws java.lang.NullPointerException
Build a TAPTable
instance with the given ADQL name, table type, description and UType.
Note 1:
The DB name is set by default to NULL so that getDBName()
returns exactly what getADQLName()
returns.
To set a specific DB name, you MUST call setDBName(String)
.
Note 2: The table type is set by default to "table".
Important notes on the given ADQL name:
getADQLName()
but will be still here when using getRawName()
. To work, the schema name must be exactly the same
as what the function TAPSchema.getRawName()
of the set schema returns.
getADQLName()
but will
still appear in the result of getRawName()
.
tableName
- Name that this table MUST have in ADQL queries.
CAN'T be NULL ; this name can never be changed after initialization.tableType
- Type of this table. If NULL, "table" will be the type of this table.description
- Description of this table. MAY be NULL.utype
- UType associating this table with a data-model. MAY be NULLjava.lang.NullPointerException
- If the given name is null
,
or if the given string is empty after simplification
(i.e. without the surrounding double quotes).setType(TableType)
public final java.lang.String getFullName()
Get the qualified name of this table.
Warning: The part of the returned full name won't be double quoted!
Note: If this table is not attached to a schema, this function will just return the ADQL name of this table.
@Deprecated public final java.lang.String getName()
getADQLName()
.getADQLName()
public final java.lang.String getADQLName()
DBTable
getADQLName
in interface DBTable
public final java.lang.String getRawName()
@Deprecated public final boolean isInitiallyQualified()
getRawName()
.
To get just the table name (with no prefix and surrounding double quotes): getADQLName()
.Tells whether the ADQL name of this table must be qualified in the "table_name" column of TAP_SCHEMA.tables and in the /schema/table/name field of the resource /tables.
Note: this value is set automatically by the constructor: "true" if the table name was qualified,
"false" otherwise. It can be changed with the function setInitiallyQualifed(boolean)
, BUT by doing so
you may generate a mismatch between the table name of TAP_SCHEMA.tables and the one of /tables.
@Deprecated public final void setInitiallyQualifed(boolean mustBeQualified)
getRawName()
.
To get just the table name (with no prefix and surrounding double quotes): getADQLName()
.Let specifying whether the table name must be qualified in TAP_SCHEMA.tables and in the resource /tables.
WARNING: Calling this function may generate a mismatch between the table name of TAP_SCHEMA.tables and
the one of the resource /tables. So, be sure to change this flag before setting the content of TAP_SCHEMA.tables
using JDBCConnection.setTAPSchema(TAPMetadata)
.
mustBeQualified
- true if the table name in TAP_SCHEMA.tables and in the resource /tables must be qualified by the schema name,
false otherwise.public final java.lang.String getDBName()
DBTable
public final void setDBName(java.lang.String name)
Change the name that this table MUST have in the database (i.e. in SQL queries).
Note:
If the given value is NULL or an empty string, getDBName()
will return exactly what getADQLName()
returns.
name
- The new database name of this table.public java.lang.String getADQLCatalogName()
DBTable
getADQLCatalogName
in interface DBTable
public java.lang.String getDBCatalogName()
DBTable
getDBCatalogName
in interface DBTable
public final java.lang.String getADQLSchemaName()
DBTable
getADQLSchemaName
in interface DBTable
public final java.lang.String getDBSchemaName()
DBTable
getDBSchemaName
in interface DBTable
public final TAPSchema getSchema()
protected final void setSchema(TAPSchema schema)
Set the schema in which this schema is.
Warning:
For consistency reasons, this function SHOULD be called only by the TAPSchema
that owns this table.
Important note:
If this table was already linked with another TAPSchema
object, the previous link is removed
here, but also in the schema (by calling TAPSchema.removeTable(String)
).
schema
- The schema that owns this table.public final TAPTable.TableType getType()
public final void setType(TAPTable.TableType type)
Set the type of this table.
Note: If the given type is NULL, nothing will be done ; the type of this table won't be changed.
type
- Its new type.public final java.lang.String getTitle()
public final void setTitle(java.lang.String title)
title
- Its new title. MAY be NULLpublic final java.lang.String getDescription()
public final void setDescription(java.lang.String description)
description
- Its new description. MAY be NULLpublic final java.lang.String getUtype()
public final void setUtype(java.lang.String utype)
utype
- Its new UType. MAY be NULLpublic final int getIndex()
public final void setIndex(int tableIndex)
tableIndex
- Its new ordering index.public java.lang.Object getOtherData()
Get the other (piece of) information associated with this table.
Note:
By default, NULL is returned, but it may be any kind of value (Integer
,
String
, Map
, List
, ...).
public void setOtherData(java.lang.Object data)
data
- Another information about this table. MAY be NULLpublic final void addColumn(TAPColumn newColumn)
Add a column to this table.
Note: If the given column is NULL, nothing will be done.
Important note:
By adding the given column inside this table, it
will be linked with this table using TAPColumn.setTable(DBTable)
.
In this function, if the column was already linked with another TAPTable
,
the former link is removed using removeColumn(String)
.
newColumn
- Column to add inside this table.public final TAPColumn addColumn(java.lang.String columnName)
Build a TAPColumn
object whose the ADQL and DB name will the given one.
Then, add this column inside this table.
Note:
The built TAPColumn
object is returned, so that being modified afterwards if needed.
columnName
- ADQL name (and indirectly also the DB name) of the column to create and add.TAPColumn
object,
or NULL if the given name is NULL or an empty string.TAPColumn.TAPColumn(String)
,
addColumn(TAPColumn)
public TAPColumn addColumn(java.lang.String columnName, DBType datatype, java.lang.String description, java.lang.String unit, java.lang.String ucd, java.lang.String utype)
Build a TAPColumn
object whose the ADQL and DB name will the given one.
Then, add this column inside this table.
Note:
The built TAPColumn
object is returned, so that being modified afterwards if needed.
columnName
- ADQL name (and indirectly also the DB name) of the column to create and add.datatype
- Type of the new column's values. If NULL, VARCHAR will be the type of the created column.description
- Description of the new column. MAY be NULLunit
- Unit of the new column's values. MAY be NULLucd
- UCD describing the scientific content of the new column. MAY be NULLutype
- UType associating the new column with a data-model. MAY be NULLTAPColumn
object,
or NULL if the given name is NULL or an empty string.TAPColumn.TAPColumn(String, DBType, String, String, String, String)
,
addColumn(TAPColumn)
public TAPColumn addColumn(java.lang.String columnName, DBType datatype, java.lang.String description, java.lang.String unit, java.lang.String ucd, java.lang.String utype, boolean principal, boolean indexed, boolean std)
Build a TAPColumn
object whose the ADQL and DB name will the given one.
Then, add this column inside this table.
Note:
The built TAPColumn
object is returned, so that being modified afterwards if needed.
columnName
- ADQL name (and indirectly also the DB name) of the column to create and add.datatype
- Type of the new column's values. If NULL, VARCHAR will be the type of the created column.description
- Description of the new column. MAY be NULLunit
- Unit of the new column's values. MAY be NULLucd
- UCD describing the scientific content of the new column. MAY be NULLutype
- UType associating the new column with a data-model. MAY be NULLprincipal
- true if the new column should be returned by default, false otherwise.indexed
- true if the new column is indexed, false otherwise.std
- true if the new column is defined by a standard, false otherwise.TAPColumn
object,
or NULL if the given name is NULL or an empty string.TAPColumn.TAPColumn(String, DBType, String, String, String, String)
,
TAPColumn.setPrincipal(boolean)
,
TAPColumn.setIndexed(boolean)
,
TAPColumn.setStd(boolean)
,
addColumn(TAPColumn)
public final boolean hasColumn(java.lang.String columnName)
Tell whether this table contains a column with the given ADQL name.
Important note: This function is case sensitive.
columnName
- ADQL name (case sensitive) of the column whose the existence must be checked.public java.util.Iterator<TAPColumn> getColumns()
public DBColumn getColumn(java.lang.String colName, boolean byAdqlName)
DBTable
getColumn
in interface DBTable
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.public final TAPColumn getColumn(java.lang.String columnName)
Search a column inside this table having the given ADQL name.
Important note: This function is case sensitive.
columnName
- ADQL name of the column to search.public boolean hasColumn(java.lang.String colName, boolean byAdqlName)
Tell whether this table contains a column with the given ADQL or DB name.
Note:
This functions is just calling getColumn(String, boolean)
and compare its result
with NULL in order to check the existence of the specified column.
colName
- ADQL or DB name that the column to search must have.byAdqlName
- true to search the column by ADQL name, false to search by DB name.getColumn(String, boolean)
public final int getNbColumns()
public final boolean isEmpty()
public final TAPColumn removeColumn(java.lang.String columnName)
Remove the specified column.
Important note: This function is case sensitive!
Note: If some foreign keys were associating the column to remove, they will be also deleted.
columnName
- ADQL name of the column to remove.deleteColumnRelations(TAPColumn)
protected final void deleteColumnRelations(TAPColumn col)
col
- A column.public final void removeAllColumns()
public final void addForeignKey(TAPForeignKey key) throws TAPException
Add the given foreign key to this table.
Note: This function will do nothing if the given foreign key is NULL.
WARNING:
The source table (TAPForeignKey.getFromTable()
) of the given foreign key MUST be this table
and the foreign key MUST be completely defined.
If not, an exception will be thrown and the key won't be added.
Note:
If the given foreign key is added to this table, all the columns of this key will be
linked to the foreign key using either TAPColumn.addSource(TAPForeignKey)
or
TAPColumn.addTarget(TAPForeignKey)
.
key
- Foreign key (whose the FROM table is this table) to add inside this table.TAPException
- If the source table of the given foreign key is not this table
or if the given key is not completely defined.public TAPForeignKey addForeignKey(java.lang.String keyId, TAPTable targetTable, java.util.Map<java.lang.String,java.lang.String> columns) throws TAPException
Build a foreign key using the ID, the target table and the given list of columns. Then, add the created foreign key to this table.
Note:
The source table of the created foreign key (TAPForeignKey.getFromTable()
) will be this table.
Note:
If the given foreign key is added to this table, all the columns of this key will be
linked to the foreign key using either TAPColumn.addSource(TAPForeignKey)
or
TAPColumn.addTarget(TAPForeignKey)
.
TAPException
- If the specified key is not completely or correctly defined.TAPForeignKey.TAPForeignKey(String, TAPTable, TAPTable, Map)
public TAPForeignKey addForeignKey(java.lang.String keyId, TAPTable targetTable, java.util.Map<java.lang.String,java.lang.String> columns, java.lang.String description, java.lang.String utype) throws TAPException
Build a foreign key using the ID, the target table, the given list of columns, the given description and the given UType. Then, add the created foreign key to this table.
Note:
The source table of the created foreign key (TAPForeignKey.getFromTable()
) will be this table.
Note:
If the given foreign key is added to this table, all the columns of this key will be
linked to the foreign key using either TAPColumn.addSource(TAPForeignKey)
or
TAPColumn.addTarget(TAPForeignKey)
.
TAPException
- If the specified key is not completely or correctly defined.TAPForeignKey.TAPForeignKey(String, TAPTable, TAPTable, Map, String, String)
public final java.util.Iterator<TAPForeignKey> getForeignKeys()
public final int getNbForeignKeys()
public final boolean removeForeignKey(TAPForeignKey keyToRemove)
Remove the given foreign key from this table.
Note:
This function will also delete the link between the columns of the foreign key
and the foreign key, using deleteRelations(TAPForeignKey)
.
keyToRemove
- Foreign key to removed from this table.public final void removeAllForeignKeys()
Remove all the foreign keys whose the source is this table.
Note:
This function will also delete the link between the columns of all the removed foreign keys
and the foreign keys, using deleteRelations(TAPForeignKey)
.
protected final void deleteRelations(TAPForeignKey key)
key
- A foreign key whose links with its columns must be deleted.public java.util.Iterator<DBColumn> iterator()
iterator
in interface java.lang.Iterable<DBColumn>
public java.lang.String toString()
toString
in class java.lang.Object
public DBTable copy(java.lang.String dbName, java.lang.String adqlName)
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
in interface DBTable
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.DBTable
.