Search in sources :

Example 1 with DBConnectionParameter

use of org.talend.dq.analysis.parameters.DBConnectionParameter 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 2 with DBConnectionParameter

use of org.talend.dq.analysis.parameters.DBConnectionParameter in project tdq-studio-se by Talend.

the class ParameterUtilTest method testToMap.

/**
 * Test method for
 * {@link org.talend.dq.helper.ParameterUtil#toMap(org.talend.dq.analysis.parameters.DBConnectionParameter)}.
 */
@Test
public void testToMap() {
    DBConnectionParameter dbParameter = new DBConnectionParameter();
    dbParameter.setParameters(new Properties());
    Map<String, String> parameterMap = ParameterUtil.toMap(dbParameter);
    // $NON-NLS-1$
    assertSame(dbParameter.getPort(), parameterMap.get("port"));
    // $NON-NLS-1$
    assertSame(dbParameter.getHost(), parameterMap.get("host"));
    // $NON-NLS-1$
    assertSame(dbParameter.getDriverPath(), parameterMap.get("driverPath"));
    // $NON-NLS-1$
    assertSame(dbParameter.getStatus(), parameterMap.get("status"));
    // $NON-NLS-1$
    assertSame(dbParameter.getFilePath(), parameterMap.get("filePath"));
    // $NON-NLS-1$
    assertSame(dbParameter.getDriverClassName(), parameterMap.get("driverClassName"));
    // $NON-NLS-1$
    assertSame(dbParameter.getPurpose(), parameterMap.get("purpose"));
    // $NON-NLS-1$
    assertSame(dbParameter.getParameters().getProperty(TaggedValueHelper.DATA_FILTER), parameterMap.get("datafilter"));
    // $NON-NLS-1$
    assertSame(dbParameter.getParameters().getProperty(TaggedValueHelper.UNIVERSE), parameterMap.get("universe"));
    assertSame(dbParameter.getParameters().getProperty(TaggedValueHelper.USER), parameterMap.get(TaggedValueHelper.USER));
    assertSame(dbParameter.getParameters().getProperty(TaggedValueHelper.PASSWORD), parameterMap.get(TaggedValueHelper.PASSWORD));
    // $NON-NLS-1$
    assertSame(dbParameter.getVersion(), parameterMap.get("version"));
    // $NON-NLS-1$
    assertSame(dbParameter.getAuthor(), parameterMap.get("author"));
    // $NON-NLS-1$
    assertSame(dbParameter.getSqlTypeName(), parameterMap.get("sqlTypeName"));
    // $NON-NLS-1$
    assertSame(dbParameter.getADDParameter(), parameterMap.get("aDDParameter"));
    // $NON-NLS-1$
    assertSame(dbParameter.getDbName(), parameterMap.get("dbName"));
    // $NON-NLS-1$
    assertSame(dbParameter.getDescription(), parameterMap.get("description"));
    // $NON-NLS-1$
    assertSame(Boolean.toString(dbParameter.isRetrieveAllMetadata()), parameterMap.get("retrieveAllMetadata"));
    // $NON-NLS-1$
    assertSame(dbParameter.getJdbcUrl(), parameterMap.get("jdbcUrl"));
}
Also used : DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with DBConnectionParameter

use of org.talend.dq.analysis.parameters.DBConnectionParameter in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method getRealOracleDatabase.

/**
 * get a real database connection,the connection parameters load from a propery file.
 *
 * @return
 */
