Search in sources :

Example 1 with DataCompare

use of com.cubrid.common.ui.compare.data.model.DataCompare in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method exportData.

private boolean exportData(final String basePath) {
    if (compareList == null || compareList.size() == 0) {
        CommonUITool.openErrorBox(Messages.msgNotExistsToExportData);
        return false;
    }
    printToConsole("\n", false);
    printToConsole(Messages.msgBeginToCompareData + "\n", true);
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(final IProgressMonitor monitor) {
            int total = compareList.size();
            monitor.beginTask(Messages.msgLoadingData, total);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    for (DataCompare comp : compareList) {
                        int counts = exportDataToFile(basePath, comp.getTableName());
                        if (counts == -1) {
                            if (comp.getRecordsTarget() == -1) {
                                String msg = Messages.bind(Messages.msgDataCompareNoTable, comp.getTableName()) + "\n";
                                printToConsoleOnWorkThread(msg, true);
                            } else {
                                String msg = Messages.bind(Messages.msgDataCompareNoData, comp.getTableName()) + "\n";
                                printToConsoleOnWorkThread(msg, true);
                            }
                        } else {
                            String msg = Messages.bind(Messages.msgDataCompareResultStatus, comp.getTableName(), counts) + "\n";
                            printToConsoleOnWorkThread(msg, true);
                        }
                        monitor.worked(1);
                    }
                    monitor.done();
                }
            });
        }
    };
    try {
        new ProgressMonitorDialog(shell).run(true, false, progress);
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
    String msg = Messages.bind(Messages.msgEndToCompareData, basePath) + "\n";
    printToConsole(msg, true);
    return true;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) Constraint(com.cubrid.common.core.common.model.Constraint) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with DataCompare

use of com.cubrid.common.ui.compare.data.model.DataCompare in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method doCompare.

private void doCompare() {
    // FIXME logic code move to core module
    runningState = RUNNING_SATE_ONLINE;
    enabledInteractive = false;
    final boolean fullscan = btnAll.getSelection();
    long startTmp = StringUtil.longValue(txtRgeBegin.getText(), 1) - 1;
    if (startTmp < 0) {
        startTmp = 0;
    }
    final long start = startTmp;
    final int limit = StringUtil.intValue(txtRgeLimit.getText(), 1000);
    Thread thread = new Thread(new Runnable() {

        public void run() {
            Connection conn = null;
            try {
                totalRecords = 0;
                for (DataCompare dataCompare : compareList) {
                    if (!dataCompare.isUse()) {
                        continue;
                    }
                    if (!dataCompare.isSameSchema()) {
                        continue;
                    }
                    long total = dataCompare.getRecordsSource();
                    long totalTarget = dataCompare.getRecordsTarget();
                    if (totalTarget <= 0) {
                        continue;
                    }
                    if (!fullscan) {
                        if (start >= total) {
                            continue;
                        }
                        totalRecords += Math.min(total, limit);
                    } else {
                        totalRecords += total;
                    }
                }
                for (DataCompare dataCompare : compareList) {
                    if (runningState != RUNNING_SATE_ONLINE) {
                        break;
                    }
                    if (!dataCompare.isSameSchema()) {
                        continue;
                    }
                    if (!dataCompare.isUse()) {
                        continue;
                    }
                    int fetchLimit = 1000;
                    if (!fullscan) {
                    //fetchLimit = limit;
                    }
                    long total = dataCompare.getRecordsSource();
                    long totalTarget = dataCompare.getRecordsTarget();
                    // Skip, if the target have no data
                    if (totalTarget <= 0) {
                        dataCompare.setProgressPosition(0);
                        dataCompare.setNotExists(total);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                compareTableViewer.refresh();
                            }
                        });
                        continue;
                    }
                    if (total <= 0) {
                        dataCompare.setProgressPosition(0);
                        dataCompare.setNotExists(0);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                compareTableViewer.refresh();
                            }
                        });
                        continue;
                    }
                    long current = dataCompare.getProgressPosition();
                    if (!fullscan) {
                        if (start >= total) {
                            continue;
                        }
                        current = 0;
                        total = current + limit;
                        dataCompare.setProgressPosition(current);
                    }
                    for (; current < total; current += fetchLimit) {
                        if (runningState != RUNNING_SATE_ONLINE) {
                            break;
                        }
                        String msg = Messages.bind(Messages.lblDataCompareLogSrcLoading, dataCompare.getTableName(), (current + 1));
                        printToConsoleOnWorkThread(msg, true);
                        conn = JDBCConnectionManager.getConnection(getSourceDB(), true);
                        List<HashedCompareData> dataList = null;
                        if (useHashMode) {
                            dataList = fetchHashedCompareData(conn, dataCompare.getSchemaInfo(), current, fetchLimit);
                        } else {
                            dataList = fetchHashedCompareDataCompatible(conn, dataCompare.getSchemaInfo(), current, fetchLimit);
                        }
                        QueryUtil.freeQuery(conn);
                        printToConsoleOnWorkThread("\n", false);
                        msg = Messages.bind(Messages.lblDataCompareLogTargetDiff + "\n", dataCompare.getTableName(), (current + 1));
                        printToConsoleOnWorkThread(msg, true);
                        conn = JDBCConnectionManager.getConnection(getTargetDB(), true);
                        if (useHashMode) {
                            compareHashedCompareData(conn, dataCompare, dataList);
                        } else {
                            compareHashedCompareDataCompatible(conn, dataCompare, dataList);
                        }
                        QueryUtil.freeQuery(conn);
                        printToConsoleOnWorkThread("\n", false);
                    }
                }
                if (runningState != RUNNING_SATE_ONLINE) {
                    runningState = RUNNING_SATE_STANDBY;
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            changeButtonStateForFinished();
                            printToConsole(Messages.msgDataCompareStopped + "\n", true);
                        }
                    });
                    return;
                }
            } catch (SQLException e) {
                LOGGER.error(e.getMessage(), e);
                final String error = e.getMessage();
                runningState = RUNNING_SATE_STANDBY;
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        changeButtonStateForFinished();
                        printToConsole(Messages.msgDataCompareStoppedError + "\n", true);
                        printToConsole(error, true);
                    }
                });
                return;
            } finally {
                QueryUtil.freeQuery(conn);
            }
            runningState = RUNNING_SATE_STANDBY;
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    changeButtonStateForFinished();
                    printToConsole(Messages.msgDataCompareCompleted + "\n", true);
                }
            });
        }
    });
    thread.start();
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) List(java.util.List) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 3 with DataCompare

