Search in sources :

Example 11 with TableSchemaCompareModel

use of com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel 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 12 with TableSchemaCompareModel

use of com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel 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 13 with TableSchemaCompareModel

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

the class TableSchemaComparator method compare.

/**
	 * Returns a list of table schema compare model
	 *
	 * @param left
	 * @param right
	 * @return TableSchemaCompareModel
	 */
public TableSchemaCompareModel compare(TableSchemaModel left, TableSchemaModel right) {
    TableSchemaCompareModel compareModel = new TableSchemaCompareModel(left, right, sourceClasses, targetClasses);
    compareModel.setTitle(left != null ? left.getName() : null);
    List<TableSchemaCompareModel> tableCompareModelList = compareDetail(left, right);
    if (tableCompareModelList == null) {
        tableCompareModelList = new ArrayList<TableSchemaCompareModel>();
    }
    compareModel.setTableCompareList(tableCompareModelList);
    compareModel.setDuplicateNameMap(duplicateNameMap);
    return compareModel;
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)

Aggregations

TableSchemaCompareModel (com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)13 TableDetailInfo (com.cubrid.common.core.common.model.TableDetailInfo)5 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)4 TableSchema (com.cubrid.common.ui.compare.schema.model.TableSchema)4 TableSchemaModel (com.cubrid.common.ui.compare.schema.model.TableSchemaModel)3 WrappedDatabaseInfo (com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo)3 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)3 ArrayList (java.util.ArrayList)3 AbstractUITask (com.cubrid.common.core.task.AbstractUITask)2 ITask (com.cubrid.common.core.task.ITask)2 TableSchemaComparator (com.cubrid.common.ui.compare.schema.TableSchemaComparator)2 TableSchemaCompareModelInputLazy (com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)2 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)2 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)2 HashMap (java.util.HashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 PartInitException (org.eclipse.ui.PartInitException)2