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

Added arraysize support, set multicolumn layout in addable modals

parent 78f330b0
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -79,14 +79,14 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {

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

    public final DBBroker getTapSchemaDBBroker() {
        if (tapSchemaDBBroker == null) {
            tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper());
            tapSchemaDBBroker = DBBrokerFactory.getDBBroker(dbWrapper.getTapSchemaDataSourceWrapper(), tapSchemaVersion);
        }
        return tapSchemaDBBroker;
    }
@@ -464,6 +464,8 @@ public class TapSchema implements EntitiesContainer<Schema>, Serializable {
                SchemaModel ivoaSchemaModel = getIvoaSchemaModel();

                broker.createIvoaSchemaStructure(ivoaSchemaModel);
                // Initializing ivoa schema slot in schemata maps
                schemas.put(ivoaSchemaModel.getName(), null);

                // Add ivoa schema into TAP_SCHEMA
                addEntireSchema(ivoaSchemaModel.getName());
+0 −1
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ 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;
+3 −3
Original line number Diff line number Diff line
@@ -31,13 +31,13 @@ import it.inaf.ia2.tsm.datalayer.pgsql.PostgresDBBroker;
 */
public class DBBrokerFactory {

    public static DBBroker getDBBroker(DataSourceWrapper dataSourceWrapper) {
    public static DBBroker getDBBroker(DataSourceWrapper dataSourceWrapper, String tapSchemaVersion) {
        switch (dataSourceWrapper.getDatabaseType()) {
            case MYSQL:
                return new MySQLDBBroker(dataSourceWrapper.getDataSource());
                return new MySQLDBBroker(dataSourceWrapper.getDataSource(), tapSchemaVersion);
            default:
                String pgDatabase = dataSourceWrapper.getCredentials().getDatabase();
                return new PostgresDBBroker(dataSourceWrapper.getDataSource(), pgDatabase);
                return new PostgresDBBroker(dataSourceWrapper.getDataSource(), pgDatabase, tapSchemaVersion);
        }
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -62,10 +62,12 @@ public abstract class DBBrokerTemplate implements DBBroker {

    protected final DataSource dataSource;
    private final char escapeCharacter;
    private final String tapSchemaVersion;

    public DBBrokerTemplate(DataSource dataSource, char escapeCharacter) {
    public DBBrokerTemplate(DataSource dataSource, char escapeCharacter, String tapSchemaVersion) {
        this.dataSource = dataSource;
        this.escapeCharacter = escapeCharacter;
        this.tapSchemaVersion = tapSchemaVersion;
    }

    protected List<String> getAllItemsNames(String query) throws SQLException {
@@ -110,7 +112,7 @@ public abstract class DBBrokerTemplate implements DBBroker {
        sb.append(String.format("(%s)", size));
    }

    protected abstract void createTable(String tapSchemaName, TableModel tableModel, Connection conn) throws SQLException;
    protected abstract void createTable(String schemaName, TableModel tableModel, Connection conn) throws SQLException;

    protected abstract String getAddPrimaryKeyQuery(String tapSchemaName, String tableName, String[] keyColumns);

@@ -764,4 +766,8 @@ public abstract class DBBrokerTemplate implements DBBroker {
        LOG.debug("{} columns found", allColumns.size());
        return allColumns;
    }

    protected String getTapSchemaVersion() {
        return tapSchemaVersion;
    }
}
+20 −8
Original line number Diff line number Diff line
@@ -50,8 +50,8 @@ public class MySQLDBBroker extends DBBrokerTemplate {

    private static final Logger LOG = LoggerFactory.getLogger(MySQLDBBroker.class);

    public MySQLDBBroker(DataSource dataSource) {
        super(dataSource, '`');
    public MySQLDBBroker(DataSource dataSource, String tapSchemaVersion) {
        super(dataSource, '`', tapSchemaVersion);
    }

    @Override
@@ -74,7 +74,7 @@ public class MySQLDBBroker extends DBBrokerTemplate {
        if (beginIndex != -1) {
            int endIndex = typeWithSize.indexOf(')');
            if (endIndex != -1) {
                Integer.parseInt(typeWithSize.substring(beginIndex + 1, endIndex));
                return Integer.parseInt(typeWithSize.substring(beginIndex + 1, endIndex));
            }
        }
        return null;
@@ -111,14 +111,26 @@ public class MySQLDBBroker extends DBBrokerTemplate {
                cm.put(Column.INDEXED_KEY, indexed);

                // Datatype and Size
                String type = resultSet.getString("Type").toLowerCase();
                String datatype = TypesMapping.getADQLTypeFromMySQLType(type);
                String type = resultSet.getString("Type").toUpperCase();
                String datatype = TypesMapping.getADQLTypeFromMySQLType(type, getTapSchemaVersion());
                Integer size = getSize(type);
                if (size != null && size > 0 && !datatype.contains("(")) {
                    // Adding size at the end of datatype
                    datatype += String.format("(%s)", size);
                }

                cm.put(Column.DATATYPE_KEY, datatype);
                cm.put(Column.SIZE_KEY, size);

                Integer arraySize = null; // TODO (v 1.1)
                String arraySize = null;
                if (size != null) {
                    arraySize = String.valueOf(size);
                    // variable length columns must have a "*" symbol on arraysize
                    if (datatype.startsWith(ADQL.VARCHAR.name())) {
                        arraySize += "*";
                    }
                }
                cm.put(Column.ARRAYSIZE_KEY, arraySize);

                allColumnsMetadata.put(columnName, cm);
            }
@@ -128,12 +140,12 @@ public class MySQLDBBroker extends DBBrokerTemplate {
    }

    @Override
    protected void createTable(String tapSchemaName, TableModel tableModel, Connection conn) throws SQLException {
    protected void createTable(String schemaName, TableModel tableModel, Connection conn) throws SQLException {

        StringBuilder querySb = new StringBuilder();

        querySb.append("CREATE TABLE IF NOT EXISTS ");
        querySb.append(escape(tapSchemaName));
        querySb.append(escape(schemaName));
        querySb.append(".");
        querySb.append(escape(tableModel.getName()));
        querySb.append(" (\n");
Loading