use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class TableManipulation method getConnectionFactory.
private ConnectionFactory getConnectionFactory() {
PooledConnectionFactoryConfiguration pooledConnectionFactoryConfiguration = persistenceConfiguration.create();
connectionFactory = ConnectionFactory.getConnectionFactory(PooledConnectionFactory.class);
connectionFactory.start(pooledConnectionFactoryConfiguration, connectionFactory.getClass().getClassLoader());
return connectionFactory;
}
use of org.infinispan.persistence.jdbc.common.configuration.PooledConnectionFactoryConfiguration in project infinispan by infinispan.
the class PooledConnectionFactory method start.
@Override
public void start(ConnectionFactoryConfiguration config, ClassLoader classLoader) throws PersistenceException {
PooledConnectionFactoryConfiguration poolConfig;
if (config instanceof PooledConnectionFactoryConfiguration) {
poolConfig = (PooledConnectionFactoryConfiguration) config;
} else {
throw new PersistenceException("ConnectionFactoryConfiguration passed in must be an instance of " + "PooledConnectionFactoryConfiguration");
}
try {
String propsFile = poolConfig.propertyFile();
if (propsFile != null) {
dataSource = AgroalDataSource.from(new AgroalPropertiesReader(PROPERTIES_PREFIX).readProperties(propsFile));
} else {
Class<?> driverClass = Util.loadClass(poolConfig.driverClass(), null);
// Default Agroal configuration with metrics disabled
String password = poolConfig.password() != null ? poolConfig.password() : "";
AgroalDataSourceConfigurationSupplier configuration = new AgroalDataSourceConfigurationSupplier().connectionPoolConfiguration(cp -> cp.maxSize(10).acquisitionTimeout(Duration.ofSeconds(30)).connectionFactoryConfiguration(cf -> cf.jdbcUrl(poolConfig.connectionUrl()).connectionProviderClass(driverClass).jdbcTransactionIsolation(AgroalConnectionFactoryConfiguration.TransactionIsolation.UNDEFINED).principal(new NamePrincipal(poolConfig.username())).credential(new SimplePassword(password))));
dataSource = AgroalDataSource.from(configuration);
}
} catch (Exception e) {
throw new PersistenceException("Failed to create a AgroalDataSource", e);
}
}
Aggregations