Search in sources :

Example 6 with TableSchemaCompareModel

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

the class TableSchemaCompareTableViewerSorter method compare.

public int compare(Viewer viewer, Object e1, Object e2) {
    TableSchemaCompareModel cm1 = (TableSchemaCompareModel) e1;
    TableSchemaCompareModel cm2 = (TableSchemaCompareModel) e2;
    switch(sortType) {
        case STATUS:
            {
                Integer status_1 = cm1.getCompareStatus();
                Integer status_2 = cm2.getCompareStatus();
                return status_1.compareTo(status_2);
            }
        case -STATUS:
            {
                Integer status_1 = cm1.getCompareStatus();
                Integer status_2 = cm2.getCompareStatus();
                return status_2.compareTo(status_1);
            }
        case SOURCE_DB:
            {
                String source_db_1 = getTableName(cm1.getLeft());
                String source_db_2 = getTableName(cm2.getLeft());
                return source_db_1.compareTo(source_db_2);
            }
        case -SOURCE_DB:
            {
                String source_db_1 = getTableName(cm1.getLeft());
                String source_db_2 = getTableName(cm2.getLeft());
                return source_db_2.compareTo(source_db_1);
            }
        case TARGET_DB:
            {
                String target_db_1 = getTableName(cm1.getRight());
                String target_db_2 = getTableName(cm2.getRight());
                return target_db_1.compareTo(target_db_2);
            }
        case -TARGET_DB:
            {
                String target_db_1 = getTableName(cm1.getRight());
                String target_db_2 = getTableName(cm2.getRight());
                return target_db_2.compareTo(target_db_1);
            }
        case SOURCE_RECORDS:
            {
                Long records_1 = cm1.getSourceRecords();
                Long records_2 = cm2.getSourceRecords();
                return records_1.compareTo(records_2);
            }
        case -SOURCE_RECORDS:
            {
                Long records_1 = cm1.getSourceRecords();
                Long records_2 = cm2.getSourceRecords();
                return records_2.compareTo(records_1);
            }
        case TARGET_RECORDS:
            {
                Long records_1 = cm1.getTargetRecords();
                Long records_2 = cm2.getTargetRecords();
                return records_1.compareTo(records_2);
            }
        case -TARGET_RECORDS:
            {
                Long records_1 = cm1.getTargetRecords();
                Long records_2 = cm2.getTargetRecords();
                return records_2.compareTo(records_1);
            }
        case SOURCE_ATTRS:
            {
                Integer attrs_1 = 0;
                if (cm1.getSourceTableDetailInfo() != null)
                    attrs_1 = cm1.getSourceTableDetailInfo().getColumnsCount();
                Integer attrs_2 = 0;
                if (cm2.getSourceTableDetailInfo() != null)
                    attrs_2 = cm2.getSourceTableDetailInfo().getColumnsCount();
                return attrs_1.compareTo(attrs_2);
            }
        case -SOURCE_ATTRS:
            {
                Integer attrs_1 = 0;
                if (cm1.getSourceTableDetailInfo() != null)
                    attrs_1 = cm1.getSourceTableDetailInfo().getColumnsCount();
                Integer attrs_2 = 0;
                if (cm2.getSourceTableDetailInfo() != null)
                    attrs_2 = cm2.getSourceTableDetailInfo().getColumnsCount();
                return attrs_2.compareTo(attrs_1);
            }
        case TARGET_ATTRS:
            {
                Integer attrs_1 = 0;
                if (cm1.getTargetTableDetailInfo() != null)
                    attrs_1 = cm1.getTargetTableDetailInfo().getColumnsCount();
                Integer attrs_2 = 0;
                if (cm2.getTargetTableDetailInfo() != null)
                    attrs_2 = cm2.getTargetTableDetailInfo().getColumnsCount();
                return attrs_1.compareTo(attrs_2);
            }
        case -TARGET_ATTRS:
            {
                Integer attrs_1 = 0;
                if (cm1.getTargetTableDetailInfo() != null)
                    attrs_1 = cm1.getTargetTableDetailInfo().getColumnsCount();
                Integer attrs_2 = 0;
                if (cm2.getTargetTableDetailInfo() != null)
                    attrs_2 = cm2.getTargetTableDetailInfo().getColumnsCount();
                return attrs_2.compareTo(attrs_1);
            }
        case SOURCE_INDEX:
            {
                Integer index_1 = 0;
                if (cm1.getSourceTableDetailInfo() != null)
                    index_1 = cm1.getSourceTableDetailInfo().getIndexCount();
                Integer index_2 = 0;
                if (cm2.getSourceTableDetailInfo() != null)
                    index_2 = cm2.getSourceTableDetailInfo().getIndexCount();
                return index_1.compareTo(index_2);
            }
        case -SOURCE_INDEX:
            {
                Integer index_1 = 0;
                if (cm1.getSourceTableDetailInfo() != null)
                    index_1 = cm1.getSourceTableDetailInfo().getIndexCount();
                Integer index_2 = 0;
                if (cm2.getSourceTableDetailInfo() != null)
                    index_2 = cm2.getSourceTableDetailInfo().getIndexCount();
                return index_2.compareTo(index_1);
            }
        case TARGET_INDEX:
            {
                Integer index_1 = 0;
                if (cm1.getTargetTableDetailInfo() != null)
                    index_1 = cm1.getTargetTableDetailInfo().getIndexCount();
                Integer index_2 = 0;
                if (cm2.getTargetTableDetailInfo() != null)
                    index_2 = cm2.getTargetTableDetailInfo().getIndexCount();
                return index_1.compareTo(index_2);
            }
        case -TARGET_INDEX:
            {
                Integer index_1 = 0;
                if (cm1.getTargetTableDetailInfo() != null)
                    index_1 = cm1.getTargetTableDetailInfo().getIndexCount();
                Integer index_2 = 0;
                if (cm2.getTargetTableDetailInfo() != null)
                    index_2 = cm2.getTargetTableDetailInfo().getIndexCount();
                return index_2.compareTo(index_1);
            }
        case SOURCE_PK:
            {
                String pk_1 = "";
                if (cm1.getSourceTableDetailInfo() != null) {
                    if (cm1.getSourceTableDetailInfo().getPkCount() > 0)
                        pk_1 = "Y";
                }
                String pk_2 = "";
                if (cm2.getSourceTableDetailInfo() != null) {
                    if (cm2.getSourceTableDetailInfo().getPkCount() > 0)
                        pk_2 = "Y";
                }
                return pk_1.compareTo(pk_2);
            }
        case -SOURCE_PK:
            {
                String pk_1 = "";
                if (cm1.getSourceTableDetailInfo() != null) {
                    if (cm1.getSourceTableDetailInfo().getPkCount() > 0)
                        pk_1 = "Y";
                }
                String pk_2 = "";
                if (cm2.getSourceTableDetailInfo() != null) {
                    if (cm2.getSourceTableDetailInfo().getPkCount() > 0)
                        pk_2 = "Y";
                }
                return pk_2.compareTo(pk_1);
            }
        case TARGET_PK:
            {
                String pk_1 = "";
                if (cm1.getTargetTableDetailInfo() != null) {
                    if (cm1.getTargetTableDetailInfo().getPkCount() > 0)
                        pk_1 = "Y";
                }
                String pk_2 = "";
                if (cm2.getTargetTableDetailInfo() != null) {
                    if (cm2.getTargetTableDetailInfo().getPkCount() > 0)
                        pk_2 = "Y";
                }
                return pk_1.compareTo(pk_2);
            }
        case -TARGET_PK:
            {
                String pk_1 = "";
                if (cm1.getTargetTableDetailInfo() != null) {
                    if (cm1.getTargetTableDetailInfo().getPkCount() > 0)
                        pk_1 = "Y";
                }
                String pk_2 = "";
                if (cm2.getTargetTableDetailInfo() != null) {
                    if (cm2.getTargetTableDetailInfo().getPkCount() > 0)
                        pk_2 = "Y";
                }
                return pk_2.compareTo(pk_1);
            }
    }
    return 0;
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)

