Search in sources :

Example 1 with ERException

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

the class CubridTableParser method getReferredColumns.

/**
	 * Get the other table columns name which is referred on the foreign key
	 * constraint
	 * 
	 * @param schemaInfo
	 * @param fkConstaint
	 * @return The results is all columns of pk in the primary table actually.
	 * @throws Exception
	 */
private List<String> getReferredColumns(SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
    List<String> resultList = new ArrayList<String>();
    String refTable = getReferencedTableName(fkConstaint);
    SchemaInfo referedSchemaInfo = getReferencedTable(refTable);
    if (referedSchemaInfo != null) {
        Constraint pkConstaint = referedSchemaInfo.getPK();
        if (pkConstaint == null) {
            throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
        }
        List<String> pklist = pkConstaint.getAttributes();
        for (int i = 0; i < pklist.size(); i++) {
            String referedKey = pklist.get(i).replace(" ASC", "").replace(" DESC", "");
            resultList.add(referedKey);
        }
    }
    return resultList;
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ArrayList(java.util.ArrayList) ERException(com.cubrid.common.ui.er.ERException) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 2 with ERException

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

the class CubridTableParser method addFKShip.

public void addFKShip(ERTable erTable, SchemaInfo schemaInfo, Constraint fkConstaint) throws Exception {
    String referencedTableName = getReferencedTableName(fkConstaint);
    SchemaInfo referencedTable = getReferencedTable(fkConstaint);
    List<String> referenceNames = getReferenceColumns(fkConstaint);
    List<String> referredPkColumnNames = getReferredColumns(schemaInfo, fkConstaint);
    boolean isSelfRef = false;
    if (referencedTable == null) {
        // If the referenced Table do not be added to the ERShema. Do not
        // load it and do not build the relationship and delete the
        // constraint
        schemaInfo.removeFKConstraint(fkConstaint);
        addEle2RemovedFKConstraints(schemaInfo.getClassname(), fkConstaint);
        return;
    }
    if (StringUtil.isEqualNotIgnoreNull(referencedTableName, erTable.getName())) {
        // self reference FK
        isSelfRef = true;
    }
    if (referenceNames.size() != referredPkColumnNames.size()) {
        throw new ERException(Messages.bind(Messages.errFKColumnMatch, new String[] { schemaInfo.getClassname(), fkConstaint.getName() }));
    }
    ERTable referencedT = erSchema.getTable(referencedTable.getClassname());
    boolean needBuildRefedTable = false;
    if (referencedT == null && !isSelfRef) {
        referencedT = new ERTable(referencedTable, erSchema);
        needBuildRefedTable = true;
    } else {
    // the referenceTable has been built, do not build again.
    }
    if (isSelfRef) {
        erTable.setHasSelfFKRef(true);
        return;
    }
    Relationship ship = new Relationship(fkConstaint.getName(), erTable, referencedT);
    for (int i = 0; i < referenceNames.size(); i++) {
        ship.addRelation(referenceNames.get(i), referredPkColumnNames.get(i));
    }
    erTable.addForeignKeyShipAndFire(ship);
    if (needBuildRefedTable) {
        buildERTable(referencedT, referencedTable);
        boolean success = erSchema.addTable(referencedT);
        if (success && !successTables.contains(referencedT)) {
            successTables.add(referencedT);
        }
    }
    referencedT.FireTargeted(ship);
    return;
}
Also used : ERException(com.cubrid.common.ui.er.ERException) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)

Example 3 with ERException

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

the class SetPhysicalLogicaMapDialog method okPressed.

protected void okPressed() {
    if (!CommonUITool.openConfirmBox(Messages.msgConfirmChangePhysicalLogicalMap)) {
        return;
    }
    PhysicalLogicRelation.delEmptyEntry(newColumnTypeMap);
    //check all column physical data types whether are valid by the new column type map
    if (!erSchema.isPhysicModel()) {
        try {
            checkNewMapValid();
        } catch (ERException e) {
            CommonUITool.openErrorBox(getShell(), e.getMessage());
            return;
        }
    }
    PhysicalLogicRelation relation = erSchema.getPhysicalLogicRelation();
    relation.setDataTypeMap(newColumnTypeMap);
    //refresh all columns physical/logical data type by map
    erSchema.setPhysicalLogicRelation(relation);
    super.okPressed();
}
Also used : PhysicalLogicRelation(com.cubrid.common.ui.er.logic.PhysicalLogicRelation) ERException(com.cubrid.common.ui.er.ERException)

Example 4 with ERException

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

the class ColumnLabelHandler method checkFormat.

public void checkFormat(String fullText) throws ERException {
    if (StringUtil.isEmpty(fullText)) {
        throw new ERException(Messages.errEmptyColumn);
    }
    String[] colInfo = fullText.split(ERTableColumn.SPLIT);
    if (colInfo.length == 2) {
        if (StringUtil.isEmpty(colInfo[0]) | StringUtil.isEmpty(colInfo[1])) {
            throw new ERException(Messages.errColumnFormat);
        }
    } else if (colInfo.length == 3) {
        if (StringUtil.isEmpty(colInfo[0]) | StringUtil.isEmpty(colInfo[1]) | StringUtil.isEmpty(colInfo[2])) {
            throw new ERException(Messages.errColumnFormat);
        }
    } else {
        throw new ERException(Messages.errColumnFormat);
    }
    ERSchema schema = column.getERSchema();
    if (schema.isPhysicModel()) {
        String err = ERTableColumn.checkName(colInfo[0]);
        if (!StringUtil.isEmpty(err)) {
            throw new ERException(err);
        }
    }
    String physicalShowType = colInfo[1];
    if (!schema.isPhysicModel()) {
        if (schema.hasLogicalTypeInMap(physicalShowType)) {
            physicalShowType = schema.convert2UpPhysicalShowType(physicalShowType);
            if (physicalShowType.startsWith(DataType.DATATYPE_ENUM)) {
                physicalShowType = physicalShowType.replaceFirst(DataType.getUpperEnumType(), DataType.getLowerEnumType());
            }
        } else {
            physicalShowType = column.getShowType(true);
        }
    }
    String err = ERTableColumn.checkDataShowType(physicalShowType);
    if (!StringUtil.isEmpty(err)) {
        throw new ERException(err);
    }
}
Also used : ERSchema(com.cubrid.common.ui.er.model.ERSchema) ERException(com.cubrid.common.ui.er.ERException)

Aggregations

ERException (com.cubrid.common.ui.er.ERException)4 Constraint (com.cubrid.common.core.common.model.Constraint)2 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)2 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)2 PhysicalLogicRelation (com.cubrid.common.ui.er.logic.PhysicalLogicRelation)1 ERSchema (com.cubrid.common.ui.er.model.ERSchema)1 ArrayList (java.util.ArrayList)1