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

Support for datatype both in ADQL and VOTable format, datatype property is now...

Support for datatype both in ADQL and VOTable format, datatype property is now editable showing a warning if the inserted value is different from the suggested value
parent 8f95d727
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@
 */
package it.inaf.ia2.tsm;

import it.inaf.ia2.tsm.model.TableModel;
import it.inaf.ia2.tsm.model.TypesMapping;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -65,22 +63,6 @@ public class Column extends ChildEntity<Table> {
        setStatus(Status.LOADED);
    }

    private void overrideDataTypeFromModels() {

        Schema parentSchema = parentTable.getParent();
        String type = null;

        if (tapSchema.getName().equals(parentSchema.getName())) {
            TableModel tableModel = tapSchema.getTapSchemaModel().getTable(parentTable.getName());
            type = tableModel.get(getName()).getType();
        }

        if (type != null) {
            String compatibleType = TypesMapping.getCompatibleADQLType(type, tapSchema.getVersion());
            getProperty(DATATYPE_KEY).init(compatibleType);
        }
    }

    public Key getForeignKey() {
        if (!foreignKeySearched) { // lazy loading (but the foreignKey value can be null, so we use this boolean)

+6 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class EntityProperty<T> implements Serializable {

    private ColumnModel propertyModel;
    private Class<T> type;
    private T defaultValue;
    private T originalValue;
    private T value;
    private boolean changed;
@@ -47,6 +48,7 @@ public class EntityProperty<T> implements Serializable {
    public EntityProperty(ColumnModel propertyModel, T defaultValue) {
        this.propertyModel = propertyModel;
        this.type = propertyModel.getJavaType();
        this.defaultValue = defaultValue;
        this.init(defaultValue);
    }

@@ -68,6 +70,10 @@ public class EntityProperty<T> implements Serializable {
        return originalValue;
    }

    public T getDefaultValue() {
        return defaultValue;
    }

    public <X> X getOriginalValue(Class<X> type) {
        return (X) originalValue;
    }
+40 −34
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ package it.inaf.ia2.tsm;
import it.inaf.ia2.tsm.datalayer.DBBroker;
import it.inaf.ia2.tsm.datalayer.DBBrokerFactory;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import it.inaf.ia2.tsm.datalayer.DataTypeMode;
import it.inaf.ia2.tsm.model.ColumnModel;
import it.inaf.ia2.tsm.model.TableModel;
import it.inaf.ia2.tsm.model.SchemaModel;
@@ -68,24 +69,22 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    private boolean loading;
    private DBWrapper dbWrapper;
    private boolean exists;
    private String tapSchemaVersion;
    private String tapSchemaName;
    private boolean obscore;
    private String obscoreVersion;
    private TapSchemaSettings settings;
    private DataTypeMode dataTypeMode;

    private transient DBBroker sourceDBBroker;
    private transient DBBroker tapSchemaDBBroker;

    public final DBBroker getSourceDBBroker() {
        if (sourceDBBroker == null) {
            sourceDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getSourceDataSourceWrapper(), tapSchemaVersion);
            sourceDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getSourceDataSourceWrapper(), dataTypeMode);
        }
        return sourceDBBroker;
    }

    public final DBBroker getTapSchemaDBBroker() {
        if (tapSchemaDBBroker == null) {
            tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), tapSchemaVersion);
            tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), dataTypeMode);
        }
        return tapSchemaDBBroker;
    }
