Search in sources :

Example 6 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class ImportERwinAction method run.

public void run() {
    // FIXME logic code move to core module
    int selected = 0;
    int logined = 0;
    Object[] objects = getSelectedObj();
    if (objects instanceof Object[]) {
        for (Object object : objects) {
            if (object instanceof CubridDatabase) {
                selected++;
                CubridDatabase database = (CubridDatabase) object;
                if (database.isLogined()) {
                    logined++;
                }
            }
        }
    }
    if (selected > 1) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectOneDbToImport);
        return;
    }
    if (selected <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectImportDbToImport);
        return;
    }
    if (logined <= 0) {
        CommonUITool.openWarningBox(com.cubrid.common.ui.cubrid.database.erwin.Messages.errERwinSelectLoginedDbToImport);
        return;
    }
    Object[] obj = getSelectedObj();
    if (obj == null || obj.length != 1) {
        return;
    }
    if (!(obj[0] instanceof CubridDatabase)) {
        return;
    }
    database = (CubridDatabase) obj[0];
    ERwinImportDialog dialog = new ERwinImportDialog(getShell(), database);
    int returnvalue = dialog.open();
    if (returnvalue != IDialogConstants.OK_ID) {
        return;
    }
    ERXmlContainer container = dialog.getContainer();
    if (container.getErrMsg() != null && !container.getErrMsg().equals("")) {
        CommonUITool.openErrorBox(container.getErrMsg());
        return;
    }
    Map<String, TableSchema> tableSchema = container.getTableSchemas();
    Map<String, ERWinSchemaInfo> schemaInfos = container.getSchemaInfos();
    String modelName = container.getDatabaseName();
    createCompareModel(modelName, tableSchema, schemaInfos);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) ERXmlContainer(com.cubrid.common.ui.cubrid.database.erwin.ERXmlContainer) ERWinSchemaInfo(com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) ERwinImportDialog(com.cubrid.common.ui.cubrid.database.erwin.dialog.ERwinImportDialog)

Example 7 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class TableSchemaCompareExtraColumnLabelProvider method getText.

public String getText(Object element) {
    TableSchemaCompareModel cm = (TableSchemaCompareModel) element;
    TableDetailInfo tableInfo = null;
    if (focus == 0) {
        if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_SMISS) {
            tableInfo = cm.getSourceTableDetailInfo();
        }
    } else if (focus == 1) {
        if (cm.getCompareStatus() != TableSchemaCompareModel.SCHEMA_TMISS) {
            tableInfo = cm.getTargetTableDetailInfo();
            if (tableInfo == null) {
                TableSchema tableSchema = (TableSchema) cm.getRight();
                SchemaInfo schemaInfo = cm.getTargetSchemas().get(tableSchema.getName());
                int columnCount = schemaInfo.getAttributes().size();
                int idxCount = 0;
                int pk = 0;
                for (Constraint constraint : schemaInfo.getConstraints()) {
                    if (constraint.getType().equals(ConstraintType.PRIMARYKEY.getText())) {
                        pk++;
                        continue;
                    } else {
                        idxCount++;
                    }
                }
                tableInfo = new TableDetailInfo();
                tableInfo.setPkCount(pk);
                tableInfo.setColumnsCount(columnCount);
                tableInfo.setIndexCount(idxCount);
            }
        }
    }
    if (type == RECORDS_COUNT) {
        long tableRecordCount = 0;
        if (tableInfo != null) {
            tableRecordCount = tableInfo.getRecordsCount();
        }
        if (focus == 0) {
            cm.setSourceRecords(tableRecordCount);
        } else if (focus == 1) {
            cm.setTargetRecords(tableRecordCount);
        }
        if (tableRecordCount < 0) {
            return Messages.notCount;
        }
        return String.valueOf(tableRecordCount);
    } else if (type == ATTRIBUTES_COUNT) {
        int attributeCount = 0;
        if (tableInfo != null) {
            attributeCount = tableInfo.getColumnsCount();
        }
        return String.valueOf(attributeCount);
    } else if (type == INDEX_COUNT) {
        int indexCount = 0;
        if (tableInfo != null) {
            indexCount = tableInfo.getIndexCount();
        }
        return String.valueOf(indexCount);
    } else if (type == PK_STATUS) {
        int pkCount = 0;
        if (tableInfo != null) {
            pkCount = tableInfo.getPkCount();
        }
        if (pkCount > 0) {
            return "Y";
        }
        return "";
    }
    return "";
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) Constraint(com.cubrid.common.core.common.model.Constraint) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 8 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class TableSchemaCompareInfoPart method copyTableAlterDDL.

/**
	 * copyTableLeftAlterDDL
	 */
