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

Started implementation of obscore creation

parent 9d856c18
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class EntityProperty<T> implements Serializable {

    public EntityProperty(PropertyModel propertyModel, T defaultValue) {
        this.propertyModel = propertyModel;
        this.type = propertyModel.getType();
        this.type = propertyModel.getJavaType();
        this.init(defaultValue);
    }

+57 −47
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ import it.inaf.ia2.tsm.datalayer.DBBrokerFactory;
import it.inaf.ia2.tsm.datalayer.DBWrapper;
import it.inaf.ia2.tsm.model.PropertyModel;
import it.inaf.ia2.tsm.model.TableModel;
import it.inaf.ia2.tsm.model.TapSchemaModel;
import it.inaf.ia2.tsm.model.TapSchemaModels;
import it.inaf.ia2.tsm.model.SchemaModel;
import it.inaf.ia2.tsm.model.SchemaModels;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -67,10 +67,12 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    private final ConsistencyChecks consistencyChecks;

    private boolean loading;
    private String version;
    private DBWrapper dbWrapper;
    private String tapSchemaName;
    private boolean exists;
    private String tapSchemaVersion;
    private String tapSchemaName;
    private boolean obscore;
    private String obscoreVersion;

    private transient DBBroker sourceDBBroker;
    private transient DBBroker tapSchemaDBBroker;
@@ -96,14 +98,16 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        consistencyChecks = new ConsistencyChecks();
    }

    public TapSchema(String version, DBWrapper dbWrapper, String tapSchemaName, boolean exists) throws SQLException {
    public TapSchema(DBWrapper dbWrapper, TapSchemaSettings settings, boolean exists) throws SQLException {
        this();

        loading = true;
        this.version = version;
        this.dbWrapper = dbWrapper;
        this.tapSchemaName = tapSchemaName;
        this.exists = exists;
        this.tapSchemaVersion = settings.getTapSchemaVersion();
        this.tapSchemaName = settings.getTapSchemaName();
        this.obscore = settings.isHasObscore();
        this.obscoreVersion = settings.getObscoreVersion();

        // Initializing schemas map
        for (String schemaName : getSourceDBBroker().getAllSchemaNames()) {
@@ -278,10 +282,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        }
    }

    public void addFictitiousKey(String fromTable, String[] fromColumns, String targetTable, String[] targetColumns) {
        // TODO
    }

    public DBBroker getDBBroker(String schemaName) {
        if (schemaName.equals(tapSchemaName)) {
            return getTapSchemaDBBroker();
@@ -301,7 +301,7 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
     * The version selected for this TAP_SCHEMA.
     */
    public String getVersion() {
        return version;
        return tapSchemaVersion;
    }

    private void loadSchemaKeysMetadata(String schemaName) throws SQLException {
@@ -428,6 +428,23 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        schemas.put(schemaName, null);
    }

    private SchemaModel getIvoaSchemaModel() {
        if (obscore) {
            return SchemaModels.getIvoaSchemaModel(obscoreVersion);
        }
        return null;
    }

    private void addEntireSchema(String schemaName) throws SQLException {
        Schema schema = addChild(schemaName);
        for (String tableName : schema.getAddableChildrenNames()) {
            Table table = schema.addChild(tableName);
            for (String columnName : table.getAddableChildrenNames()) {
                table.addChild(columnName);
            }
        }
    }

    /**
     * Save or update the TAP_SCHEMA changes into the database.
     */
@@ -436,18 +453,22 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        DBBroker broker = getTapSchemaDBBroker();

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

            // Adding TAP_SCHEMA into TAP_SCHEMA
            Schema tapSchemaSchema = addChild(tapSchemaName);
            for (String tableName : tapSchemaSchema.getAddableChildrenNames()) {
                Table table = tapSchemaSchema.addChild(tableName);
                for (String columnName : table.getAddableChildrenNames()) {
                    table.addChild(columnName);
                }
            }
            addEntireSchema(tapSchemaName);
            fillColumnDescriptionsAndStd(tapSchemaModel, tapSchemaName);

            if (obscore) {
                SchemaModel ivoaSchemaModel = getIvoaSchemaModel();

                broker.createIvoaSchemaStructure(ivoaSchemaModel);

            fillTapSchemaDescriptions();
                // Add ivoa schema into TAP_SCHEMA
                addEntireSchema(ivoaSchemaModel.getName());
                fillColumnDescriptionsAndStd(ivoaSchemaModel);
            }
        }

        fillKeyIds();
@@ -493,20 +514,6 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        }
    }

