Search in sources :

Example 41 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo 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 42 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class DataCompareEditorPart method compareHashedCompareData.

private void compareHashedCompareData(Connection conn, DataCompare dataCompare, List<HashedCompareData> dataList) {
    // FIXME logic code move to core module
    if (dataList == null || dataList.size() == 0) {
        // TODO error
        return;
    }
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    SchemaInfo schemaInfo = dataCompare.getSchemaInfo();
    StringBuilder extraColumns = new StringBuilder();
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT MD5(CONCAT(");
    StringBuilder cols = new StringBuilder();
    List<DBAttribute> attrs = schemaInfo.getAttributes();
    // TODO Collections.sort
    for (int i = 0, len = attrs.size(); i < len; i++) {
        DBAttribute attr = attrs.get(i);
        if (cols.length() > 0) {
            cols.append(",");
        }
        makeColumnsClause(extraColumns, cols, attr);
    }
    sql.append(cols);
    sql.append(")) AS _record_hash_ ");
    if (extraColumns.length() > 0) {
        sql.append(",");
        sql.append(extraColumns);
    }
    String escapedTableName = QuerySyntax.escapeKeyword(schemaInfo.getClassname());
    sql.append(" FROM ").append(escapedTableName);
    sql.append(" WHERE ");
    {
        HashedCompareData data = dataList.get(0);
        for (int i = 0, len = data.getPkColumns().size(); i < len; i++) {
            if (i > 0) {
                sql.append(" AND ");
            }
            String columnName = data.getPkColumns().get(i);
            sql.append(QuerySyntax.escapeKeyword(columnName)).append("=?");
        }
    }
    for (HashedCompareData data : dataList) {
        if (runningState != RUNNING_SATE_ONLINE) {
            return;
        }
        boolean exists = false;
        String hash = null;
        try {
            pstmt = conn.prepareStatement(sql.toString());
            for (int i = 0, len = data.getPkColumns().size(); i < len; i++) {
                String columnValue = data.getPkValues().get(i);
                pstmt.setString(i + 1, columnValue);
            }
            rs = pstmt.executeQuery();
            if (!rs.next()) {
                exists = false;
            } else {
                exists = true;
                hash = rs.getString("_record_hash_");
            }
        } catch (SQLException e) {
            exists = false;
            printToConsoleOnWorkThread(StringUtil.NEWLINE, false);
            printToConsoleOnWorkThread(e.getMessage(), true);
            LOGGER.error(sql.toString(), e);
        } finally {
            QueryUtil.freeQuery(pstmt, rs);
        }
        dataCompare.increaseProgress();
        if (!exists) {
            dataCompare.increaseNotExists();
            addLog(schemaInfo.getClassname(), data, charset);
        } else {
            if (data.getHash().equals(hash)) {
                dataCompare.increaseMatches();
            } else {
                dataCompare.increaseNotMatches();
                addLog(schemaInfo.getClassname(), data, charset);
            }
        }
        completedRecords++;
        refreshProgressBar();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                compareTableViewer.refresh();
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ResultSet(java.sql.ResultSet) HashedCompareData(com.cubrid.common.ui.compare.data.model.HashedCompareData) PreparedStatement(java.sql.PreparedStatement) Constraint(com.cubrid.common.core.common.model.Constraint) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 43 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class CubridColumnNavigatorView method setFocus.

public void setFocus() {
    CubridNavigatorView mainNav = CubridNavigatorView.findNavigationView();
    if (mainNav != null) {
        DatabaseInfo databaseInfo = mainNav.getCurrentDatabaseInfo();
        SchemaInfo schemaInfo = mainNav.getCurrentSchemaInfo();
        updateView(databaseInfo, schemaInfo);
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 44 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class AttributeTableViewerContentProvider method getElements.

/**
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
	 * @param inputElement the input element
	 * @return the array of elements to display in the viewer
	 */
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof SchemaInfo) {
        SchemaInfo schema = (SchemaInfo) inputElement;
        List<DBAttribute> list = new ArrayList<DBAttribute>();
        if (showClassAttribute) {
            list.addAll(schema.getClassAttributes());
        }
        list.addAll(schema.getAttributes());
        return list.toArray();
    } else {
        return new Object[0];
    }
}
Also used : DBAttribute(com.cubrid.common.core.common.model.DBAttribute) ArrayList(java.util.ArrayList) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 45 with SchemaInfo

use of com.cubrid.common.core.common.model.SchemaInfo in project cubrid-manager by CUBRID.

the class EditTableAction method doRun.

private void doRun(ISchemaNode table, int type) {
    final DatabaseInfo databaseInfo = NodeUtil.findDatabaseInfo(table);
    if (databaseInfo == null) {
        return;
    }
    final String tableName = table.getName();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            databaseInfo.removeSchema(tableName);
            SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
            if (schemaInfo == null) {
                openErrorBox(shell, databaseInfo.getErrorMessage(), monitor);
                return false;
            }
            return true;
        }
    };
    boolean supportCharset = CompatibleUtil.isSupportCreateDBByCharset(databaseInfo);
    JDBCGetAllDbUserTask allUserTask = new JDBCGetAllDbUserTask(databaseInfo);
    taskExcutor.addTask(allUserTask);
    GetCollations collationTask = null;
    if (supportCharset) {
        collationTask = new GetCollations(databaseInfo);
        taskExcutor.addTask(collationTask);
    }
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    if (!taskExcutor.isSuccess()) {
        return;
    }
    List<String> dbUserList = allUserTask.getDbUserList();
    SchemaInfo schemaInfo = databaseInfo.getSchemaInfo(tableName);
    TableEditorInput input = new TableEditorInput(table.getDatabase(), false, schemaInfo, table, type);
    input.setDbUserList(dbUserList);
    if (supportCharset) {
        List<Collation> collations = collationTask.getCollations();
        input.setCollationList(collations);
    }
    try {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        //If true, active opened editor of it and return, else open new editor.
        for (IEditorReference editorRef : workbenchWindow.getActivePage().getEditorReferences()) {
            IEditorPart oldEditor = editorRef.getEditor(true);
            if (oldEditor.getEditorInput() instanceof TableEditorInput) {
                TableEditorInput oldInput = (TableEditorInput) oldEditor.getEditorInput();
                ISchemaNode oldTable = oldInput.getEditedTableNode();
                if (oldTable != null && oldTable.equals(table)) {
                    workbenchWindow.getActivePage().activate(oldEditor);
                    return;
                }
            }
        }
        workbenchWindow.getActivePage().openEditor(input, TableEditorPart.ID);
    } catch (Exception ignore) {
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TableEditorInput(com.cubrid.common.ui.cubrid.table.editor.TableEditorInput) JDBCGetAllDbUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask) IEditorPart(org.eclipse.ui.IEditorPart) GetCollations(com.cubrid.cubridmanager.core.cubrid.table.task.GetCollations) Collation(com.cubrid.cubridmanager.core.cubrid.database.model.Collation) IWorkbench(org.eclipse.ui.IWorkbench) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEditorReference(org.eclipse.ui.IEditorReference) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Aggregations

SchemaInfo (com.cubrid.common.core.common.model.SchemaInfo)136 DBAttribute (com.cubrid.common.core.common.model.DBAttribute)57 Constraint (com.cubrid.common.core.common.model.Constraint)56 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)15 List (java.util.List)15 ERTableColumn (com.cubrid.common.ui.er.model.ERTableColumn)11 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)11 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)10 Connection (java.sql.Connection)10 SerialInfo (com.cubrid.common.core.common.model.SerialInfo)9 SQLException (java.sql.SQLException)9 TableItem (org.eclipse.swt.widgets.TableItem)9 SchemaComment (com.cubrid.common.core.schemacomment.model.SchemaComment)8 SchemaDDL (com.cubrid.cubridmanager.core.cubrid.table.model.SchemaDDL)8 PartitionInfo (com.cubrid.common.core.common.model.PartitionInfo)7 ERWinSchemaInfo (com.cubrid.common.ui.cubrid.database.erwin.model.ERWinSchemaInfo)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 DBResolution (com.cubrid.common.core.common.model.DBResolution)6 Map (java.util.Map)5