Example 7 with TableSchemaCompareModel

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

the class ERSchemaEditor method compareTableSchemas.

public void compareTableSchemas(final String modelName, final Map<String, TableSchema> tableSchema, final Map<String, SchemaInfo> schemaInfos) {
    final List<TableSchemaCompareModelInputLazy> input = new ArrayList<TableSchemaCompareModelInputLazy>();
    ITask reportBugTask = new AbstractUITask() {

        private boolean success = false;

        public void cancel() {
        }

        public void finish() {
        }

        public boolean isCancel() {
            return false;
        }

        public boolean isSuccess() {
            return success;
        }

        public void execute(IProgressMonitor monitor) {
            CubridDatabase database = erSchema.getCubridDatabase();
            List<TableDetailInfo> leftDbTableInfoList = TableSchemaCompareUtil.getTableInfoList(database);
            final CubridDatabase virtualDb = new CubridDatabase(modelName, modelName);
            virtualDb.setVirtual(true);
            DatabaseInfo info = database.getDatabaseInfo();
            virtualDb.setDatabaseInfo(info);
            WrappedDatabaseInfo wrappedDatabaseInfo = new WrappedDatabaseInfo(info);
            wrappedDatabaseInfo.addSchemaInfos(schemaInfos);
            wrappedDatabaseInfo.addTableSchemas(tableSchema);
            ERXmlDatabaseInfoMapper.addWrappedDatabaseInfo(info, wrappedDatabaseInfo);
            TableSchemaModel leftModel = TableSchemaCompareUtil.createTableSchemaModel(leftDbTableInfoList);
            TableSchemaModel rightModel = new TableSchemaModel();
            rightModel.getTableSchemaMap().putAll(tableSchema);
            TableSchemaComparator comparator = new TableSchemaComparator(database, virtualDb);
            TableSchemaCompareModel model = comparator.compare(leftModel, rightModel);
            model.setSourceDB(database);
            model.setTargetDB(virtualDb);
            input.add(new TableSchemaCompareModelInputLazy(model));
            success = true;
        }
    };
    TaskExecutor taskExecutor = new CommonTaskExec(com.cubrid.common.ui.common.Messages.titleSchemaComparison);
    taskExecutor.addTask(reportBugTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input.get(0), TableSchemaCompareInfoPart.ID);
        } catch (Exception e) {
        }
    }
}
Also used : TableSchemaCompareModelInputLazy(com.cubrid.common.ui.compare.schema.control.TableSchemaCompareModelInputLazy) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ITask(com.cubrid.common.core.task.ITask) 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) TableSchemaComparator(com.cubrid.common.ui.compare.schema.TableSchemaComparator) ArrayList(java.util.ArrayList) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) TableSchemaModel(com.cubrid.common.ui.compare.schema.model.TableSchemaModel) WrappedDatabaseInfo(com.cubrid.common.ui.cubrid.database.erwin.WrappedDatabaseInfo) PartInitException(org.eclipse.ui.PartInitException) SQLException(java.sql.SQLException) TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) AbstractUITask(com.cubrid.common.core.task.AbstractUITask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 8 with TableSchemaCompareModel

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

the class TableSchemaCompareInfoPart method fetchRecordCountProcess.

private void fetchRecordCountProcess(IProgressMonitor monitor, Set<String> selectedItemKeys) {
    // FIXME logic code move to core module
    if (compareModel == null) {
        return;
    }
    List<TableSchemaCompareModel> compareList = compareModel.getTableCompareList();
    if (compareList == null) {
        return;
    }
    int total = compareList.size();
    monitor.beginTask(Messages.loadDetailInfo, total);
    for (TableSchemaCompareModel compareModel : compareList) {
        monitor.worked(1);
        if (monitor.isCanceled()) {
            break;
        }
        TableDetailInfo tableInfo1 = compareModel.getSourceTableDetailInfo();
        TableDetailInfo tableInfo2 = compareModel.getTargetTableDetailInfo();
        // It should be collected only selected list on comparision table;
        String srcTableName = "";
        if (tableInfo1 != null) {
            srcTableName = StringUtil.nvl(tableInfo1.getTableName());
        }
        String dstTableName = "";
        if (tableInfo2 != null) {
            dstTableName = StringUtil.nvl(tableInfo2.getTableName());
        }
        String key = srcTableName + "$" + dstTableName;
        if (!selectedItemKeys.contains(key)) {
            continue;
        }
        if (tableInfo1 != null) {
            SchemaInfo schemaInfo = compareModel.getSourceSchemas().get(tableInfo1.getTableName());
            if (schemaInfo != null) {
                long counts = countTableRecords(sourceDB.getDatabaseInfo(), tableInfo1.getTableName());
                tableInfo1.setRecordsCount(counts);
            }
        }
        if (monitor.isCanceled()) {
            break;
        }
        if (tableInfo2 != null) {
            SchemaInfo schemaInfo = compareModel.getTargetSchemas().get(tableInfo2.getTableName());
            if (schemaInfo != null) {
                long counts = countTableRecords(targetDB.getDatabaseInfo(), tableInfo2.getTableName());
                tableInfo2.setRecordsCount(counts);
            }
        }
    }
    monitor.done();
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel) TableDetailInfo(com.cubrid.common.core.common.model.TableDetailInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 9 with TableSchemaCompareModel

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

the class TableSchemaCompareTableViewerContentProvider method getElements.

public Object[] getElements(Object inputElement) {
    if (inputElement instanceof TableSchemaCompareModel) {
        TableSchemaCompareModel model = (TableSchemaCompareModel) inputElement;
        List<TableSchemaCompareModel> list = model.getTableCompareList();
        if (list == null) {
            return new TableSchemaCompareModel[0];
        }
        return list.toArray(new TableSchemaCompareModel[list.size()]);
    }
    return new Object[] {};
}
Also used : TableSchemaCompareModel(com.cubrid.common.ui.compare.schema.model.TableSchemaCompareModel)

Example 10 with TableSchemaCompareModel

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

the class TableSchemaCompareDetailTableViewerLabelProvider method getColumnText.

public String getColumnText(Object element, int columnIndex) {
    if (!(element instanceof TableSchemaCompareModel)) {
        return "";
    }
    TableSchemaCompareModel cm = (TableSchemaCompareModel) element;
    String sourceTable = getTableName(cm.getLeft());
    String targetTable = getTableName(cm.getRight());
    switch(columnIndex) {
        case 0:
            return "";
        case 1:
            if (cm.getCompareStatus() == TableSchemaCompareModel.SCHEMA_SMISS)
                sourceTable = Messages.statusMissing;
            return sourceTable;
        case 2:
            if (cm.getCompareStatus() == TableSchemaCompareModel.SCHEMA_TMISS)
                targetTable = Messages.statusMissing;
            return targetTable;
        default:
            return "";
    }
}
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