//    public void addFictitiousKey(Table fromTable, String[] fromColumns, Table targetTable, String[] targetColumns) {
//        Key key = new Key(dbWrapper, this, fromTable.getCompleteName(), targetTable.getCompleteName());
//        key.setId((getMaxKeyId() + 1) + "");
//
//        for (int i = 0; i < fromColumns.length; i++) {
//            key.addKeyColumn(fromColumns[i], targetColumns[i]);
//        }
//
//        fromTable.addFromKey(key);
//        targetTable.addTargetKey(key);
//
//        allKeys.add(key);
//        checkKeys();
//    }
    /**
     * Set keys visibility based on other entities visibility (a key is visible
     * if all schemas, tables and columns involved have
@@ -646,8 +653,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
        return consistencyChecks;
    }

    public TapSchemaModel getTapSchemaModel() {
        return TapSchemaModels.getTapSchemaModel(version);
    public SchemaModel getTapSchemaModel() {
        return SchemaModels.getTapSchemaModel(tapSchemaVersion);
    }

    public final TableModel getTableModel(String tableName) {
@@ -671,23 +678,26 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
    }

    /**
     * Fill descriptions of the TAP_SCHEMA schema entities.
     * Fill descriptions of the TAP_SCHEMA schema entities for a given
     * SchemaModel (TAP_SCHEMA or ivoa).
     */
    private void fillTapSchemaDescriptions() {
        TapSchemaModel tapSchemaModel = getTapSchemaModel();
        boolean hasStd = tapSchemaModel.get(TapSchema.COLUMNS_TABLE).get(STD_KEY) != null;
        Schema tapSchema = getChild(tapSchemaName);
        tapSchema.setValue(DESCRIPTION_KEY, tapSchemaModel.getDescription());
    private void fillColumnDescriptionsAndStd(SchemaModel schemaModel, String schemaName) {
        Schema schema = getChild(schemaName);
        schema.setValue(DESCRIPTION_KEY, schemaModel.getDescription());
        for (TableModel tableModel : getTapSchemaModel().getTables().values()) {
            Table table = tapSchema.getChild(tableModel.getName());
            tapSchema.setValue(DESCRIPTION_KEY, tableModel.getDescription());
            Table table = schema.getChild(tableModel.getName());
            schema.setValue(DESCRIPTION_KEY, tableModel.getDescription());
            for (PropertyModel propertyModel : tableModel.getProperties().values()) {
                Column column = table.getChild(propertyModel.getName());
                tapSchema.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
                if (hasStd) {
                schema.setValue(DESCRIPTION_KEY, propertyModel.getDescription());
                if (propertyModel.isStandard()) {
                    column.setValue(STD_KEY, 1);
                }
            }
        }
    }

    private void fillColumnDescriptionsAndStd(SchemaModel schemaModel) {
        fillColumnDescriptionsAndStd(schemaModel, schemaModel.getName());
    }
}
+10 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ package it.inaf.ia2.tsm;

import it.inaf.ia2.tsm.model.PropertyModel;
import it.inaf.ia2.tsm.model.TableModel;
import it.inaf.ia2.tsm.model.TypesMapping;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
@@ -68,15 +69,19 @@ public abstract class TapSchemaEntity implements Serializable {
            Object defaultValue = null;
            if (propModel.getLoaderKey() != null) {
                defaultValue = metadata.get(propModel.getLoaderKey());
                if (defaultValue != null && propModel.getType() != defaultValue.getClass()) {

                if (defaultValue != null) {
                    // Special case for boolean to integer conversion
                    if (defaultValue.getClass() == Boolean.class && propModel.getType() == Integer.class) {
                    Class javaType = propModel.getJavaType();
                    if (javaType != defaultValue.getClass()) {
                        if (defaultValue.getClass() == Boolean.class && javaType == Integer.class) {
                            defaultValue = ((Boolean) defaultValue) ? 1 : 0;
                        } else {
                            throw new UnsupportedOperationException("Unable to convert " + defaultValue.getClass().getCanonicalName() + " into " + propModel.getType());
                        }
                    }
                }
            }
            EntityProperty ep = new EntityProperty(propModel, defaultValue);
            this.properties.put(propModel.getName(), ep);
        }
+41 −22
Original line number Diff line number Diff line
@@ -20,33 +20,52 @@
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package it.inaf.ia2.tsm.model;
package it.inaf.ia2.tsm;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.io.Serializable;

/**
 *
 * @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
 */
public class Tasman {
public class TapSchemaSettings implements Serializable {

    public static final String[] XML_MODEL_FILES;
    private static final long serialVersionUID = -4152480696306984772L;

    static {
        try (InputStream in = Tasman.class.getClassLoader().getResourceAsStream("core.properties")) {
            Properties props = new Properties();
            props.load(in);
            String[] models = props.getProperty("models").split(",");
            XML_MODEL_FILES = new String[models.length];
            for (int i = 0; i < models.length; i++) {
                String suffix = models[i];
                XML_MODEL_FILES[i] = "tap_schema" + File.separator + "tap_schema-" + suffix + ".xml";
    private String tapSchemaVersion;
    private String tapSchemaName;
    private boolean hasObscore;
    private String obscoreVersion;

    public String getTapSchemaVersion() {
        return tapSchemaVersion;
    }

    public void setTapSchemaVersion(String tapSchemaVersion) {
        this.tapSchemaVersion = tapSchemaVersion;
    }
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);

    public String getTapSchemaName() {
        return tapSchemaName;
    }

    public void setTapSchemaName(String tapSchemaName) {
        this.tapSchemaName = tapSchemaName;
    }

    public boolean isHasObscore() {
        return hasObscore;
    }

    public void setHasObscore(boolean hasObscore) {
        this.hasObscore = hasObscore;
    }

    public String getObscoreVersion() {
        return obscoreVersion;
    }

    public void setObscoreVersion(String obscoreVersion) {
        this.obscoreVersion = obscoreVersion;
    }
}
+13 −12
Original line number Diff line number Diff line
@@ -27,19 +27,20 @@ package it.inaf.ia2.tsm.datalayer;
 *
 * @author Sonia Zorba {@literal <zorba at oats.inaf.it>}
 */
public class ADQL {
public enum ADQL {

    private static final String ADQL_PREFIX = "adql:";
    
    public static final String INTEGER = ADQL_PREFIX + "INTEGER";
    public static final String SMALLINT = ADQL_PREFIX + "SMALLINT";
    public static final String BIGINT = ADQL_PREFIX + "BIGINT";
    public static final String REAL = ADQL_PREFIX + "REAL";
    public static final String CHAR = ADQL_PREFIX + "CHAR";
    public static final String VARCHAR = ADQL_PREFIX + "VARCHAR";
    public static final String TIMESTAMP = ADQL_PREFIX + "TIMESTAMP";
    INTEGER,
    SMALLINT,
    BIGINT,
    REAL,
    DOUBLE,
    BOOLEAN,
    CHAR,
    CLOB,
    VARCHAR,
    TIMESTAMP;

    public static String getDataType(String dataType) {
        return ADQL_PREFIX + dataType.toUpperCase();
        return dataType.toUpperCase();
    }
}
Loading