Search in sources :

Example 31 with Catalog

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

the class AbstractSchemaEvaluator method evalSchemaIndicLow.

protected void evalSchemaIndicLow(final CatalogIndicator catalogIndic, final SchemaIndicator schemaIndic, final Catalog tdCatalog, final Schema tdSchema, ReturnCode ok) throws SQLException {
    // MOD klliu 2011-02-17 bug 18961
    boolean hasSchema = tdSchema != null;
    boolean hasCatalog = false;
    String schemaName = hasSchema ? tdSchema.getName() : null;
    String catName = null;
    if (tdCatalog == null) {
        if (tdSchema.eContainer() instanceof Catalog) {
            hasCatalog = true;
            catName = ((Catalog) tdSchema.eContainer()).getName();
        }
    } else {
        hasCatalog = true;
        catName = hasCatalog ? tdCatalog.getName() : null;
    }
    schemaIndic.setAnalyzedElement(hasSchema ? tdSchema : tdCatalog);
    // profile tables
    int tableCount = 0;
    final String[] tablePatterns = tablePattern != null && tablePattern.contains(String.valueOf(FILTER_SEP)) ? StringUtils.split(this.tablePattern, FILTER_SEP) : new String[] { this.tablePattern };
    for (String pat : tablePatterns) {
        // MOD zshen bug 12041: the variable trimPat must be null(not a "") if it isn't a table name.
        String trimPat = pat != null && !PluginConstant.EMPTY_STRING.equals(pat) ? pat.trim() : null;
        try {
            Package pacage = tdSchema == null ? tdCatalog : tdSchema;
            // MOD gdbu 2011-9-22 TDQ-3607
            checkConnectionBeforeGetTableView();
            List<? extends NamedColumnSet> tables = DqRepositoryViewService.getTables(getConnection(), getDataManager(), pacage, trimPat, true, false);
            // ~TDQ-3607
            for (NamedColumnSet t : tables) {
                if (this.getMonitor() != null) {
                    StringBuilder taskName = new StringBuilder();
                    if (catName != null) {
                        // $NON-NLS-1$
                        taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementCatalog", catName)).append(// $NON-NLS-1$
                        ", ");
                    }
                    if (schemaName != null) {
                        // $NON-NLS-1$
                        taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementSchema", schemaName)).append(// $NON-NLS-1$
                        ", ");
                    }
                    // $NON-NLS-1$
                    taskName.append(Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElementTable", t.getName()));
                    this.getMonitor().setTaskName(// $NON-NLS-1$
                    Messages.getString("ColumnAnalysisSqlExecutor.AnalyzedElement", taskName.toString()));
                }
                tableCount++;
                evalAllCounts(catName, schemaName, t, schemaIndic, true, ok);
            }
        } catch (Exception e) {
            log.error(e, e);
        }
    }
    schemaIndic.setTableCount(tableCount);
    // do the same for views
    int viewCount = 0;
    final String[] viewPatterns = viewPattern != null && viewPattern.contains(String.valueOf(FILTER_SEP)) ? StringUtils.split(this.viewPattern, FILTER_SEP) : new String[] { this.viewPattern };
    for (String pat : viewPatterns) {
        // MOD zshen bug 12041: the variable trimPat must be null(not a "") if it isn't a view name.
        String trimPat = pat != null && !PluginConstant.EMPTY_STRING.equals(pat) ? pat.trim() : null;
        try {
            Package pacage = tdSchema == null ? tdCatalog : tdSchema;
            // MOD gdbu 2011-9-22 TDQ-3607
            checkConnectionBeforeGetTableView();
            List<? extends NamedColumnSet> views = DqRepositoryViewService.getViews(getConnection(), getDataManager(), pacage, trimPat, true, false);
            // ~TDQ-3607
            for (NamedColumnSet t : views) {
                viewCount++;
                evalAllCounts(catName, schemaName, t, schemaIndic, false, ok);
            }
        } catch (Exception e) {
            log.error(e, e);
        }
    }
    schemaIndic.setViewCount(viewCount);
    if (hasCatalog && hasSchema && catalogIndic != null) {
        // add it to list of indicators
        this.addToConnectionIndicator(catalogIndic, schemaIndic);
        // add it to list of indicators
        catalogIndic.addSchemaIndicator(schemaIndic);
        // --- increment values of catalog indicator
        catalogIndic.setTableCount(catalogIndic.getTableCount() + tableCount);
        catalogIndic.setTableRowCount(catalogIndic.getTableRowCount() + schemaIndic.getTableRowCount());
        catalogIndic.setViewRowCount(catalogIndic.getViewRowCount() + schemaIndic.getViewRowCount());
        // Added 20130221 TDQ-6546: add the missed the view count
        catalogIndic.setViewCount(catalogIndic.getViewCount() + schemaIndic.getViewCount());
        // Added 20130401 TDQ-6823: add the missed key and index count for the catelog(which contains schemas)
        catalogIndic.setKeyCount(catalogIndic.getKeyCount() + schemaIndic.getKeyCount());
        catalogIndic.setIndexCount(catalogIndic.getIndexCount() + schemaIndic.getIndexCount());
    } else if (!hasCatalog) {
        // has schema only
        // add it to list of indicators
        this.addToConnectionIndicator(schemaIndic);
    } else if (!hasSchema) {
        // has catalog only
        if (SchemaPackage.eINSTANCE.getCatalogIndicator().equals(schemaIndic.eClass())) {
            this.addToConnectionIndicator(schemaIndic);
        } else {
            // $NON-NLS-1$
            log.error(Messages.getString("AbstractSchemaEvaluator.NoCatalogSchema"));
        }
    }
}
Also used : SchemaPackage(org.talend.dataquality.indicators.schema.SchemaPackage) Package(orgomg.cwm.objectmodel.core.Package) Catalog(orgomg.cwm.resource.relational.Catalog) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) SQLException(java.sql.SQLException)

