use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.
the class ColumnAnalysisDetailsPage method checkUDIInvalid.
/**
* Judge whether there are exist invalid udi
*
* @param modelElementIndicator
* @return
*/
private boolean checkUDIInvalid(ModelElementIndicator modelElementIndicator, boolean isExist) {
for (IndicatorUnit indicatorUnit : modelElementIndicator.getIndicatorUnits()) {
boolean isExistSqlExpr = false;
boolean sqlCaseNormal = false;
if (IndicatorEnum.UserDefinedIndicatorEnum == indicatorUnit.getType()) {
// mean that is there exist sql expression
if (!indicatorUnit.getIndicator().getIndicatorDefinition().getSqlGenericExpression().isEmpty()) {
isExistSqlExpr = true;
DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(this.getCurrentModelElement(), ExecutionLanguage.SQL);
if (dbmsLanguage.getSqlExpression(indicatorUnit.getIndicator().getIndicatorDefinition()) != null) {
sqlCaseNormal = true;
}
}
if (isExist && !(isExistSqlExpr && sqlCaseNormal)) {
// case1:find JUDI exist and isExist=true then return true
return true;
} else if (!isExist && !UDIHelper.isJavaUDI(indicatorUnit.getIndicator())) {
// case2:find JUDI is not exist and isExist=false then return true
return true;
}
}
}
// other case(both valid)
return false;
}
use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.
the class AbstractSchemaEvaluatorTest method testgetCatalogNameWithQuote_sqlServer.
@Test
public void testgetCatalogNameWithQuote_sqlServer() {
SchemaEvaluator schemaEvaluator = new SchemaEvaluator();
catalog.getOwnedElement().add(schema);
analysisElements.clear();
analysisElements.add(schema);
// $NON-NLS-1$
stub(method(Evaluator.class, "getAnalyzedElements")).toReturn(analysisElements);
when(schemarIndicator.getAnalyzedElement()).thenReturn(schema);
DbmsLanguage mysqlDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL.getLanguage(), dbVersion);
// $NON-NLS-1$
stub(method(DbmsLanguageFactory.class, "createDbmsLanguage", DataManager.class, ExecutionLanguage.class)).toReturn(mysqlDbmsLanguage);
String catalogNameWithQuote = schemaEvaluator.getCatalogNameWithQuote(schemarIndicator);
assertNotNull(catalogNameWithQuote);
assertEquals(catalogNameWithQuote, catalogName);
}
use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.
the class AbstractSchemaEvaluatorTest method testgetCatalogNameWithQuote_mySql.
@Test
public void testgetCatalogNameWithQuote_mySql() {
CatalogEvaluator catalogEvaluator = new CatalogEvaluator();
analysisElements.clear();
analysisElements.add(catalog);
// $NON-NLS-1$
stub(method(Evaluator.class, "getAnalyzedElements")).toReturn(analysisElements);
when(schemarIndicator.getAnalyzedElement()).thenReturn(catalog);
DbmsLanguage mysqlDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MYSQLDEFAULTURL.getLanguage(), dbVersion);
// $NON-NLS-1$
stub(method(DbmsLanguageFactory.class, "createDbmsLanguage", DataManager.class, ExecutionLanguage.class)).toReturn(mysqlDbmsLanguage);
String catalogNameWithQuote = catalogEvaluator.getCatalogNameWithQuote(schemarIndicator);
assertNotNull(catalogNameWithQuote);
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals(catalogNameWithQuote, "`" + catalogName + "`");
}
use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method testGetTableName_2.
/**
* try the oracle db type. Test method for
* {@link org.talend.dq.helper.AnalysisExecutorHelper#getTableName(orgomg.cwm.objectmodel.core.ModelElement, org.talend.dq.dbms.DbmsLanguage)}
* .
*/
@Test
public void testGetTableName_2() {
TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
tdTable.setName("tableName");
tdColumn.setOwner(tdTable);
// $NON-NLS-1$
tdColumn.setName("columnName");
DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.ORACLEWITHSIDDEFAULTURL.getLanguage(), null);
// mock(Schema.class);
Package schema = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
// $NON-NLS-1$
schema.setName("schemaName");
tdTable.setNamespace(schema);
// $NON-NLS-1$
assertEquals("\"SCHEMANAME\".\"TABLENAME\"", AnalysisExecutorHelper.getTableName(tdColumn, dbmsLanguage));
}
use of org.talend.dq.dbms.DbmsLanguage in project tdq-studio-se by Talend.
the class ModelElementIndicatorRuleTest method testPatternRule_7.
/**
* test for teradata connection and Pattern Frequency Statistics indicators should be disabled.
*/
@Test
public void testPatternRule_7() {
when(tdsql.getJavaDataType()).thenReturn(Types.VARCHAR);
DatabaseConnection connection = mock(DatabaseConnection.class);
PowerMockito.mockStatic(ConnectionHelper.class);
when(ConnectionHelper.getTdDataProvider(me)).thenReturn(connection);
when(ConnectionHelper.isTeradata(connection)).thenReturn(true);
DbmsLanguage dbmsLanguage = mock(DbmsLanguage.class);
// $NON-NLS-1$
when(dbmsLanguage.getDbmsName()).thenReturn("MySQL");
when(dbmsLanguage.getDbVersion()).thenReturn(null);
PowerMockito.mockStatic(DbmsLanguageFactory.class);
when(DbmsLanguageFactory.createDbmsLanguage(connection)).thenReturn(dbmsLanguage);
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
when(tdsql.getJavaDataType()).thenReturn(Types.DATE);
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
}
Aggregations