Search in sources :

Example 6 with ReloadCompareException

use of org.talend.cwm.compare.exception.ReloadCompareException in project tdq-studio-se by Talend.

the class TOPRepositoryService method reloadDatabase.

/**
 * Comment method "reloadDatabase".
 *
 * @param connectionItem
 * @deprecated instead of it by TDQCompareService.reloadDatabase
 */
@Deprecated
public ReturnCode reloadDatabase(ConnectionItem connectionItem) {
    ReturnCode retCode = new ReturnCode(Boolean.TRUE);
    Connection conn = connectionItem.getConnection();
    try {
        if (conn instanceof DatabaseConnection) {
            List<ModelElement> dependencyClients = EObjectHelper.getDependencyClients(conn);
            if (!(dependencyClients == null || dependencyClients.isEmpty())) {
                int isOk = DeleteModelElementConfirmDialog.showElementImpactConfirmDialog(null, new ModelElement[] { conn }, // $NON-NLS-1$
                DefaultMessagesImpl.getString("TOPRepositoryService.dependcyTile"), DefaultMessagesImpl.getString("TOPRepositoryService.dependcyMessage", // $NON-NLS-1$
                conn.getLabel()));
                if (isOk != Dialog.OK) {
                    retCode.setOk(Boolean.FALSE);
                    // $NON-NLS-1$
                    retCode.setMessage("The user canceled the operation!");
                    return retCode;
                }
            }
            final IComparisonLevel creatComparisonLevel = ComparisonLevelFactory.creatComparisonLevel(conn);
            Connection newConnection = creatComparisonLevel.reloadCurrentLevelElement();
            // update the sql explore.
            Property property = PropertyHelper.getProperty(newConnection);
            if (property != null) {
                Item newItem = property.getItem();
                if (newItem != null) {
                    CWMPlugin.getDefault().updateConnetionAliasByName(newConnection, newConnection.getLabel());
                // notifySQLExplorer(newItem);
                }
            }
            // update the related analyses.
            WorkbenchUtils.impactExistingAnalyses(newConnection);
        }
    } catch (ReloadCompareException e) {
        log.error(e, e);
        retCode.setOk(Boolean.FALSE);
        retCode.setMessage(e.getMessage());
    } catch (PartInitException e) {
        log.error(e, e);
        retCode.setOk(Boolean.FALSE);
        retCode.setMessage(e.getMessage());
    }
    return retCode;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property) IComparisonLevel(org.talend.cwm.compare.factory.IComparisonLevel)

Example 7 with ReloadCompareException

use of org.talend.cwm.compare.exception.ReloadCompareException in project tdq-studio-se by Talend.

the class ChangeConnectionAction method changedDatabaseConnection.

