use of com.cubrid.common.ui.compare.data.model.CompareViewData in project cubrid-manager by CUBRID.
the class DataCompareDetailEditorPart method initTableViewer.
private void initTableViewer() {
TableViewerColumn col = null;
for (int i = 0, len = columnList.size(); i < len; i++) {
String columnName = columnList.get(i);
col = new TableViewerColumn(compareTableViewer, SWT.NONE);
col.getColumn().setWidth(100);
col.getColumn().setText(columnName);
}
if (dataList == null) {
dataList = new ArrayList<CompareViewData>();
}
compareTableViewer.setContentProvider(new DataCompareViewContentProvider());
compareTableViewer.setLabelProvider(new DataCompareViewLabelProvider());
compareTableViewer.setInput(dataList);
}
use of com.cubrid.common.ui.compare.data.model.CompareViewData in project cubrid-manager by CUBRID.
the class DataCompareDetailEditorPart method loadData.
private boolean loadData(int beginPage) {
// FIXME logic code move to core module
List<CompareViewData> newList = new ArrayList<CompareViewData>();
List<String> pkColumns = new ArrayList<String>();
List<String> pkTypes = new ArrayList<String>();
if (beginPage <= 0) {
beginPage = 1;
}
int rowCount = 0;
int beginPos = (beginPage - 1) * ROW_LIMIT;
int endPos = beginPos + ROW_LIMIT;
String filepath = compInput.getDiffFilePath();
BufferedReader in = null;
Connection connSrc = null;
Connection connTgt = null;
try {
String charset = compInput.getSourceDB().getCharSet();
boolean preparedColumnMeta = false;
synchronized (this) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(filepath), charset));
String row = null;
while ((row = in.readLine()) != null) {
String trimmedRow = row.trim();
if (trimmedRow.length() == 0) {
continue;
}
rowCount++;
if (rowCount < beginPos) {
continue;
}
if (rowCount > endPos) {
break;
}
String[] values = row.split("\t");
List<String> pkValues = new ArrayList<String>();
for (int i = 0; i < values.length; i += 3) {
if (!preparedColumnMeta) {
String columnName = values[0];
pkColumns.add(columnName);
String columnType = values[1];
pkTypes.add(columnType);
}
String columnValue = values[2];
pkValues.add(columnValue);
}
preparedColumnMeta = true;
CompareViewData src = new CompareViewData();
src.setIndex(rowCount);
src.setSource(true);
src.setPkColumnValues(pkValues);
newList.add(src);
CompareViewData tgt = new CompareViewData();
tgt.setIndex(rowCount);
tgt.setSource(false);
tgt.setPkColumnValues(pkValues);
newList.add(tgt);
src.setReferer(tgt);
tgt.setReferer(src);
}
}
// if it's page is 1, it might allow no contents.
if (newList.size() > 0 || page == 1 && beginPage == 1) {
connSrc = JDBCConnectionManager.getConnection(compInput.getSourceDB(), true);
connTgt = JDBCConnectionManager.getConnection(compInput.getTargetDB(), true);
for (CompareViewData compViewData : newList) {
if (compViewData.isSource()) {
fetchData(connSrc, compViewData, compInput.getSourceSchemaInfo(), pkColumns, pkTypes, true);
} else {
fetchData(connTgt, compViewData, compInput.getSourceSchemaInfo(), pkColumns, pkTypes, false);
}
}
dataList = newList;
return true;
}
} catch (Exception e) {
LOGGER.error("", e);
} finally {
FileUtil.close(in);
QueryUtil.freeQuery(connSrc);
QueryUtil.freeQuery(connTgt);
}
return false;
}
use of com.cubrid.common.ui.compare.data.model.CompareViewData in project cubrid-manager by CUBRID.
the class DataCompareEditorPart method exportDataToFile.
private int exportDataToFile(String basePath, String tableName) {
// FIXME logic code move to core module
String hashedTableName = StringUtil.md5(tableName);
String filepath = logFileBasePath + File.separatorChar + logFileBaseName + "_" + hashedTableName + ".compared";
String targetPath = basePath + File.separatorChar + tableName + ".sql";
if (!new File(filepath).exists()) {
return -1;
}
BufferedReader in = null;
BufferedWriter out = null;
try {
String charset = getSourceDB().getCharSet();
boolean preparedColumnMeta = false;
int rowCount = 0;
List<String> pkColumns = new ArrayList<String>();
List<String> pkTypes = new ArrayList<String>();
synchronized (this) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(filepath), charset));
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetPath), charset));
String row = null;
while ((row = in.readLine()) != null) {
String trimmedRow = row.trim();
if (trimmedRow.length() == 0) {
continue;
}
String[] values = row.split("\t");
List<String> pkValues = new ArrayList<String>();
for (int i = 0; i < values.length; i += 3) {
if (!preparedColumnMeta) {
String columnName = values[0];
pkColumns.add(columnName);
String columnType = values[1];
pkTypes.add(columnType);
}
String columnValue = values[2];
pkValues.add(columnValue);
}
preparedColumnMeta = true;
CompareViewData src = new CompareViewData();
src.setIndex(rowCount);
src.setSource(true);
src.setPkColumnValues(pkValues);
String sql = makeSelectQuery(src, tableName, pkColumns, pkTypes);
out.write(sql);
rowCount++;
}
}
return rowCount;
} catch (UnsupportedEncodingException e) {
LOGGER.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
LOGGER.error(e.getMessage(), e);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
} finally {
FileUtil.close(in);
FileUtil.close(out);
}
return 0;
}
use of com.cubrid.common.ui.compare.data.model.CompareViewData in project cubrid-manager by CUBRID.
the class DataCompareViewLabelProvider method getForeground.
public Color getForeground(Object element, int columnIndex) {
if (element instanceof CompareViewData) {
CompareViewData comp = (CompareViewData) element;
String curr = null;
if (comp.getData() != null && comp.getData().size() > columnIndex) {
curr = comp.getData().get(columnIndex);
}
String prev = null;
if (comp.getReferer() != null && comp.getReferer().getData() != null && comp.getReferer().getData().size() > columnIndex) {
prev = comp.getReferer().getData().get(columnIndex);
}
if (!StringUtil.isEqual(curr, prev)) {
return DIFFERENT_COLOR;
}
}
return null;
}
Aggregations