Search in sources :

Example 11 with ERSchema

use of com.cubrid.common.ui.er.model.ERSchema in project cubrid-manager by CUBRID.

the class ExportImportGsonDataController method importGsonData.

public boolean importGsonData(Shell parentShell, String gsonData) {
    Gson gson = new Gson();
    ERSchema deserializedERSchema = null;
    try {
        deserializedERSchema = gson.fromJson(gsonData, ERSchema.class);
    } catch (Exception e) {
        CommonUITool.openErrorBox(parentShell, e.getMessage());
        return false;
    }
    if (deserializedERSchema == null) {
        return false;
    }
    getERSchema().deleteAllTableAndFire();
    Map<String, SchemaInfo> schemainfoMap = deserializedERSchema.getAllSchemaInfo();
    boolean isImportMap = false;
    if (deserializedERSchema.getPhysicalLogicRelation() != null) {
        isImportMap = CommonUITool.openConfirmBox(com.cubrid.common.ui.er.Messages.msgConfirmImportRelationMap);
    }
    buildERDSchema(getERSchema(), deserializedERSchema, schemainfoMap, isImportMap);
    return true;
}
Also used : ERSchema(com.cubrid.common.ui.er.model.ERSchema) Gson(com.google.gson.Gson) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 12 with ERSchema

use of com.cubrid.common.ui.er.model.ERSchema in project cubrid-manager by CUBRID.

the class EditVirtualTableDialog method okPressed.

protected void okPressed() {
    if (!checkValid()) {
        return;
    }
    String message = (oldSchemaInfo == null) ? Messages.msgCreateTableConfirm : Messages.msgAlterTableConfirm;
    if (!CommonUITool.openConfirmBox(message)) {
        return;
    }
    SchemaInfo newSchemaInfo = getNewSchemaInfo();
    newSchemaInfo.removeInvalidPKAndIndex(true);
    newERTable.setName(tableNameText.getText().trim(), isPhysical);
    if (erSchema.isPhysicModel()) {
        newSchemaInfo.setDescription(tableDescText.getText().trim());
    }
    //remove empty column
    List<ERTableColumn> columns = newERTable.getColumns();
    for (int i = columns.size() - 1; i >= 0; i--) {
        if (StringUtil.isEmpty(columns.get(i).getName())) {
            columns.remove(i);
        }
    }
    //check
    ERSchema tmpErSchema = new ERSchema(erSchema.getName() + "_tmp", erSchema.getInput());
    Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
    schemaInfos.put(newSchemaInfo.getClassname(), newSchemaInfo);
    CubridTableParser tableParser = new CubridTableParser(tmpErSchema);
    tableParser.buildERTables(schemaInfos.values(), -1, -1, false);
    Map<String, Exception> failedTables = tableParser.getFailedTables();
    Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
    if (failedTables.size() > 0) {
        Set<String> tables = failedTables.keySet();
        String tableName = tables.iterator().next();
        CommonUITool.openErrorBox(failedTables.get(tableName).getMessage());
        return;
    }
    if (removedFKs.size() > 0) {
        Set<String> tables = removedFKs.keySet();
        String tableName = tables.iterator().next();
        List<Constraint> constraints = removedFKs.get(tableName);
        CommonUITool.openErrorBox("Foreign relation is error. Please check the relation of " + constraints.get(0).getName() + ", in table of " + tableName);
        return;
    }
    try {
        if (isTableNameChanged() && erSchema.isContainsTable(newERTable.getName(isPhysical), isPhysical)) {
            throw new Exception(Messages.bind(Messages.errExistTable, newERTable.getName(isPhysical)));
        }
        newERTable.checkValidate();
    } catch (Exception e) {
        CommonUITool.openErrorBox(e.getMessage());
        return;
    }
    super.okPressed();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) Constraint(com.cubrid.common.core.common.model.Constraint) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ERSchema(com.cubrid.common.ui.er.model.ERSchema) ArrayList(java.util.ArrayList) List(java.util.List) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 13 with ERSchema

