Search in sources :

Example 36 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 of column
 *
 * @param column
 * @param where
 * @return
 */
public Expression getTableQueryExpression(MetadataTable metadataTable, String where) {
    Schema parentSchema = SchemaHelper.getParentSchema(metadataTable);
    Catalog parentCatalog = CatalogHelper.getParentCatalog(metadataTable);
    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, metadataTable.getName());
    Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
    String expressionBody = getQuerySql(getSelectColumnsStr(metadataTable), qualifiedName, where);
    queryExpression.setBody(expressionBody);
    queryExpression.setLanguage(this.getDbmsName());
    return queryExpression;
}
Also used : 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)

Example 37 with Catalog

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

the class MSSqlDbmsLanguage method getCatalog.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.dbms.DbmsLanguage#getCatalog(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
protected Catalog getCatalog(ModelElement columnSetOwner) {
    // get the schema first
    Schema schema = getSchema(columnSetOwner);
    // get the catalog according to the schema
    Catalog catalog = super.getCatalog(schema);
    return catalog;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 38 with Catalog

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

the class NetezzaDbmsLanguage method getCatalog.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.dbms.DbmsLanguage#getCatalog(orgomg.cwm.objectmodel.core.ModelElement)
     */
@Override
protected Catalog getCatalog(ModelElement columnSetOwner) {
    // get the schema first
    Schema schema = getSchema(columnSetOwner);
    // get the catalog according to the schema
    Catalog catalog = super.getCatalog(schema);
    return catalog;
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 39 with Catalog

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

the class DQReferenceMerger method addInTarget.

/*
     * override this method to fix a specail case: when add a catalog on database server,this new one can't be added in
     * local db connection
     */
@Override
protected void addInTarget(ReferenceChange diff, boolean rightToLeft) {
    final Match match = diff.getMatch();
    final EObject expectedContainer;
    if (rightToLeft) {
        expectedContainer = match.getLeft();
    } else {
        expectedContainer = match.getRight();
    }
    if (expectedContainer == null) {
        // one of the "required" diffs should have created our container.
        return;
    }
    final Comparison comparison = match.getComparison();
    final EReference reference = diff.getReference();
    final EObject expectedValue;
    final Match valueMatch = comparison.getMatch(diff.getValue());
    if (valueMatch == null) {
        // This is an out of scope value.
        if (diff.getValue().eIsProxy()) {
            // Copy the proxy
            expectedValue = EcoreUtil.copy(diff.getValue());
        } else {
            // Use the same value.
            expectedValue = diff.getValue();
        }
    } else if (rightToLeft) {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setLeft(expectedValue);
        } else {
            // qiongli: when I add catalog on remote server,test on reload, should replace "valueMatch.getLeft()"
            // with "valueMatch.getRight()" at here.
            // expectedValue = valueMatch.getLeft();
            expectedValue = valueMatch.getRight();
            // qiongli: remove the newest DataManage from the right Catalog or Schema,avoid a missing
            // "datamanage herf=" "
            Catalog catlog = SwitchHelpers.CATALOG_SWITCH.doSwitch(expectedValue);
            Schema schema = SwitchHelpers.SCHEMA_SWITCH.doSwitch(expectedValue);
            if (catlog != null) {
                EList<DataManager> dataManager = catlog.getDataManager();
                dataManager.clear();
            } else if (schema != null) {
                EList<DataManager> dataManager = schema.getDataManager();
                dataManager.clear();
            }
        }
    } else {
        if (reference.isContainment()) {
            expectedValue = createCopy(diff.getValue());
            valueMatch.setRight(expectedValue);
        } else {
            expectedValue = valueMatch.getLeft();
        }
    }
    // We have the container, reference and value. We need to know the insertion index.
    if (reference.isMany()) {
        final int insertionIndex = findInsertionIndex(comparison, diff, rightToLeft);
        final List<EObject> targetList = (List<EObject>) safeEGet(expectedContainer, reference);
        addAt(targetList, expectedValue, insertionIndex);
    } else {
        safeESet(expectedContainer, reference, expectedValue);
    }
    if (reference.isContainment()) {
        // Copy XMI ID when applicable.
        final Resource initialResource = diff.getValue().eResource();
        final Resource targetResource = expectedValue.eResource();
        if (initialResource instanceof XMIResource && targetResource instanceof XMIResource) {
            ((XMIResource) targetResource).setID(expectedValue, ((XMIResource) initialResource).getID(diff.getValue()));
        }
    }
// no need to check this for DQ items,
// checkImpliedDiffsOrdering(diff, rightToLeft);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) Resource(org.eclipse.emf.ecore.resource.Resource) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) Catalog(orgomg.cwm.resource.relational.Catalog) Match(org.eclipse.emf.compare.Match) EList(org.eclipse.emf.common.util.EList) Comparison(org.eclipse.emf.compare.Comparison) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) List(java.util.List) XMIResource(org.eclipse.emf.ecore.xmi.XMIResource) EReference(org.eclipse.emf.ecore.EReference)

Example 40 with Catalog

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

the class TableAnalysisSqlExecutor method getValidStatement.

/**
 * DOC xqliu Comment method "getValidStatement". 2009-10-29 bug 9702
 *
 * @param dataFilterAsString
 * @param indicator
 * @param valid
 * @return
 */
public String getValidStatement(String dataFilterAsString, Indicator indicator, boolean valid) {
    if (!isAnalyzedElementValid(indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
    if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
        return PluginConstant.EMPTY_STRING;
    }
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    if (!isExpressionValid(sqlGenericExpression, indicator)) {
        return PluginConstant.EMPTY_STRING;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpressionAnalysis = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpressionAnalysis.add(dataFilterAsString);
    }
    List<String> whereExpressionDQRule = new ArrayList<String>();
    String setAliasA = PluginConstant.EMPTY_STRING;
    final EList<JoinElement> joinConditions = indicator.getJoinConditions();
    if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
        WhereRule wr = (WhereRule) indicatorDefinition;
        whereExpressionDQRule.add(wr.getWhereExpression());
        // MOD scorreia 2009-03-13 copy joins conditions into the indicator
        joinConditions.clear();
        if (!isJoinConditionEmpty(indicator)) {
            for (JoinElement joinelt : wr.getJoins()) {
                JoinElement joinCopy = EcoreUtil.copy(joinelt);
                joinConditions.add(joinCopy);
                setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? joinCopy.getTableAliasA() : setAliasA;
            }
        }
    }
    NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
    String schemaName = getQuotedSchemaName(set);
    // --- normalize table name
    String catalogName = getQuotedCatalogName(set);
    if (catalogName == null && schemaName != null) {
        // try to get catalog above schema
        final Schema parentSchema = SchemaHelper.getParentSchema(set);
        final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
        catalogName = parentCatalog != null ? parentCatalog.getName() : null;
    }
    String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
    // ### evaluate SQL Statement depending on indicators ###
    String completedSqlString = null;
    // --- default case
    // allow join
    String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
    String genericSql = sqlGenericExpression.getBody();
    // $NON-NLS-1$//$NON-NLS-2$
    setAliasA = PluginConstant.EMPTY_STRING.equals(setAliasA) ? "*" : setAliasA + ".*";
    // $NON-NLS-1$
    genericSql = genericSql.replace("COUNT(*)", setAliasA);
    completedSqlString = dbms().fillGenericQueryWithJoin(genericSql, setName, joinclause);
    // ~
    completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, valid);
    return completedSqlString;
}
Also used : JoinElement(org.talend.dataquality.rules.JoinElement) WhereRule(org.talend.dataquality.rules.WhereRule) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Schema(orgomg.cwm.resource.relational.Schema) ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet) 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