@@ -103,16 +102,15 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        loading = true;
        this.dbWrapper = dbWrapper;
        this.exists = exists;
        this.tapSchemaVersion = settings.getTapSchemaVersion();
        this.tapSchemaName = settings.getTapSchemaName();
        this.obscore = settings.isHasObscore();
        this.obscoreVersion = settings.getObscoreVersion();
        this.settings = settings;

        dataTypeMode = getTapSchemaModel().getDataTypeMode();

        // Initializing schemas map
        for (String schemaName : getSourceDBBroker().getAllSchemaNames()) {
            schemas.put(schemaName, null);
        }
        schemas.put(tapSchemaName, null); // the TAP_SCHEMA contains itself
        schemas.put(settings.getTapSchemaName(), null); // the TAP_SCHEMA contains itself

        if (exists) {
            loadSavedTapSchema();
@@ -282,7 +280,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    }

    public DBBroker getDBBroker(String schemaName) {
        if (schemaName.equals(tapSchemaName)) {
        if (schemaName.equals(getName())) {
            return getTapSchemaDBBroker();
        } else {
            return getSourceDBBroker();
@@ -293,14 +291,18 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
     * The name of the TAP_SCHEMA schema.
     */
    public final String getName() {
        return tapSchemaName;
        return settings.getTapSchemaName();
    }

    /**
     * The version selected for this TAP_SCHEMA.
     */
    public String getVersion() {
        return tapSchemaVersion;
        return settings.getTapSchemaVersion();
    }

    public DataTypeMode getDataTypeMode() {
        return dataTypeMode;
    }

    private void loadSchemaKeysMetadata(String schemaName) throws SQLException {
@@ -428,8 +430,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    }

    public SchemaModel getIvoaSchemaModel() {
        if (obscore) {
            return SchemaModels.getIvoaSchemaModel(obscoreVersion);
        if (settings.isHasObscore()) {
            return SchemaModels.getIvoaSchemaModel(settings.getObscoreVersion());
        }
        return null;
    }
@@ -453,13 +455,13 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {

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

            // Adding TAP_SCHEMA into TAP_SCHEMA
            addEntireSchema(tapSchemaName);
            fillColumnProperties(tapSchemaModel, tapSchemaName);
            addEntireSchema(getName());
            fillColumnProperties(tapSchemaModel, getName());

            if (obscore) {
            if (settings.isHasObscore()) {
                SchemaModel ivoaSchemaModel = getIvoaSchemaModel();

                // ivoa schema has to be created into source database
@@ -561,7 +563,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {

        StringBuilder sb = new StringBuilder("\n");

        sb.append(String.format(">> TAP_SCHEMA %s <<\n", tapSchemaName));
        sb.append(String.format(">> TAP_SCHEMA %s <<\n", getName()));

        for (Schema schema : getChildren()) {
            sb.append("--");
@@ -655,8 +657,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        return consistencyChecks;
    }

    public SchemaModel getTapSchemaModel() {
        return SchemaModels.getTapSchemaModel(tapSchemaVersion);
    public final SchemaModel getTapSchemaModel() {
        return SchemaModels.getTapSchemaModel(getVersion());
    }

    public final TableModel getTableModel(String tableName) {
@@ -687,7 +689,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    }

    public boolean isHasObscore() {
        return obscore;
        return settings.isHasObscore();
    }

    /**
@@ -704,15 +706,19 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        for (TableModel tableModel : schemaModel.getTables()) {
            Table table = schema.getChild(tableModel.getName());
            table.setValue(DESCRIPTION_KEY, tableModel.getDescription());
            for (ColumnModel propertyModel : tableModel.getColumns()) {
                Column column = table.getChild(propertyModel.getName());
                column.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
                column.setValue(Column.UCD_KEY, propertyModel.getUcd());
                column.setValue(Column.UNIT_KEY, propertyModel.getUnit());
                column.setValue(Column.UTYPE_KEY, propertyModel.getUtype());

                Object compatibleStd = useIntegerAsBool ? getIntAsBool(propertyModel.isStandard()) : propertyModel.isStandard();
                Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(propertyModel.isPrincipal()) : propertyModel.isPrincipal();
            for (ColumnModel columnModel : tableModel.getColumns()) {
                Column column = table.getChild(columnModel.getName());
                if (!columnModel.isMandatory() && column == null) {
                    // column could be null if it is not mandatory
                    continue;
                }
                column.setValue(DESCRIPTION_KEY, columnModel.getDescription());
                column.setValue(Column.UCD_KEY, columnModel.getUcd());
                column.setValue(Column.UNIT_KEY, columnModel.getUnit());
                column.setValue(Column.UTYPE_KEY, columnModel.getUtype());

                Object compatibleStd = useIntegerAsBool ? getIntAsBool(columnModel.isStandard()) : columnModel.isStandard();
                Object compatiblePrincipal = useIntegerAsBool ? getIntAsBool(columnModel.isPrincipal()) : columnModel.isPrincipal();
                column.setValue(Column.STD_KEY, compatibleStd);
                column.setValue(Column.PRINCIPAL_KEY, compatiblePrincipal);
            }
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
 */
package it.inaf.ia2.tsm;

import it.inaf.ia2.tsm.datalayer.DataTypeMode;
import java.io.Serializable;

/**
+19 −6
Original line number Diff line number Diff line
@@ -29,18 +29,31 @@ package it.inaf.ia2.tsm.datalayer;
 */
public enum ADQL {

    INTEGER,
    VARCHAR,
    CHAR,
    BOOLEAN,
    SMALLINT,
    INTEGER,
    BIGINT,
    REAL,
    DOUBLE,
    BOOLEAN,
    CHAR,
    TIMESTAMP,
    CLOB,
    VARCHAR,
    TIMESTAMP;
    BLOB,
    BINARY,
    VARBINARY,
    REGION,
    POINT;

    /**
     * For not standard types
     */
    public static String getDataType(String dataType) {
        return dataType.toUpperCase();
        // removing size from datatype.
        return dataType.toUpperCase().replaceAll("\\(.+\\)", "");
    }

    public static boolean isVariable(ADQL adql) {
        return adql.equals(VARCHAR) || adql.equals(VARBINARY);
    }
}
Loading