Search in sources :

Example 41 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class RenameComparedElementAction method getRightResource.

private Resource getRightResource(ColumnSet selectedColumnSet) throws ReloadCompareException {
    Connection tempReloadProvider = createTempConnectionFile();
    Package matchedPackage = DQStructureComparer.findMatchedPackage((Package) originCompareElement, tempReloadProvider);
    IFolderNode columnSetFolderNode = FolderNodeHelper.getFolderNode(matchedPackage, selectedColumnSet);
    columnSetFolderNode.loadChildren();
    ColumnSet findMatchedColumnSet = DQStructureComparer.findMatchedColumnSet(selectedColumnSet, tempReloadProvider);
    List<TdColumn> columns = null;
    try {
        columns = DqRepositoryViewService.getColumns(tempReloadProvider, findMatchedColumnSet, null, true);
    } catch (Exception e1) {
        throw new ReloadCompareException(e1);
    }
    URI uri = tempReloadProvider.eResource().getURI();
    Resource rightResource = null;
    rightResource = EMFSharedResources.getInstance().getResource(uri, true);
    if (rightResource == null) {
        // $NON-NLS-1$
        throw new ReloadCompareException("NoFactoryFoundForURI" + uri.toFileString());
    }
    rightResource.getContents().clear();
    for (TdColumn column : columns) {
        DQStructureComparer.clearSubNode(column);
        rightResource.getContents().add(column);
    }
    EMFSharedResources.getInstance().saveResource(rightResource);
    return rightResource;
}
Also used : IFolderNode(org.talend.dq.nodes.foldernode.IFolderNode) TdColumn(org.talend.cwm.relational.TdColumn) Connection(org.talend.core.model.metadata.builder.connection.Connection) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) Resource(org.eclipse.emf.ecore.resource.Resource) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package) URI(org.eclipse.emf.common.util.URI) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException)

Example 42 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class AnalyzedColumnSetsSynDialog method reloadInputModel.

