Skip to content
Permalink
Browse files

[WFLY-10798] Setting correct TCCL for Datasource constructor

  • Loading branch information
spyrkob committed Apr 24, 2019
1 parent 283c936 commit 766193d304c62b7a98650f0eac63ee38316efac1
@@ -133,22 +133,35 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
boolean driverLoaded = false;
if (serviceLoader != null) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(module.getClassLoader());
try {
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
driverLoaded = true;
//just consider first definition and create service for this. User can use different implementation only
// w/ explicit declaration of driver-class attribute
break;
}
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
if (!driverLoaded)
SUBSYSTEM_DATASOURCES_LOGGER.cannotFindDriverClassName(driverName);
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName)
.asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Driver driver = null;
try {
Thread.currentThread().setContextClassLoader(module.getClassLoader());
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
driver = constructor.newInstance();
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);

0 comments on commit 766193d

Please sign in to comment.
You can’t perform that action at this time.