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;
}
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();
}
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;
}
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());
}
});
}
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();
}
Aggregations