@Override
public void reloadInputModel() {
    ColumnSet anaColumnSet = null;
    modelInput.clear();
    synedEleMap.clear();
    for (ModelElement element : analyzedElements) {
        try {
            anaColumnSet = (ColumnSet) element;
            synedEleMap.put(anaColumnSet, null);
            Package anaPackage = ColumnSetHelper.getParentCatalogOrSchema(anaColumnSet);
            if (anaPackage == null) {
                return;
            }
            Package connPackage = null;
            // MOD by zshen for bug 16775 on 2010.12.28 for mssql case
            for (Package pk : newDataProvider.getDataPackage()) {
                if (pk instanceof Catalog && anaPackage instanceof Schema) {
                    Catalog catl = CatalogHelper.getParentCatalog(anaPackage);
                    if (null != catl && pk.getName().equalsIgnoreCase(catl.getName())) {
                        connPackage = pk;
                        break;
                    }
                } else if (null != anaPackage && pk.getName().equalsIgnoreCase(anaPackage.getName())) {
                    connPackage = pk;
                    break;
                }
            }
            if (connPackage == null) {
                SynTreeModel synTreeModel = new SynTreeModel(anaColumnSet);
                synTreeModel.setOldDataProvElement(anaPackage);
                // synTreeModel.setNewDataProvElement(connPackage);
                modelInput.add(synTreeModel);
                break;
            }
            List<? extends MetadataTable> connColumnSetList = null;
            // MOD by zshen for bug 16775 on 2010.12.28 for mssql case
            if (connPackage instanceof Catalog && anaPackage instanceof Schema) {
                for (Schema sche : CatalogHelper.getSchemas((Catalog) connPackage)) {
                    if (sche.getName().equalsIgnoreCase(anaPackage.getName())) {
                        connPackage = sche;
                    // if (anaColumnSet instanceof TdTable) {
                    // connColumnSetList = PackageHelper.getTables(sche);
                    // } else {
                    // connColumnSetList = PackageHelper.getViews(sche);
                    // }
                    // break;
                    }
                }
            }
            boolean loadFromDb = connPackage.getOwnedElement().size() == 0;
            if (anaColumnSet instanceof TdTable) {
                connColumnSetList = DqRepositoryViewService.getTables(newDataProvider, connPackage, null, loadFromDb, false);
                // connColumnSetList = PackageHelper.getTables(connPackage);
                if (loadFromDb) {
                    for (MetadataTable table : connColumnSetList) {
                        PackageHelper.addMetadataTable(table, connPackage);
                    }
                }
            } else {
                connColumnSetList = DqRepositoryViewService.getViews(newDataProvider, connPackage, null, loadFromDb, false);
                // connColumnSetList = PackageHelper.getViews(connPackage);
                if (loadFromDb) {
                    for (MetadataTable table : connColumnSetList) {
                        PackageHelper.addMetadataTable(table, connPackage);
                    }
                }
            }
            ColumnSet connColumnSet = null;
            for (Object colSet : connColumnSetList) {
                if (((ColumnSet) colSet).getName().equalsIgnoreCase(anaColumnSet.getName())) {
                    connColumnSet = (ColumnSet) colSet;
                    break;
                }
            }
            if (connColumnSet == null) {
                SynTreeModel synTreeModel = new SynTreeModel(anaColumnSet);
                synTreeModel.setOldDataProvElement(anaColumnSet);
                synTreeModel.setNewDataProvElement(connPackage);
                modelInput.add(synTreeModel);
                continue;
            }
            synedEleMap.put(anaColumnSet, connColumnSet);
        } catch (Exception e) {
            log.error(e, e);
            e.printStackTrace();
        }
    }
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdTable(org.talend.cwm.relational.TdTable) Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 43 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class ColumnSetAnalysisExecutor method createSqlStatement.

/*
     * (non-Jsdoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
     */
@Override
protected String createSqlStatement(Analysis analysis) {
    // MOD yyi 2011-02-22 17871:delimitefile
    if (isDelimitedFile) {
        return PluginConstant.EMPTY_STRING;
    }
    // ~
    this.cachedAnalysis = analysis;
    // $NON-NLS-1$
    StringBuilder sql = new StringBuilder("SELECT ");
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    // MOD yyi 2011-02-22 17871:delimitefile
    EList<ModelElement> analysedElements = null;
    for (Indicator indicator : indicators) {
        if (ColumnsetPackage.eINSTANCE.getColumnSetMultiValueIndicator().isSuperTypeOf(indicator.eClass())) {
            ColumnSetMultiValueIndicator colSetMultValIndicator = (ColumnSetMultiValueIndicator) indicator;
            if (analysedElements == null) {
                analysedElements = colSetMultValIndicator.getAnalyzedColumns();
            } else {
                analysedElements.addAll(colSetMultValIndicator.getAnalyzedColumns());
            }
        }
    }
    if (analysedElements == null || analysedElements.isEmpty()) {
        setError(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisExecutor.CannotCreateSQLStatement", analysis.getName()));
        return null;
    }
    // MOD yyi 2011-02-22 17871:delimitefile, indiactor changed
    final Iterator<ModelElement> iterator = analysedElements.iterator();
    while (iterator.hasNext()) {
        // for (ModelElement modelElement : analysedElements) {
        ModelElement modelElement = iterator.next();
        // --- preconditions
        TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
        if (col == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenElementIsNotColumn", modelElement));
            return null;
        }
        Classifier owner = col.getOwner();
        if (owner == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoOwnerFound", col.getName()));
        }
        ColumnSet colSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(owner);
        if (colSet == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoContainerFound", col.getName()));
            return null;
        }
        // select all the column to be prepare for drill down when user need.
        if (!analysis.getParameters().isStoreData()) {
            sql.append(this.quote(col.getName()));
            // append comma if more columns exist
            if (iterator.hasNext()) {
                sql.append(',');
            }
        }
    }
    TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysedElements.get(0));
    // select all the column to be prepare for drill down.
    if (analysis.getParameters().isStoreData()) {
        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues columnset
        EObject eContainer = firstColumn.eContainer();
        List<TdColumn> columnList = ColumnSetHelper.getColumns(SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer));
        // ~
        Iterator<TdColumn> iter = columnList.iterator();
        while (iter.hasNext()) {
            TdColumn column = iter.next();
            sql.append(this.quote(column.getName()));
            // append comma if more columns exist
            if (iter.hasNext()) {
                sql.append(',');
            }
        }
    }
    // add from clause
    sql.append(dbms().from());
    sql.append(dbms().getQueryColumnSetWithPrefix(firstColumn));
    // add where clause
    // --- get data filter
    ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
    handler.setAnalysis(analysis);
    String stringDataFilter = handler.getStringDataFilter();
    sql.append(GenericSQLHandler.WHERE_CLAUSE);
    String sqlStatement = sql.toString();
    sqlStatement = dbms().addWhereToStatement(sqlStatement, stringDataFilter);
    return sqlStatement;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Classifier(orgomg.cwm.objectmodel.core.Classifier) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) EObject(org.eclipse.emf.ecore.EObject)

