Search in sources :

Example 6 with ColumnSet

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

the class CatalogSchemaComparisonLevel method getLeftResource.

@Override
protected Resource getLeftResource() throws ReloadCompareException {
    Package selectedPackage = getPackageFromObject(selectedObj);
    // if (selectedObj instanceof RepositoryNode) {
    // selectedPackage = (Package) RepositoryNodeHelper.getMetadataElement((RepositoryNode) selectedObj);
    // } else {
    // selectedPackage = (Package) selectedObj;
    // }
    // MOD mzhao 2009-01-20 Extract method findMatchedPackage to
    // DQStructureComparer class
    // for common use.
    Package findMatchPackage = DQStructureComparer.findMatchedPackage(selectedPackage, copyedDataProvider);
    List<ColumnSet> columnSets = new ArrayList<ColumnSet>();
    if (isCompareTabel) {
        columnSets.addAll(PackageHelper.getTables(findMatchPackage));
    }
    if (isCompareView) {
        columnSets.addAll(PackageHelper.getViews(findMatchPackage));
    }
    Resource leftResource = copyedDataProvider.eResource();
    // ComparatorsFactory.sort(columnSets,
    // ComparatorsFactory.MODELELEMENT_COMPARATOR_ID);
    leftResource.getContents().clear();
    for (ColumnSet columnSet : columnSets) {
        // MOD mzhao 2009-01-20 Extract method clearSubNode to
        // DQStructureComparer class
        // for common use.
        DQStructureComparer.clearSubNode(columnSet);
        leftResource.getContents().add(columnSet);
    }
    // }
    EMFSharedResources.getInstance().saveResource(leftResource);
    return upperCaseResource(leftResource);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package)

Example 7 with ColumnSet

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

the class CatalogSchemaComparisonLevel method reloadElementOfPackage.

/**
 * DOC rli Comment method "reloadElementOfPackage".
 *
 * @param toReloadObj
 * @return
 * @throws ReloadCompareException
 */
private List<ColumnSet> reloadElementOfPackage(Package toReloadObj) throws ReloadCompareException {
    List<ColumnSet> columnSetList = new ArrayList<ColumnSet>();
    try {
        // MOD by msjian bug 2011-5-16 20875, the reload element is not added correctly
        Catalog catalogObj = SwitchHelpers.CATALOG_SWITCH.doSwitch(toReloadObj);
        Schema schemaObj = SwitchHelpers.SCHEMA_SWITCH.doSwitch(toReloadObj);
        if (schemaObj != null) {
            List<ModelElement> elementList = schemaObj.getOwnedElement();
            if (elementList != null && elementList.size() > 0) {
                elementList.clear();
            }
            List<TdTable> tables = DqRepositoryViewService.getTables(tempReloadProvider, schemaObj, null, true, true);
            SchemaHelper.addTables(tables, schemaObj);
            columnSetList.addAll(tables);
            List<TdView> views = DqRepositoryViewService.getViews(tempReloadProvider, schemaObj, null, true, true);
            SchemaHelper.addViews(views, schemaObj);
            columnSetList.addAll(views);
        } else {
            List<ModelElement> elementList = catalogObj.getOwnedElement();
            if (elementList != null && elementList.size() > 0) {
                elementList.clear();
            }
            List<TdTable> tables = DqRepositoryViewService.getTables(tempReloadProvider, catalogObj, null, true, true);
            CatalogHelper.addTables(tables, catalogObj);
            columnSetList.addAll(tables);
            List<TdView> views = DqRepositoryViewService.getViews(tempReloadProvider, catalogObj, null, true, true);
            CatalogHelper.addViews(views, catalogObj);
            columnSetList.addAll(views);
        }
    // else {
    // List<TdTable> tables = DqRepositoryViewService.getTables(tempReloadProvider, (Schema) toReloadObj, null,
    // true);
    // SchemaHelper.addTables(tables, (Schema) toReloadObj);
    // columnSetList.addAll(tables);
    // 
    // List<TdView> views = DqRepositoryViewService.getViews(tempReloadProvider, (Schema) toReloadObj, null,
    // true);
    // SchemaHelper.addViews(views, (Schema) toReloadObj);
    // columnSetList.addAll(views);
    // 
    // }
    } catch (Exception e1) {
        throw new ReloadCompareException(e1);
    }
    // EMFSharedResources.getInstance().saveResource(tempReloadProvider.eResource());
    return columnSetList;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog) ReloadCompareException(org.talend.cwm.compare.exception.ReloadCompareException) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdView(org.talend.cwm.relational.TdView)