public static Connection getRealOracleDatabase() {
    Properties connectionParams = DBPropertiesUtils.getDefault().getProperties();
    // $NON-NLS-1$
    String driverClassName = connectionParams.getProperty("driver_oracle");
    // $NON-NLS-1$
    String dbUrl = connectionParams.getProperty("url_oracle");
    // $NON-NLS-1$
    String sqlTypeName = connectionParams.getProperty("sqlTypeName_oracle");
    // $NON-NLS-1$
    String dbVersion = connectionParams.getProperty("dbVersion_oracle");
    // $NON-NLS-1$
    String userName = connectionParams.getProperty("user_oracle");
    // $NON-NLS-1$
    String password = connectionParams.getProperty("password_oracle");
    DBConnectionParameter params = new DBConnectionParameter();
    // $NON-NLS-1$
    params.setName("My connection");
    params.setDriverClassName(driverClassName);
    params.setJdbcUrl(dbUrl);
    params.setSqlTypeName(sqlTypeName);
    params.setParameters(connectionParams);
    params.getParameters();
    Properties properties = new Properties();
    properties.setProperty(TaggedValueHelper.USER, userName);
    properties.setProperty(TaggedValueHelper.PASSWORD, password);
    properties.setProperty(TaggedValueHelper.DB_PRODUCT_VERSION, dbVersion);
    params.setParameters(properties);
    // create connection
    ConnectionUtils.setTimeout(false);
    MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
    IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
    metaConnection.setDbVersionString(dbVersion);
    ReturnCode rc = null;
    try {
        rc = instance.checkConnection(metaConnection);
    } catch (java.lang.RuntimeException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
    }
    Connection dataProvider = null;
    if (rc.isOk()) {
        dataProvider = instance.fillUIConnParams(metaConnection, null);
        dataProvider.setName(DATA_PROVIDER_NAME);
        // 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(dataProvider);
    return dataProvider;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Properties(java.util.Properties) EProperties(org.talend.repository.model.IRepositoryNode.EProperties) DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Example 4 with DBConnectionParameter

use of org.talend.dq.analysis.parameters.DBConnectionParameter in project tdq-studio-se by Talend.

the class ParameterUtil method main.

/**
 * zshen Comment method "main". a test for the method toMap.
 *
 * @param args
 */
@SuppressWarnings("unused")
private static void main(String[] args) {
    DBConnectionParameter dbParameter = new DBConnectionParameter();
    dbParameter.setParameters(new Properties());
    Map<String, String> parameterMap = ParameterUtil.toMap(dbParameter);
    IMetadataConnection metadataConnection = MetadataFillFactory.getDBInstance().fillUIParams(parameterMap);
    System.out.println(metadataConnection);
}
Also used : DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Properties(java.util.Properties)

Example 5 with DBConnectionParameter

use of org.talend.dq.analysis.parameters.DBConnectionParameter in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method getRealOracleDatabase.

/**
 * get a real database connection,the connection parameters load from a propery file.
 *
 * @return
 */
public Connection getRealOracleDatabase() {
    Properties connectionParams = DBPropertiesUtils.getDefault().getProperties();
    // $NON-NLS-1$
    String driverClassName = connectionParams.getProperty("driver_oracle");
    // $NON-NLS-1$
    String dbUrl = connectionParams.getProperty("url_oracle");
    // $NON-NLS-1$
    String sqlTypeName = connectionParams.getProperty("sqlTypeName_oracle");
    // $NON-NLS-1$
    String dbVersion = connectionParams.getProperty("dbVersion_oracle");
    // $NON-NLS-1$
    String userName = connectionParams.getProperty("user_oracle");
    // $NON-NLS-1$
    String password = connectionParams.getProperty("password_oracle");
    DBConnectionParameter params = new DBConnectionParameter();
    // $NON-NLS-1$
    params.setName("oracle_Connection");
    params.setDriverClassName(driverClassName);
    params.setJdbcUrl(dbUrl);
    params.setSqlTypeName(sqlTypeName);
    Properties properties = new Properties();
    properties.setProperty(TaggedValueHelper.USER, userName);
    properties.setProperty(TaggedValueHelper.PASSWORD, password);
    properties.setProperty(TaggedValueHelper.DB_PRODUCT_VERSION, dbVersion);
    params.setParameters(properties);
    // create connection
    ConnectionUtils.setTimeout(false);
    MetadataFillFactory instance = MetadataFillFactory.getDBInstance();
    IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(params));
    metaConnection.setDbVersionString(dbVersion);
    ReturnCode rc = null;
    try {
        rc = instance.checkConnection(metaConnection);
    } catch (java.lang.RuntimeException e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        Assert.fail("connect to " + dbUrl + "failed," + e.getMessage());
    }
    Connection dataProvider = null;
    if (rc.isOk()) {
        dataProvider = instance.fillUIConnParams(metaConnection, null);
        dataProvider.setName("oracleDB");
        // 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(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)

Aggregations

DBConnectionParameter (org.talend.dq.analysis.parameters.DBConnectionParameter)7 Properties (java.util.Properties)6 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)5 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 SQLException (java.sql.SQLException)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)3 Test (org.junit.Test)1 EProperties (org.talend.repository.model.IRepositoryNode.EProperties)1 TypedProperties (org.talend.utils.properties.TypedProperties)1