Search in sources :

Example 1 with HiveConnectionHandler

use of org.talend.metadata.managment.hive.handler.HiveConnectionHandler in project tdq-studio-se by Talend.

the class AnalysisExecutor method getConnection.

/**
 * DOC scorreia Comment method "getConnection".
 *
 * @param analysis
 * @param schema
 * @return
 */
protected TypedReturnCode<java.sql.Connection> getConnection(Analysis analysis) {
    // MODSCA 2008-03-25 scorreia schema is not used. removed (was used before to select the catalog of the db)
    // now it is done elsewhere
    TypedReturnCode<java.sql.Connection> rc = new TypedReturnCode<java.sql.Connection>();
    DataManager datamanager = analysis.getContext().getConnection();
    if (datamanager == null) {
        // $NON-NLS-1$
        rc.setReturnCode(Messages.getString("AnalysisExecutor.DataManagerNull", analysis.getName()), false);
        return rc;
    }
    if (datamanager != null && datamanager.eIsProxy()) {
        datamanager = (DataManager) EObjectHelper.resolveObject(datamanager);
    }
    Connection dataprovider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(datamanager);
    if (dataprovider == null) {
        rc.setReturnCode(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "AnalysisExecutor.DataProviderNull", // $NON-NLS-1$
        datamanager.getName(), analysis.getName()), false);
        return rc;
    }
    // create hive connection
    IMetadataConnection metadataConnection = ConvertionHelper.convert(dataprovider);
    if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
        try {
            HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
            java.sql.Connection createConnection = hiveConnHandler.createHiveConnection();
            rc.setOk(true);
            rc.setObject(createConnection);
        } catch (ClassNotFoundException e) {
            log.error(e);
            rc.setOk(false);
        } catch (InstantiationException e) {
            log.error(e);
            rc.setOk(false);
        } catch (IllegalAccessException e) {
            log.error(e);
            rc.setOk(false);
        } catch (SQLException e) {
            log.error(e);
            rc.setOk(false);
        }
        return rc;
    } else {
        // create other type connection
        TypedReturnCode<java.sql.Connection> connection = JavaSqlFactory.createConnection(dataprovider);
        if (!connection.isOk()) {
            rc.setReturnCode(connection.getMessage(), false);
            return rc;
        }
        rc.setObject(connection.getObject());
        return rc;
    }
}
Also used : HiveConnectionHandler(org.talend.metadata.managment.hive.handler.HiveConnectionHandler) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode)

Example 2 with HiveConnectionHandler

use of org.talend.metadata.managment.hive.handler.HiveConnectionHandler in project tdq-studio-se by Talend.

the class TdqAnalysisConnectionPool method newConnection.

/**
 * DOC xqliu Comment method "newConnection".
 *
 * @return
 */
private Connection newConnection() {
    Connection conn = null;
    if (isFull()) {
        return conn;
    }
    DataManager datamanager = analysis.getContext().getConnection();
    if (datamanager == null) {
        // $NON-NLS-1$
        log.error(Messages.getString("AnalysisExecutor.DataManagerNull", analysis.getName()));
        return null;
    }
    if (datamanager != null && datamanager.eIsProxy()) {
        datamanager = (DataManager) EObjectHelper.resolveObject(datamanager);
    }
    org.talend.core.model.metadata.builder.connection.Connection dataprovider = SwitchHelpers.CONNECTION_SWITCH.doSwitch(datamanager);
    TypedReturnCode<Connection> trcConn = null;
    IMetadataConnection metadataConnection = ConvertionHelper.convert(dataprovider);
    if (metadataConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
        trcConn = new TypedReturnCode<Connection>(false);
        try {
            HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
            Connection hiveConnection = hiveConnHandler.createHiveConnection();
            if (hiveConnection != null) {
                trcConn.setOk(true);
                trcConn.setObject(hiveConnection);
            }
        } catch (ClassNotFoundException e) {
            trcConn.setOk(false);
            log.error(e);
        } catch (InstantiationException e) {
            trcConn.setOk(false);
            log.error(e);
        } catch (IllegalAccessException e) {
            trcConn.setOk(false);
            log.error(e);
        } catch (SQLException e) {
            trcConn.setOk(false);
            log.error(e);
        }
    } else {
        trcConn = JavaSqlFactory.createConnection(dataprovider);
    }
    if (trcConn != null && trcConn.isOk()) {
        conn = trcConn.getObject();
        synchronized (this.synchronizedFlag) {
            this.getPConnections().add(new PooledTdqAnalysisConnection(conn));
        }
    }
    if (conn != null) {
        try {
            if (metadataConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
            // don't set the max connection number if it is hive connection
            } else {
                DatabaseMetaData metaData = conn.getMetaData();
                int currentDriverMaxConnections = new Float(metaData.getMaxConnections() * DEFAULT_CONNECTION_NUMBER_OFFSET).intValue();
                synchronized (this.synchronizedFlag) {
                    this.setDriverMaxConnections(currentDriverMaxConnections);
                }
            }
        } catch (SQLException e) {
            log.debug(e, e);
        }
    }
    return conn;
}
Also used : HiveConnectionHandler(org.talend.metadata.managment.hive.handler.HiveConnectionHandler) SQLException(java.sql.SQLException) Connection(java.sql.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 3 with HiveConnectionHandler

use of org.talend.metadata.managment.hive.handler.HiveConnectionHandler in project tdq-studio-se by Talend.

the class TOPRepositoryService method createHiveConnection.

/*
       * (non-Javadoc)
       * 
       * @see
       * org.talend.core.ITDQRepositoryService#createHiveConnection(org.talend.core.model.metadata.IMetadataConnection)
       */
public java.sql.Connection createHiveConnection(IMetadataConnection metadataConnection) {
    java.sql.Connection connection = null;
    if (metadataConnection != null && EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
        try {
            HiveConnectionHandler hiveConnHandler = HiveConnectionManager.getInstance().createHandler(metadataConnection);
            connection = hiveConnHandler.createHiveConnection();
        } catch (ClassNotFoundException e) {
            log.error(e);
        } catch (InstantiationException e) {
            log.error(e);
        } catch (IllegalAccessException e) {
            log.error(e);
        } catch (SQLException e) {
            log.error(e);
        }
    }
    return connection;
}
Also used : HiveConnectionHandler(org.talend.metadata.managment.hive.handler.HiveConnectionHandler) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)3 HiveConnectionHandler (org.talend.metadata.managment.hive.handler.HiveConnectionHandler)3 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 DataManager (orgomg.cwm.foundation.softwaredeployment.DataManager)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Connection (org.talend.core.model.metadata.builder.connection.Connection)1 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)1