Search in sources :

Example 6 with MetadataFillFactory

use of org.talend.metadata.managment.model.MetadataFillFactory 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)

Example 7 with MetadataFillFactory

use of org.talend.metadata.managment.model.MetadataFillFactory 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 8 with MetadataFillFactory

use of org.talend.metadata.managment.model.MetadataFillFactory in project tdq-studio-se by Talend.

the class ConnectionService method createConnection.

public static TypedReturnCode<Connection> createConnection(DBConnectionParameter parameter) {
    TypedReturnCode<Connection> tReturnCode = new TypedReturnCode<Connection>(false);
    MetadataFillFactory instance = null;
    instance = MetadataFillFactory.getDBInstance();
    IMetadataConnection metaConnection = instance.fillUIParams(ParameterUtil.toMap(parameter));
    ReturnCode rc = instance.createConnection(metaConnection);
    if (rc.isOk()) {
        Connection dbConn = instance.fillUIConnParams(metaConnection, null);
        DatabaseMetaData dbMetadata = null;
        List<String> packageFilter = ConnectionUtils.getPackageFilter(parameter);
        java.sql.Connection sqlConn = null;
        try {
            if (rc instanceof TypedReturnCode) {
                @SuppressWarnings("rawtypes") Object sqlConnObject = ((TypedReturnCode) rc).getObject();
                if (sqlConnObject instanceof java.sql.Connection) {
                    sqlConn = (java.sql.Connection) sqlConnObject;
                    dbMetadata = org.talend.utils.sql.ConnectionUtils.getConnectionMetadata(sqlConn);
                }
            }
            instance.fillCatalogs(dbConn, dbMetadata, packageFilter);
            instance.fillSchemas(dbConn, dbMetadata, packageFilter);
            tReturnCode.setObject(dbConn);
        } catch (SQLException e) {
            log.error(e, e);
        // Need to add a dialog for report the reson of error
        } finally {
            if (sqlConn != null) {
                ConnectionUtils.closeConnection(sqlConn);
            }
        }
    } else {
        tReturnCode.setMessage(rc.getMessage());
        tReturnCode.setOk(false);
    }
    return tReturnCode;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) SQLException(java.sql.SQLException) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseMetaData(java.sql.DatabaseMetaData) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) MetadataFillFactory(org.talend.metadata.managment.model.MetadataFillFactory)

Aggregations

MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)8 SQLException (java.sql.SQLException)7 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)7 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 ReturnCode (org.talend.utils.sugars.ReturnCode)6 DatabaseMetaData (java.sql.DatabaseMetaData)4 DBConnectionParameter (org.talend.dq.analysis.parameters.DBConnectionParameter)4 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)4 Properties (java.util.Properties)3 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)3 EObject (org.eclipse.emf.ecore.EObject)2 Connection (java.sql.Connection)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 EDatabaseTypeName (org.talend.core.database.EDatabaseTypeName)1 TdSoftwareSystem (org.talend.cwm.softwaredeployment.TdSoftwareSystem)1 EMFSharedResources (org.talend.dq.writer.EMFSharedResources)1