Search in sources :

Example 36 with IMetadataConnection

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

the class ConnectionUtils method updataTaggedValueForConnectionItem.

/**
 * Updata DB_PRODUCT tagged values for connection item in case they are not present in current file.
 *
 * @throws SQLException
 */
public static synchronized void updataTaggedValueForConnectionItem(Connection dataProvider) {
    if (dataProvider instanceof DatabaseConnection && StringUtils.isBlank(TaggedValueHelper.getValueString(TaggedValueHelper.DB_PRODUCT_NAME, dataProvider))) {
        Property property = PropertyHelper.getProperty(dataProvider);
        if (property != null) {
            Item item = property.getItem();
            if (item != null) {
                DatabaseConnection dbConn = (DatabaseConnection) dataProvider;
                IMetadataConnection metaConnection = ConvertionHelper.convert(dbConn);
                dbConn = (DatabaseConnection) MetadataFillFactory.getDBInstance(dataProvider).fillUIConnParams(metaConnection, dbConn);
                if (dbConn != null && Platform.isRunning()) {
                    try {
                        ProxyRepositoryFactory.getInstance().save(item);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Property(org.talend.core.model.properties.Property)

Example 37 with IMetadataConnection

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

the class SqlexplorerService method loadManagedDriverForHive.

/**
 * TDDQ-8113 load hive drive by DynamicClassLoader,then set the attribute for Hive ManagedDriver.
 *
 * @param connection
 */
private void loadManagedDriverForHive(DatabaseConnection connection) {
    DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
    String id = AliasAndManaDriverHelper.getInstance().joinManagedDriverId(connection);
    ManagedDriver manDr = driverManager.getDriver(id);
    IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
    ClassLoader classLoader = null;
    if (EDatabaseTypeName.IMPALA.getXmlName().equalsIgnoreCase(connection.getDatabaseType())) {
        classLoader = AliasAndManaDriverHelper.getInstance().getImpalaClassLoader(metadataConnection);
    } else {
        classLoader = HiveClassLoaderFactory.getInstance().getClassLoader(metadataConnection);
    }
    if (classLoader != null && classLoader instanceof DynamicClassLoader) {
        DynamicClassLoader dynClassLoader = (DynamicClassLoader) classLoader;
        String libStorePath = dynClassLoader.getLibStorePath();
        File libFolder = new File(libStorePath);
        if (libFolder.exists()) {
            List<String> relaPathLs = new ArrayList<String>();
            relaPathLs.addAll(dynClassLoader.getLibraries());
            Set<String> findAllJarPath = findAllJarPath(libFolder, relaPathLs);
            if (!findAllJarPath.isEmpty()) {
                manDr.getJars().addAll(findAllJarPath);
                try {
                    manDr.registerHiveSQLDriver(connection);
                } catch (ClassNotFoundException e) {
                    log.error(e);
                } catch (InstantiationException e) {
                    log.error(e);
                } catch (IllegalAccessException e) {
                    log.error(e);
                }
            }
        }
    }
}
Also used : DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) ArrayList(java.util.ArrayList) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) URLClassLoader(java.net.URLClassLoader) MyURLClassLoader(net.sourceforge.sqlexplorer.util.MyURLClassLoader) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 38 with IMetadataConnection

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

the class AliasAndManaDriverHelper method joinHiveManagedDriverId.

private String joinHiveManagedDriverId(DatabaseConnection dbConn) {
    IMetadataConnection metadataConn = ConvertionHelper.convert(dbConn);
    String url = metadataConn.getUrl();
    StringBuffer str = new StringBuffer();
    String id = PluginConstant.EMPTY_STRING;
    if (url != null) {
        if (url.startsWith(DatabaseConnConstants.HIVE_2_URL_FORMAT)) {
            str.append("HIVE2");
        } else {
            str.append("HIVE");
        }
        String distroKey = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_HIVE_DISTRIBUTION);
        String distroVersion = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_HIVE_VERSION);
        String hiveModel = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_HIVE_MODE);
        str.append(":").append(distroKey).append(":").append(distroVersion).append(":").append(hiveModel);
        id = str.toString();
    }
    return id;
}
Also used : IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection)

Aggregations

IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)38 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)27 SQLException (java.sql.SQLException)18 Connection (org.talend.core.model.metadata.builder.connection.Connection)14 ArrayList (java.util.ArrayList)12 List (java.util.List)7 MetadataFillFactory (org.talend.metadata.managment.model.MetadataFillFactory)7 ReturnCode (org.talend.utils.sugars.ReturnCode)7 Properties (java.util.Properties)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)6 DatabaseMetaData (java.sql.DatabaseMetaData)5 DBConnectionParameter (org.talend.dq.analysis.parameters.DBConnectionParameter)5 Shell (org.eclipse.swt.widgets.Shell)4 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)4 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)4 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Connection (java.sql.Connection)3 ResultSet (java.sql.ResultSet)3