use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method createCatalogSchema.
/**
* DOC talend Comment method "createSchema".
*
* @param schemaOld2
*/
private void createCatalogSchema(String schemaOld2) {
Connection connection = createDatabaseConnectionItem.getConnection();
((DatabaseConnection) connection).setUiSchema(this.contextSchemaName);
List<Catalog> catalogs = ConnectionHelper.getCatalogs(connection);
Catalog catalog = catalogs.get(0);
Schema createSchema = SchemaHelper.createSchema(schemaOld);
List<Schema> schemas = new ArrayList<Schema>();
schemas.add(createSchema);
CatalogHelper.addSchemas(schemas, catalog);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class SwitchContextGroupNameImplTest method createCatalog.
/**
* DOC talend Comment method "createCatalog".
*
* @param catalogName
*/
private void createCatalog(String catalogName) {
Connection connection = createDatabaseConnectionItem.getConnection();
Catalog createCatalog = CatalogHelper.createCatalog(catalogOld);
ConnectionHelper.addCatalog(createCatalog, connection);
((DatabaseConnection) connection).setSID(contextCatalogName);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection 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));
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ModelElementEditonDistance method distance.
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.compare.match.eobject.EditionDistance#distance(org.eclipse.emf.compare.Comparison,
* org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
@Override
public double distance(Comparison inProgress, EObject a, EObject b) {
boolean isSame = false;
if (a instanceof DatabaseConnection) {
return 0;
}
if (a instanceof Catalog && b instanceof Catalog) {
Catalog catalog1 = (Catalog) a;
Catalog catalog2 = (Catalog) b;
isSame = StringUtils.equalsIgnoreCase(catalog1.getName(), catalog2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof Schema && b instanceof Schema) {
Schema schema1 = (Schema) a;
Schema schema2 = (Schema) b;
isSame = StringUtils.equalsIgnoreCase(schema1.getName(), schema2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdTable && b instanceof TdTable) {
TdTable tdTable1 = (TdTable) a;
TdTable tdTable2 = (TdTable) b;
isSame = StringUtils.equalsIgnoreCase(tdTable1.getName(), tdTable2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdView && b instanceof TdView) {
TdView tdView1 = (TdView) a;
TdView tdView2 = (TdView) b;
isSame = StringUtils.equalsIgnoreCase(tdView1.getName(), tdView2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdColumn && b instanceof TdColumn) {
TdColumn tdColumn1 = (TdColumn) a;
TdColumn tdColumn2 = (TdColumn) b;
isSame = StringUtils.equalsIgnoreCase(tdColumn1.getName(), tdColumn2.getName()) && distance(inProgress, tdColumn1.getSqlDataType(), tdColumn2.getSqlDataType()) == 0;
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TaggedValue && b instanceof TaggedValue) {
TaggedValue taggedValue1 = (TaggedValue) a;
TaggedValue taggedValue2 = (TaggedValue) b;
isSame = StringUtils.equalsIgnoreCase(taggedValue1.getTag(), taggedValue2.getTag()) && StringUtils.equalsIgnoreCase(taggedValue1.getValue(), taggedValue2.getValue());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdExpression && b instanceof TdExpression) {
TdExpression tdExpression1 = (TdExpression) a;
TdExpression tdExpression2 = (TdExpression) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getLanguage(), tdExpression2.getLanguage()) && StringUtils.equalsIgnoreCase(tdExpression1.getBody(), tdExpression2.getBody());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof TdSqlDataType && b instanceof TdSqlDataType) {
TdSqlDataType tdExpression1 = (TdSqlDataType) a;
TdSqlDataType tdExpression2 = (TdSqlDataType) b;
isSame = StringUtils.equalsIgnoreCase(tdExpression1.getName(), tdExpression2.getName());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataColumn && b instanceof MetadataColumn) {
// Added yyin TDQ-8360
MetadataColumn metaColumn1 = (MetadataColumn) a;
MetadataColumn metaColumn2 = (MetadataColumn) b;
isSame = StringUtils.equalsIgnoreCase(metaColumn1.getLabel(), metaColumn2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
} else if (a instanceof MetadataTable && b instanceof MetadataTable) {
MetadataTable mTable1 = (MetadataTable) a;
MetadataTable mTable2 = (MetadataTable) b;
isSame = StringUtils.equalsIgnoreCase(mTable1.getLabel(), mTable2.getLabel());
return isSame ? 0 : Double.MAX_VALUE;
}
return super.distance(inProgress, a, b);
}
use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.
the class ConnectionInfoPage method checkDBConnection.
private ReturnCode checkDBConnection() {
Connection connection = getCurrentModelElement();
if (connection == null) {
// $NON-NLS-1$
return new ReturnCode("connection is null!", false);
}
String userName = loginText.getText();
String password = passwordText.getText();
// MOD qiongli 2011-9-5 feature TDQ-3317,handle context model
if (connection.isContextMode()) {
userName = JavaSqlFactory.getUsername(connection);
password = JavaSqlFactory.getPassword(connection);
}
Properties props = new Properties();
props.put(TaggedValueHelper.USER, userName);
props.put(TaggedValueHelper.PASSWORD, password);
// org.talend.cwm.db.connection.ConnectionUtils.checkCOnnection method
return MetadataConnectionUtils.checkConnection((DatabaseConnection) connection);
}
Aggregations