Commit 894886d6 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Supported renaming of ivoa schema name, fixed various bugs

parent e258024b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ public class Column extends ChildEntity<Table> {

    public final static String TABLE_NAME_KEY = "table_name";
    public final static String COLUMN_NAME_KEY = "column_name";
    public final static String DESCRIPTION_KEY = "description";
    public final static String DATATYPE_KEY = "datatype";
    public final static String SIZE_KEY = "size";
    public final static String ARRAYSIZE_KEY = "arraysize";
+5 −2
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
        DBBroker broker = tapSchema.getDBBroker(name);

        tables = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        tablesTypes = broker.getAllTableTypes(name);
        tablesTypes = broker.getAllTableTypes(getRealSchemaName());

        for (String tableName : broker.getAllTablesNames(getRealSchemaName())) {
            tables.put(tableName, null);
@@ -70,10 +70,13 @@ public class Schema extends ChildEntity<TapSchema> implements EntitiesContainer<
        setStatus(Status.LOADED);
    }

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

+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public class Table extends ChildEntity<Schema> implements EntitiesContainer<Colu
        if (tapSchema.getName().equals(parentSchema.getName())) {
            return tapSchema.getTapSchemaModel().getTable(simpleName);
        }
        if (tapSchema.isHasObscore() && parentSchema.getName().equals("ivoa")
        if (tapSchema.isHasObscore() && parentSchema.getName().equals(TapSchema.STANDARD_IVOA_SCHEMA_NAME)
                && simpleName.equals("obscore")) {
            return tapSchema.getIvoaSchemaModel().getTable(simpleName);
        }
+116 −90
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ import org.slf4j.LoggerFactory;
 */
public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    
    public static final String STANDARD_NAME = "TAP_SCHEMA";
    public static final String STANDARD_TAP_SCHEMA_NAME = "TAP_SCHEMA";
    public static final String STANDARD_IVOA_SCHEMA_NAME = "ivoa";

    // Mandatory tables constants
    public static final String TABLES_TABLE = "tables";
@@ -69,6 +70,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    private DBWrapper dbWrapper;
    private String dbName;
    private String name;
    private String ivoaSchemaDBName;
    private String ivoaSchemaName;
    private boolean exists;
    private TapSchemaSettings settings;
    private DataTypeMode dataTypeMode;
@@ -96,7 +99,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        // for serialization
        schemas = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        allKeys = new HashSet<>();
        //consistencyChecks = new ConsistencyChecks();
    }
    
    public TapSchema(DBWrapper dbWrapper, TapSchemaSettings settings, boolean exists) throws SQLException {
@@ -118,17 +120,27 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        // 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())) {
        if (hasDBName) {
            if (!STANDARD_TAP_SCHEMA_NAME.equals(settings.getTapSchemaName())) {
                dbName = settings.getTapSchemaName();
            }
            if (!STANDARD_IVOA_SCHEMA_NAME.equals(settings.getIvoaSchemaName())) {
                ivoaSchemaDBName = settings.getIvoaSchemaName();
            }
        }
    }
    
    private void loadName() {
        if (dbName != null) {
            name = STANDARD_NAME;
            name = STANDARD_TAP_SCHEMA_NAME;
        } else {
            name = settings.getTapSchemaName();
        }
        if (ivoaSchemaDBName != null) {
            ivoaSchemaName = STANDARD_IVOA_SCHEMA_NAME;
        } else {
            ivoaSchemaName = settings.getIvoaSchemaName();
        }
    }
    
    public final void load() throws SQLException {
@@ -140,6 +152,9 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
            schemas.put(schemaName, null);
        }
        schemas.put(getName(), null); // the TAP_SCHEMA contains itself
        if (settings.isHasObscore() && ivoaSchemaDBName != null) {
            schemas.put(getIvoaSchemaName(), null);
        }
        
        if (exists) {
            consistencyChecks = TapSchemaLoader.loadExistingTapSchema((this));
@@ -356,7 +371,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        SchemaModel ivoaSchemaModel = getIvoaSchemaModel();

        // ivoa schema has to be created into source database
        getSourceDBBroker().createIvoaSchemaStructure(ivoaSchemaModel);
        getSourceDBBroker().createIvoaSchemaStructure(ivoaSchemaModel, getRealSchemaName(ivoaSchemaModel.getName()));
        // Initializing ivoa schema slot in schemata maps
        schemas.put(ivoaSchemaModel.getName(), null);

@@ -388,7 +403,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        
        List<Key> newKeys = new ArrayList<>();
        for (Key key : allKeys) {
            if (key.isVisible()) {
            if (key.isVisible() && key.getId() == null) {
                newKeys.add(key);
            }
        }
@@ -396,7 +411,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        int maxKeyId = getMaxKeyId();
        for (Key newKey : newKeys) {
            maxKeyId++;
            newKey.setId(maxKeyId + "");
            newKey.setId(String.valueOf(maxKeyId));
        }
    }

@@ -551,7 +566,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        Map<String, Object> metadata = new HashMap<>();
        metadata.put(Schema.SCHEMA_NAME_KEY, schemaName);
        String dbNameMetadata = null;
        if (dbName != null && schemaName.equals(STANDARD_NAME)) {
        if (dbName != null && schemaName.equals(STANDARD_TAP_SCHEMA_NAME)) {
            dbNameMetadata = dbName;
        }
        metadata.put(Schema.DBNAME, dbNameMetadata);
@@ -626,14 +641,25 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        return dbName;
    }
    
    public String getIvoaSchemaDBName() {
        return ivoaSchemaDBName;
    }
    
    public String getIvoaSchemaName() {
        return ivoaSchemaName;
    }
    
    public String getRealName() {
        return getRealSchemaName(getName());
    }
    
    public String getRealSchemaName(String schemaName) {
        if (dbName != null && STANDARD_NAME.equals(schemaName)) {
        if (dbName != null && STANDARD_TAP_SCHEMA_NAME.equals(schemaName)) {
            return dbName;
        }
        if (ivoaSchemaDBName != null && STANDARD_IVOA_SCHEMA_NAME.equals(schemaName)) {
            return ivoaSchemaDBName;
        }
        return schemaName;
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -78,9 +78,9 @@ public class TapSchemaLoader {

    private void checkObscore() {
        if (tapSchema.isHasObscore()) {
            String ivoaSchemaName = tapSchema.getIvoaSchemaModel().getName();
            String ivoaSchemaName = tapSchema.getIvoaSchemaName();
            if (tapSchema.getChild(ivoaSchemaName) == null) {
                if (tapSchema.isAddable(ivoaSchemaName)) {
                if (tapSchema.isAddable(tapSchema.getRealSchemaName(ivoaSchemaName))) {
                    consistencyChecks.setObscoreToAdd(true);
                } else {
                    consistencyChecks.setMissingObscore(true);
@@ -94,7 +94,7 @@ public class TapSchemaLoader {
    private void checkModel(SchemaModel schemaModel) {

        String schemaName = schemaModel.getName();
        if ("tap_schema".equals(schemaName)) {
        if (TapSchema.STANDARD_TAP_SCHEMA_NAME.equals(schemaName)) {
            schemaName = tapSchema.getName();
        }

Loading