use of io.cdap.cdap.spi.data.sql.jdbc.JDBCDriverShim in project cdap by caskdata.
the class PostgreSqlStorageProvider method loadJDBCDriver.
private static void loadJDBCDriver(CConfiguration cConf, String storageImpl) {
String driverExtensionPath = cConf.get(Constants.Dataset.DATA_STORAGE_SQL_DRIVER_DIRECTORY);
String driverName = cConf.get(Constants.Dataset.DATA_STORAGE_SQL_JDBC_DRIVER_NAME);
if (driverExtensionPath == null || driverName == null) {
throw new IllegalArgumentException("The JDBC driver directory and driver name must be specified.");
}
File driverExtensionDir = new File(driverExtensionPath, storageImpl);
if (!driverExtensionDir.exists()) {
throw new IllegalArgumentException("The JDBC driver driver " + driverExtensionDir + " does not exist.");
}
// Create a separate classloader for the JDBC driver, which doesn't have any CDAP dependencies in it.
ClassLoader driverClassLoader = new DirectoryClassLoader(driverExtensionDir, null);
try {
Driver driver = (Driver) Class.forName(driverName, true, driverClassLoader).newInstance();
// wrap the driver class and register it ourselves since the driver manager will not use driver from other
// classloader
JDBCDriverShim driverShim = new JDBCDriverShim(driver);
DriverManager.registerDriver(driverShim);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
throw Throwables.propagate(e);
}
LOG.info("Successfully loaded {} from {}", driverName, driverExtensionPath);
}
use of io.cdap.cdap.spi.data.sql.jdbc.JDBCDriverShim in project cdap by cdapio.
the class PostgreSqlStorageProvider method loadJDBCDriver.
private static void loadJDBCDriver(CConfiguration cConf, String storageImpl) {
String driverExtensionPath = cConf.get(Constants.Dataset.DATA_STORAGE_SQL_DRIVER_DIRECTORY);
String driverName = cConf.get(Constants.Dataset.DATA_STORAGE_SQL_JDBC_DRIVER_NAME);
if (driverExtensionPath == null || driverName == null) {
throw new IllegalArgumentException("The JDBC driver directory and driver name must be specified.");
}
File driverExtensionDir = new File(driverExtensionPath, storageImpl);
if (!driverExtensionDir.exists()) {
throw new IllegalArgumentException("The JDBC driver driver " + driverExtensionDir + " does not exist.");
}
// Create a separate classloader for the JDBC driver, which doesn't have any CDAP dependencies in it.
ClassLoader driverClassLoader = new DirectoryClassLoader(driverExtensionDir, null);
try {
Driver driver = (Driver) Class.forName(driverName, true, driverClassLoader).newInstance();
// wrap the driver class and register it ourselves since the driver manager will not use driver from other
// classloader
JDBCDriverShim driverShim = new JDBCDriverShim(driver);
DriverManager.registerDriver(driverShim);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
throw Throwables.propagate(e);
}
LOG.info("Successfully loaded {} from {}", driverName, driverExtensionPath);
}
Aggregations