Commit e258024b authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Supported dbname column, for compatibility with taplib.

parent 06003c06
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
    <modelVersion>4.0.0</modelVersion>
    <groupId>it.inaf.ia2.tap</groupId>
    <artifactId>tasman-core</artifactId>
    <version>1.3.1</version>
    <version>1.3.2</version>
    <packaging>jar</packaging>
    <name>tasman-core</name>
    <properties>
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public class Column extends ChildEntity<Table> {
    public final static String UCD_KEY = "ucd";
    public final static String UNIT_KEY = "unit";
    public final static String COLUMN_INDEX = "column_index"; // TAP version >= 1.1
    public final static String DBNAME = "dbname";

    // Original datatype (computed from information_schema data), used for consistency checking
    public final static String ORIGINAL_DATATYPE_KEY = "original_datatype";
+9 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<Table> {

    public final static String SCHEMA_NAME_KEY = "schema_name";
    public final static String DBNAME = "dbname";

    private static final long serialVersionUID = 8828583158332877855L;
    private static final Logger LOG = LoggerFactory.getLogger(Schema.class);
@@ -61,7 +62,7 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
        tables = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        tablesTypes = broker.getAllTableTypes(name);

        for (String tableName : broker.getAllTablesNames(name)) {
        for (String tableName : broker.getAllTablesNames(getRealSchemaName())) {
            tables.put(tableName, null);
        }
        LOG.debug("Schema {} contains {} tables", name, tables.size());
@@ -69,6 +70,13 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
        setStatus(Status.LOADED);
    }

    public String getRealSchemaName() {
        if (tapSchema.getDBName() != null && this.getName().equals(tapSchema.getName())) {
            return tapSchema.getDBName();
        }
        return getName();
    }

    /**
     * {@inheritDoc} The value in the {@code schema_name} column.
     */
+2 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
    public final static String SCHEMA_NAME_KEY = "schema_name";
    public final static String TABLE_NAME_KEY = "table_name";
    public final static String TABLE_TYPE_KEY = "table_type";
    public final static String DBNAME = "dbname";

    private static final long serialVersionUID = 8265331530960896871L;
    private static final Logger LOG = LoggerFactory.getLogger(Table.class);
@@ -98,7 +99,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu

        DBBroker broker = tapSchema.getDBBroker(schema.getName());
        tableTableModel = getTableTableModel();
        columnsMetadata = broker.getAllColumnsMetadata(schema.getName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode());
        columnsMetadata = broker.getAllColumnsMetadata(schema.getRealSchemaName(), tableSimpleName, tableTableModel, tapSchema.getDataTypeMode());
        fixIndexedMetadataValues();

        for (Map.Entry<String, Map<String, Object>> entry : columnsMetadata.entrySet()) {
+55 −4
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import org.slf4j.LoggerFactory;
 */
public class TapSchema implements EntitiesContainer<Schema>, Serializable {

    public static final String STANDARD_NAME = "TAP_SCHEMA";

    // Mandatory tables constants
    public static final String TABLES_TABLE = "tables";
    public static final String SCHEMAS_TABLE = "schemas";
@@ -65,6 +67,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {

    private boolean loading;
    private DBWrapper dbWrapper;
    private String dbName;
    private String name;
    private boolean exists;
    private TapSchemaSettings settings;
    private DataTypeMode dataTypeMode;
@@ -101,12 +105,32 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        this.dbWrapper = dbWrapper;
        this.exists = exists;
        this.settings = settings;
        // Don't change the instructions order!
        loadDBName();
        loadName();

        dataTypeMode = getTapSchemaModel().getDataTypeMode();

        load();
    }

    private void loadDBName() {
        // Detect if the TAP_SCHEMA version supports dbmodel
        SchemaModel tapSchemaModel = SchemaModels.getTapSchemaModel(settings.getTapSchemaVersion());
        boolean hasDBName = tapSchemaModel.getTable(SCHEMAS_TABLE).get("dbname") != null;
        if (hasDBName && !STANDARD_NAME.equals(settings.getTapSchemaName())) {
            dbName = settings.getTapSchemaName();
        }
    }

    private void loadName() {
        if (dbName != null) {
            name = STANDARD_NAME;
        } else {
            name = settings.getTapSchemaName();
        }
    }

    public final void load() throws SQLException {

        loading = true;
@@ -115,7 +139,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        for (String schemaName : getSourceDBBroker().getAllSchemaNames()) {
            schemas.put(schemaName, null);
        }
        schemas.put(settings.getTapSchemaName(), null); // the TAP_SCHEMA contains itself
        schemas.put(getName(), null); // the TAP_SCHEMA contains itself

        if (exists) {
            consistencyChecks = TapSchemaLoader.loadExistingTapSchema((this));
@@ -138,7 +162,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
     * The name of the TAP_SCHEMA schema.
     */
    public final String getName() {
        return settings.getTapSchemaName();
        return name;
    }

    /**
@@ -153,7 +177,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    }

    private void loadSchemaKeysMetadata(String schemaName) throws SQLException {
        allKeys.addAll(getDBBroker(schemaName).getKeys(this, schemaName));
        allKeys.addAll(getDBBroker(schemaName)
                .getKeys(this, schemaName, getRealSchemaName(schemaName)));
    }

    public Set<Key> getAllKeys() {
@@ -307,7 +332,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {

        if (!exists) {
            SchemaModel tapSchemaModel = getTapSchemaModel();
            broker.createTapSchemaStructure(getName(), tapSchemaModel);
            broker.createTapSchemaStructure(getRealName(), tapSchemaModel);

            // Adding TAP_SCHEMA into TAP_SCHEMA
            addEntireSchema(getName());
@@ -525,6 +550,11 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    public Map<String, Object> getSchemaMetadata(String schemaName) {
        Map<String, Object> metadata = new HashMap<>();
        metadata.put(Schema.SCHEMA_NAME_KEY, schemaName);
        String dbNameMetadata = null;
        if (dbName != null && schemaName.equals(STANDARD_NAME)) {
            dbNameMetadata = dbName;
        }
        metadata.put(Schema.DBNAME, dbNameMetadata);
        return metadata;
    }

@@ -585,4 +615,25 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    public void fillColumnsProperties(SchemaModel schemaModel) {
        fillColumnProperties(schemaModel, schemaModel.getName());
    }

    /**
     * Allows to name the TAP_SCHEMA using the standard name, but referring to a
     * differently named schema. This value is null if the TAP_SCHEMA version
     * doesn't support the dbname column or if the schema name is already the
     * standard value.
     */
    public String getDBName() {
        return dbName;
    }

    public String getRealName() {
        return getRealSchemaName(getName());
    }

    public String getRealSchemaName(String schemaName) {
        if (dbName != null && STANDARD_NAME.equals(schemaName)) {
            return dbName;
        }
        return schemaName;
    }
}
Loading