Commit 1991f0df authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Bugfix Reload button on new TAP_SCHEMA schemas, UCD dialog improvements,...

Bugfix Reload button on new TAP_SCHEMA schemas, UCD dialog improvements, protected TAP_SCHEMA entities from removal, minor changes
parent 471f2ac7
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>TapSchemaManagerAPI</artifactId>
    <version>1.0.1</version>
    <version>1.0.3</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+7 −0
Original line number Diff line number Diff line
@@ -153,4 +153,11 @@ public class Credentials implements Serializable {
        }
        return null;
    }

    @Override
    public String toString() {
        return String.format("[%s] type=%s, hostname=%s, port=%s, username=%s, password=%s, database=%s",
                Credentials.class.getCanonicalName(),
                databaseType, hostname, port, username, password, database);
    }
}
+4 −36
Original line number Diff line number Diff line
@@ -22,13 +22,11 @@
 */
package it.inaf.ia2.tsm.api;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import it.inaf.ia2.tsm.api.contract.DatabaseType;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -161,12 +159,12 @@ public class DBWrapper implements Serializable {
        public DataSource getTapSchemaDataSource() {
            if (credentials != null) {
                if (dataSource == null) {
                    dataSource = createDataSource(credentials);
                    dataSource = TSMUtil.createDataSource(credentials);
                }
                return dataSource;
            }
            if (tapSchemaDataSource == null) {
                tapSchemaDataSource = createDataSource(tapSchemaCredentials);
                tapSchemaDataSource = TSMUtil.createDataSource(tapSchemaCredentials);
            }
            return tapSchemaDataSource;
        }
@@ -174,44 +172,14 @@ public class DBWrapper implements Serializable {
        public DataSource getSourceDataSource() {
            if (credentials != null) {
                if (dataSource == null) {
                    dataSource = createDataSource(credentials);
                    dataSource = TSMUtil.createDataSource(credentials);
                }
                return dataSource;
            }
            if (sourceDataSource == null) {
                sourceDataSource = createDataSource(sourceCredentials);
                sourceDataSource = TSMUtil.createDataSource(sourceCredentials);
            }
            return sourceDataSource;
        }

        private DataSource createDataSource(Credentials credentials) {

            switch (credentials.getDatabaseType()) {

                case MYSQL:
                    MysqlDataSource myds = new MysqlDataSource();

                    myds.setServerName(credentials.getHostname());
                    myds.setPortNumber(credentials.getPort());
                    myds.setUser(credentials.getUsername());
                    myds.setPassword(credentials.getPassword());

                    return myds;

                case POSTGRES:
                    PGPoolingDataSource pgds = new PGPoolingDataSource();

                    pgds.setServerName(credentials.getHostname());
                    pgds.setPortNumber(credentials.getPort());
                    pgds.setUser(credentials.getUsername());
                    pgds.setPassword(credentials.getPassword());
                    pgds.setDatabaseName(credentials.getDatabase());

                    return pgds;

                default:
                    throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
            }
        }
    }
}
+13 −4
Original line number Diff line number Diff line
@@ -582,11 +582,22 @@ public class Dao {
        }
    }

    public static List<String> getAllTAPSchemasNames(Credentials credentials) throws SQLException {
        DatabaseType dbType = credentials.getDatabaseType();
        DataSource ds = TSMUtil.createDataSource(credentials);
        List<String> allSchemas = DaoSchema.getAllSchemasNames(ds, dbType);
        return getAllTAPSchemasNames(ds, dbType, allSchemas);
    }

    public static List<String> getAllTAPSchemasNames(DBWrapper dbs) throws SQLException {
        List<String> allSchemas = DaoSchema.getAllSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType());
        return getAllTAPSchemasNames(dbs, allSchemas);
    }

    public static List<String> getAllTAPSchemasNames(DBWrapper dbs, List<String> allSchemas) throws SQLException {
        return getAllTAPSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType(), allSchemas);
    }

    /**
     * Retrieve the list of all TAP_SCHEMA schemas names contained in the
     * TAP_SCHEMA <code>DataSource</code>.<br>
@@ -600,7 +611,7 @@ public class Dao {
     * @return list of all TAP_SCHEMA schemas names alphabetically and case
     * insensitively ordered.
     */
    public static List<String> getAllTAPSchemasNames(DBWrapper dbs, List<String> allSchemas) throws SQLException {
    public static List<String> getAllTAPSchemasNames(DataSource dataSource, DatabaseType dbType, List<String> allSchemas) throws SQLException {

        List<String> allTAPSchemas = new ArrayList<>();

@@ -612,8 +623,6 @@ public class Dao {
                    keys = false,
                    keyColumns = false;

            DatabaseType dbType = dbs.getTapSchemaDatabaseType();

            String query;
            if (dbType == DatabaseType.MYSQL) {
                query = "SHOW TABLES FROM `" + schemaName + "`";
@@ -625,7 +634,7 @@ public class Dao {

            log.debug("Executing query {}", query);

            try (Connection connection = dbs.getTapSchemaConnection();
            try (Connection connection = dataSource.getConnection();
                    Statement statement = connection.createStatement();
                    ResultSet resultSet = statement.executeQuery(query)) {
                while (resultSet.next()) {
+6 −1
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ public class DaoSchema {

    private static final Logger log = LoggerFactory.getLogger(DaoSchema.class);

    public static List<String> getAllSchemasNames(Credentials credentials) throws SQLException {
        DataSource ds = TSMUtil.createDataSource(credentials);
        return getAllSchemasNames(ds, credentials.getDatabaseType());
    }

    /**
     * Retrieve the list of the names of the all the schemas contained into the
     * database specified by the <code>DataSource</code> parameter.
Loading