Search in sources :

Example 1 with ConnectionStatus

use of org.talend.core.repository.model.connection.ConnectionStatus in project tdi-studio-se by Talend.

the class DbTableController method checkConnection.

/**
     * qzhang Comment method "checkConnection".
     * 
     * @param metadataConnection
     */
protected boolean checkConnection(IMetadataConnection metadataConnection) {
    try {
        ConnectionStatus testConnection = ExtractMetaDataFromDataBase.testConnection(metadataConnection.getDbType(), metadataConnection.getUrl(), metadataConnection.getUsername(), metadataConnection.getPassword(), metadataConnection.getSchema(), metadataConnection.getDriverClass(), metadataConnection.getDriverJarPath(), metadataConnection.getDbVersionString(), metadataConnection.getAdditionalParams());
        connParameters.setConnectionComment(testConnection.getMessageException());
        if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connParameters.getDbType())) {
            return true;
        }
        return testConnection.getResult();
    } catch (Exception e) {
        //$NON-NLS-1$ //$NON-NLS-2$
        log.error(Messages.getString("CommonWizard.exception") + "\n" + e.toString());
    }
    return false;
}
Also used : ConnectionStatus(org.talend.core.repository.model.connection.ConnectionStatus) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 2 with ConnectionStatus

use of org.talend.core.repository.model.connection.ConnectionStatus in project tdi-studio-se by Talend.

the class GuessSchemaController method checkConnection.

/**
     * qzhang Comment method "checkConnection".
     *
     * @param metadataConnection
     */
protected boolean checkConnection(IMetadataConnection metadataConnection) {
    try {
        if (EDatabaseTypeName.HIVE.getDisplayName().equals(metadataConnection.getDbType())) {
            ConnectionStatus connectionStatus = new ConnectionStatus();
            connectionStatus.setResult(false);
            try {
                if (HiveModeInfo.get(metadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
                    JavaSqlFactory.doHivePreSetup((DatabaseConnection) metadataConnection.getCurrentConnection());
                }
                HiveConnectionManager.getInstance().checkConnection(metadataConnection);
                connectionStatus.setResult(true);
            } catch (Exception e) {
                //$NON-NLS-1$//$NON-NLS-2$
                log.error("" + "\n" + e.toString());
            }
            return connectionStatus.getResult();
        }
        if (EDatabaseTypeName.IMPALA.getDisplayName().equals(metadataConnection.getDbType())) {
            ConnectionStatus connectionStatus = new ConnectionStatus();
            connectionStatus.setResult(false);
            try {
                ImpalaConnectionManager.getInstance().checkConnection(metadataConnection);
                connectionStatus.setResult(true);
            } catch (Exception e) {
                //$NON-NLS-1$//$NON-NLS-2$
                log.error("" + "\n" + e.toString());
            }
            return connectionStatus.getResult();
        }
        ConnectionStatus testConnection = ExtractMetaDataFromDataBase.testConnection(metadataConnection.getDbType(), metadataConnection.getUrl(), metadataConnection.getUsername(), metadataConnection.getPassword(), metadataConnection.getSchema(), metadataConnection.getDriverClass(), metadataConnection.getDriverJarPath(), metadataConnection.getDbVersionString(), metadataConnection.getAdditionalParams());
        connParameters.setConnectionComment(testConnection.getMessageException());
        return testConnection.getResult();
    } catch (Exception e) {
        //$NON-NLS-1$//$NON-NLS-2$
        log.error("" + "\n" + e.toString());
    }
    return false;
}
Also used : ConnectionStatus(org.talend.core.repository.model.connection.ConnectionStatus) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException)

Example 3 with ConnectionStatus

use of org.talend.core.repository.model.connection.ConnectionStatus in project tdi-studio-se by Talend.

the class DbTableController method checkConnection.

/**
     * nma Comment method "checkConnection".
     * 
     * @param metadataConnection, IContextManager
     */
protected boolean checkConnection(IMetadataConnection metadataConnection, IContextManager contextManager) {
    try {
        String DBType = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbType(), contextManager);
        String userName = ContextParameterUtils.parseScriptContextCode(metadataConnection.getUsername(), contextManager);
        String password = ContextParameterUtils.parseScriptContextCode(metadataConnection.getPassword(), contextManager);
        String schema = ContextParameterUtils.parseScriptContextCode(metadataConnection.getSchema(), contextManager);
        String driveClass = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDriverClass(), contextManager);
        String driverJarPath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDriverJarPath(), contextManager);
        String dbVersion = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbVersionString(), contextManager);
        String additionalParams = ContextParameterUtils.parseScriptContextCode(metadataConnection.getAdditionalParams(), contextManager);
        // specially used for URL
        String server = ContextParameterUtils.parseScriptContextCode(metadataConnection.getServerName(), contextManager);
        String port = ContextParameterUtils.parseScriptContextCode(metadataConnection.getPort(), contextManager);
        String sidOrDatabase = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDatabase(), contextManager);
        String filePath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getFileFieldName(), contextManager);
        String datasource = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDataSourceName(), contextManager);
        String dbRootPath = ContextParameterUtils.parseScriptContextCode(metadataConnection.getDbRootPath(), contextManager);
        String additionParam = ContextParameterUtils.parseScriptContextCode(metadataConnection.getAdditionalParams(), contextManager);
        String newURL = DatabaseConnStrUtil.getURLString(DBType, dbVersion, server, userName, password, port, sidOrDatabase, filePath.toLowerCase(), datasource, dbRootPath, additionParam);
        ConnectionStatus testConnection = ExtractMetaDataFromDataBase.testConnection(DBType, newURL, userName, password, schema, driveClass, driverJarPath, dbVersion, additionalParams);
        ConnectionParameters connParameters2 = new ConnectionParameters();
        if (connParameters == null) {
            connParameters = connParameters2;
        }
        connParameters.setConnectionComment(testConnection.getMessageException());
        if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connParameters.getDbType())) {
            return true;
        }
        return testConnection.getResult();
    } catch (Exception e) {
        //$NON-NLS-1$ //$NON-NLS-2$
        log.error(Messages.getString("CommonWizard.exception") + "\n" + e.toString());
    }
    return false;
}
Also used : ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) ConnectionStatus(org.talend.core.repository.model.connection.ConnectionStatus) SQLException(java.sql.SQLException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

SQLException (java.sql.SQLException)3 ConnectionStatus (org.talend.core.repository.model.connection.ConnectionStatus)3 PersistenceException (org.talend.commons.exception.PersistenceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectionParameters (org.talend.core.sqlbuilder.util.ConnectionParameters)1 ProcessorException (org.talend.designer.runprocess.ProcessorException)1