use of com.cubrid.common.ui.er.model.ERSchema in project cubrid-manager by CUBRID.

the class SetPhysicalLogicaMapDialog method checkNewMapValid.

private void checkNewMapValid() throws ERException {
    ERSchema copySchema = erSchema.clone();
    PhysicalLogicRelation relation = copySchema.getPhysicalLogicRelation();
    relation.setDataTypeMap(newColumnTypeMap);
    //refresh all columns physical/logical data type by map
    copySchema.setPhysicalLogicRelation(relation);
    List<ERTable> tables = copySchema.getTables();
    for (ERTable table : tables) {
        table.checkValidate();
    }
}
Also used : ERSchema(com.cubrid.common.ui.er.model.ERSchema) PhysicalLogicRelation(com.cubrid.common.ui.er.logic.PhysicalLogicRelation) ERTable(com.cubrid.common.ui.er.model.ERTable)

Example 14 with ERSchema

use of com.cubrid.common.ui.er.model.ERSchema in project cubrid-manager by CUBRID.

the class ERDNDController method addTables.

private void addTables(List<SchemaInfo> schemaInfoList, int x, int y) {
    if (schemaInfoList == null) {
        return;
    }
    List<String> existTables = new ArrayList<String>();
    String message = "";
    ERSchema erSchema = editor.getERSchema();
    Iterator<SchemaInfo> it = schemaInfoList.iterator();
    while (it.hasNext()) {
        SchemaInfo table = (SchemaInfo) it.next();
        ERTable existTable = erSchema.getTable(table.getClassname());
        if (existTable != null) {
            existTables.add(table.getClassname());
            it.remove();
            continue;
        }
    }
    CubridTableParser tableParser = new CubridTableParser(erSchema);
    if (schemaInfoList.size() == 1) {
        tableParser.buildERTables(schemaInfoList, x, y, false);
    } else {
        tableParser.buildERTables(schemaInfoList, x, y, true);
    }
    erSchema.FireAddedTable(tableParser.getSuccessTables());
    Map<String, Exception> failedTables = tableParser.getFailedTables();
    Map<String, List<Constraint>> removedFKs = tableParser.getRemovedFKConstraints();
    if (failedTables.size() > 0) {
        message = Messages.bind(com.cubrid.common.ui.er.Messages.errorAddTables, failedTables.keySet());
    }
    if (existTables.size() > 0) {
        if (!message.equals("")) {
            message += "\n";
        }
        message += Messages.bind(com.cubrid.common.ui.er.Messages.errExistTables, existTables);
    }
    if (removedFKs.size() > 0) {
        if (!message.equals("")) {
            message += "\n";
        }
        message += Messages.bind(com.cubrid.common.ui.er.Messages.cannotBeBuiltFK, tableParser.getOneRemovedFK().getName());
        if (tableParser.getRemovedFKCount() > 1) {
            message += ", ...";
        }
    }
    if (!message.equals("")) {
        CommonUITool.openErrorBox(message);
    }
}
Also used : ArrayList(java.util.ArrayList) ERSchema(com.cubrid.common.ui.er.model.ERSchema) ERTable(com.cubrid.common.ui.er.model.ERTable) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) ArrayList(java.util.ArrayList) List(java.util.List) SQLException(java.sql.SQLException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 15 with ERSchema

use of com.cubrid.common.ui.er.model.ERSchema in project cubrid-manager by CUBRID.

the class ERAttributeCellModifier method modify.

public void modify(Object element, String property, Object value) {
    // FIXME move this logic to core module
    final TableItem item = (TableItem) element;
    if (item == null) {
        return;
    }
    ERTableColumn erColumn = (ERTableColumn) item.getData();
    ERTable table = editor.getDialog().getNewERTable();
    if (!StringUtil.isEmpty(erColumn.getName())) {
        erColumn = table.getColumn(erColumn.getName());
    }
    DBAttribute attr = erColumn.getAttr();
    String oldAttrName = attr.getName();
    DBAttribute oldAttribute = null;
    if (editor.getOldSchemaInfo() != null) {
        oldAttribute = editor.getOldSchemaInfo().getDBAttributeByName(oldAttrName, false);
    }
    ERTableColumn oldColumn = editor.getDialog().getOldERTable().getColumn(oldAttrName);
    if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
        SchemaInfo schemaInfo = editor.getNewSchemaInfo();
        if (schemaInfo == null) {
            return;
        }
        boolean on = ((Boolean) value).booleanValue();
        erColumn.setIsPrimaryKey(on);
        if (on) {
            Constraint constraint = schemaInfo.getPK();
            if (constraint == null) {
                constraint = new Constraint("pk", Constraint.ConstraintType.PRIMARYKEY.getText());
                schemaInfo.addConstraint(constraint);
            }
            constraint.addAttribute(attr.getName());
        } else {
            Constraint constraint = schemaInfo.getPK();
            if (constraint == null) {
                return;
            }
            List<String> columns = constraint.getAttributes();
            if (columns == null || columns.size() == 0) {
                return;
            }
            boolean isContain = columns.remove(attr.getName());
            /*For bug TOOLS-3972 The collumn's setting in Edit Table Inconsistent with the setting in Set Primary Key*/
            if (isContain && columns.size() == 0) {
                schemaInfo.removeConstraintByName(constraint.getName(), constraint.getType());
            }
            /*For bug TOOLS-3046 : deal with edit column*/
            if (oldAttribute != null && isContain) {
                attr.setNotNull(false);
            }
        }
        editor.makeChangeLogForIndex(oldAttrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
        String newName = (String) value;
        SchemaInfo schemaInfo = editor.getNewSchemaInfo();
        if (schemaInfo == null) {
            // TODO Improve error message
            CommonUITool.openErrorBox(Messages.errEmptyNameOnEditTableColumn);
            return;
        }
        if (!StringUtil.isEmpty(newName) && isPhysical && !ValidateUtil.isValidIdentifier(newName)) {
            CommonUITool.openErrorBox(Messages.errColumnName);
            return;
        }
        List<ERTableColumn> columns = table.getColumns();
        for (ERTableColumn col : columns) {
            if (StringUtil.isEqualIgnoreCase(col.getName(isPhysical), newName) && erColumn != col) {
                CommonUITool.openErrorBox(Messages.errSameNameOnEditTableColumn);
                return;
            }
        }
        if (!StringUtil.isEqualIgnoreCase(erColumn.getName(isPhysical), newName)) {
            if (isPhysical) {
                replaceNewConstraintAttributeName(schemaInfo, attr.getName(), newName);
            }
            String oldName = erColumn.getName(isPhysical);
            erColumn.setName(newName, isPhysical);
            if (erColumn.isNew()) {
                erColumn.setName(newName, !isPhysical);
                for (ERTableColumn col : columns) {
                    if (StringUtil.isEqualIgnoreCase(col.getName(!isPhysical), newName) && erColumn != col) {
                        CommonUITool.openErrorBox(Messages.errSameNameOnEditTableColumn);
                        erColumn.setName(oldName, isPhysical);
                        erColumn.setName(oldName, !isPhysical);
                        return;
                    }
                }
            }
            if (!hasAddedToSchemaInfo(attr)) {
                if (!StringUtil.isEmpty(newName)) {
                    if (!columns.contains(erColumn)) {
                        erColumn.getAttr().setInherit(editor.getNewSchemaInfo().getClassname());
                        table.addColumn(erColumn);
                        editor.removeElementByName(newName);
                    }
                    if (!StringUtil.isEmpty(oldAttrName)) {
                        editor.makeChangeLogForIndex(oldAttrName, erColumn.getAttr(), oldAttribute);
                    }
                }
            } else {
                editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
            }
        }
        ERTableColumn col = null;
        if (columns.size() > 0) {
            Table columnsTable = editor.getColumnsTable();
            col = (ERTableColumn) columnsTable.getItem(columnsTable.getItemCount() - 1).getData();
        }
        if (!StringUtil.isEmpty(newName) && (col == null || !StringUtil.isEmpty(col.getName(isPhysical)))) {
            editor.addNewColumn();
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
        String dataTypeRaw = (String) value;
        ERSchema schema = erColumn.getERSchema();
        if (isPhysical) {
            if (dataTypeRaw.equalsIgnoreCase(DataType.getUpperEnumType())) {
                dataTypeRaw += "('" + DataType.ENUM_DAFAULT_VALUE + "')";
            }
            erColumn.setPhysicalDataType(DataType.reviseDataType(dataTypeRaw));
            if (!DataType.isIntegerType(attr.getType())) {
                attr.setAutoIncrement(null);
            }
            if (!DataType.canUseCollation(attr.getType())) {
                attr.setCollation("");
            }
            String physicalRealType = erColumn.getRealType();
            if (erColumn.getERSchema().hasPhysicalTypeInMap(physicalRealType) || erColumn.isNew()) {
                String logicalType = schema.convert2LogicalShowType(physicalRealType);
                erColumn.setShowType(logicalType, false);
            }
        } else {
            if (!DataType.DATATYPE_STRING.equalsIgnoreCase(dataTypeRaw)) {
                dataTypeRaw = DataType.reviseDataType(dataTypeRaw);
            }
            erColumn.setShowType(dataTypeRaw, false);
            if (erColumn.getERSchema().hasLogicalTypeInMap(dataTypeRaw) || erColumn.isNew()) {
                String physicalType = schema.convert2UpPhysicalShowType(dataTypeRaw);
                if (DataType.DATATYPE_STRING.equalsIgnoreCase(dataTypeRaw)) {
                    physicalType = DataType.reviseDataType(physicalType);
                }
                erColumn.setPhysicalDataType(physicalType);
            }
        }
        editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
        String defaultVal = (String) value;
        boolean isStringType = DataType.isStringType(attr.getType());
        boolean isEmpty = StringUtil.isEmpty(defaultVal);
        boolean isNull = false;
        if (defaultVal == null || DataType.NULL_EXPORT_FORMAT.equals(defaultVal) || DataType.VALUE_NULL.equals(defaultVal) || (isEmpty && !isStringType)) {
            isNull = true;
        }
        if (isNull) {
            attr.setDefault(null);
        } else {
            if (attr.getAutoIncrement() != null) {
                attr.setDefault(null);
                CommonUITool.openErrorBox(Messages.errCanNotSetDefaultOnAI);
                return;
            }
            boolean isConfirmReset = "".equals(defaultVal) && oldAttribute != null && !"".equals(oldAttribute.getDefault());
            if (isConfirmReset) {
                String confirmResetDef = Messages.confirmResetDef;
                if (CommonUITool.openConfirmBox(confirmResetDef)) {
                    attr.setDefault(null);
                } else {
                    attr.setDefault(defaultVal);
                }
            } else {
                attr.setDefault(defaultVal);
            }
        }
        editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            attr.setAutoIncrement(null);
            return;
        }
        String param = (String) value;
        if (StringUtil.isNotEmpty(param)) {
            if (!param.matches("\\s*[0-9]+\\s*,\\s*[0-9]+\\s*")) {
                CommonUITool.openErrorBox(Messages.errInvalidAutoIncrForm);
                return;
            }
            String defaultValue = attr.getDefault();
            if (StringUtil.isNotEmpty(defaultValue)) {
                CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
                return;
            }
            String[] params = param.split(",");
            String startVal = params[0].trim();
            String incrVal = params[1].trim();
            SchemaInfo schemaInfo = editor.getNewSchemaInfo();
            SerialInfo serial = new SerialInfo();
            serial.setOwner(schemaInfo.getOwner());
            serial.setClassName(schemaInfo.getClassname());
            serial.setAttName(oldAttrName);
            serial.setCacheCount("1");
            serial.setCurrentValue(startVal);
            serial.setCyclic(false);
            serial.setIncrementValue(incrVal);
            serial.setMaxValue(String.valueOf(Integer.MAX_VALUE));
            serial.setMinValue(startVal);
            serial.setStartedValue(startVal);
            if (attr.getAutoIncrement() != null && schemaInfo != null && schemaInfo.getAutoIncrementColumn() != null && schemaInfo.getAutoIncrementColumn().getAutoIncrement() != null) {
                String oldAI = attr.getAutoIncrement().getTableAutoIncrementString();
                String newAI = serial.getTableAutoIncrementString();
                if (StringUtil.isEqual(oldAI, newAI)) {
                    return;
                }
            }
            attr.setAutoIncrement(serial);
        } else {
            attr.setAutoIncrement(null);
        }
        editor.changeForEditElement(oldAttrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
        boolean on = ((Boolean) value).booleanValue();
        attr.setNotNull(on);
        editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
        boolean on = ((Boolean) value).booleanValue();
        if (on && attr.isShared()) {
            CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
            return;
        }
        attr.setUnique(on);
        editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
        boolean on = ((Boolean) value).booleanValue();
        String defaultValue = attr.getDefault();
        if (on && StringUtil.isEmpty(defaultValue)) {
            CommonUITool.openErrorBox(Messages.msgInputSharedValue);
            return;
        }
        if (on && attr.isUnique()) {
            CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
            return;
        }
        attr.setShared(on);
        editor.getDialog().changeForEditElement(oldAttrName, erColumn, oldColumn);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        String orignCollation = attr.getCollation();
        Integer selection = StringUtil.intValue(value.toString(), 0);
        if (selection > -1) {
            String newCollation = editor.getCollationArray()[selection];
            if (!StringUtil.isEqualNotIgnoreNull(orignCollation, newCollation)) {
                attr.setCollation(newCollation);
            }
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        attr.setDescription((String) value);
    }
    editor.loadColumnData();
    editor.afterModifyColumn(oldColumn == null ? null : oldColumn.getName(isPhysical), erColumn.getName(isPhysical));
}
Also used : Table(org.eclipse.swt.widgets.Table) ERTable(com.cubrid.common.ui.er.model.ERTable) Constraint(com.cubrid.common.core.common.model.Constraint) TableItem(org.eclipse.swt.widgets.TableItem) ERTable(com.cubrid.common.ui.er.model.ERTable) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ERSchema(com.cubrid.common.ui.er.model.ERSchema) List(java.util.List) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

ERSchema (com.cubrid.common.ui.er.model.ERSchema)16 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)6 ERTable (com.cubrid.common.ui.er.model.ERTable)5 Constraint (com.cubrid.common.core.common.model.Constraint)3 ERSchemaEditor (com.cubrid.common.ui.er.editor.ERSchemaEditor)3 CubridTableParser (com.cubrid.common.ui.er.model.CubridTableParser)3 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)1 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)1 AddFKDialog (com.cubrid.common.ui.cubrid.table.dialog.AddFKDialog)1 ERException (com.cubrid.common.ui.er.ERException)1 SchemaEditorInput (com.cubrid.common.ui.er.SchemaEditorInput)1 AddTableCommand (com.cubrid.common.ui.er.commands.AddTableCommand)1 DeleteTableCommand (com.cubrid.common.ui.er.commands.DeleteTableCommand)1 ERSchemaTableNodesLoader (com.cubrid.common.ui.er.loader.ERSchemaTableNodesLoader)1 PhysicalLogicRelation (com.cubrid.common.ui.er.logic.PhysicalLogicRelation)1 Relationship (com.cubrid.common.ui.er.model.Relationship)1