private ReturnCode changedDatabaseConnection() throws ReloadCompareException {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final EList<ModelElement> analyzedElements = analysisItem.getAnalysis().getContext() == null ? null : analysisItem.getAnalysis().getContext().getAnalysedElements();
    if (analyzedElements == null || analyzedElements.size() == 0) {
        analysisItem.getAnalysis().getContext().setConnection(newDataProvider);
        return new ReturnCode(Boolean.TRUE);
    }
    // MOD qiongli 2011-1-10,feature 16796.
    if (oldDataProvider instanceof DelimitedFileConnection) {
        // "Can't change this connection!");
        if (!// $NON-NLS-1$
        MessageDialog.openConfirm(// $NON-NLS-1$
        shell, // $NON-NLS-1$
        DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnection"), DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnectionTips"))) {
            // $NON-NLS-1$
            return new ReturnCode(Boolean.FALSE);
        }
    }
    // Open synchronized dialog.
    boolean retCode = MessageDialog.openQuestion(shell, // $NON-NLS-1$
    DefaultMessagesImpl.getString("ChangeConnectionAction.ChangeConnection"), // $NON-NLS-1$
    DefaultMessagesImpl.getString("ChangeConnectionAction.MayCauseAsynProblem"));
    if (retCode) {
        if (analyzedElements.get(0) instanceof TdColumn) {
            anaEleSynDialog = new AnalyzedColumnsSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
        } else if (analyzedElements.get(0) instanceof ColumnSet) {
            anaEleSynDialog = new AnalyzedColumnSetsSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
        } else if (analyzedElements.get(0) instanceof Package) {
            anaEleSynDialog = new AnalyzedPackageSynDialog(shell, analysisItem.getAnalysis(), newDataProvider, analyzedElements);
        }
        final List<SynTreeModel> treeModelLs = anaEleSynDialog == null ? null : anaEleSynDialog.getSynInputModel();
        if (treeModelLs != null && treeModelLs.size() > 0) {
            // Make attempt to reload from db before showing asyned
            // message.
            boolean isReload = MessageDialog.openQuestion(shell, // $NON-NLS-1$
            DefaultMessagesImpl.getString("ChangeConnectionAction.ReloadFromDatabase"), // $NON-NLS-1$
            DefaultMessagesImpl.getString("ChangeConnectionAction.ExistElementAsynchronuos"));
            if (isReload) {
                ModelElement newDataProviderModel = treeModelLs.get(0).getNewDataProvElement();
                if (newDataProviderModel != null && (newDataProviderModel instanceof ColumnSet || newDataProviderModel instanceof Package)) {
                    if (newDataProviderModel instanceof Package) {
                        IRunnableWithProgress op = new IRunnableWithProgress() {

                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                try {
                                    reloadByColumnSetFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
                                    if (analyzedElements.get(0) instanceof TdColumn) {
                                        // Reload column folder
                                        reloadByColumnFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
                                    }
                                } catch (ReloadCompareException e) {
                                    log.error(e, e);
                                }
                            }
                        };
                        try {
                            ProgressUI.popProgressDialog(op);
                        } catch (InvocationTargetException e) {
                            log.error(e, e);
                        } catch (InterruptedException e) {
                            log.error(e, e);
                        }
                    } else if (newDataProviderModel instanceof ColumnSet) {
                        IRunnableWithProgress op = new IRunnableWithProgress() {

                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                try {
                                    reloadByColumnFolderLevel(treeModelLs, anaEleSynDialog, newDataProvider);
                                } catch (ReloadCompareException e) {
                                    log.error(e, e);
                                }
                            }
                        };
                        try {
                            ProgressUI.popProgressDialog(op);
                        } catch (InvocationTargetException e) {
                            log.error(e, e);
                        } catch (InterruptedException e) {
                            log.error(e, e);
                        }
                    }
                }
            }
        }
        // Open asyned dialog.
        if (treeModelLs != null && treeModelLs.size() > 0) {
            // Open confirmation dialog to see whether user want to
            // continue or not.
            int returnCode = anaEleSynDialog.open();
            if (returnCode != Window.OK) {
                return new ReturnCode(Boolean.FALSE);
            }
        }
        // Synchronize analyzed elements.
        boolean isExistSynedElement = synAnalyzedElements(anaEleSynDialog, analysisItem.getAnalysis(), oldDataProvider, newDataProvider);
        // Add new dependencies.
        if (isExistSynedElement) {
            DependenciesHandler.getInstance().setDependencyOn(analysisItem.getAnalysis(), newDataProvider);
            ElementWriterFactory.getInstance().createDataProviderWriter().save(newDataProvider);
        }
        // Refresh analysis editor viewer.
        ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, false);
        // Refresh the repository tree view to adapt for the new analysis
        CorePlugin.getDefault().refreshDQView(RepositoryNodeHelper.getDataProfilingFolderNode(EResourceConstant.ANALYSIS));
    } else {
        return new ReturnCode(Boolean.FALSE);
    }
    return new ReturnCode(Boolean.TRUE);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TdColumn(org.talend.cwm.relational.TdColumn) AnalyzedColumnSetsSynDialog(org.talend.dataprofiler.core.ui.dialog.AnalyzedColumnSetsSynDialog) AnalyzedPackageSynDialog(org.talend.dataprofiler.core.ui.dialog.AnalyzedPackageSynDialog) SynTreeModel(org.talend.dataprofiler.core.ui.dialog.AnalyzedElementSynDialog.SynTreeModel) Package(orgomg.cwm.objectmodel.core.Package) AnalyzedColumnsSynDialog(org.talend.dataprofiler.core.ui.dialog.AnalyzedColumnsSynDialog)

Example 8 with ReloadCompareException

use of org.talend.cwm.compare.exception.ReloadCompareException in project tdq-studio-se by Talend.

the class DQStructureComparer method findMatchedColumn.

/**
 * DOC mzhao Find the matched column of toMatchDataProvider.
 *
 * @param column
 * @param toMatchDataProvider
 * @return
 * @throws ReloadCompareException
 */
