Search in sources :

Example 56 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ColumnAnalysisSqlExecutorTest method setUp.

/**
 * DOC zshen Comment method "setUp".
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // create analysis element
    TdColumn testTdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    testTdColumn.setName("columnName");
    // testAnalysisResult.setModelElement(testTdColumn);
    // create sqlDataType
    TdSqlDataType testTdSqlDataType = RelationalFactory.eINSTANCE.createTdSqlDataType();
    testTdColumn.setSqlDataType(testTdSqlDataType);
    testTdSqlDataType.setJavaDataType(DataminingType.NOMINAL_VALUE);
    // create TdTable
    TdTable testTdTable = RelationalFactory.eINSTANCE.createTdTable();
    testTdColumn.setNamespace(testTdTable);
    // $NON-NLS-1$
    testTdTable.setName("generateTable");
    // create connection
    DatabaseConnection testDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(testDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getDBKey());
    // create catalog
    Catalog testCatalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    testCatalog.setName("TBI");
    testTdTable.setNamespace(testCatalog);
    testCatalog.setNamespace(testDatabaseConnection);
    testCatalog.getDataManager().add(testDatabaseConnection);
    // create analysis
    testAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // create Analaysis result
    AnalysisResult testAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    testAnalysis.setResults(testAnalysisResult);
    // create analysis parameter
    AnalysisParameters testAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    testAnalysis.setParameters(testAnalysisParameters);
    // create analysis Content
    AnalysisContext testAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
    testAnalysis.setContext(testAnalysisContext);
    testAnalysisContext.setConnection(testDatabaseConnection);
    // create row count indicatorDefinition
    testIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    testIndicatorDefinition.setLabel("Pattern Frequency Table");
    // create row count indicator
    testFrequencyIndicator = IndicatorsFactory.eINSTANCE.createPatternFreqIndicator();
    testAnalysisResult.getIndicators().add(testFrequencyIndicator);
    testFrequencyIndicator.setAnalyzedElement(testTdColumn);
    testFrequencyIndicator.setIndicatorDefinition(testIndicatorDefinition);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) Catalog(orgomg.cwm.resource.relational.Catalog) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Before(org.junit.Before)

Example 57 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class TalendCWMServiceTest method testGetNameContexTrueForCatalog.

/**
 * Test method for
 * {@link org.talend.core.service.TalendCWMService#getReadableName(orgomg.cwm.foundation.softwaredeployment.DataManager, java.lang.String)}
 * .
 *
 * @throws PersistenceException
 */
@Test
public void testGetNameContexTrueForCatalog() throws PersistenceException {
    // $NON-NLS-1$
    String connectionName = "conn1";
    // $NON-NLS-1$
    String catalogName = "catalog1";
    // $NON-NLS-1$
    String ContextTpeyName = "default";
    // should be label of
    String Connectionlabel = ConnectionContextHelper.convertContextLabel(connectionName);
    // connection property when
    // use
    String prefixName = Connectionlabel + ConnectionContextHelper.LINE;
    String paramName = prefixName + DBConnectionContextUtils.EDBParamName.Database;
    String contextCatalogName = ContextParameterUtils.JAVA_NEW_CONTEXT_PREFIX + paramName;
    // ContextType--default
    ContextType createContextDefault = TalendFileFactory.eINSTANCE.createContextType();
    createContextDefault.setName(ContextTpeyName);
    ContextParameterType createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
    createContextParameterTypeForDefault.setName(paramName);
    createContextParameterTypeForDefault.setValue(catalogName);
    createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
    // ~ContextType--default
    // ConntextItem
    ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
    Property contextProperty = PropertiesFactory.eINSTANCE.createProperty();
    contextProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    contextProperty.setVersion(VersionUtils.DEFAULT_VERSION);
    // $NON-NLS-1$
    contextProperty.setStatusCode("");
    // $NON-NLS-1$
    contextProperty.setLabel("context1");
    contextItem.setProperty(contextProperty);
    JobContextManager contextManager = new JobContextManager();
    String nextId = factory.getNextId();
    contextProperty.setId(nextId);
    contextProperty.setLabel(contextProperty.getDisplayName());
    contextManager.saveToEmf(contextItem.getContext());
    contextItem.setDefaultContext(contextManager.getDefaultContext().getName());
    contextItem.getContext().add(createContextDefault);
    factory.create(contextItem, Path.EMPTY);
    // ContextItem
    // DatabaseConnection
    DatabaseConnection createDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createDatabaseConnection.setName(connectionName);
    createDatabaseConnection.setContextMode(true);
    createDatabaseConnection.setContextId(contextProperty.getId());
    createDatabaseConnection.setContextName(ContextTpeyName);
    // ~DatabaseConnection
    String readableName = null;
    readableName = TalendCWMService.getReadableName(createDatabaseConnection, contextCatalogName);
    assert (catalogName.equals(readableName));
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) JobContextManager(org.talend.core.model.context.JobContextManager) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) Test(org.junit.Test)

