Commit 3098bbd2 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Improvements in key visualization and bugfix

parent 2a350bbe
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
package it.inaf.oats.ia2.tapschemamanager.businesslayer;

import it.inaf.oats.ia2.tapschemamanager.datalayer.ColumnEntity;
import it.inaf.oats.ia2.tapschemamanager.datalayer.TapSchemaHandler;

/**
 *
@@ -20,12 +21,12 @@ public class Column extends EntityWrapper {
    private final boolean primaryKey;
    private final boolean indexed;

    private boolean foreignKey;
    private final String foreignKeyReference;

    private boolean hidden;

    public Column(ColumnEntity columnEntity, boolean primaryKey) {
        super(columnEntity, UTYPE, UCD, UNIT, DESCRIPTION, STD);
    public Column(TapSchemaHandler tapSchemaHandler, ColumnEntity columnEntity, boolean primaryKey) {
        super(columnEntity, UTYPE, UCD, UNIT, DESCRIPTION, STD, PRINCIPAL);
        hidden = true;
        this.primaryKey = primaryKey;
        this.datatype = columnEntity.getDatatype();
@@ -38,6 +39,10 @@ public class Column extends EntityWrapper {
        addValue(DESCRIPTION, columnEntity.getDescription());
        addValue(STD, columnEntity.getStd() + "");
        addValue(PRINCIPAL, columnEntity.getPrincipal() + "");

        String tableName = columnEntity.getTableName();
        String schemaName = columnEntity.getTable().getSchemaName();
        foreignKeyReference = tapSchemaHandler.getForeignKeyReference(schemaName, tableName, columnEntity.getName());
    }

    @Override
@@ -53,6 +58,8 @@ public class Column extends EntityWrapper {
            columnEntity.setDescription(value);
        } else if (key.equals(STD)) {
            columnEntity.setStd(Integer.parseInt(value));
        } else if (key.equals(PRINCIPAL)) {
            columnEntity.setPrincipal(Integer.parseInt(value));
        }
    }

@@ -83,8 +90,8 @@ public class Column extends EntityWrapper {
        return primaryKey;
    }

    public boolean isForeignKey() {
        return foreignKey;
    public String getForeignKey() {
        return foreignKeyReference;
    }

    public boolean isIndexed() {
+3 −3
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class Schema extends EntityWrapper implements EntityWrapperContainer {
        }
        selectedTable = name;

        getSchemaEntity().addTable((TableEntity) table.getEntity());
        tapSchemaHandler.addTable(getName(), table.getTableEntity());
    }

    @Override
@@ -93,7 +93,7 @@ public class Schema extends EntityWrapper implements EntityWrapperContainer {
        }
        selectedTable = tables.isEmpty() ? null : tables.keySet().iterator().next();

        getSchemaEntity().getTables().remove(table.getFullName());
        tapSchemaHandler.removeTable(getSchemaEntity(), table.getTableEntity());
    }

    public Table getTable(String name) {
@@ -138,7 +138,7 @@ public class Schema extends EntityWrapper implements EntityWrapperContainer {
        Table table = tables.get(entityName);
        List<String> columns = table.getColumnsNames();
        if (!columns.isEmpty()) {
            table.selectEntity(columns.get(0));
            table.selectEntity(Util.getFirstInAlphabeticalOrder(columns));
        }
    }

+5 −10
Original line number Diff line number Diff line
@@ -23,19 +23,17 @@ public class Table extends EntityWrapper implements EntityWrapperContainer {
    private String selectedColumn;
    private final Map<String, Column> columns;

    private final TapSchemaHandler tapSchemaHandler;
    private final String schemaName;
    private final String tableName;

//    public Table(TapSchemaHandler tapSchemaHandler, String schemaName, String tableName) throws SQLException {
//        this(tapSchemaHandler, schemaName, tableName, new TableEntity(schemaName + "." + tableName));
//        setStatus(Status.ADDED_NOT_PERSISTED);
//    }
    public Table(TapSchemaHandler tapSchemaHandler, String schemaName, String tableName, TableEntity tableEntity) throws SQLException {
        super(tableEntity, UTYPE, DESCRIPTION);

        addValue(UTYPE, tableEntity.getUtype());
        addValue(DESCRIPTION, tableEntity.getDescription());

        this.tapSchemaHandler = tapSchemaHandler;
        this.schemaName = schemaName;
        this.tableName = tableName;

@@ -44,7 +42,7 @@ public class Table extends EntityWrapper implements EntityWrapperContainer {
        Set<String> alreadyLoadedColumns = tableEntity.getColumns().keySet();
        for (ColumnInfo columnInfo : tapSchemaHandler.getColumnInfo(schemaName, tableName)) {
            ColumnEntity columnEntity = columnInfo.getColumnEntity();
            Column column = new Column(columnEntity, columnInfo.isPrimaryKey());
            Column column = new Column(tapSchemaHandler, columnEntity, columnInfo.isPrimaryKey());
            columns.put(columnEntity.getName(), column);

            if (alreadyLoadedColumns.contains(columnEntity.getName())) {
@@ -53,8 +51,6 @@ public class Table extends EntityWrapper implements EntityWrapperContainer {
            }
        }

        // Load foreign keys constraints
        // TODO ...
        setStatus(Status.ADDED_PERSISTED);
    }

@@ -96,7 +92,7 @@ public class Table extends EntityWrapper implements EntityWrapperContainer {
        }
        selectedColumn = name;

        getTableEntity().addColumn(column.getColumnEntity());
        tapSchemaHandler.addColumn(getTableEntity(), column.getColumnEntity());
    }

    @Override
@@ -111,8 +107,7 @@ public class Table extends EntityWrapper implements EntityWrapperContainer {
        List<String> visibleColumns = getColumnsNames();
        selectedColumn = visibleColumns.isEmpty() ? null : visibleColumns.get(0);

        column.setStatus(Status.ADDED_NOT_PERSISTED);
        getTableEntity().addColumn(column.getColumnEntity());
        tapSchemaHandler.removeColumn(getTableEntity(), name);
    }

    public Column getColumn(String name) {
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class TapSchema implements EntityWrapperContainer {
        Schema schema = schemas.get(entityName);
        List<String> tables = schema.getTablesNames();
        if (!tables.isEmpty()) {
            schema.selectEntity(tables.get(0));
            schema.selectEntity(Util.getFirstInAlphabeticalOrder(tables));
        }
    }

+13 −1
Original line number Diff line number Diff line
package it.inaf.oats.ia2.tapschemamanager.businesslayer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

@@ -26,4 +25,17 @@ class Util {
        list.addAll(set);
        return list;
    }

    protected static String getFirstInAlphabeticalOrder(List<String> list) {
        String result = null;
        for (String value : list) {
            if (result == null) {
                result = value;
            }
            if (result.compareTo(value) > 0) {
                result = value;
            }
        }
        return result;
    }
}
Loading