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);
}
}
}
}
}
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;
}
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++;
}
}
}
Aggregations