Example 32 with Catalog

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

the class AbstractSchemaEvaluator method checkSchema.

/**
 * yyi 2009-11-30 10187 check schema is exist in DB.
 *
 * @param catName
 * @return
 */
protected boolean checkSchema(Schema schema) {
    EObject container = schema.eContainer();
    if (container != null) {
        Catalog catalog = SwitchHelpers.CATALOG_SWITCH.doSwitch(container);
        if (catalog != null) {
            try {
                getConnection().setCatalog(catalog.getName());
                List<Schema> schemas = MetadataFillFactory.getDBInstance(getDataManager()).fillSchemaToCatalog(getDataManager(), getConnection().getMetaData(), catalog, null);
                if (schemas != null) {
                    for (Schema tdSchema : schemas) {
                        if (tdSchema.getName().equals(schema.getName())) {
                            return true;
                        }
                    }
                }
                return false;
            } catch (SQLException e) {
                log.error(e);
            }
        }
    }
    return checkSchemaByName(schema.getName());
}
Also used : SQLException(java.sql.SQLException) EObject(org.eclipse.emf.ecore.EObject) Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 33 with Catalog

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

the class AbstractSchemaEvaluator method getCatalogNameWithQuote.

/**
 * just extract this method from evalAllCounts,and need to junit.
 *
 * @param SchemaIndicator
 */
protected String getCatalogNameWithQuote(SchemaIndicator schemaIndic) {
    String quCatalog = null;
    ModelElement analyzedElement = schemaIndic.getAnalyzedElement();
    if (analyzedElement != null) {
        EObject eContainer = analyzedElement.eContainer();
        if (SwitchHelpers.CATALOG_SWITCH.doSwitch(analyzedElement) != null) {
            quCatalog = dbms().quote(((Catalog) analyzedElement).getName());
        } else if (eContainer != null && SwitchHelpers.CATALOG_SWITCH.doSwitch(eContainer) != null) {
            quCatalog = dbms().quote(((Catalog) eContainer).getName());
        }
    }
    return quCatalog;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObject(org.eclipse.emf.ecore.EObject) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 34 with Catalog

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

the class DbmsLanguage method getCatalogOrSchemaName.

/**
 * get the catalog or schema name according to the analyzed column.
 *
 * @param analyzedColumn
 * @return if the catalog is not null, return catalog's name, else if schema is not null, return schema's name, else
 * return null
 */
public String getCatalogOrSchemaName(TdColumn tdColumn) {
    String name = null;
    // get the catalog/schema name from the context
    DatabaseConnection dbConn = ConnectionHelper.getTdDataProvider(tdColumn);
    if (dbConn != null && dbConn.isContextMode()) {
        name = getCatalogNameFromContext(dbConn);
        if (!StringUtils.isEmpty(name)) {
            return name;
        }
        name = getSchemaNameFromContext(dbConn);
        if (!StringUtils.isEmpty(name)) {
            return name;
        }
    }
    // if the catalog/schema name from the context is empty, get it by the column
    if (StringUtils.isEmpty(name)) {
        ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(tdColumn);
        // Get catalog
        Catalog catalog = getCatalog(columnSet);
        if (catalog != null) {
            return catalog.getName();
        }
        // Get schema
        Schema schema = getSchema(columnSet);
        if (schema != null) {
            return schema.getName();
        }
        // no catalog and schema
        // $NON-NLS-1$
        log.error(Messages.getString("DbmsLanguage.NoCatalogOrSchema", columnSet.getName()));
    }
    return name;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 35 with Catalog

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

the class DbmsLanguage method getTableQueryExpression.

/**
 * Get the query Expression for one table
 *
 * @param column
 * @param where
 * @return
 */
public Expression getTableQueryExpression(TdColumn column, String where) {
    ModelElement columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
    Schema parentSchema = SchemaHelper.getParentSchema(columnSet);
    Catalog parentCatalog = CatalogHelper.getParentCatalog(columnSet);
    if (parentSchema != null) {
        parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
    }
    String schemaName = parentSchema == null ? null : parentSchema.getName();
    String catalogName = parentCatalog == null ? null : parentCatalog.getName();
    String qualifiedName = this.toQualifiedName(catalogName, schemaName, columnSet.getName());
    Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
    String expressionBody = getQuerySql(ASTERISK, qualifiedName, where);
    queryExpression.setBody(expressionBody);
    queryExpression.setLanguage(this.getDbmsName());
    return queryExpression;
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Aggregations

Catalog (orgomg.cwm.resource.relational.Catalog)106 Schema (orgomg.cwm.resource.relational.Schema)56 Connection (org.talend.core.model.metadata.builder.connection.Connection)32 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 ArrayList (java.util.ArrayList)28 TdTable (org.talend.cwm.relational.TdTable)27 Test (org.junit.Test)19 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 TdColumn (org.talend.cwm.relational.TdColumn)19 IRepositoryNode (org.talend.repository.model.IRepositoryNode)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)16 Package (orgomg.cwm.objectmodel.core.Package)15 MetadataCatalogRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataCatalogRepositoryObject)12 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)9 List (java.util.List)8 PersistenceException (org.talend.commons.exception.PersistenceException)8