Example 58 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class TalendCWMServiceTest method testGetNameContexTrueForSchema.

/**
 * Test method for
 * {@link org.talend.core.service.TalendCWMService#getReadableName(orgomg.cwm.foundation.softwaredeployment.DataManager, java.lang.String)}
 * .
 *
 * @throws PersistenceException
 */
@Test
public void testGetNameContexTrueForSchema() throws PersistenceException {
    // $NON-NLS-1$
    String connectionName = "conn1";
    // $NON-NLS-1$
    String catalogName = "catalog1";
    // $NON-NLS-1$
    String ContextTpeyName = "default";
    // should be label of
    String Connectionlabel = ConnectionContextHelper.convertContextLabel(connectionName);
    // connection property when
    // use
    String prefixName = Connectionlabel + ConnectionContextHelper.LINE;
    String paramName = prefixName + DBConnectionContextUtils.EDBParamName.Schema;
    String contextCatalogName = ContextParameterUtils.JAVA_NEW_CONTEXT_PREFIX + paramName;
    // ContextType--default
    ContextType createContextDefault = TalendFileFactory.eINSTANCE.createContextType();
    createContextDefault.setName(ContextTpeyName);
    ContextParameterType createContextParameterTypeForDefault = TalendFileFactory.eINSTANCE.createContextParameterType();
    createContextParameterTypeForDefault.setName(paramName);
    createContextParameterTypeForDefault.setValue(catalogName);
    createContextDefault.getContextParameter().add(createContextParameterTypeForDefault);
    // ~ContextType--default
    // ConntextItem
    ContextItem contextItem = PropertiesFactory.eINSTANCE.createContextItem();
    Property contextProperty = PropertiesFactory.eINSTANCE.createProperty();
    contextProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
    contextProperty.setVersion(VersionUtils.DEFAULT_VERSION);
    // $NON-NLS-1$
    contextProperty.setStatusCode("");
    // $NON-NLS-1$
    contextProperty.setLabel("context2");
    contextItem.setProperty(contextProperty);
    JobContextManager contextManager = new JobContextManager();
    String nextId = factory.getNextId();
    contextProperty.setId(nextId);
    contextProperty.setLabel(contextProperty.getDisplayName());
    contextManager.saveToEmf(contextItem.getContext());
    contextItem.setDefaultContext(contextManager.getDefaultContext().getName());
    contextItem.getContext().add(createContextDefault);
    factory.create(contextItem, Path.EMPTY);
    // ContextItem
    // DatabaseConnection
    DatabaseConnection createDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    createDatabaseConnection.setName(connectionName);
    createDatabaseConnection.setContextMode(true);
    createDatabaseConnection.setContextId(contextProperty.getId());
    createDatabaseConnection.setContextName(ContextTpeyName);
    // ~DatabaseConnection
    String readableName = null;
    readableName = TalendCWMService.getReadableName(createDatabaseConnection, contextCatalogName);
    assert (catalogName.equals(readableName));
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) JobContextManager(org.talend.core.model.context.JobContextManager) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) Test(org.junit.Test)

