use of io.agroal.api.configuration.supplier.AgroalPropertiesReader in project hibernate-orm by hibernate.
the class AgroalConnectionProvider method configure.
@Override
@SuppressWarnings("unchecked")
public void configure(Map props) throws HibernateException {
LOGGER.debug("Configuring Agroal");
try {
AgroalPropertiesReader agroalProperties = new AgroalPropertiesReader(CONFIG_PREFIX).readProperties(props);
agroalProperties.modify().connectionPoolConfiguration(cp -> cp.connectionFactoryConfiguration(cf -> {
copyProperty(props, AvailableSettings.DRIVER, cf::driverClassName, Function.identity());
copyProperty(props, AvailableSettings.URL, cf::jdbcUrl, Function.identity());
copyProperty(props, AvailableSettings.USER, cf::principal, NamePrincipal::new);
copyProperty(props, AvailableSettings.PASS, cf::credential, SimplePassword::new);
copyProperty(props, AvailableSettings.AUTOCOMMIT, cf::autoCommit, Boolean::valueOf);
resolveIsolationSetting(props, cf);
return cf;
}));
agroalDataSource = AgroalDataSource.from(agroalProperties);
} catch (Exception e) {
throw new HibernateException(e);
}
LOGGER.debug("Agroal Configured");
}
use of io.agroal.api.configuration.supplier.AgroalPropertiesReader in project indy by Commonjava.
the class ConnectionPoolProvider method init.
public void init() throws IndyLifecycleException {
logger.info("Starting connection pool binding...");
Properties properties = System.getProperties();
properties.setProperty(INITIAL_CONTEXT_FACTORY, CPInitialContextFactory.class.getName());
System.setProperties(properties);
InitialContext ctx;
try {
ctx = new InitialContext();
} catch (NamingException e) {
throw new IndyLifecycleException("Failed to create JNDI InitialContext for binding datasources", e);
}
Map<String, ConnectionPoolInfo> poolConfigs = config.getPools();
logger.info("Creating bindings for {} pools from config: {}", poolConfigs.size(), config);
for (ConnectionPoolInfo poolInfo : poolConfigs.values()) {
try {
AgroalPropertiesReader propertiesReader = new AgroalPropertiesReader(ConnectionPoolConfig.DS_PROPERTY_PREFIX);
AgroalDataSourceConfiguration config = propertiesReader.readProperties(poolInfo.getProperties()).get();
config.setMetricsEnabled(poolInfo.isUseMetrics());
AgroalDataSource ds = AgroalDataSource.from(config, new AgroalDataSourceLogger(poolInfo.getName()));
if (poolInfo.isUseMetrics()) {
registerMetrics(ds.getMetrics(), poolInfo.getName());
}
if (poolInfo.isUseHealthChecks()) {
registerHealthChecks(ds, poolInfo.getName());
}
String jndiName = "java:/comp/env/jdbc/" + poolInfo.getName();
logger.info("Binding datasource: {}", jndiName);
ctx.rebind(jndiName, ds);
} catch (NamingException e) {
throw new IndyLifecycleException("Failed to bind datasource: " + poolInfo.getName(), e);
} catch (SQLException e) {
throw new IndyLifecycleException("Failed to start datasource: " + poolInfo.getName(), e);
}
}
}
Aggregations