use of com.cubrid.common.core.common.model.SchemaInfo 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.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class EditVirtualTableDialog method addNewColumn.
public void addNewColumn() {
SchemaInfo newSchemaInfo = getNewSchemaInfo();
if (newSchemaInfo == null) {
return;
}
// boolean hasNotFinishedColumn = false;
boolean hasDuplicatedColumn = false;
List<ERTableColumn> items = newERTable.getColumns();
if (items != null && items.size() > 0) {
Set<String> matches = new HashSet<String>();
// check whether there is no name column
for (ERTableColumn col : items) {
if (col == null) {
continue;
}
if (StringUtil.isEmpty(col.getName(erSchema.isPhysicModel()))) {
continue;
}
if (matches.contains(col.getName(erSchema.isPhysicModel()))) {
hasDuplicatedColumn = true;
break;
}
matches.add(col.getName(erSchema.isPhysicModel()));
}
}
if (hasDuplicatedColumn) {
CommonUITool.openErrorBox(Messages.errSameNameOnEditTableAddColumn);
return;
}
String collation = null;
if (newSchemaInfo != null && newSchemaInfo.getCollation() != null) {
collation = newSchemaInfo.getCollation();
} else {
collation = Collation.DEFAULT_COLLATION;
}
DBAttribute addAttribute = new DBAttribute("", DataType.DATATYPE_CHAR, newSchemaInfo.getClassname(), false, false, false, false, null, collation);
ERTableColumn column = new ERTableColumn(newERTable, addAttribute, false);
column.setIsNew(true);
tempERColumnList.add(column);
loadColumnData();
columnTableView.setSelection(new StructuredSelection(addAttribute), true);
columnsTable.setFocus();
handleSelectionChangeInColumnTable();
}
use of com.cubrid.common.core.common.model.SchemaInfo 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.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ERDNDController method getSelectedSchemaInfos.
/**
* Replace the SQL, and get clone SchemaInfo list
*
* @return boolean
*/
private List<SchemaInfo> getSelectedSchemaInfos() {
// FIXME move this logic to core module
List<ISchemaNode> schemaNodeList = new ArrayList<ISchemaNode>();
List<SchemaInfo> validSchemaInfoList = new ArrayList<SchemaInfo>();
boolean isValid = fillInSelectedNode(schemaNodeList);
if (!isValid || (schemaNodeList.isEmpty())) {
return null;
}
boolean isSame = checkSourceDB(schemaNodeList);
if (!isSame) {
CommonUITool.openInformationBox(com.cubrid.common.ui.er.Messages.errDragTableSource);
return null;
}
Connection conn = null;
String err = null;
try {
conn = JDBCConnectionManager.getConnection(schemaNodeList.get(0).getDatabase().getDatabaseInfo(), false);
// Get all tables SchemaInfo
for (ISchemaNode node : schemaNodeList) {
SchemaInfo tableInfo = getSchemaInfo(node, conn);
if (tableInfo == null) {
String error = node.getDatabase().getDatabaseInfo().getErrorMessage();
if (StringUtil.isEmpty(error)) {
error = com.cubrid.common.ui.er.Messages.errNotExistDraggedTable;
}
CommonUITool.openErrorBox(error);
return null;
}
validSchemaInfoList.add(tableInfo);
}
} catch (Exception e) {
LOGGER.error("", e);
err = e.getMessage();
} finally {
QueryUtil.freeQuery(conn);
}
if (err != null) {
CommonUITool.openErrorBox(editor.getGraphicalControl().getShell(), err);
}
return validSchemaInfoList;
}
use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.
the class ViewDashboardEditorPart method refresh.
public void refresh() {
OpenViewsDetailInfoPartProgress progress = new OpenViewsDetailInfoPartProgress(database);
progress.loadViewsInfo();
if (progress.isSuccess()) {
viewList = progress.getViewList();
viewsDetailInfoTable.setInput(viewList);
viewsDetailInfoTable.refresh();
List<CTabItem> closeTabItem = new ArrayList<CTabItem>();
for (CTabItem cTabItem : tabFolder.getItems()) {
ViewsDetailInfoCTabItem viewsDetailInfoCTabItem = (ViewsDetailInfoCTabItem) cTabItem;
//refresh column data
if (findItemName(viewsDetailInfoCTabItem.getText())) {
SchemaInfo schemaInfo = database.getDatabaseInfo().getSchemaInfo(viewsDetailInfoCTabItem.getText());
viewsDetailInfoCTabItem.getViewInfoComposite().setInput(schemaInfo);
} else {
//tag non-exist view tab
closeTabItem.add(cTabItem);
}
}
//dispose non-exist view tab
for (CTabItem cTabItem : closeTabItem) {
cTabItem.dispose();
}
//if the select item is disposed ,set the first on selection
if (tabFolder.getItems().length > 0 && tabFolder.getSelection().isDisposed()) {
tabFolder.setSelection(0);
}
viewChangeFlag = false;
}
}
Aggregations