Example 8 with ColumnSet

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

the class SubelementCompareAction method findMatchedModelElement.

/**
 * DOC klliu Comment method "findMatchedModelElement". don't understand this method!!!
 *
 * @param parent
 * @param similarElement
 * @return
 */
private ModelElement findMatchedModelElement(EObject parent, EObject similarElement) {
    if (parent instanceof Connection) {
        if (similarElement instanceof Schema) {
            Schema schema = (Schema) similarElement;
            // Case of MS SQL Server.
            if (selectedOjbect instanceof Catalog) {
                // ??????
                List<Schema> schemas = CatalogHelper.getSchemas((Catalog) selectedOjbect);
                if (schemas != null && schemas.size() > 0) {
                    for (Schema tdSchema : schemas) {
                        if (tdSchema.getName().equalsIgnoreCase((schema).getName())) {
                            return tdSchema;
                        }
                    }
                }
            }
            // case of MS SQL Server, Postgresql......
            EObject eContainer = schema.eContainer();
            if (eContainer != null && eContainer instanceof Catalog) {
                List<Catalog> catalogs = ConnectionHelper.getCatalogs((Connection) parent);
                for (Catalog catalog : catalogs) {
                    if (((Catalog) eContainer).getName().equals(catalog.getName())) {
                        List<Schema> schemas = CatalogHelper.getSchemas(catalog);
                        if (schemas != null && schemas.size() > 0) {
                            for (Schema tdSchema : schemas) {
                                if (tdSchema.getName().equalsIgnoreCase((schema).getName())) {
                                    return tdSchema;
                                }
                            }
                        }
                    }
                }
            }
            // Case of Oracle
            List<Schema> schames = ConnectionHelper.getSchema((Connection) parent);
            for (Schema schame : schames) {
                if (schame.getName().equalsIgnoreCase((schema).getName())) {
                    return schame;
                }
            }
        }
        // Case of Mysql
        if (similarElement instanceof Catalog) {
            List<Catalog> catalogs = ConnectionHelper.getCatalogs((Connection) parent);
            for (Catalog catalog : catalogs) {
                if (catalog.getName().equalsIgnoreCase(((Catalog) similarElement).getName())) {
                    return catalog;
                }
            }
        }
    } else if (parent instanceof Package) {
        // MOD klliu bug 15822 resolve proxy caused two Instance,so we must use one Instance
        if (parent != null && parent.eIsProxy()) {
            parent = EObjectHelper.resolveObject(parent);
        }
        // MOD mzhao bug 8581 2009-08-05
        List<ColumnSet> columnSets = new ArrayList<ColumnSet>();
        columnSets.addAll(PackageHelper.getTables((Package) parent));
        columnSets.addAll(PackageHelper.getViews((Package) parent));
        for (ModelElement columnSet : columnSets) {
            if (((ColumnSet) columnSet).getName().equalsIgnoreCase(((ColumnSet) similarElement).getName())) {
                return columnSet;
            }
        }
    }
    return null;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Schema(orgomg.cwm.resource.relational.Schema) EObject(org.eclipse.emf.ecore.EObject) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) List(java.util.List) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Package(orgomg.cwm.objectmodel.core.Package) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 9 with ColumnSet

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

the class AnalysisColumnCompareTreeViewer method setColumnABForMatchingIndicator.

/**
 * DOC rli Comment method "setColumnAB".
 */
