in src/main/java/org/apache/commons/dbcp2/managed/BasicManagedDataSource.java [70:108]
protected ConnectionFactory createConnectionFactory() throws SQLException {
if (transactionManager == null) {
throw new SQLException("Transaction manager must be set before a connection can be created");
}
// If xa data source is not specified a DriverConnectionFactory is created and wrapped with a
// LocalXAConnectionFactory
if (xaDataSource == null) {
final ConnectionFactory connectionFactory = super.createConnectionFactory();
final XAConnectionFactory xaConnectionFactory = new LocalXAConnectionFactory(getTransactionManager(),
getTransactionSynchronizationRegistry(), connectionFactory);
transactionRegistry = xaConnectionFactory.getTransactionRegistry();
return xaConnectionFactory;
}
// Create the XADataSource instance using the configured class name if it has not been set
if (xaDataSourceInstance == null) {
Class<?> xaDataSourceClass = null;
try {
xaDataSourceClass = Class.forName(xaDataSource);
} catch (final Exception t) {
final String message = "Cannot load XA data source class '" + xaDataSource + "'";
throw new SQLException(message, t);
}
try {
xaDataSourceInstance = (XADataSource) xaDataSourceClass.getConstructor().newInstance();
} catch (final Exception t) {
final String message = "Cannot create XA data source of class '" + xaDataSource + "'";
throw new SQLException(message, t);
}
}
// finally, create the XAConnectionFactory using the XA data source
final XAConnectionFactory xaConnectionFactory = new DataSourceXAConnectionFactory(getTransactionManager(),
xaDataSourceInstance, getUsername(), Utils.toCharArray(getPassword()), getTransactionSynchronizationRegistry());
transactionRegistry = xaConnectionFactory.getTransactionRegistry();
return xaConnectionFactory;
}