use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method testUpdateContextGroupSuccessGeneralJdbc.
/**
* Test method for
* {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
* . fail4: the Connection type is GENERAL_JDBC case
*/
@Test
public void testUpdateContextGroupSuccessGeneralJdbc() {
((DatabaseConnection) createDatabaseConnectionItem.getConnection()).setDatabaseType(EDatabaseTypeName.GENERAL_JDBC.getXmlName());
boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(createDatabaseConnectionItem, ContextTpeyNameNew);
Connection connection = createDatabaseConnectionItem.getConnection();
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
assertTrue(updateContextGroup);
assertTrue(catalogs.size() == 1);
assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogNew));
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method testUpdateContextGroupSuccessODBC.
/**
* Test method for
* {@link org.talend.repository.ui.utils.SwitchContextGroupNameImpl#updateContextGroup(org.talend.core.model.properties.ConnectionItem)}
* . fail3: the Connection type is ODBC case
*/
@Test
public void testUpdateContextGroupSuccessODBC() {
((DatabaseConnection) createDatabaseConnectionItem.getConnection()).setDatabaseType(EDatabaseTypeName.GODBC.getXmlName());
boolean updateContextGroup = SwitchContextGroupNameImpl.getInstance().updateContextGroup(createDatabaseConnectionItem, ContextTpeyNameNew);
Connection connection = createDatabaseConnectionItem.getConnection();
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
assertTrue(updateContextGroup);
assertTrue(catalogs.size() == 1);
assertTrue(catalogs.get(0).getName().equalsIgnoreCase(catalogNew));
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class CatalogAnalysisExecutor method evaluate.
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
* java.lang.String)
*/
@Override
protected ReturnCode evaluate(Analysis analysis, java.sql.Connection connection, String sqlStatement) {
CatalogEvaluator eval = new CatalogEvaluator();
// MOD xqliu 2009-02-09 bug 6237
eval.setMonitor(getMonitor());
// // --- add indicators
EList<Indicator> indicators = analysis.getResults().getIndicators();
for (Indicator indicator : indicators) {
ModelElement analyzedElement = indicator.getAnalyzedElement();
if (analyzedElement == null) {
continue;
}
Catalog cat = SwitchHelpers.CATALOG_SWITCH.doSwitch(analyzedElement);
if (cat == null) {
continue;
}
eval.storeIndicator(cat, indicator);
// ADDED rli 2008-07-10 fixed for the SchemaIndicator will increased after connection analysis running.
indicator.reset();
}
ReturnCode retCode = runAnalysisLow(analysis, sqlStatement, eval, connection);
if (getMonitor() != null) {
getMonitor().worked(compIndicatorsWorked);
}
return retCode;
}
use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method createSqlQuery.
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
if (!isAnalyzedElementValid(indicator)) {
return Boolean.FALSE;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return Boolean.FALSE;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return Boolean.FALSE;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionDQRule = new ArrayList<String>();
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
if (withWhereOfRule) {
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);
}
}
}
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;
}
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
// ~
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
// completedSqlString is the final query
String finalQuery = completedSqlString;
TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
indicator.setInstantiatedExpression(instantiateSqlExpression);
return true;
}
use of orgomg.cwm.resource.relational.Catalog 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;
}
Aggregations