Commit 3169ce87 authored by Pietro Apollo's avatar Pietro Apollo
Browse files

function selfUpdateTapSchema implemented

parent f2f154d7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -328,12 +328,20 @@ public class SelectSchemataPage extends BasePage {
                            username,
                            password,
                            tapschemaName);
                    /*
                    updateTapSchema.autoUpdateTapSchema(
                            hostname,
                            port,
                            username,
                            password,
                            tapschemaName);
                            */
                    updateTapSchema.selfUpdateTapSchema(
                            hostname,
                            port,
                            username,
                            password,
                            tapschemaName);
                    selectedDatabases.add(tapschemaName);
                    
                    TapSchema tapschema = updateTapSchema.populateFromDatabases(
+103 −1
Original line number Diff line number Diff line
@@ -778,7 +778,7 @@ public class UpdateTapSchema {
        }
        return alert;
    }
    
    /*
    public void autoUpdateTapSchema(
            String hostname,
            String port,
@@ -1065,5 +1065,107 @@ public class UpdateTapSchema {
            connection.close();
        }
    }
    */
    public void selfUpdateTapSchema(
            String hostname,
            String port,
            String username,
            String password,
            String tapschemaName)
            throws Exception
    {
        String url = "jdbc:mysql://" + hostname + ":" + port + "/";
        Connection connection = null;
        Statement statement = null;
        
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                    url,
                    username,
                    password
            );
            
            statement = connection.createStatement();
            String queryString = "INSERT INTO " + tapschemaName + ".`schemas` " +
                    "(schema_name, description, utype, schemaID) VALUES " +
                    "('" + tapschemaName + "', 'a special schema to describe a TAP tableset', null, null);";
            statement.executeUpdate(queryString);

            queryString = "INSERT INTO " + tapschemaName + ".tables " +
                    "(schema_name, table_name, table_type, description, utype, tableID) VALUES " +
                    "('" + tapschemaName + "', '" + tapschemaName + ".schemas', 'table', 'description of schemas in this tableset', null, null), " +
                    "('" + tapschemaName + "', '" + tapschemaName + ".tables', 'table', 'description of tables in this tableset', null, null), " +
                    "('" + tapschemaName + "', '" + tapschemaName + ".columns', 'table', 'description of columns in this tableset', null, null), " +
                    "('" + tapschemaName + "', '" + tapschemaName + ".keys', 'table', 'description of foreign keys in this tableset', null, null), " +
                    "('" + tapschemaName + "', '" + tapschemaName + ".key_columns', 'table', 'description of foreign key columns in this tableset', null, null);";
            statement.executeUpdate(queryString);

            queryString = "INSERT INTO " + tapschemaName + ".columns " +
                    "(table_name, column_name, description, utype, ucd, unit, datatype, size, principal, indexed, std, columnID) VALUES " + 
                    "('" + tapschemaName + ".schemas', 'schema_name', 'schema name for reference to TAP_SCHEMA.schemas', null, null, null, 'adql:VARCHAR', 64, 1, 1, 0, null), " + 
                    "('" + tapschemaName + ".schemas', 'utype', 'lists the utypes of schemas in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".schemas', 'description', 'describes schemas in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".schemas', 'schemaID', null, null, null, null, 'adql:BIGINT', 0, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".tables', 'schema_name', 'the schema this table belongs to', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".tables', 'table_name', 'the fully qualified table name', null, null, null, 'adql:VARCHAR', 128, 1, 1, 0, null), " +
                    "('" + tapschemaName + ".tables', 'table_type', 'one of: table view', null, null, null, 'adql:VARCHAR', 8, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".tables', 'utype', 'lists the utype of tables in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".tables', 'description', 'describes tables in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".tables', 'tableID', null, null, null, null, 'adql:BIGINT', 0, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'table_name', 'the table this column belongs to', null, null, null, 'adql:VARCHAR', 128, 1, 1, 0, null), " +
                    "('" + tapschemaName + ".columns', 'column_name', 'the column name', null, null, null, 'adql:VARCHAR', 64, 1, 1, 0, null), " +
                    "('" + tapschemaName + ".columns', 'utype', 'lists the utypes of columns in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'ucd', 'lists the UCDs of columns in the tableset', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'unit', 'lists the unit used for column values in the tableset', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'description', 'describes the columns in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'datatype', 'lists the ADQL datatype of columns in the tableset', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'size', 'lists the size of variable-length columns in the tableset', null, null, null, 'adql:INTEGER', null, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'principal', 'a principal column; 1 means 1, 0 means 0', null, null, null, 'adql:INTEGER', null, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'indexed', 'an indexed column; 1 means 1, 0 means 0', null, null, null, 'adql:INTEGER', null, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'std', 'a standard column; 1 means 1, 0 means 0', null, null, null, 'adql:INTEGER', null, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".columns', 'columnID', null, null, null, null, 'adql:BIGINT', 0, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".keys', 'key_id', 'unique key to join to TAP_SCHEMA.key_columns', null, null, null, 'adql:VARCHAR', 64, 1, 1, 0, null), " +
                    "('" + tapschemaName + ".keys', 'from_table', 'the table with the foreign key', null, null, null, 'adql:VARCHAR', 128, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".keys', 'target_table', 'the table with the primary key', null, null, null, 'adql:VARCHAR', 128, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".keys', 'utype', 'lists the utype of keys in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".keys', 'description', 'describes keys in the tableset', null, null, null, 'adql:VARCHAR', 512, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".keys', 'keyID', null, null, null, null, 'adql:BIGINT', 0, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".key_columns', 'key_id', 'key to join to TAP_SCHEMA.keys', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".key_columns', 'from_column', 'column in the from_table', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".key_columns', 'target_column', 'column in the target_table', null, null, null, 'adql:VARCHAR', 64, 1, 0, 0, null), " +
                    "('" + tapschemaName + ".key_columns', 'key_columnID', null, null, null, null, 'adql:BIGINT', 0, 1, 0, 0, null);";
            statement.executeUpdate(queryString);

            queryString = "INSERT INTO " + tapschemaName + ".keys " +
                    "(key_id, from_table, target_table, keyID) VALUES " +
                    "('1', '" + tapschemaName + ".tables', '" + tapschemaName + ".schemas', null), " +
                    "('2', '" + tapschemaName + ".columns', '" + tapschemaName + ".tables', null), " +
                    "('3', '" + tapschemaName + ".keys', '" + tapschemaName + ".tables', null), " +
                    "('4', '" + tapschemaName + ".keys', '" + tapschemaName + ".tables', null), " +
                    "('5', '" + tapschemaName + ".key_columns', '" + tapschemaName + ".keys', null);";
            statement.executeUpdate(queryString);

            queryString = "INSERT INTO " + tapschemaName + ".key_columns " +
                    "(key_id, from_column, target_column, key_columnID) VALUES " + 
                    "('1', 'schema_name', 'schema_name', null), " +
                    "('2', 'table_name', 'table_name', null), " +
                    "('3', 'from_table', 'table_name', null), " +
                    "('4', 'target_table', 'table_name', null), " +
                    "('5', 'key_id', 'key_id', null);";
            statement.executeUpdate(queryString);
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
            throw new Exception(exception.getMessage());
        }
        finally
        {
            statement.close();
            connection.close();
        }
    }
                     
}