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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations