From 93c36a099b2a0f0330a498dca7ede9dfc6a447e3 Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Tue, 26 Sep 2017 14:26:53 +0200 Subject: [PATCH] [TAP] The additional table TAP_SCHEMA.coossys must not be be returned as a standard table. The same for the additional column TAP_SCHEMA.columns.coosys_id. --- src/tap/db/JDBCConnection.java | 37 +++++++++++++++++-------------- src/tap/metadata/TAPMetadata.java | 34 ++++++++++++++++------------ 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/src/tap/db/JDBCConnection.java b/src/tap/db/JDBCConnection.java index a109ed1..cf8450d 100644 --- a/src/tap/db/JDBCConnection.java +++ b/src/tap/db/JDBCConnection.java @@ -903,6 +903,7 @@ public class JDBCConnection implements DBConnection { * <ol> * <li>{@link #loadSchemas(TAPTable, TAPMetadata, Statement)}</li> * <li>{@link #loadTables(TAPTable, TAPMetadata, Statement)}</li> + * <li>{@link #loadCoosys(TAPTable, TAPMetadata, Statement)}</li> * <li>{@link #loadColumns(TAPTable, List, Statement)}</li> * <li>{@link #loadKeys(TAPTable, TAPTable, List, Statement)}</li> * </ol> @@ -941,11 +942,16 @@ public class JDBCConnection implements DBConnection { List<TAPTable> lstTables = loadTables(tap_schema.getTable(STDTable.TABLES.label), metadata, stmt); // load all coordinate systems from TAP_SCHEMA.coosys: [non standard] - Map<String, TAPCoosys> mapCoosys = null; - if (isTableExisting(tap_schema.getDBName(), STDTable.COOSYS.label, stmt.getConnection().getMetaData())){ + Map<String,TAPCoosys> mapCoosys = null; + if (isTableExisting(tap_schema.getDBName(), "coosys", stmt.getConnection().getMetaData())){ if (logger != null) logger.logDB(LogLevel.INFO, this, "LOAD_TAP_SCHEMA", "Loading TAP_SCHEMA.coosys.", null); - mapCoosys = loadCoosys(tap_schema.getTable(STDTable.COOSYS.label), metadata, stmt); + // create the TAP_SCHEMA.coosys table: + TAPTable coosysTable = TAPMetadata.getCoosysTable(); + // add TAP_SCHEMA.coosys to the schema TAP_SCHEMA: + tap_schema.addTable(coosysTable); + // load all declared coordinate systems from it: + mapCoosys = loadCoosys(coosysTable, metadata, stmt); } // load all columns from TAP_SCHEMA.columns: @@ -1156,7 +1162,7 @@ public class JDBCConnection implements DBConnection { close(rs); } } - + /** * Load all coordinate systems declared in the TAP_SCHEMA. * @@ -1171,7 +1177,7 @@ public class JDBCConnection implements DBConnection { * * @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; try{ // Build the SQL query: @@ -1187,15 +1193,14 @@ public class JDBCConnection implements DBConnection { rs = stmt.executeQuery(sqlBuf.toString()); // Create all coosys: - HashMap<String, TAPCoosys> mapCoosys = new HashMap<String, TAPCoosys>(); + HashMap<String,TAPCoosys> mapCoosys = new HashMap<String,TAPCoosys>(); while(rs.next()){ - String coosysId = rs.getString(1), - system = rs.getString(2), equinox = rs.getString(3), - epoch = rs.getString(4); + String coosysId = rs.getString(1), system = rs.getString(2), + equinox = rs.getString(3), epoch = rs.getString(4); // create the new coosys: TAPCoosys newCoosys = new TAPCoosys(coosysId, system, nullifyIfNeeded(equinox), nullifyIfNeeded(epoch)); - + // create and add the new coosys: metadata.addCoosys(newCoosys); mapCoosys.put(coosysId, newCoosys); @@ -1210,8 +1215,6 @@ public class JDBCConnection implements DBConnection { close(rs); } } - - /** * <p>Load into the corresponding tables all columns listed in TAP_SCHEMA.columns.</p> @@ -1233,7 +1236,7 @@ public class JDBCConnection implements DBConnection { * @throws DBException If a table can not be found, or if any other error occurs while interacting with the database. * * @deprecated This method is now replaced by {@link #loadColumns(TAPTable, List, Map, Statement)} which has an additional parameter: - * the list of declared coordinate systems. + * the list of declared coordinate systems. */ @Deprecated protected void loadColumns(final TAPTable tableDef, final List<TAPTable> lstTables, final Statement stmt) throws DBException{ @@ -1262,7 +1265,7 @@ public class JDBCConnection implements DBConnection { * * @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; try{ // Determine whether the dbName column exists: @@ -1354,10 +1357,10 @@ public class JDBCConnection implements DBConnection { newColumn.setStd(std); newColumn.setDBName(dbName); newColumn.setIndex(colIndex); - + // set the coordinate system if any is specified: if (hasCoosys){ - int indCoosys = 12; + int indCoosys = 12; if (hasColumnIndex) indCoosys++; if (hasDBName) @@ -1366,7 +1369,7 @@ public class JDBCConnection implements DBConnection { if (coosysId != null){ newColumn.setCoosys(mapCoosys.get(coosysId)); if (logger != null && newColumn.getCoosys() == null) - logger.logDB(LogLevel.WARNING, this, "LOAD_TAP_SCHEMA", "No coordinate system for the column \""+columnName+"\"! Cause: unknown coordinate system: \""+coosysId+"\".", null); + logger.logDB(LogLevel.WARNING, this, "LOAD_TAP_SCHEMA", "No coordinate system for the column \"" + columnName + "\"! Cause: unknown coordinate system: \"" + coosysId + "\".", null); } } diff --git a/src/tap/metadata/TAPMetadata.java b/src/tap/metadata/TAPMetadata.java index 107dd35..01b5d90 100644 --- a/src/tap/metadata/TAPMetadata.java +++ b/src/tap/metadata/TAPMetadata.java @@ -38,6 +38,7 @@ import javax.servlet.http.HttpServletResponse; import adql.db.DBTable; import adql.db.DBType; import adql.db.DBType.DBDatatype; +import tap.db.JDBCConnection; import tap.metadata.TAPTable.TableType; import tap.resource.Capabilities; import tap.resource.TAPResource; @@ -892,6 +893,23 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour return tap_schema; } + /** + * Get the minimum definition of the table TAP_SCHEMA.coosys as expected by + * the library (see {@link JDBCConnection#getTAPSchema()}. + * + * @return The created definition of TAP_SCHEMA.coosys. + * + * @since 2.1 + */ + public static final TAPTable getCoosysTable(){ + TAPTable coosys = new TAPTable(STDSchema.TAPSCHEMA + ".coosys", TableType.table, "List of coordinate systems of coordinate columns published in this TAP service.", null); + coosys.addColumn("id", new DBType(DBDatatype.VARCHAR), "ID of the coordinate system definition as it must be in the VOTable.", null, null, null, true, true, false); + coosys.addColumn("system", new DBType(DBDatatype.VARCHAR), "The coordinate system (among \"ICRS\", \"eq_FK5\", \"eq_FK4\", \"ecl_FK4\", \"ecl_FK5\", \"galactic\", \"supergalactic\", \"xy\", \"barycentric\", \"geo_app\").", null, null, null, false, false, false); + coosys.addColumn("equinox", new DBType(DBDatatype.VARCHAR), "Required to fix the equatorial or ecliptic systems (as e.g. \"J2000\" as the default for \"eq_FK5\" or \"B1950\" as the default for \"eq_FK4\").", null, null, null, false, false, false); + coosys.addColumn("epoch", new DBType(DBDatatype.VARCHAR), "Epoch of the positions (if necessary).", null, null, null, false, false, false); + return coosys; + } + /** * <p>Get the definition of the specified standard TAP table.</p> * @@ -931,14 +949,6 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour tables.addColumn("utype", new DBType(DBDatatype.VARCHAR), "UTYPE if table corresponds to a data model", null, null, null, false, false, true); return tables; - case COOSYS: - TAPTable coosys = new TAPTable(STDSchema.TAPSCHEMA + "." + STDTable.COOSYS, TableType.table, "List of coordinate systems of coordinate columns published in this TAP service.", null); - coosys.addColumn("id", new DBType(DBDatatype.VARCHAR), "ID of the coordinate system definition as it must be in the VOTable.", null, null, null, true, true, false); - coosys.addColumn("system", new DBType(DBDatatype.VARCHAR), "The coordinate system (among \"ICRS\", \"eq_FK5\", \"eq_FK4\", \"ecl_FK4\", \"ecl_FK5\", \"galactic\", \"supergalactic\", \"xy\", \"barycentric\", \"geo_app\").", null, null, null, false, false, false); - coosys.addColumn("equinox", new DBType(DBDatatype.VARCHAR), "Required to fix the equatorial or ecliptic systems (as e.g. \"J2000\" as the default for \"eq_FK5\" or \"B1950\" as the default for \"eq_FK4\").", null, null, null, false, false, false); - coosys.addColumn("epoch", new DBType(DBDatatype.VARCHAR), "Epoch of the positions (if necessary).", null, null, null, false, false, false); - return coosys; - case COLUMNS: TAPTable columns = new TAPTable(STDSchema.TAPSCHEMA + "." + STDTable.COLUMNS, TableType.table, "List of columns of all tables listed in TAP_SCHEMA.TABLES and published in this TAP service.", null); columns.addColumn("column_index", new DBType(DBDatatype.INTEGER), "this index is used to recommend column ordering for clients", null, null, null, false, false, true); @@ -954,7 +964,6 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour columns.addColumn("indexed", new DBType(DBDatatype.INTEGER), "an indexed column; 1 means true, 0 means false", null, null, null, false, false, true); columns.addColumn("principal", new DBType(DBDatatype.INTEGER), "a principal column; 1 means true, 0 means false", null, null, null, false, false, true); columns.addColumn("std", new DBType(DBDatatype.INTEGER), "a standard column; 1 means true, 0 means false", null, null, null, false, false, true); - columns.addColumn("coosys_id", new DBType(DBDatatype.VARCHAR), "ID of the used coordinate systems (if any).", null, null, null, false, false, false); return columns; case KEYS: @@ -1031,14 +1040,11 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour * Enumeration of all tables of TAP_SCHEMA. * * @author Grégory Mantelet (ARI) - * @version 2.1 (07/2017) + * @version 2.1 (09/2017) * @since 2.0 */ public enum STDTable{ - SCHEMAS("schemas"), TABLES("tables"), COLUMNS("columns"), KEYS("keys"), KEY_COLUMNS("key_columns"), - /** Non standard table but anyway expected by this library in order to associated coordinate columns with a coordinate system. - * @since 2.1 */ - COOSYS("coosys"); + SCHEMAS("schemas"), TABLES("tables"), COLUMNS("columns"), KEYS("keys"), KEY_COLUMNS("key_columns"); /** Real name of the table. */ public final String label; -- GitLab