Search in sources :

Example 6 with DBConnectionParameter

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

the class MultiColAnalysisCreationTest method getDataManager.

/**
 * DOC scorreia Comment method "getDataManager".
 *
 * @return
 */
public Connection getDataManager() {
    // $NON-NLS-1$
    TypedProperties connectionParams = PropertiesLoader.getProperties(AllDataProfilerCoreTests.class, "db.properties");
    // $NON-NLS-1$
    String driverClassName = connectionParams.getProperty("driver");
    // $NON-NLS-1$
    String dbUrl = connectionParams.getProperty("url");
    // $NON-NLS-1$
    String sqlTypeName = connectionParams.getProperty("sqlTypeName");
    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();
    // 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(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) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) TypedProperties(org.talend.utils.properties.TypedProperties) DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Example 7 with DBConnectionParameter

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

the class ConnectionUtils method createConnectionParam.

/**
 * DOC xqliu Comment method "createConnectionParam".
 *
 * @param conn
 * @return
 */
public static DBConnectionParameter createConnectionParam(Connection conn) {
    DBConnectionParameter connectionParam = new DBConnectionParameter();
    Properties properties = new Properties();
    // MOD xqliu 2010-08-06 bug 14593
    properties.setProperty(TaggedValueHelper.USER, JavaSqlFactory.getUsername(conn));
    properties.setProperty(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(conn));
    // ~ 14593
    connectionParam.setParameters(properties);
    connectionParam.setName(conn.getName());
    connectionParam.setAuthor(MetadataHelper.getAuthor(conn));
    connectionParam.setDescription(MetadataHelper.getDescription(conn));
    connectionParam.setPurpose(MetadataHelper.getPurpose(conn));
    connectionParam.setStatus(MetadataHelper.getDevStatus(conn));
    connectionParam.setDriverPath(((DatabaseConnection) conn).getDriverJarPath());
    connectionParam.setDriverClassName(JavaSqlFactory.getDriverClass(conn));
    connectionParam.setJdbcUrl(JavaSqlFactory.getURL(conn));
    connectionParam.setHost(JavaSqlFactory.getServerName(conn));
    connectionParam.setPort(JavaSqlFactory.getPort(conn));
    if (conn instanceof DatabaseConnection) {
        connectionParam.setSqlTypeName(((DatabaseConnection) conn).getDatabaseType());
        String dbmsId = ((DatabaseConnection) conn).getDbmsId();
        connectionParam.setDbmsId(dbmsId);
        // ADD klliu 2011-05-19 21704: Refactoring this "otherParameter" !
        connectionParam.setFilterCatalog(dbmsId);
    }
    // MOD klliu if oracle set schema to other parameter
    if (conn instanceof DatabaseConnection) {
        DatabaseConnection dbConnection = (DatabaseConnection) conn;
        connectionParam.setOtherParameter(dbConnection.getUiSchema());
        // ADD klliu 2011-05-19 21704: Refactoring this "otherParameter" !
        connectionParam.setFilterSchema(dbConnection.getUiSchema());
    }
    // MOD mzhao adapte model. MDM connection editing need handle
    // additionally.
    // connectionParam.getParameters().setProperty(TaggedValueHelper.UNIVERSE,
    // DataProviderHelper.getUniverse(connection));
    connectionParam.setDbName(JavaSqlFactory.getSID(conn));
    // MOD by zshen for bug 15314
    String retrieveAllMetadata = MetadataHelper.getRetrieveAllMetadata(conn);
    connectionParam.setRetrieveAllMetadata(retrieveAllMetadata == null ? true : new Boolean(retrieveAllMetadata).booleanValue());
    return connectionParam;
}
Also used : DBConnectionParameter(org.talend.dq.analysis.parameters.DBConnectionParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Properties(java.util.Properties)

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