public void setColumnABForMatchingIndicator(RowMatchingIndicator rowMatchingIndicator, List<RepositoryNode> columnsA, List<RepositoryNode> columnsB) {
    if (columnsA.size() != 0 && columnsA.get(0).getObject() instanceof MetadataColumnRepositoryObject) {
        RepositoryNode node = columnsA.get(0);
        MetadataColumnRepositoryObject columnObject = (MetadataColumnRepositoryObject) node.getObject();
        TdColumn column = ((TdColumn) columnObject.getTdColumn());
        ColumnSet columnSetOwner = ColumnHelper.getColumnOwnerAsColumnSet(column);
        rowMatchingIndicator.setAnalyzedElement(columnSetOwner);
    }
    rowMatchingIndicator.getColumnSetA().clear();
    for (RepositoryNode reposNode : columnsA) {
        rowMatchingIndicator.getColumnSetA().add((TdColumn) ((MetadataColumnRepositoryObject) reposNode.getObject()).getTdColumn());
    }
    rowMatchingIndicator.getColumnSetB().clear();
    for (RepositoryNode reposNode : columnsB) {
        rowMatchingIndicator.getColumnSetB().add((TdColumn) ((MetadataColumnRepositoryObject) reposNode.getObject()).getTdColumn());
    }
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 10 with ColumnSet

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

the class RowMatchExplorer method getRowsNotMatchStatement.

/**
 * get Rows for NotMatched Statement.
 *
 * @return
 */
public String getRowsNotMatchStatement() {
    ColumnSet tablea = (ColumnSet) indicator.getAnalyzedElement();
    String tableA = tablea.getName();
    // $NON-NLS-1$
    String query = "SELECT A.*" + dbmsLanguage.from();
    if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator() == indicator.eClass()) {
        ColumnSet tableb = ColumnHelper.getColumnOwnerAsColumnSet(((RowMatchingIndicator) indicator).getColumnSetB().get(0));
        String tableB = tableb.getName();
        EList<TdColumn> columnSetA = ((RowMatchingIndicator) indicator).getColumnSetA();
        EList<TdColumn> columnSetB = ((RowMatchingIndicator) indicator).getColumnSetB();
        // $NON-NLS-1$
        String clauseA = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tablea);
        // $NON-NLS-1$
        String clauseB = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tableb);
        String where = null;
        // $NON-NLS-1$
        String onClause = " ON ";
        String realWhereClause = dbmsLanguage.where();
        for (int i = 0; i < columnSetA.size(); i++) {
            where = dbmsLanguage.and();
            if (i == 0) {
                where = dbmsLanguage.where();
            } else {
                onClause += where;
                realWhereClause += where;
            }
            realWhereClause += // $NON-NLS-1$
            " B" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetB.get(i).getName()) + dbmsLanguage.isNull();
            onClause += // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            " (A" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetA.get(i).getName()) + "=" + " B" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetB.get(i).getName()) + // $NON-NLS-1$
            ") ";
        }
        clauseA += (tableA.equals(tableB) ? whereDataFilter(tableA, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_A : AnalysisHelper.DATA_FILTER_B)) : whereDataFilter(tableA, null)) + // $NON-NLS-1$
        ") A";
        clauseB += (tableB.equals(tableA) ? whereDataFilter(tableB, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_B : AnalysisHelper.DATA_FILTER_A)) : whereDataFilter(tableB, null)) + // $NON-NLS-1$
        ") B";
        // MOD qiongli 2012-8-14 TDQ-5907.
        if (dbmsLanguage instanceof HiveDbmsLanguage) {
            // $NON-NLS-1$
            query += clauseA + " LEFT OUTER JOIN " + clauseB + onClause + realWhereClause;
        } else {
            // $NON-NLS-1$
            query += clauseA + " LEFT JOIN " + clauseB + onClause + realWhereClause;
        }
    }
    return getComment(MENU_VIEW_NOT_MATCH_ROWS) + query;
}
Also used : HiveDbmsLanguage(org.talend.dq.dbms.HiveDbmsLanguage) TdColumn(org.talend.cwm.relational.TdColumn) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

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