Search in sources :

Example 16 with SchemaInfo

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();
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) ERTable(com.cubrid.common.ui.er.model.ERTable) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 17 with SchemaInfo

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();
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ERTableColumn(com.cubrid.common.ui.er.model.ERTableColumn) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) HashSet(java.util.HashSet)

Example 18 with SchemaInfo

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());
        }
    }
}
Also used : Constraint(com.cubrid.common.core.common.model.Constraint) ERSchema(com.cubrid.common.ui.er.model.ERSchema) CubridTableParser(com.cubrid.common.ui.er.model.CubridTableParser) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) AddFKDialog(com.cubrid.common.ui.cubrid.table.dialog.AddFKDialog)

Example 19 with SchemaInfo

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;
}
Also used : ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) SQLException(java.sql.SQLException) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 20 with SchemaInfo

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;
    }
}
Also used : ViewsDetailInfoCTabItem(com.cubrid.common.ui.cubrid.view.editor.ViewDashboardComposite.ViewsDetailInfoCTabItem) OpenViewsDetailInfoPartProgress(com.cubrid.common.ui.spi.progress.OpenViewsDetailInfoPartProgress) ArrayList(java.util.ArrayList) ViewsDetailInfoCTabItem(com.cubrid.common.ui.cubrid.view.editor.ViewDashboardComposite.ViewsDetailInfoCTabItem) CTabItem(org.eclipse.swt.custom.CTabItem) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5