Search in sources :

Example 76 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ConnectionUtils method getHadoopClusterIDOfHive.

/**
 * get the hadoop cluster ID .
 *
 * @param viewObject
 * @return
 */
public static String getHadoopClusterIDOfHive(IRepositoryViewObject viewObject) {
    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) viewObject.getProperty().getItem();
    DatabaseConnection dbConnection = (DatabaseConnection) dbItem.getConnection();
    return dbConnection.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CLUSTER_ID);
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 77 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ConnectionUtils method isGeneralJdbc.

/**
 * if the Connection's type is General JDBC return true.
 *
 * @param conn a database connection
 * @return
 */
public static boolean isGeneralJdbc(Connection conn) {
    boolean jdbc = false;
    if (conn instanceof DatabaseConnection) {
        DatabaseConnection dbConn = (DatabaseConnection) conn;
        EDatabaseTypeName databaseType = EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType());
        if (EDatabaseTypeName.GENERAL_JDBC.equals(databaseType)) {
            jdbc = true;
        }
    }
    return jdbc;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName)

Example 78 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ConnectionUtils method setName.

/**
 * DOC zshen Comment method "setName".
 *
 * @param conn
 * @param password
 */
public static void setName(Connection conn, String name) {
    DatabaseConnection dbConn = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(conn);
    if (dbConn != null) {
        dbConn.setName(name);
        dbConn.setLabel(name);
    }
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 79 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ConnectionUtils method isConnectionAvailable.

/**
 * This method is used to check conectiton is avalible for analysis or report ,when analysis or report runs.
 *
 * @param analysisDataProvider
 * @return
 */
public static ReturnCode isConnectionAvailable(Connection analysisDataProvider) {
    ReturnCode returnCode = new ReturnCode();
    if (analysisDataProvider == null) {
        returnCode.setOk(false);
        // $NON-NLS-1$
        returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle"));
        return returnCode;
    }
    // check hive connection
    IMetadataConnection metadataConnection = ConvertionHelper.convert(analysisDataProvider);
    if (metadataConnection != null) {
        if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConnection.getDbType())) {
            try {
                // need to do this first when check for hive embed connection.
                if (isHiveEmbedded(analysisDataProvider)) {
                    JavaSqlFactory.doHivePreSetup(analysisDataProvider);
                }
                HiveConnectionManager.getInstance().checkConnection(metadataConnection);
                returnCode.setOk(true);
            } catch (ClassNotFoundException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (InstantiationException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (IllegalAccessException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            } catch (SQLException e) {
                returnCode.setOk(false);
                returnCode.setMessage(e.toString());
            }
            return returnCode;
        }
    }
    // MOD klliu check file connection is available
    if (analysisDataProvider instanceof FileConnection) {
        FileConnection fileConn = (FileConnection) analysisDataProvider;
        // ADD msjian TDQ-4559 2012-2-28: when the fileconnection is context mode, getOriginalFileConnection.
        if (fileConn.isContextMode()) {
            IRepositoryContextService service = CoreRuntimePlugin.getInstance().getRepositoryContextService();
            if (service != null) {
                fileConn = service.cloneOriginalValueConnection(fileConn);
            }
        }
        // TDQ-4559 ~
        String filePath = fileConn.getFilePath();
        try {
            BufferedReader filePathAvailable = FilesUtils.isFilePathAvailable(filePath, fileConn);
            if (filePathAvailable == null) {
                returnCode.setOk(false);
                // $NON-NLS-1$ //$NON-NLS-2$
                returnCode.setMessage(Messages.getString("ConnectionUtils.checkConnFailTitle") + " " + filePath);
            }
        } catch (UnsupportedEncodingException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (FileNotFoundException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        } catch (IOException e) {
            returnCode.setOk(false);
            returnCode.setMessage(e.toString());
        }
        return returnCode;
    }
    // ~
    Properties props = new Properties();
    props.put(TaggedValueHelper.USER, JavaSqlFactory.getUsername(analysisDataProvider));
    props.put(TaggedValueHelper.PASSWORD, JavaSqlFactory.getPassword(analysisDataProvider));
    if (analysisDataProvider instanceof DatabaseConnection) {
        // MOD qiongli TDQ-11507,for GeneralJdbc,should check connection too after validation jar and jdbc driver .
        if (isTcompJdbc(analysisDataProvider) || isGeneralJdbc(analysisDataProvider)) {
            ReturnCode rcJdbc = checkJdbcJarFilePathDriverClassName((DatabaseConnection) analysisDataProvider);
            if (!rcJdbc.isOk()) {
                return rcJdbc;
            }
        }
        // MOD qiongli 2014-5-14 in order to check and connect a dbConnection by a correct driver,replace
        // 'ConnectionUtils.checkConnection(...)' with 'managerConn.check(metadataConnection)'.
        ManagerConnection managerConn = new ManagerConnection();
        returnCode.setOk(managerConn.check(metadataConnection));
        returnCode.setMessage(managerConn.getMessageException());
    }
    return returnCode;
}
Also used : ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) ReturnCode(org.talend.utils.sugars.ReturnCode) SQLException(java.sql.SQLException) FileNotFoundException(java.io.FileNotFoundException) IRepositoryContextService(org.talend.core.IRepositoryContextService) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IOException(java.io.IOException) Properties(java.util.Properties) BufferedReader(java.io.BufferedReader) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Example 80 with DatabaseConnection

use of org.talend.core.model.metadata.builder.connection.DatabaseConnection in project tdq-studio-se by Talend.

the class ConnectionUtils method getRetrieveAllMetadata.

/**
 * if the connection has sid return false, else return true (don't need the TaggedValue any more).
 *
 * @param element
 * @return
 */
public static boolean getRetrieveAllMetadata(ModelElement element) {
    if (element != null && element instanceof Connection) {
        if (element instanceof DatabaseConnection) {
            DatabaseConnection dbConn = (DatabaseConnection) element;
            String sid = JavaSqlFactory.getSID(dbConn);
            if (sid != null && !"".equals(sid.trim())) {
                // $NON-NLS-1$
                // MOD klliu bug 22900
                TaggedValue taggedValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.RETRIEVE_ALL, element.getTaggedValue());
                // if connection is created by 4.2 or 5.0 ,the tagedValue(RETRIEVE_ALL) has been removed.
                if (taggedValue != null) {
                    String value = taggedValue.getValue();
                    if (value.equals("true")) {
                        // $NON-NLS-1$
                        return true;
                    }
                }
                // ~
                if (ConnectionHelper.isOracle(dbConn) || isPostgresql(dbConn)) {
                    String uiSchema = dbConn.getUiSchema();
                    if (uiSchema != null && !"".equals(uiSchema.trim())) {
                        // $NON-NLS-1$
                        return false;
                    } else {
                        return true;
                    }
                } else {
                    return false;
                }
            } else {
                return true;
            }
        } else if (element instanceof FileConnection) {
            // do file connection can filter catalog/schema?
            return true;
        }
    }
    return true;
}
Also used : TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) 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) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ManagerConnection(org.talend.metadata.managment.repository.ManagerConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) FileConnection(org.talend.core.model.metadata.builder.connection.FileConnection)

Aggregations

DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)211 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)66 Connection (org.talend.core.model.metadata.builder.connection.Connection)53 ConnectionItem (org.talend.core.model.properties.ConnectionItem)42 ArrayList (java.util.ArrayList)41 PersistenceException (org.talend.commons.exception.PersistenceException)41 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)39 Test (org.junit.Test)33 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)30 Property (org.talend.core.model.properties.Property)30 Item (org.talend.core.model.properties.Item)26 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)20 IElementParameter (org.talend.core.model.process.IElementParameter)19 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 RepositoryNode (org.talend.repository.model.RepositoryNode)18 SQLException (java.sql.SQLException)17 TdTable (org.talend.cwm.relational.TdTable)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 List (java.util.List)15 ReturnCode (org.talend.utils.sugars.ReturnCode)14