driver = null;
}
final boolean logSql = SystemInstance.get().getOptions().get(GLOBAL_LOG_SQL_PROPERTY,
"true".equalsIgnoreCase((String) properties.remove(LOG_SQL_PROPERTY)));
final DataSourceCreator creator = creator(properties.remove(DATA_SOURCE_CREATOR_PROP), logSql);
boolean useContainerLoader = "true".equalsIgnoreCase(SystemInstance.get().getProperty("openejb.resources.use-container-loader", "true")) && (impl == null || impl.getClassLoader() == DataSourceFactory.class.getClassLoader());
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
if (useContainerLoader) {
final ClassLoader containerLoader = DataSourceFactory.class.getClassLoader();
Thread.currentThread().setContextClassLoader(containerLoader);
try {
useContainerLoader = basicChecksThatDataSourceCanBeCreatedFromContainerLoader(properties, containerLoader);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
if (useContainerLoader) {
Thread.currentThread().setContextClassLoader(containerLoader);
} else {
LOGGER.info("Can't use container loader to create datasource " + name + " so using application one");
}
}
try {
CommonDataSource ds;
if (createDataSourceFromClass(impl)) { // opposed to "by driver"
trimNotSupportedDataSourceProperties(properties);
final ObjectRecipe recipe = new ObjectRecipe(impl);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.NAMED_PARAMETERS);
recipe.allow(Option.PRIVATE_PROPERTIES);
recipe.setAllProperties(properties);
if (!properties.containsKey("url") && properties.containsKey("JdbcUrl")) { // depend on the datasource class so add all well known keys
recipe.setProperty("url", properties.getProperty("JdbcUrl"));
}
final DataSource dataSource = (DataSource) recipe.create();
if (managed) {
if (usePool(properties)) {
ds = creator.poolManaged(name, dataSource, properties);
} else {
ds = creator.managed(name, dataSource);
}
} else {
if (usePool(properties)) {
ds = creator.pool(name, dataSource, properties);
} else {
ds = dataSource;
}
}
} else { // by driver
if (managed) {
final XAResourceWrapper xaResourceWrapper = SystemInstance.get().getComponent(XAResourceWrapper.class);
if (xaResourceWrapper != null) {
ds = creator.poolManagedWithRecovery(name, xaResourceWrapper, impl.getName(), properties);
} else {
ds = creator.poolManaged(name, impl.getName(), properties);
}
} else {
ds = creator.pool(name, impl.getName(), properties);
}
}
// ds and creator are associated here, not after the proxying of the next if if active
setCreatedWith(creator, ds);