this.dataSourceConfig = dataSourceConfig;
}
protected final BaseWrapperManagedConnectionFactory createManagedConnectionFactory(final String jndiName,
final Driver driver) throws ResourceException, StartException {
final XAManagedConnectionFactory xaManagedConnectionFactory = new XAManagedConnectionFactory();
try {
xaManagedConnectionFactory.setClassLoaderPlugin(new ClassLoaderPlugin() {
@Override
public ClassLoader getClassLoader() {
return driver.getClass().getClassLoader();
}
});
xaManagedConnectionFactory.setXADataSourceClass(dataSourceConfig.getXaDataSourceClass());
} catch (Exception e) {
throw new StartException("Failed to load XA DataSource class - " + dataSourceConfig.getXaDataSourceClass());
}
xaManagedConnectionFactory.setJndiName(jndiName);
xaManagedConnectionFactory.setSpy(true);
if (dataSourceConfig.getNewConnectionSql() != null) {
xaManagedConnectionFactory.setNewConnectionSQL(dataSourceConfig.getNewConnectionSql());
}
if (dataSourceConfig.getTransactionIsolation() != null) {
xaManagedConnectionFactory.setTransactionIsolation(dataSourceConfig.getTransactionIsolation().name());
}
if (dataSourceConfig.getUrlDelimiter() != null) {
xaManagedConnectionFactory.setURLDelimiter(dataSourceConfig.getUrlDelimiter());
}
if (dataSourceConfig.getUrlSelectorStrategyClassName() != null) {
xaManagedConnectionFactory.setUrlSelectorStrategyClassName(dataSourceConfig.getUrlSelectorStrategyClassName());
}
final DsSecurity security = dataSourceConfig.getSecurity();
if (security != null) {
if (security.getUserName() != null) {
xaManagedConnectionFactory.setUserName(security.getUserName());
}
if (security.getPassword() != null) {
xaManagedConnectionFactory.setPassword(security.getPassword());
}
}
final TimeOut timeOut = dataSourceConfig.getTimeOut();
if (timeOut != null) {
if (timeOut.getUseTryLock() != null) {
xaManagedConnectionFactory.setUseTryLock(timeOut.getUseTryLock().intValue());
}
if (timeOut.getQueryTimeout() != null) {
xaManagedConnectionFactory.setQueryTimeout(timeOut.getQueryTimeout().intValue());
}
}
final Statement statement = dataSourceConfig.getStatement();
if (statement != null) {
if (statement.getTrackStatements() != null) {
xaManagedConnectionFactory.setTrackStatements(statement.getTrackStatements().name());
}
if (statement.isSharePreparedStatements() != null) {
xaManagedConnectionFactory.setSharePreparedStatements(statement.isSharePreparedStatements());
}
if (statement.getPreparedStatementsCacheSize() != null) {
xaManagedConnectionFactory.setPreparedStatementCacheSize(statement.getPreparedStatementsCacheSize().intValue());
}
}
final Validation validation = dataSourceConfig.getValidation();
if (validation != null) {
if (validation.isValidateOnMatch()) {
xaManagedConnectionFactory.setValidateOnMatch(validation.isValidateOnMatch());
}
if (validation.getCheckValidConnectionSql() != null) {
xaManagedConnectionFactory.setCheckValidConnectionSQL(validation.getCheckValidConnectionSql());
}
final Extension validConnectionChecker = validation.getValidConnectionChecker();
if (validConnectionChecker != null) {
if (validConnectionChecker.getClassName() != null) {
xaManagedConnectionFactory.setValidConnectionCheckerClassName(validConnectionChecker.getClassName());
}
if (validConnectionChecker.getConfigPropertiesMap() != null) {
xaManagedConnectionFactory
.setValidConnectionCheckerProperties(buildConfigPropsString(validConnectionChecker
.getConfigPropertiesMap()));
}
}
final Extension exceptionSorter = validation.getExceptionSorter();
if (exceptionSorter != null) {
if (exceptionSorter.getClassName() != null) {
xaManagedConnectionFactory.setExceptionSorterClassName(exceptionSorter.getClassName());
}
if (exceptionSorter.getConfigPropertiesMap() != null) {
xaManagedConnectionFactory.setExceptionSorterProperties(buildConfigPropsString(exceptionSorter
.getConfigPropertiesMap()));
}
}
final Extension staleConnectionChecker = validation.getStaleConnectionChecker();
if (staleConnectionChecker != null) {
if (staleConnectionChecker.getClassName() != null) {
xaManagedConnectionFactory.setStaleConnectionCheckerClassName(staleConnectionChecker.getClassName());
}
if (staleConnectionChecker.getConfigPropertiesMap() != null) {
xaManagedConnectionFactory
.setStaleConnectionCheckerProperties(buildConfigPropsString(staleConnectionChecker
.getConfigPropertiesMap()));
}
}
}