public static TdColumn findMatchedColumn(TdColumn column, Connection toMatchDataProvider) throws ReloadCompareException {
    // MOD klliu update ColumnHelper.getColumnSetOwner(column)
    ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
    ColumnSet toReloadColumnSet = DQStructureComparer.findMatchedColumnSet(columnSet, toMatchDataProvider);
    List<TdColumn> columns = ColumnSetHelper.getColumns(toReloadColumnSet);
    TdColumn oldColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(column);
    TdColumn toMatchedColumn = null;
    if (oldColumn != null) {
        for (TdColumn col : columns) {
            if (oldColumn.getName().equals(col.getName())) {
                toMatchedColumn = col;
                break;
            }
        }
    }
    if (toMatchedColumn == null) {
        throw new ReloadCompareException(// $NON-NLS-1$
        DefaultMessagesImpl.getString(// $NON-NLS-1$
        "DQStructureComparer.NotFoundCorrespondColumnNode", column.getName()));
    }
    return toMatchedColumn;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 9 with ReloadCompareException

use of org.talend.cwm.compare.exception.ReloadCompareException in project tdq-studio-se by Talend.

the class DQStructureComparer method findMatchedPackage.

/**
 * Find the matched package of matchDataProvider.
 *
 * @param selectedPackage
 * @param matchDataProvider
 * @return
 * @throws ReloadCompareException
 */
public static Package findMatchedPackage(Package selectedPackage, Connection matchDataProvider) throws ReloadCompareException {
    // code clean by gdbu 2011-4-18 : when conn is null , throw a ReloadCompareException.
    if (null == matchDataProvider) {
        // $NON-NLS-1$
        throw new ReloadCompareException(DefaultMessagesImpl.getString("DQStructureComparer.ConnectionIsNull"));
    }
    // code clean
    Catalog catalogCase = SwitchHelpers.CATALOG_SWITCH.doSwitch(selectedPackage);
    if (catalogCase != null) {
        return findMatchedCatalogObj(catalogCase, matchDataProvider);
    } else {
        Schema schemaCase = (Schema) selectedPackage;
        Catalog parentCatalog = CatalogHelper.getParentCatalog(schemaCase);
        if (parentCatalog != null) {
            Catalog matchCatalog = findMatchedCatalogObj(parentCatalog, matchDataProvider);
            List<Schema> schemas = CatalogHelper.getSchemas(matchCatalog);
            return findMatchedSchema(schemaCase, schemas);
        } else {
            List<Schema> schemas = ConnectionHelper.getSchema(matchDataProvider);
            return findMatchedSchema(schemaCase, schemas);
        }
    }
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 10 with ReloadCompareException

use of org.talend.cwm.compare.exception.ReloadCompareException in project tdq-studio-se by Talend.

the class DQStructureComparer method findMatchedColumnSet.

/**
 * Find the matched columnSet of matchDataProvider.
 *
 * @param selectedColumnSet
 * @return
 * @throws ReloadCompareException
 */
public static ColumnSet findMatchedColumnSet(ColumnSet selectedColumnSet, Connection toMatchDataProvider) throws ReloadCompareException {
    Package parentCatalogOrSchema = ColumnSetHelper.getParentCatalogOrSchema(selectedColumnSet);
    // find the corresponding package from reloaded object.
    Package toReloadPackage = DQStructureComparer.findMatchedPackage(parentCatalogOrSchema, toMatchDataProvider);
    // find the corresponding columnSet from reloaded object.
    TdTable oldTable = SwitchHelpers.TABLE_SWITCH.doSwitch(selectedColumnSet);
    ColumnSet toReloadcolumnSet = null;
    if (oldTable != null) {
        List<TdTable> tables = PackageHelper.getTables(toReloadPackage);
        for (TdTable table : tables) {
            // bug 11934 MOD zshen judge the tableOwner when database is sybase.
            if (oldTable.getName().equals(table.getName())) {
                // ~11934
                toReloadcolumnSet = table;
                break;
            }
        }
    } else {
        List<TdView> views = PackageHelper.getViews(toReloadPackage);
        for (TdView view : views) {
            // bug 11934 MOD zshen judge the viewOwner when database is sybase.
            if (selectedColumnSet.getName().equals(view.getName())) {
                // ~11934
                toReloadcolumnSet = view;
                break;
            }
        }
    }
    if (toReloadcolumnSet == null) {
        throw new ReloadCompareException(// $NON-NLS-1$
        DefaultMessagesImpl.getString(// $NON-NLS-1$
        "DQStructureComparer.NotFindCorrespondNode", selectedColumnSet.getName()));
    }
    return toReloadcolumnSet;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TdView(org.talend.cwm.relational.TdView) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package)

Aggregations

ReloadCompareException (org.talend.cwm.compare.exception.ReloadCompareException)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)10 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 IComparisonLevel (org.talend.cwm.compare.factory.IComparisonLevel)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IFile (org.eclipse.core.resources.IFile)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)4 TdColumn (org.talend.cwm.relational.TdColumn)4 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)4 Package (orgomg.cwm.objectmodel.core.Package)4 URI (org.eclipse.emf.common.util.URI)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ReturnCode (org.talend.utils.sugars.ReturnCode)3 Shell (org.eclipse.swt.widgets.Shell)2 PartInitException (org.eclipse.ui.PartInitException)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2