use of com.cubrid.common.ui.compare.data.model.DataCompare in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method doRefresh.

private void doRefresh(boolean collectRecordCount) {
    // FIXME logic code move to core module
    Map<String, DataCompare> dataCompareMap = new HashMap<String, DataCompare>();
    if (compareList != null) {
        for (DataCompare dataCompare : compareList) {
            dataCompareMap.put(dataCompare.getTableName(), dataCompare);
        }
    }
    DatabaseInfo sourceDB = ((DataCompareEditorInput) getEditorInput()).getSourceDB();
    DatabaseInfo targetDB = ((DataCompareEditorInput) getEditorInput()).getTargetDB();
    if (logFileBaseName != null) {
        FileUtil.delete(logFileBasePath + File.separatorChar + logFileBaseName);
        logFileBaseName = null;
    }
    logFileBaseName = sourceDB.getDbName() + "_" + System.currentTimeMillis();
    GetAllSchemaTask sourceSchemaTask = new GetAllSchemaTask(sourceDB);
    GetAllSchemaTask targetSchemaTask = new GetAllSchemaTask(targetDB);
    TaskExecutor taskExecutor = new CommonTaskExec(Messages.loadEntireSchemaComparison);
    taskExecutor.addTask(sourceSchemaTask);
    taskExecutor.addTask(targetSchemaTask);
    new ExecTaskWithProgress(taskExecutor).exec();
    if (taskExecutor.isSuccess()) {
        synchronized (compareList) {
            compareList.clear();
            Set<String> partitions = new HashSet<String>();
            List<SchemaInfo> sourceList = sourceSchemaTask.getSchemaList();
            List<SchemaInfo> targetList = targetSchemaTask.getSchemaList();
            for (SchemaInfo schemaInfo : sourceList) {
                if (schemaInfo.getPartitionList() != null) {
                    for (PartitionInfo partition : schemaInfo.getPartitionList()) {
                        String partClassName = partition.getPartitionClassName();
                        partitions.add(partClassName);
                    }
                }
            }
            for (SchemaInfo schemaInfo : sourceList) {
                DataCompare dataCompare = dataCompareMap.get(schemaInfo.getClassname());
                if (dataCompare == null) {
                    dataCompare = new DataCompare();
                    dataCompare.setTableName(schemaInfo.getClassname());
                    dataCompare.setSchemaInfo(schemaInfo);
                    dataCompare.setRefreshed(false);
                } else {
                    dataCompare.setMatches(0);
                    dataCompare.setNotExists(0);
                    dataCompare.setNotMatches(0);
                    dataCompare.setProgressPosition(0);
                }
                if (schemaInfo.hasPK() && !partitions.contains(schemaInfo.getClassname())) {
                    SchemaInfo targetSchemeInfo = getSchemeInfoByName(schemaInfo.getClassname(), targetList);
                    boolean isSameSchema = canCompareData(schemaInfo, targetSchemeInfo);
                    dataCompare.setSameSchema(isSameSchema);
                    compareList.add(dataCompare);
                }
            }
            Collections.sort(compareList, new Comparator<DataCompare>() {

                public int compare(DataCompare o1, DataCompare o2) {
                    if (o1 == null || o1.getTableName() == null) {
                        return -1;
                    } else if (o2 == null || o2.getTableName() == null) {
                        return 1;
                    }
                    return o1.getTableName().compareToIgnoreCase(o2.getTableName());
                }
            });
        }
        compareTableViewer.refresh();
    }
    if (!collectRecordCount) {
        return;
    }
    totalRecords = 0;
    completedRecords = 0;
    refreshRecordCount();
    refreshedRecordCounts = true;
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) HashMap(java.util.HashMap) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) GetAllSchemaTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask) PartitionInfo(com.cubrid.common.core.common.model.PartitionInfo) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) HashSet(java.util.HashSet) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 4 with DataCompare

