Search in sources :

Example 66 with DatabaseConnection

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);
}
Also used : Schema(orgomg.cwm.resource.relational.Schema) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 67 with DatabaseConnection

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);
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 68 with DatabaseConnection

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));
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with DatabaseConnection

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);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdView(org.talend.cwm.relational.TdView) TdExpression(org.talend.cwm.relational.TdExpression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(orgomg.cwm.resource.relational.Schema) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 70 with DatabaseConnection

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);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Properties(java.util.Properties)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14