private void copyTableAlterDDL(CubridDatabase leftDB, CubridDatabase rightDB, boolean leftToRight) {
    // FIXME logic code move to core module
    StringBuffer clipboardDataString = new StringBuffer();
    TableItem[] tableItems = tablesSchemaCompareTable.getTable().getSelection();
    String title = "";
    String msg = "";
    for (int i = 0; i < tableItems.length; i++) {
        if (i > 0) {
            clipboardDataString.append(StringUtil.NEWLINE);
            clipboardDataString.append(StringUtil.NEWLINE);
        }
        TableSchemaCompareModel compareModel = (TableSchemaCompareModel) tableItems[i].getData();
        TableSchema leftTableSchema = (TableSchema) compareModel.getLeft();
        TableSchema rightTableSchema = (TableSchema) compareModel.getRight();
        String tableCompare = leftTableSchema.getName();
        if (StringUtil.isEmpty(leftTableSchema.getName())) {
            tableCompare = rightTableSchema.getName();
        }
        String alterDDL = null;
        if (compareModel.getCompareStatus() != TableSchemaCompareModel.SCHEMA_EQUAL && compareModel.getCompareStatus() != TableSchemaCompareModel.RECORDS_DIFF) {
            Map<String, SchemaInfo> sourceSchemas = compareModel.getSourceSchemas();
            Map<String, SchemaInfo> targetSchemas = compareModel.getTargetSchemas();
            SchemaInfo sourceTableSchemaInfo = null;
            SchemaInfo targetTableSchemaInfo = null;
            if (leftToRight) {
                sourceTableSchemaInfo = sourceSchemas.get(tableCompare);
                targetTableSchemaInfo = targetSchemas.get(tableCompare);
            } else {
                targetTableSchemaInfo = sourceSchemas.get(tableCompare);
                sourceTableSchemaInfo = targetSchemas.get(tableCompare);
            }
            alterDDL = tableComp.getTableAlterScript(leftDB, rightDB, tableCompare, sourceTableSchemaInfo, targetTableSchemaInfo);
            if (StringUtil.isNotEmpty(alterDDL)) {
                clipboardDataString.append(alterDDL.trim());
            }
        }
    }
    Clipboard clipboard = CommonUITool.getClipboard();
    if (clipboardDataString.length() != 0) {
        if ("--NotSupportAlterAutoIncrement".equals(clipboardDataString.toString())) {
            title = Messages.compareStatusTip;
            msg = Messages.alterAutoIncrementNotSupport;
        } else {
            TextTransfer textTransfer = TextTransfer.getInstance();
            Transfer[] transfers = new Transfer[] { textTransfer };
            Object[] data = new Object[] { clipboardDataString.toString() };
            clipboard.setContents(data, transfers);
            title = Messages.alterScript;
            msg = Messages.tableSchemaAlterCopyMessage;
        }
    } else {
        clipboard.clearContents();
        title = Messages.emptyAlterScript;
        msg = Messages.schemaIdenticalMessage;
    }
    CommonUITool.openInformationBox(title, msg);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) TableItem(org.eclipse.swt.widgets.TableItem) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 9 with TableSchema

use of com.cubrid.common.ui.compare.schema.model.TableSchema in project cubrid-manager by CUBRID.

the class ERSchemaEditor method compareDDL2DB.

public void compareDDL2DB() {
    DatabaseInfo info = database.getDatabaseInfo();
    if (info == null) {
        CommonUITool.openErrorBox(Messages.errNoDatabase);
        return;
    }
    if (!info.isLogined()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    ServerInfo serverInfo = info.getServerInfo();
    if (serverInfo != null && !serverInfo.isConnected()) {
        CommonUITool.openErrorBox(Messages.msgDBNotLogin);
        return;
    }
    Map<String, SchemaInfo> schemaInfos = erSchema.getAllSchemaInfo();
    Map<String, TableSchema> tableSchemas = new HashMap<String, TableSchema>();
    WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info.getDbName(), info.getServerInfo());
    ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
    wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
    SchemaDDL ddl = new SchemaDDL(null, wrappedDatabaseInfo);
    for (String tableName : schemaInfos.keySet()) {
        SchemaInfo schemaInfo = schemaInfos.get(tableName);
        if (schemaInfo == null || !tableName.equals(schemaInfo.getClassname())) {
            continue;
        }
        // now do not support view table
        String strDDL = ddl.getSchemaDDL(schemaInfo, true, true);
        TableSchema tableSchema = new TableSchema(tableName, "");
        tableSchema.setSchemaInfo(strDDL);
        tableSchemas.put(tableSchema.getName(), tableSchema);
    }
    wrappedDatabaseInfo.addTableSchemas(tableSchemas);
    compareTableSchemas(getEditorInput().getName(), tableSchemas, schemaInfos);
}
Also used : TableSchema(com.cubrid.common.ui.compare.schema.model.TableSchema) ERVirtualDatabaseInfo(com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) HashMap(java.util.HashMap) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) SchemaDDL(com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

TableSchema (com.cubrid.common.ui.compare.schema.model.TableSchema)9 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)4 TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)3 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)3 HashMap (java.util.HashMap)3 Constraint (com.cubrid.common.core.common.model.Constraint)2 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)2 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)2 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)2 ERXmlContainer (com.cubrid.common.ui.cubrid.database.erwin.ERXmlContainer)1 ERwinImportDialog (com.cubrid.common.ui.cubrid.database.erwin.dialog.ERwinImportDialog)1 ERVirtualDatabaseInfo (com.cubrid.common.ui.er.model.ERVirtualDatabaseInfo)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 GetAllSchemaTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask)1 ArrayList (java.util.ArrayList)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1