Example 59 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method getDB2DataManager.

/**
 * getDataManager of DB2
 *
 * @return
 */
public Connection getDB2DataManager() {
    // TypedProperties connectionParams = PropertiesLoader.getProperties(IndicatorEvaluator.class, "db.properties"); //$NON-NLS-1$
    // $NON-NLS-1$
    String driverClassName = "com.ibm.db2.jcc.DB2Driver";
    // $NON-NLS-1$
    String dbUrl = "jdbc:db2://192.168.31.135:50000/sample";
    // $NON-NLS-1$
    String sqlTypeName = "IBM DB2";
    DBConnectionParameter params = new DBConnectionParameter();
    // $NON-NLS-1$
    params.setName("DB2_Connection");
    params.setDriverClassName(driverClassName);
    params.setJdbcUrl(dbUrl);
    params.setSqlTypeName(sqlTypeName);
    Properties properties = new Properties();
    properties.setProperty(TaggedValueHelper.UNIVERSE, "");
    properties.setProperty(TaggedValueHelper.DATA_FILTER, "");
    properties.setProperty(TaggedValueHelper.USER, "db2inst1");
    properties.setProperty(TaggedValueHelper.PASSWORD, "db2inst1");
    params.setParameters(properties);
    // create connection
    ConnectionUtils.setTimeout(false);
    MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
    IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
    ReturnCode rc = null;
    try {
        rc = instance.checkConnection(metaConnection);
    } catch (java.lang.RuntimeException e) {
        Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
    }
    Connection dataProvider = null;
    if (rc.isOk()) {
        dataProvider = instance.fillUIConnParams(metaConnection, null);
        dataProvider.setName("DB2_Connection");
        // because the DI side code is changed, modify the following code.
        metaConnection.setCurrentConnection(dataProvider);
        try {
            ProjectNodeHelper.fillCatalogAndSchemas(metaConnection, (DatabaseConnection) dataProvider);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    Assert.assertNotNull("Can not connect to Database: " + dbUrl, dataProvider);
    return dataProvider;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Properties(java.util.Properties) DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Example 60 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class PatternExplorerRealTest method testGetInvalidValuesStatement_3.

/**
 * Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidValuesStatement()}. when the test
 * for indicator is user define indicator
 */
@Test
public void testGetInvalidValuesStatement_3() {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicator.setIndicatorDefinition(indicatorDef);
    TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    udiTdExpression.setBody(ViewInvalidValues);
    indicatorDef.getViewInvalidValuesExpression().add(udiTdExpression);
    // create pattern parameter
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicator.setParameters(createIndicatorParameters);
    Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
    createIndicatorParameters.setDataValidDomain(createDomain);
    Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
    createDomain.getPatterns().add(createPattern);
    RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
    createPattern.getComponents().add(createPatternComponent);
    TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    createPatternComponent.setExpression(createTdExpression);
    createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createTdExpression.setBody("`su.*`");
    TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTable.setName("table1");
    TableHelper.addColumn(createTdTable, element);
    Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    createCatalog.setName("catalog1");
    List<TdTable> tableList = new ArrayList<TdTable>();
    tableList.add(createTdTable);
    CatalogHelper.addTables(tableList, createCatalog);
    indicator.setAnalyzedElement(element);
    Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
    createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createIndiExpression.setBody("SELECT *  FROM `tbi`.`customer`  WHERE (customer.lname = \"sunny\")");
    indicator.setInstantiatedExpression(createIndiExpression);
    Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
    AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
    analysis.setContext(createAnalysisContext);
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
    createAnalysisContext.setConnection(createDatabaseConnection);
    ChartDataEntity cdEntity = new ChartDataEntity();
    cdEntity.setIndicator(indicator);
    Assert.assertTrue(patternExplorer.setAnalysis(analysis));
    patternExplorer.setEnitty(cdEntity);
    String clause = patternExplorer.getInvalidValuesStatement();
    // $NON-NLS-1$
    assertEquals("SELECT `lname` FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) Catalog(orgomg.cwm.resource.relational.Catalog) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

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