Example 44 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class FunctionalDependencyExecutor method getTableNameFromColumn.

private String getTableNameFromColumn(TdColumn column) {
    ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(column);
    if (columnSetOwner == null) {
        // $NON-NLS-1$
        log.error(Messages.getString("FunctionalDependencyExecutor.COLUMNSETOWNERISNULL", column.getName()));
    } else {
        // this is so bad code
        Package pack = ColumnSetHelper.getParentCatalogOrSchema(columnSetOwner);
        if (SwitchHelpers.SCHEMA_SWITCH.doSwitch(pack) != null) {
            schemaName = pack.getName();
            Package catalog = ColumnSetHelper.getParentCatalogOrSchema(pack);
            // MOD mzhao 2010-02-10 Fix a NEP.
            if (catalog != null && SwitchHelpers.CATALOG_SWITCH.doSwitch(catalog) != null) {
                catalogName = catalog.getName();
            }
        }
        if (SwitchHelpers.CATALOG_SWITCH.doSwitch(pack) != null) {
            catalogName = pack.getName();
        }
        return dbms().toQualifiedName(catalogName, schemaName, columnSetOwner.getName());
    }
    return null;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) ColumnsetPackage(org.talend.dataquality.indicators.columnset.ColumnsetPackage) Package(orgomg.cwm.objectmodel.core.Package)

Example 45 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class RowMatchingAnalysisExecutor method getAnalyzedTable.

/**
 * Method "getAnalyzedTable".
 *
 * @param indicator
 * @return the table name (within quotes)
 */
private String getAnalyzedTable(Indicator indicator) {
    // MOD mzhao bug 11481. get table name with catalog or schema prefix.
    String analyzedTableName = null;
    ColumnSet columnSetOwner = (ColumnSet) indicator.getAnalyzedElement();
    if (columnSetOwner == null) {
        log.error(Messages.getString("RowMatchingAnalysisExecutor.COLUMNSETOWNERISNULL", // $NON-NLS-1$
        AnalysisExecutorHelper.getIndicatorName(indicator)));
    } else {
        if (columnSetOwner.eIsProxy()) {
            columnSetOwner = (ColumnSet) EObjectHelper.resolveObject(columnSetOwner);
        }
        String schemaName = getQuotedSchemaName(columnSetOwner);
        String table = quote(columnSetOwner.getName());
        String catalogName = getQuotedCatalogName(columnSetOwner);
        if (catalogName == null && schemaName != null) {
            // try to get catalog above schema
            final Schema parentSchema = SchemaHelper.getParentSchema(columnSetOwner);
            final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
            catalogName = parentCatalog != null ? parentCatalog.getName() : null;
        }
        analyzedTableName = dbms().toQualifiedName(catalogName, schemaName, table);
    }
    return analyzedTableName;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

ColumnSet (orgomg.cwm.resource.relational.ColumnSet)55 TdColumn (org.talend.cwm.relational.TdColumn)35 Package (orgomg.cwm.objectmodel.core.Package)14 ArrayList (java.util.ArrayList)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)11 Connection (org.talend.core.model.metadata.builder.connection.Connection)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 ReloadCompareException (org.talend.cwm.compare.exception.ReloadCompareException)7 TdTable (org.talend.cwm.relational.TdTable)7 Catalog (orgomg.cwm.resource.relational.Catalog)7 Schema (orgomg.cwm.resource.relational.Schema)7 Resource (org.eclipse.emf.ecore.resource.Resource)6 EObject (org.eclipse.emf.ecore.EObject)5 ReturnCode (org.talend.utils.sugars.ReturnCode)5 Indicator (org.talend.dataquality.indicators.Indicator)4 IRepositoryNode (org.talend.repository.model.IRepositoryNode)4 List (java.util.List)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)3