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

Bugfix consistency check on missing schema

parent 57bb2a37
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -624,11 +624,14 @@ public class Dao {
                    keyColumns = false;

            String query;
            if (dbType == DatabaseType.MYSQL) {
            switch (dbType) {
                case MYSQL:
                    query = "SHOW TABLES FROM `" + schemaName + "`";
            } else if (dbType == DatabaseType.POSTGRES) {
                    break;
                case POSTGRES:
                    query = "SELECT tablename FROM pg_catalog.pg_tables where schemaname = '" + schemaName + "'";
            } else {
                    break;
                default:
                    throw new UnsupportedOperationException("Database type " + dbType + " not supported");
            }

+9 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ package it.inaf.ia2.tsm.api;

import it.inaf.ia2.tsm.api.contract.DatabaseType;
import it.inaf.ia2.tsm.api.contract.Column;
import it.inaf.ia2.tsm.api.contract.Schema;
import it.inaf.ia2.tsm.api.contract.Status;
import it.inaf.ia2.tsm.api.contract.Table;
import it.inaf.ia2.tsm.api.contract.TapSchema;
@@ -248,11 +249,18 @@ public class DaoColumn {
                String schemaName = tableNameSplit[0];
                String tableSimpleName = tableNameSplit[1];

                Table table = tapSchema.getChild(schemaName).getChild(tableSimpleName);
                Schema schema = tapSchema.getChild(schemaName);
                if (schema == null) {
                    return null;
                }
                Table table = schema.getChild(tableSimpleName);
                if (table == null) {
                    return null;
                }
                Column column = table.addChild(columnName);
                if (column == null) {
                    return null;
                }
                column.setStatus(Status.ADDED_PERSISTED);
                return column;
            }
+32 −22
Original line number Diff line number Diff line
@@ -66,11 +66,14 @@ public class DaoTable {
        DatabaseType dbType = TSMUtil.getSchemaDatabaseType(dbWrapper, tapSchema, schemaName);

        String query;
        if (dbType == DatabaseType.MYSQL) {
        switch (dbType) {
            case MYSQL:
                query = "SHOW TABLES FROM `" + schemaName + "`";
        } else if (dbType == DatabaseType.POSTGRES) {
                break;
            case POSTGRES:
                query = "SELECT tablename FROM pg_catalog.pg_tables where schemaname = '" + schemaName + "'";
        } else {
                break;
            default:
                throw new UnsupportedOperationException("Database type " + dbType + " not supported");
        }

@@ -106,16 +109,19 @@ public class DaoTable {
        DatabaseType dbType = TSMUtil.getSchemaDatabaseType(dbWrapper, tapSchema, schemaName);

        String query;
        if (dbType == DatabaseType.MYSQL) {
        switch (dbType) {
            case MYSQL:
                query = "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = '" + schemaName + "'";
        } else if (dbType == DatabaseType.POSTGRES) {
                break;
            case POSTGRES:
                query = "SELECT tablename AS table_name, 'table' AS table_type\n"
                        + "FROM pg_catalog.pg_tables WHERE schemaname = '" + schemaName + "'\n"
                        + "UNION\n"
                        + "SELECT table_name AS table_name, 'view' AS table_type\n"
                        + "FROM INFORMATION_SCHEMA.views\n"
                        + "WHERE table_schema = '" + schemaName + "'";
        } else {
                break;
            default:
                throw new UnsupportedOperationException("Database type " + dbType + " not supported");
        }

@@ -151,6 +157,7 @@ public class DaoTable {

                Schema schema = tapSchema.getChild(schemaName);

                if (schema != null) {
                    Table table = schema.addChild(completeTableName.split(Pattern.quote("."))[1]);
                    if (table == null) {
                        return null;
@@ -158,6 +165,9 @@ public class DaoTable {
                    table.setStatus(Status.ADDED_PERSISTED);
                    return table;
                }
                // Schema was marked for removal in the ConsistencyChecks
                return null;
            }
        };

        selectQueryBuilder.executeQuery(dbWrapper.getTapSchemaConnection());
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ public class ConsistencyChecksBean implements Serializable {
        this.tapSchema = tapSchema;
    }

    public boolean isTapSchemaContainsOnlyTapSchema() {
        return tapSchema.getChildren().size() == 1
                && tapSchema.getChildren().get(0).getName().equals(tapSchema.getName());
    }

    public String proceed() throws SQLException {
        tapSchema.getConsistencyChecks().amendTapSchema(dbWrapper, tapSchema);
        tapSchema.save();
+5 −0
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@
                        </h:panelGroup>
                        <br/>

                        <h:panelGroup rendered="#{consistency.tapSchemaContainsOnlyTapSchema}" layout="block" class="alert alert-danger text-center">
                            <span class="glyphicon glyphicon-warning-sign"></span>
                            <strong>If you proceed this TAP_SCHEMA will contain only itself! You may have selected wrong source credentials.</strong>
                        </h:panelGroup>
                        
                        <div class="alert alert-warning text-center">
                            <span class="glyphicon glyphicon-warning-sign"></span>
                            <strong>If you proceed the TAP_SCHEMA Manager will fix these values.</strong>
+2 −2

File changed.

Contains only whitespace changes.

Loading