use of com.cubrid.common.ui.compare.data.model.DataCompare in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method createContent.

private void createContent(Composite parent) {
    compareTableViewer = new TableViewer(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    compareTableViewer.setUseHashlookup(true);
    compareTableViewer.setColumnProperties(columnNames);
    CommonUITool.createGridLayout(compareTableViewer.getTable(), 1, 0, 10, 0, 10, 0, 0, 0, 0);
    compareTableViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    compareTableViewer.getTable().setLinesVisible(true);
    compareTableViewer.getTable().setHeaderVisible(true);
    sorter = new DataCompareSchemaListViewSorter();
    sorter.setSortType(DataCompareSchemaListViewSorter.SORT_TABLE);
    compareTableViewer.setSorter(sorter);
    makeContextMenu(compareTableViewer);
    final TableViewerColumn firstCol = new TableViewerColumn(compareTableViewer, SWT.NONE);
    firstCol.getColumn().setWidth(30);
    firstCol.getColumn().setResizable(false);
    firstCol.getColumn().setAlignment(SWT.CENTER);
    firstCol.getColumn().setImage(CommonUIPlugin.getImage("icons/unchecked.gif"));
    firstCol.getColumn().addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = compareTableViewer.getTable().getItems();
            if (items == null) {
                return;
            }
            for (TableItem item : items) {
                DataCompare dataCompare = (DataCompare) item.getData();
                dataCompare.setUse(isSelectAll);
            }
            compareTableViewer.refresh();
            Image image = null;
            if (isSelectAll) {
                image = CommonUIPlugin.getImage("icons/checked.gif");
            } else {
                image = CommonUIPlugin.getImage("icons/unchecked.gif");
            }
            firstCol.getColumn().setImage(image);
            isSelectAll = !isSelectAll;
        }
    });
    TableViewerColumn col = new TableViewerColumn(compareTableViewer, SWT.NONE);
    col.getColumn().setWidth(200);
    col.getColumn().setText(Messages.lblDataCompareTable);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_TABLE);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordSource);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_SOURCE_RECORDS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordTarget);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_TARGET_RECORDS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordProgress);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_PROGRESS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordMatch);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_MATCHES);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordNoMatch);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_NOT_MATCHES);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(100);
    col.getColumn().setText(Messages.lblDataCompareRecordNotExist);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_NOT_EXISTS);
    col = new TableViewerColumn(compareTableViewer, SWT.LEFT);
    col.getColumn().setWidth(300);
    col.getColumn().setText(Messages.lblDataCompareRecordError);
    makeSortTableColumn(col, DataCompareSchemaListViewSorter.SORT_ERROR);
    CellEditor[] cellEditor = new CellEditor[1];
    cellEditor[0] = new CheckboxCellEditor(compareTableViewer.getTable());
    compareTableViewer.setCellEditors(cellEditor);
    compareTableViewer.setCellModifier(new DataCompareCellModifier(this));
    compareTableViewer.setContentProvider(new DataCompareSchemaListContentProvider());
    compareTableViewer.setLabelProvider(new DataCompareSchemaListLabelProvider());
    compareList = new ArrayList<DataCompare>();
    compareTableViewer.setInput(compareList);
    txtProgress = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    txtProgress.setEditable(false);
    txtProgress.setWordWrap(true);
    txtProgress.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, 100));
    txtProgress.setBackground(txtProgress.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    txtProgress.setForeground(txtProgress.getDisplay().getSystemColor(SWT.COLOR_GREEN));
    compareTableViewer.getTable().setToolTipText(Messages.msgYouCanSeeDetailDblclick);
    compareTableViewer.getTable().addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.character == ' ') {
                TableItem[] items = compareTableViewer.getTable().getSelection();
                if (items == null) {
                    return;
                }
                for (TableItem item : items) {
                    DataCompare dataCompare = (DataCompare) item.getData();
                    dataCompare.setUse(!dataCompare.isUse());
                }
                compareTableViewer.refresh();
            }
        }
    });
    compareTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            if (!refreshedRecordCounts) {
                CommonUITool.openWarningBox(Messages.msgClickRefreshToEsimateDiff);
                return;
            }
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            DataCompare model = (DataCompare) selection.getFirstElement();
            if (!model.isSameSchema()) {
                CommonUITool.openWarningBox(Messages.msgTheSchemaDiff);
                return;
            }
            if (model.getRecordsTarget() == -1) {
                CommonUITool.openWarningBox(Messages.msgTargetNotFound);
                return;
            }
            if (model.getRecordsSource() == 0 && model.getRecordsTarget() > 0) {
                CommonUITool.openWarningBox(Messages.msgTargetNoData);
                return;
            }
            if (model.getRecordsSource() == 0) {
                CommonUITool.openWarningBox(Messages.msgNoDataToCompare);
                return;
            }
            if (model.getProgressPosition() == 0) {
                CommonUITool.openWarningBox(Messages.msgNotYetCompared);
                return;
            }
            if (model.getNotMatches() == 0 && model.getNotExists() == 0) {
                CommonUITool.openWarningBox(Messages.msgSameData);
                return;
            }
            showDataCompareDetailEditor(model.getSchemaInfo());
        }
    });
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) KeyAdapter(org.eclipse.swt.events.KeyAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 5 with DataCompare

use of com.cubrid.common.ui.compare.data.model.DataCompare in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method checkUncheckItems.

private void checkUncheckItems(TableViewer tableViewer, boolean check) {
    Table table = tableViewer.getTable();
    int selectionCount = table.getSelectionCount();
    if (selectionCount > 1) {
        TableItem[] items = table.getSelection();
        for (TableItem item : items) {
            DataCompare dataCompare = (DataCompare) item.getData();
            dataCompare.setUse(check);
        }
    }
    tableViewer.refresh();
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) DataCompare(com.cubrid.common.ui.compare.data.model.DataCompare) Constraint(com.cubrid.common.core.common.model.Constraint)

Aggregations

DataCompare (com.cubrid.common.ui.compare.data.model.DataCompare)11 Constraint (com.cubrid.common.core.common.model.Constraint)5 TableItem (org.eclipse.swt.widgets.TableItem)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SQLException (java.sql.SQLException)2 Table (org.eclipse.swt.widgets.Table)2 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)1 SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 GetAllSchemaTask (com.cubrid.cubridmanager.core.cubrid.table.task.GetAllSchemaTask)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1