use of com.cubrid.common.ui.er.model.CubridTableParser in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method postEdittedTable.
/**
* Parse the table and add new table to the er schema
*
* @param erSchema ERSchema
*/
public void postEdittedTable(ERSchema erSchema) {
ERTable tmpTable = (ERTable) oldERTable.clone();
SchemaInfo newSchemaInfo = getNewSchemaInfo();
//update table name
if (!oldERTable.getName(isPhysical).equals(newERTable.getName(isPhysical))) {
oldERTable.modifyNameAndFire(newERTable.getName(isPhysical), isPhysical);
}
//update table collation
oldERTable.getSchemaInfo().setCollation(newSchemaInfo.getCollation());
//deleted columns
for (String oldColName : deletedColumns) {
oldERTable.removeColumnAndFire(oldERTable.getColumn(oldColName, isPhysical));
}
//modified columns
Set<String> oldNames = modifiedColumns.keySet();
for (String oldColName : oldNames) {
String newName = modifiedColumns.get(oldColName);
ERTableColumn oldColumn = oldERTable.getColumn(oldColName, isPhysical);
ERTableColumn newCol = newERTable.getColumn(newName, isPhysical);
if (oldColumn == null) {
continue;
}
ERTableColumn firedOldColumn = oldColumn.clone();
if (newCol == null) {
continue;
}
//will modify the old column to new
oldERTable.modifyColumn(oldColName, isPhysical, newCol);
oldColumn.firePropertyChange(ERTableColumn.TEXT_CHANGE, firedOldColumn, newCol);
}
//added columns
for (String addedColumn : addedColumns) {
ERTableColumn newColumn = newERTable.getColumn(addedColumn, isPhysical);
if (newColumn == null) {
continue;
}
//from new to old now
newColumn.setIsNew(false);
if (oldERTable.getColumn(addedColumn, isPhysical) != null) {
continue;
}
oldERTable.addColumnAndFire(newColumn);
}
//update pk
Constraint newPK = newSchemaInfo.getPK();
Constraint oldPK = oldERTable.getSchemaInfo().getPK();
if (oldPK != null) {
oldERTable.getSchemaInfo().removeConstraintByName(oldPK.getName(), ConstraintType.PRIMARYKEY.getText());
}
if (newPK != null) {
oldERTable.getSchemaInfo().addConstraint(newPK);
}
//update fk
List<Constraint> oldFKs = oldERTable.getSchemaInfo().getFKConstraints();
oldERTable.deleteAllFKShipsAndFire();
for (Constraint fk : oldFKs) {
oldERTable.getSchemaInfo().addConstraint(fk);
}
CubridTableParser tableParser = new CubridTableParser(erSchema);
try {
tableParser.buildReferenceShip(oldERTable, newSchemaInfo);
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
oldERTable = tmpTable;
return;
}
syncLogicalNameAndPhysicalComment();
}
use of com.cubrid.common.ui.er.model.CubridTableParser in project cubrid-manager by CUBRID.
the class CreateRelationshipCommand method execute.
@Override
public void execute() {
if (!check()) {
return;
}
ERSchema erSchema = foreignTable.getERSchema();
SchemaInfo fkSchemaInfo = erSchema.getSchemaInfo(foreignTable.getName());
AddFKDialog dlg = new AddFKDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), erSchema.getCubridDatabase(), fkSchemaInfo, null, false, erSchema.getAllSchemaInfo());
dlg.setDefaultTableName(primaryTable.getName());
int returnCode = dlg.open();
if (returnCode == AddFKDialog.OK) {
Constraint fk = dlg.getRetFK();
if (fk == null) {
return;
}
CubridTableParser parser = new CubridTableParser(erSchema);
try {
parser.addFKShip(foreignTable, fkSchemaInfo, fk);
fkSchemaInfo.addConstraint(fk);
} catch (Exception e) {
CommonUITool.openErrorBox(e.getMessage());
}
}
}
use of com.cubrid.common.ui.er.model.CubridTableParser in project cubrid-manager by CUBRID.
the class ExportImportGsonDataController method buildERDSchema.
private void buildERDSchema(ERSchema originSchema, ERSchema deserializedERSchema, Map<String, SchemaInfo> schemaInfos, boolean isImportMap) {
String message = "";
CubridTableParser tableParser = new CubridTableParser(originSchema);
tableParser.buildERTables(schemaInfos.values(), -1, -1, false);
if (isImportMap) {
originSchema.setPhysicalLogicRelation(deserializedERSchema.getPhysicalLogicRelation());
}
List<ERTable> successTables = tableParser.getSuccessTables();
for (ERTable table : successTables) {
ERTable savedTable = deserializedERSchema.getTable(table.getName());
table.setLogicalName(savedTable.getLogicalName());
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn column : columns) {
String colName = column.getName();
ERTableColumn savedColumn = savedTable.getColumn(colName, true);
column.setLogicalName(savedColumn.getLogicalName());
column.setLogicalType(savedColumn.getLogicalType());
}
if (originSchema.isLayoutManualDesired()) {
table.setBounds(savedTable.getBounds());
}
}
originSchema.FireAddedTable(successTables);
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 (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);
}
}
use of com.cubrid.common.ui.er.model.CubridTableParser in project cubrid-manager by CUBRID.
the class ImportERwinDataController method buildERDSchema.
private void buildERDSchema(ERSchema erSchema, Map<String, ERWinSchemaInfo> schemaInfos) {
String message = "";
CubridTableParser tableParser = new CubridTableParser(erSchema);
Set<SchemaInfo> dbSchemaInfos = new HashSet<SchemaInfo>();
Collection<ERWinSchemaInfo> erwinSchemas = schemaInfos.values();
for (ERWinSchemaInfo erwinSchema : erwinSchemas) {
SchemaInfo schemaInfo = (SchemaInfo) erwinSchema;
dbSchemaInfos.add(schemaInfo);
}
tableParser.buildERTables(dbSchemaInfos, -1, -1, true);
tableParser.appendLogicalInfo(schemaInfos);
List<ERTable> successTables = tableParser.getSuccessTables();
for (ERTable table : successTables) {
ERWinSchemaInfo savedTable = schemaInfos.get(table.getName());
table.setLogicalName(savedTable.getLogicalName());
List<ERTableColumn> columns = table.getColumns();
for (ERTableColumn column : columns) {
String colName = column.getName();
ERWinDBAttribute savedDBAttr = savedTable.getERWinDBAttr(colName);
column.setLogicalName(savedDBAttr.getLogicalName());
column.setLogicalType(savedDBAttr.getLogicalDataType());
}
}
erSchema.FireAddedTable(successTables);
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 (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);
}
}
use of com.cubrid.common.ui.er.model.CubridTableParser 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();
}
Aggregations