Skip to content
Snippets Groups Projects
Commit a5406513 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[TAP] Fix the TAP_SCHEMA mapping.

When defining in the configuration file a different name for TAP_SCHEMA content,
the service implementor was also forced to define the same mapping in the
database with the column `dbName`.

This is no longer necessary. From now on, the `dbName` column will be ignored
for all standard TAP_SCHEMA content. Instead, the name specified in the
configuration file (if any) will be used instead. This way, the mapping for
standard TAP_SCHEMA content is only specified once and at only one place:
the configuration file.

_This commit resolves the GitHub issue #98_
parent bad46063
No related branches found
No related tags found
No related merge requests found
...@@ -317,7 +317,7 @@ public class JDBCConnection implements DBConnection { ...@@ -317,7 +317,7 @@ public class JDBCConnection implements DBConnection {
* Keys and values are case sensitive. * Keys and values are case sensitive.
* </p> * </p>
* @since 2.1 */ * @since 2.1 */
protected Map<String,String> dbMapping = null; protected Map<String, String> dbMapping = null;
/** /**
* <p>Creates a JDBC connection to the specified database and with the specified JDBC driver. * <p>Creates a JDBC connection to the specified database and with the specified JDBC driver.
...@@ -850,12 +850,12 @@ public class JDBCConnection implements DBConnection { ...@@ -850,12 +850,12 @@ public class JDBCConnection implements DBConnection {
* *
* @since 2.1 * @since 2.1
*/ */
public void setDBMapping(final Map<String,String> mapping){ public void setDBMapping(final Map<String, String> mapping){
if (mapping == null) if (mapping == null)
dbMapping = null; dbMapping = null;
else{ else{
if (dbMapping == null) if (dbMapping == null)
dbMapping = new HashMap<String,String>(mapping.size()); dbMapping = new HashMap<String, String>(mapping.size());
else else
dbMapping.clear(); dbMapping.clear();
dbMapping.putAll(mapping); dbMapping.putAll(mapping);
...@@ -948,7 +948,7 @@ public class JDBCConnection implements DBConnection { ...@@ -948,7 +948,7 @@ public class JDBCConnection implements DBConnection {
List<TAPTable> lstTables = loadTables(tap_schema.getTable(STDTable.TABLES.label), metadata, stmt); List<TAPTable> lstTables = loadTables(tap_schema.getTable(STDTable.TABLES.label), metadata, stmt);
// load all coordinate systems from TAP_SCHEMA.coosys: [non standard] // load all coordinate systems from TAP_SCHEMA.coosys: [non standard]
Map<String,TAPCoosys> mapCoosys = null; Map<String, TAPCoosys> mapCoosys = null;
if (isTableExisting(tap_schema.getDBName(), "coosys", stmt.getConnection().getMetaData())){ if (isTableExisting(tap_schema.getDBName(), "coosys", stmt.getConnection().getMetaData())){
if (logger != null) if (logger != null)
logger.logDB(LogLevel.INFO, this, "LOAD_TAP_SCHEMA", "Loading TAP_SCHEMA.coosys.", null); logger.logDB(LogLevel.INFO, this, "LOAD_TAP_SCHEMA", "Loading TAP_SCHEMA.coosys.", null);
...@@ -1042,6 +1042,10 @@ public class JDBCConnection implements DBConnection { ...@@ -1042,6 +1042,10 @@ public class JDBCConnection implements DBConnection {
newSchema.setDBName(dbName); newSchema.setDBName(dbName);
newSchema.setIndex(schemaIndex); newSchema.setIndex(schemaIndex);
// force the dbName of TAP_SCHEMA to be the same as the used one:
if (STDSchema.TAPSCHEMA.label.equalsIgnoreCase(schemaName))
newSchema.setDBName(tableDef.getDBSchemaName());
// add the new schema inside the given metadata: // add the new schema inside the given metadata:
metadata.addSchema(newSchema); metadata.addSchema(newSchema);
} }
...@@ -1146,7 +1150,8 @@ public class JDBCConnection implements DBConnection { ...@@ -1146,7 +1150,8 @@ public class JDBCConnection implements DBConnection {
if (typeStr != null){ if (typeStr != null){
try{ try{
type = TableType.valueOf(typeStr.toLowerCase()); type = TableType.valueOf(typeStr.toLowerCase());
}catch(IllegalArgumentException iae){} }catch(IllegalArgumentException iae){
}
} }
// create the new table: // create the new table:
...@@ -1154,6 +1159,13 @@ public class JDBCConnection implements DBConnection { ...@@ -1154,6 +1159,13 @@ public class JDBCConnection implements DBConnection {
newTable.setDBName(dbName); newTable.setDBName(dbName);
newTable.setIndex(tableIndex); newTable.setIndex(tableIndex);
// force the dbName of TAP_SCHEMA table to be the same as the used one:
if (STDSchema.TAPSCHEMA.label.equalsIgnoreCase(schemaName)){
String simpleTableName = (endPrefix > 0) ? tableName.substring(endPrefix + 1) : tableName;
if (tableDef.getSchema() != null && tableDef.getSchema().getTable(simpleTableName) != null)
newTable.setDBName(tableDef.getSchema().getTable(simpleTableName).getDBName());
}
// add the new table inside its corresponding schema: // add the new table inside its corresponding schema:
schema.addTable(newTable); schema.addTable(newTable);
lstTables.add(newTable); lstTables.add(newTable);
...@@ -1183,7 +1195,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1183,7 +1195,7 @@ public class JDBCConnection implements DBConnection {
* *
* @since 2.1 * @since 2.1
*/ */
protected Map<String,TAPCoosys> loadCoosys(final TAPTable tableDef, final TAPMetadata metadata, final Statement stmt) throws DBException{ protected Map<String, TAPCoosys> loadCoosys(final TAPTable tableDef, final TAPMetadata metadata, final Statement stmt) throws DBException{
ResultSet rs = null; ResultSet rs = null;
try{ try{
// Build the SQL query: // Build the SQL query:
...@@ -1199,7 +1211,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1199,7 +1211,7 @@ public class JDBCConnection implements DBConnection {
rs = stmt.executeQuery(sqlBuf.toString()); rs = stmt.executeQuery(sqlBuf.toString());
// Create all coosys: // Create all coosys:
HashMap<String,TAPCoosys> mapCoosys = new HashMap<String,TAPCoosys>(); HashMap<String, TAPCoosys> mapCoosys = new HashMap<String, TAPCoosys>();
while(rs.next()){ while(rs.next()){
String coosysId = rs.getString(1), system = rs.getString(2), String coosysId = rs.getString(1), system = rs.getString(2),
equinox = rs.getString(3), epoch = rs.getString(4); equinox = rs.getString(3), epoch = rs.getString(4);
...@@ -1271,7 +1283,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1271,7 +1283,7 @@ public class JDBCConnection implements DBConnection {
* *
* @since 2.1 * @since 2.1
*/ */
protected void loadColumns(final TAPTable tableDef, final List<TAPTable> lstTables, final Map<String,TAPCoosys> mapCoosys, final Statement stmt) throws DBException{ protected void loadColumns(final TAPTable tableDef, final List<TAPTable> lstTables, final Map<String, TAPCoosys> mapCoosys, final Statement stmt) throws DBException{
ResultSet rs = null; ResultSet rs = null;
try{ try{
// Determine whether the dbName column exists: // Determine whether the dbName column exists:
...@@ -1349,7 +1361,8 @@ public class JDBCConnection implements DBConnection { ...@@ -1349,7 +1361,8 @@ public class JDBCConnection implements DBConnection {
if (datatype != null){ if (datatype != null){
try{ try{
tapDatatype = DBDatatype.valueOf(datatype.toUpperCase()); tapDatatype = DBDatatype.valueOf(datatype.toUpperCase());
}catch(IllegalArgumentException iae){} }catch(IllegalArgumentException iae){
}
} }
// ...build the column type: // ...build the column type:
DBType type; DBType type;
...@@ -1381,6 +1394,10 @@ public class JDBCConnection implements DBConnection { ...@@ -1381,6 +1394,10 @@ public class JDBCConnection implements DBConnection {
} }
} }
// force the dbName of TAP_SCHEMA column to be the same as the used one:
if (STDSchema.TAPSCHEMA.label.equalsIgnoreCase(table.getADQLSchemaName()) && tableDef.getSchema() != null && tableDef.getSchema().getTable(table.getADQLName()) != null && tableDef.getSchema().getTable(table.getADQLName()).getColumn(columnName) != null)
newColumn.setDBName(tableDef.getSchema().getTable(table.getADQLName()).getColumn(columnName).getDBName());
// add the new column inside its corresponding table: // add the new column inside its corresponding table:
table.addColumn(newColumn); table.addColumn(newColumn);
} }
...@@ -1460,7 +1477,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1460,7 +1477,7 @@ public class JDBCConnection implements DBConnection {
} }
// get the list of columns joining the two tables of the foreign key: // get the list of columns joining the two tables of the foreign key:
HashMap<String,String> columns = new HashMap<String,String>(); HashMap<String, String> columns = new HashMap<String, String>();
ResultSet rsKeyCols = null; ResultSet rsKeyCols = null;
try{ try{
keyColumnsStmt.setString(1, key_id); keyColumnsStmt.setString(1, key_id);
...@@ -1652,7 +1669,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1652,7 +1669,7 @@ public class JDBCConnection implements DBConnection {
} }
// 4. Finally, build the join between the standard tables and the custom ones: // 4. Finally, build the join between the standard tables and the custom ones:
TAPTable[] stdTables = new TAPTable[]{TAPMetadata.getStdTable(STDTable.SCHEMAS),TAPMetadata.getStdTable(STDTable.TABLES),TAPMetadata.getStdTable(STDTable.COLUMNS),TAPMetadata.getStdTable(STDTable.KEYS),TAPMetadata.getStdTable(STDTable.KEY_COLUMNS)}; TAPTable[] stdTables = new TAPTable[]{ TAPMetadata.getStdTable(STDTable.SCHEMAS), TAPMetadata.getStdTable(STDTable.TABLES), TAPMetadata.getStdTable(STDTable.COLUMNS), TAPMetadata.getStdTable(STDTable.KEYS), TAPMetadata.getStdTable(STDTable.KEY_COLUMNS) };
for(int i = 0; i < stdTables.length; i++){ for(int i = 0; i < stdTables.length; i++){
// CASE: no custom definition: // CASE: no custom definition:
...@@ -1721,7 +1738,7 @@ public class JDBCConnection implements DBConnection { ...@@ -1721,7 +1738,7 @@ public class JDBCConnection implements DBConnection {
* @see JDBCTranslator#isCaseSensitive(IdentifierField) * @see JDBCTranslator#isCaseSensitive(IdentifierField)
*/ */
private void dropTAPSchemaTables(final TAPTable[] stdTables, final Statement stmt, final DatabaseMetaData dbMeta) throws SQLException{ private void dropTAPSchemaTables(final TAPTable[] stdTables, final Statement stmt, final DatabaseMetaData dbMeta) throws SQLException{
String[] stdTablesToDrop = new String[]{null,null,null,null,null}; String[] stdTablesToDrop = new String[]{ null, null, null, null, null };
ResultSet rs = null; ResultSet rs = null;
try{ try{
...@@ -2251,10 +2268,10 @@ public class JDBCConnection implements DBConnection { ...@@ -2251,10 +2268,10 @@ public class JDBCConnection implements DBConnection {
executeUpdate(stmtKeys, nbKeys); executeUpdate(stmtKeys, nbKeys);
// add the key columns into KEY_COLUMNS: // add the key columns into KEY_COLUMNS:
Iterator<Map.Entry<String,String>> itAssoc = key.iterator(); Iterator<Map.Entry<String, String>> itAssoc = key.iterator();
while(itAssoc.hasNext()){ while(itAssoc.hasNext()){
nbKeyColumns++; nbKeyColumns++;
Map.Entry<String,String> assoc = itAssoc.next(); Map.Entry<String, String> assoc = itAssoc.next();
stmtKeyCols.setString(1, key.getKeyId()); stmtKeyCols.setString(1, key.getKeyId());
stmtKeyCols.setString(2, assoc.getKey()); stmtKeyCols.setString(2, assoc.getKey());
stmtKeyCols.setString(3, assoc.getValue()); stmtKeyCols.setString(3, assoc.getValue());
...@@ -3588,7 +3605,7 @@ public class JDBCConnection implements DBConnection { ...@@ -3588,7 +3605,7 @@ public class JDBCConnection implements DBConnection {
* @param lst List to update. * @param lst List to update.
* @param it All items to append inside the list. * @param it All items to append inside the list.
*/ */
private < T > void appendAllInto(final List<T> lst, final Iterator<T> it){ private <T> void appendAllInto(final List<T> lst, final Iterator<T> it){
while(it.hasNext()) while(it.hasNext())
lst.add(it.next()); lst.add(it.next());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment