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

Web app changes; credentials insertion and schema selection JSP pages added.

parent 5df3d36f
Loading
Loading
Loading
Loading
+18 −5
Original line number Original line Diff line number Diff line
@@ -2,7 +2,6 @@ package it.inaf.oats.ia2.tap.tsm.datalayer;


import it.inaf.oats.ia2.tap.tsm.model.*;
import it.inaf.oats.ia2.tap.tsm.model.*;
import java.sql.Connection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ArrayList;
@@ -14,8 +13,8 @@ import java.util.List;
 */
 */
public class TapSchemaDL {
public class TapSchemaDL {


    public static ArrayList<String> getAllSchemasNames(Connection connection) throws SQLException {
    public static List<String> getAllSchemasNames(Connection connection) throws SQLException {
        final ArrayList<String> allSchemas = new ArrayList<String>();
        final List<String> allSchemas = new ArrayList<String>();
        (new ResultSetReader("SHOW DATABASES;") {
        (new ResultSetReader("SHOW DATABASES;") {


            @Override
            @Override
@@ -27,7 +26,7 @@ public class TapSchemaDL {
        return allSchemas;
        return allSchemas;
    }
    }


    public static ArrayList<String> getAllTAPSchemasNames(Connection connection, final ArrayList<String> allSchemas) throws SQLException {
    public static List<String> getAllTAPSchemasNames(Connection connection, final List<String> allSchemas) throws SQLException {


        class TAPSchemaChecker {
        class TAPSchemaChecker {


@@ -44,7 +43,7 @@ public class TapSchemaDL {
            }
            }
        }
        }


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


        for (String schemaName : allSchemas) {
        for (String schemaName : allSchemas) {


@@ -82,6 +81,20 @@ public class TapSchemaDL {
        return allTAPSchemas;
        return allTAPSchemas;
    }
    }


    public static List<String> getExposedSchemas(Connection connection, final String tapSchemaName) throws SQLException {
        final List<String> exposedSchemas = new ArrayList<String>();

        (new ResultSetReader("SELECT schema_name FROM " + tapSchemaName + ".`schemas`") {

            @Override
            public void manipulateItem(ResultSet resultSet) throws SQLException {
                exposedSchemas.add(resultSet.getString(1));
            }
        }).read(connection);

        return exposedSchemas;
    }

    public static void loadSelectedSchemas(final Connection connection, TapSchema tapSchema, List<String> selectedSchemas) throws SQLException {
    public static void loadSelectedSchemas(final Connection connection, TapSchema tapSchema, List<String> selectedSchemas) throws SQLException {
        for (String schemaName : selectedSchemas) {
        for (String schemaName : selectedSchemas) {
            Schema schema = new Schema(connection, schemaName, tapSchema.getName(), tapSchema.toCreate());
            Schema schema = new Schema(connection, schemaName, tapSchema.getName(), tapSchema.toCreate());
+2 −0
Original line number Original line Diff line number Diff line
@@ -403,6 +403,8 @@ public class UpdateManager {
            }
            }


            connection.commit();
            connection.commit();
            
            tapSchema.update();
        } catch (SQLException e) {
        } catch (SQLException e) {
            try {
            try {
                if (connection != null && !connection.getAutoCommit()) {
                if (connection != null && !connection.getAutoCommit()) {
+1 −7
Original line number Original line Diff line number Diff line
@@ -19,8 +19,6 @@ public class Column extends DbEntity {


    // uneditable properties
    // uneditable properties
    //public static final String DESCRIPTION = "description";
    //public static final String DESCRIPTION = "description";
    
    
    private String tableName;
    private String tableName;
    private String name;
    private String name;


@@ -29,7 +27,6 @@ public class Column extends DbEntity {
//    private final EditableValue<String> unit;
//    private final EditableValue<String> unit;
//    private final EditableValue<String> description;
//    private final EditableValue<String> description;
//    private final EditableValue<Boolean> std;
//    private final EditableValue<Boolean> std;

    private String datatype;
    private String datatype;
    private int size;
    private int size;


@@ -83,7 +80,6 @@ public class Column extends DbEntity {
//        return null;
//        return null;
//    }
//    }
//    private boolean checked;
//    private boolean checked;

    public String getTableName() {
    public String getTableName() {
        return tableName;
        return tableName;
    }
    }
@@ -132,7 +128,6 @@ public class Column extends DbEntity {
//    public void setDescription(String description) {
//    public void setDescription(String description) {
//        setValue(DESCRIPTION, description);
//        setValue(DESCRIPTION, description);
//    }
//    }

    public String getDatatype() {
    public String getDatatype() {
        return datatype;
        return datatype;
    }
    }
@@ -208,7 +203,6 @@ public class Column extends DbEntity {
//        }
//        }
//        return null;
//        return null;
//    }
//    }

    @Override
    @Override
    public void update(Connection connection) throws SQLException {
    public void update(Connection connection) throws SQLException {
        PreparedStatement statement = null;
        PreparedStatement statement = null;
+0 −2
Original line number Original line Diff line number Diff line
@@ -17,9 +17,7 @@ public class Credentials implements Serializable {
    private String password;
    private String password;


    public Credentials() {
    public Credentials() {
        this.hostname = "localhost";
        this.port = 3306;
        this.port = 3306;
        this.username = "root";
    }
    }


    public Credentials(String hostname, int port, String username, String password) {
    public Credentials(String hostname, int port, String username, String password) {
+18 −3
Original line number Original line Diff line number Diff line
@@ -33,7 +33,7 @@ class EditableValue {


    boolean isChanged() {
    boolean isChanged() {
        if (originalValue == null) {
        if (originalValue == null) {
            return newValue != null && !((String) newValue).equals("");
            return newValue != null && !newValue.equals("");
        }
        }
        return !originalValue.equals(newValue);
        return !originalValue.equals(newValue);
    }
    }
@@ -108,8 +108,8 @@ public abstract class DbEntity {
        return false;
        return false;
    }
    }


    public Map<String, String> getChanges() {
    public Map<String, Object> getChanges() {
        Map<String, String> changes = new HashMap<String, String>();
        Map<String, Object> changes = new HashMap<String, Object>();
        for (String key : values.keySet()) {
        for (String key : values.keySet()) {
            EditableValue editableValue = values.get(key);
            EditableValue editableValue = values.get(key);
            if (editableValue != null) {
            if (editableValue != null) {
@@ -119,6 +119,21 @@ public abstract class DbEntity {
        return changes;
        return changes;
    }
    }
    
    
    public void setUpdated() {
        if (getStatus() == Status.SELECTED_TO_SAVE) {
            setStatus(Status.SELECTED_SAVED);
        }
        for (EditableValue value : values.values()) {
            value.setValue(value.getValue());
        }
    }
    
    public void setOriginalValues() {
        for (EditableValue value : values.values()) {
            value.newValue = value.originalValue;
        }
    }

    public abstract String getName();
    public abstract String getName();


    public abstract void insert(Connection connection) throws SQLException;
    public abstract void insert(Connection connection) throws SQLException;
Loading