Skip to content
Snippets Groups Projects
Commit 26cee66c authored by gmantele's avatar gmantele
Browse files

[TAP] Add support for schema_index in TAP_SCHEMA.schemas.

Commit following 6fc7f8fd.
parent 484ce70e
No related branches found
No related tags found
No related merge requests found
...@@ -885,17 +885,25 @@ public class JDBCConnection implements DBConnection { ...@@ -885,17 +885,25 @@ public class JDBCConnection implements DBConnection {
/* note: if the schema notion is not supported by this DBMS, the column "dbname" is ignored. */ /* note: if the schema notion is not supported by this DBMS, the column "dbname" is ignored. */
boolean hasDBName = supportsSchema && isColumnExisting(tableDef.getDBSchemaName(), tableDef.getDBName(), DB_NAME_COLUMN, connection.getMetaData()); boolean hasDBName = supportsSchema && isColumnExisting(tableDef.getDBSchemaName(), tableDef.getDBName(), DB_NAME_COLUMN, connection.getMetaData());
// Determine whether the schemaIndex column exists:
boolean hasSchemaIndex = isColumnExisting(tableDef.getDBSchemaName(), tableDef.getDBName(), "schema_index", connection.getMetaData());
// Build the SQL query: // Build the SQL query:
StringBuffer sqlBuf = new StringBuffer("SELECT "); StringBuffer sqlBuf = new StringBuffer("SELECT ");
sqlBuf.append(translator.getColumnName(tableDef.getColumn("schema_name"))); sqlBuf.append(translator.getColumnName(tableDef.getColumn("schema_name")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("description"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("description")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("utype"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("utype")));
if (hasSchemaIndex)
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("schema_index")));
if (hasDBName){ if (hasDBName){
sqlBuf.append(", "); sqlBuf.append(", ");
translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN); translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN);
} }
sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema)); sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema));
sqlBuf.append(" ORDER BY 1"); if (hasSchemaIndex)
sqlBuf.append(" ORDER BY 1,4,2");
else
sqlBuf.append(" ORDER BY 1");
// Execute the query: // Execute the query:
rs = stmt.executeQuery(sqlBuf.toString()); rs = stmt.executeQuery(sqlBuf.toString());
...@@ -904,12 +912,14 @@ public class JDBCConnection implements DBConnection { ...@@ -904,12 +912,14 @@ public class JDBCConnection implements DBConnection {
while(rs.next()){ while(rs.next()){
String schemaName = rs.getString(1), String schemaName = rs.getString(1),
description = rs.getString(2), utype = rs.getString(3), description = rs.getString(2), utype = rs.getString(3),
dbName = (hasDBName ? rs.getString(4) : null); dbName = (hasDBName ? (hasSchemaIndex ? rs.getString(5) : rs.getString(4)) : null);
int schemaIndex = (hasSchemaIndex ? (rs.getObject(4) == null ? -1 : rs.getInt(4)) : -1);
// create the new schema: // create the new schema:
TAPSchema newSchema = new TAPSchema(schemaName, nullifyIfNeeded(description), nullifyIfNeeded(utype)); TAPSchema newSchema = new TAPSchema(schemaName, nullifyIfNeeded(description), nullifyIfNeeded(utype));
if (dbName != null && dbName.trim().length() > 0) if (dbName != null && dbName.trim().length() > 0)
newSchema.setDBName(dbName); newSchema.setDBName(dbName);
newSchema.setIndex(schemaIndex);
// add the new schema inside the given metadata: // add the new schema inside the given metadata:
metadata.addSchema(newSchema); metadata.addSchema(newSchema);
...@@ -965,15 +975,15 @@ public class JDBCConnection implements DBConnection { ...@@ -965,15 +975,15 @@ public class JDBCConnection implements DBConnection {
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("table_type"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("table_type")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("description"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("description")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("utype"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("utype")));
if (hasTableIndex)
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("table_index")));
if (hasDBName){ if (hasDBName){
sqlBuf.append(", "); sqlBuf.append(", ");
translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN); translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN);
} }
if (hasTableIndex)
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("table_index")));
sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema)); sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema));
if (hasTableIndex) if (hasTableIndex)
sqlBuf.append(" ORDER BY 1,7,2"); sqlBuf.append(" ORDER BY 1,6,2");
else else
sqlBuf.append(" ORDER BY 1,2"); sqlBuf.append(" ORDER BY 1,2");
sqlBuf.append(';'); sqlBuf.append(';');
...@@ -987,8 +997,8 @@ public class JDBCConnection implements DBConnection { ...@@ -987,8 +997,8 @@ public class JDBCConnection implements DBConnection {
String schemaName = rs.getString(1), String schemaName = rs.getString(1),
tableName = rs.getString(2), typeStr = rs.getString(3), tableName = rs.getString(2), typeStr = rs.getString(3),
description = rs.getString(4), utype = rs.getString(5), description = rs.getString(4), utype = rs.getString(5),
dbName = (hasDBName ? rs.getString(6) : null); dbName = (hasDBName ? (hasTableIndex ? rs.getString(7) : rs.getString(6)) : null);
int tableIndex = (hasTableIndex ? (rs.getObject(7) == null ? -1 : rs.getInt(7)) : -1); int tableIndex = (hasTableIndex ? (rs.getObject(6) == null ? -1 : rs.getInt(6)) : -1);
// get the schema: // get the schema:
TAPSchema schema = metadata.getSchema(schemaName); TAPSchema schema = metadata.getSchema(schemaName);
...@@ -1086,15 +1096,15 @@ public class JDBCConnection implements DBConnection { ...@@ -1086,15 +1096,15 @@ public class JDBCConnection implements DBConnection {
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("principal"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("principal")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("indexed"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("indexed")));
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("std"))); sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("std")));
if (hasColumnIndex)
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("column_index")));
if (hasDBName){ if (hasDBName){
sqlBuf.append(", "); sqlBuf.append(", ");
translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN); translator.appendIdentifier(sqlBuf, DB_NAME_COLUMN, IdentifierField.COLUMN);
} }
if (hasColumnIndex)
sqlBuf.append(", ").append(translator.getColumnName(tableDef.getColumn("column_index")));
sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema)); sqlBuf.append(" FROM ").append(translator.getTableName(tableDef, supportsSchema));
if (hasColumnIndex) if (hasColumnIndex)
sqlBuf.append(" ORDER BY 1,13,2"); sqlBuf.append(" ORDER BY 1,12,2");
else else
sqlBuf.append(" ORDER BY 1,2"); sqlBuf.append(" ORDER BY 1,2");
sqlBuf.append(';'); sqlBuf.append(';');
...@@ -1109,9 +1119,9 @@ public class JDBCConnection implements DBConnection { ...@@ -1109,9 +1119,9 @@ public class JDBCConnection implements DBConnection {
description = rs.getString(3), unit = rs.getString(4), description = rs.getString(3), unit = rs.getString(4),
ucd = rs.getString(5), utype = rs.getString(6), ucd = rs.getString(5), utype = rs.getString(6),
datatype = rs.getString(7), datatype = rs.getString(7),
dbName = (hasDBName ? rs.getString(12) : null); dbName = (hasDBName ? (hasColumnIndex ? rs.getString(13) : rs.getString(12)) : null);
int size = rs.getInt(8), int size = rs.getInt(8),
colIndex = (hasColumnIndex ? (rs.getObject(13) == null ? -1 : rs.getInt(13)) : -1); colIndex = (hasColumnIndex ? (rs.getObject(12) == null ? -1 : rs.getInt(12)) : -1);
boolean principal = toBoolean(rs.getObject(9)), boolean principal = toBoolean(rs.getObject(9)),
indexed = toBoolean(rs.getObject(10)), indexed = toBoolean(rs.getObject(10)),
std = toBoolean(rs.getObject(11)); std = toBoolean(rs.getObject(11));
......
...@@ -828,6 +828,7 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour ...@@ -828,6 +828,7 @@ public class TAPMetadata implements Iterable<TAPSchema>, VOSIResource, TAPResour
case SCHEMAS: case SCHEMAS:
TAPTable schemas = new TAPTable(STDSchema.TAPSCHEMA + "." + STDTable.SCHEMAS, TableType.table, "List of schemas published in this TAP service.", null); TAPTable schemas = new TAPTable(STDSchema.TAPSCHEMA + "." + STDTable.SCHEMAS, TableType.table, "List of schemas published in this TAP service.", null);
schemas.addColumn("schema_index", new DBType(DBDatatype.INTEGER), "this index is used to recommend schema ordering for clients", null, null, null, false, false, true);
schemas.addColumn("schema_name", new DBType(DBDatatype.VARCHAR), "schema name, possibly qualified", null, null, null, true, true, true); schemas.addColumn("schema_name", new DBType(DBDatatype.VARCHAR), "schema name, possibly qualified", null, null, null, true, true, true);
schemas.addColumn("description", new DBType(DBDatatype.VARCHAR), "brief description of schema", null, null, null, true, false, true); schemas.addColumn("description", new DBType(DBDatatype.VARCHAR), "brief description of schema", null, null, null, true, false, true);
schemas.addColumn("utype", new DBType(DBDatatype.VARCHAR), "UTYPE if schema corresponds to a data model", null, null, null, false, false, true); schemas.addColumn("utype", new DBType(DBDatatype.VARCHAR), "UTYPE if schema corresponds to a data model", null, null, null, false, false, true);
......
...@@ -75,6 +75,11 @@ public class TAPSchema implements Iterable<TAPTable> { ...@@ -75,6 +75,11 @@ public class TAPSchema implements Iterable<TAPTable> {
* <i>Note: Standard TAP schema field ; MAY be NULL.</i> */ * <i>Note: Standard TAP schema field ; MAY be NULL.</i> */
private String utype = null; private String utype = null;
/** Ordering index of this schema inside its whole schema set.
* <i>Note: SHOULD be a standard TAP schema field in TAP 1.1, as table_index and column_index are resp. in TAP_SCHEMA.tables and TAP_SCHEMA.columns.</i>
* @since 2.1 */
private int index = -1;
/** Let add some information in addition of the ones of the TAP protocol. /** Let add some information in addition of the ones of the TAP protocol.
* <i>Note: This object can be anything: an {@link Integer}, a {@link String}, a {@link Map}, a {@link List}, ... * <i>Note: This object can be anything: an {@link Integer}, a {@link String}, a {@link Map}, a {@link List}, ...
* Its content is totally free and never used or checked.</i> */ * Its content is totally free and never used or checked.</i> */
...@@ -319,6 +324,28 @@ public class TAPSchema implements Iterable<TAPTable> { ...@@ -319,6 +324,28 @@ public class TAPSchema implements Iterable<TAPTable> {
this.utype = utype; this.utype = utype;
} }
/**
* Get the ordering index of this schema inside its whole schema set.
*
* @return Its ordering index.
*
* @since 2.1
*/
public final int getIndex(){
return index;
}
/**
* Set the ordering index of this schema inside its whole schema set.
*
* @param schemaIndex Its new ordering index.
*
* @since 2.1
*/
public final void setIndex(int schemaIndex){
this.index = schemaIndex;
}
/** /**
* <p>Get the other (piece of) information associated with this schema.</p> * <p>Get the other (piece of) information associated with this schema.</p>
* *
......
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