Search in sources :

Example 1 with CompareViewData

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);
}
Also used : CompareViewData(com.cubrid.common.ui.compare.data.model.CompareViewData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 2 with CompareViewData

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) PartInitException(org.eclipse.ui.PartInitException) BufferedReader(java.io.BufferedReader) CompareViewData(com.cubrid.common.ui.compare.data.model.CompareViewData)

Example 3 with CompareViewData

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Constraint(com.cubrid.common.core.common.model.Constraint) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) CompareViewData(com.cubrid.common.ui.compare.data.model.CompareViewData) File(java.io.File)

Example 4 with CompareViewData

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;
}
Also used : CompareViewData(com.cubrid.common.ui.compare.data.model.CompareViewData)

Aggregations

CompareViewData (com.cubrid.common.ui.compare.data.model.CompareViewData)4 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Constraint (com.cubrid.common.core.common.model.Constraint)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 PartInitException (org.eclipse.ui.PartInitException)1