Search in sources :

Example 6 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager 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 7 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class AliasAndManaDriverHelper method getManaDriverByConnection.

/**
 * find a ManaDriver based on driver class name.if not found ,create a new one ManagedDriver.
 *
 * @param connection
 * @param driverManager
 * @return
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 */
public ManagedDriver getManaDriverByConnection(Connection connection) throws Exception {
    ManagedDriver manaDriver = null;
    DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
    DatabaseConnection dbConn = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(connection);
    String driverClass = JavaSqlFactory.getDriverClass(connection);
    if (dbConn == null || dbConn.getDatabaseType() == null || driverClass == null) {
        log.error("can not find a right ManagedDriver by null!");
        return null;
    }
    String managedDriverId = joinManagedDriverId(dbConn);
    String databaseType = dbConn.getDatabaseType();
    manaDriver = driverManager.getDriver(managedDriverId);
    return manaDriver;
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager)

Example 8 with DriverManager

use of net.sourceforge.sqlexplorer.dbproduct.DriverManager in project tdq-studio-se by Talend.

the class CreateAliasDlg method populateCombo.

private void populateCombo() {
    String previous = cboDriver.getText();
    if (previous != null) {
        previous = previous.trim();
        if (previous.length() == 0)
            previous = null;
    }
    if (previous != null)
        previous = previous.toLowerCase();
    DriverManager driverModel = SQLExplorerPlugin.getDefault().getDriverModel();
    cboDriver.removeAll();
    TreeSet<ManagedDriver> drivers = new TreeSet<ManagedDriver>();
    drivers.addAll(driverModel.getDrivers());
    int index = 0;
    for (ManagedDriver driver : drivers) {
        try {
            driver.registerSQLDriver();
        } catch (ClassNotFoundException e) {
        // Nothing
        }
        if (driver.isDriverClassLoaded() == true) {
            cboDriver.add(driver.getName());
            comboDriverIndexes.put(new Integer(index), driver);
            if (previous != null && driver.getName().toLowerCase().startsWith(previous))
                cboDriver.select(index);
            index++;
        }
    }
}
Also used : ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) TreeSet(java.util.TreeSet) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager)

Aggregations

DriverManager (net.sourceforge.sqlexplorer.dbproduct.DriverManager)8 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)7 AliasManager (net.sourceforge.sqlexplorer.dbproduct.AliasManager)2 SQLExplorerPlugin (net.sourceforge.sqlexplorer.plugin.SQLExplorerPlugin)2 AliasAndManaDriverHelper (net.sourceforge.sqlexplorer.util.AliasAndManaDriverHelper)2 PartInitException (org.eclipse.ui.PartInitException)2 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 MissingResourceException (java.util.MissingResourceException)1 TreeSet (java.util.TreeSet)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 Alias (net.sourceforge.sqlexplorer.dbproduct.Alias)1 User (net.sourceforge.sqlexplorer.dbproduct.User)1 SQLHistory (net.sourceforge.sqlexplorer.history.SQLHistory)1 MyURLClassLoader (net.sourceforge.sqlexplorer.util.MyURLClassLoader)1 IFile (org.eclipse.core.resources.IFile)1