use of org.apache.openejb.resource.jdbc.plugin.DataSourcePlugin in project tomee by apache.
the class BasicManagedDataSource method createDataSource.
protected DataSource createDataSource() throws SQLException {
final ReentrantLock l = lock;
l.lock();
try {
final Object dataSource = Reflections.get(this, "dataSource");
if (dataSource != null) {
return DataSource.class.cast(dataSource);
}
// check password codec if available
if (null != passwordCipher) {
final PasswordCipher cipher = PasswordCipherFactory.getPasswordCipher(passwordCipher);
// always use the initial encrypted value
final String plainPwd = cipher.decrypt(initialPassword.toCharArray());
// override previous password value
super.setPassword(plainPwd);
}
// get the plugin
final DataSourcePlugin helper = BasicDataSourceUtil.getDataSourcePlugin(getUrl());
// configure this
if (helper != null) {
final String currentUrl = getUrl();
final String newUrl = helper.updatedUrl(currentUrl);
if (!currentUrl.equals(newUrl)) {
super.setUrl(newUrl);
}
}
wrapTransactionManager();
// create the data source
if (helper == null || !helper.enableUserDirHack()) {
try {
return super.createDataSource();
} catch (final Throwable e) {
throw BasicDataSource.toSQLException(e);
}
} else {
// wrap super call with code that sets user.dir to openejb.base and then resets it
final Properties systemProperties = JavaSecurityManagers.getSystemProperties();
final String userDir = systemProperties.getProperty("user.dir");
try {
final File base = SystemInstance.get().getBase().getDirectory();
systemProperties.setProperty("user.dir", base.getAbsolutePath());
try {
return super.createDataSource();
} catch (final Throwable e) {
throw BasicDataSource.toSQLException(e);
}
} finally {
systemProperties.setProperty("user.dir", userDir);
}
}
} finally {
l.unlock();
}
}
Aggregations