use of com.jolbox.bonecp.BoneCPConfig in project jaffa-framework by jaffa-projects.
the class BoneCPDataSourceConnectionFactory method configPool.
/**
* Configures the bone cp pool
* @throws ClassNotFoundException Exception thrown if the driver can not be loaded
* @throws SQLException if there is any sql issues with the connection
*/
private void configPool() throws ClassNotFoundException, SQLException {
synchronized (connectionPoolLock) {
if (connectionPool != null) {
return;
}
// load the driver
Class.forName(getDriverClass());
// set up the configuration
BoneCPConfig config = new BoneCPConfig();
config.setAcquireRetryDelay(getMaxConnTime() == null ? 1 : getMaxConnTime().longValue(), TimeUnit.SECONDS);
config.setDisableConnectionTracking(true);
config.setMaxConnectionsPerPartition((getMaximumConnections() == null ? 50 : getMaximumConnections()) / 4);
config.setMinConnectionsPerPartition((getMinimumConnections() == null ? 20 : getMinimumConnections()) / 4);
config.setMaxConnectionAge(getMaxCheckoutSeconds() == null ? 30 : getMaxCheckoutSeconds(), TimeUnit.SECONDS);
config.setJdbcUrl(getUrl());
config.setUsername(getUser());
config.setPartitionCount(getPartitions() == null || getPartitions() <= 0 ? 1 : getPartitions());
config.setAcquireRetryAttempts(getRetryAttempts() == null ? 10 : getRetryAttempts());
config.setPassword(getPassword());
// create the pool
connectionPool = new BoneCP(config);
}
}
use of com.jolbox.bonecp.BoneCPConfig in project qpid-broker-j by apache.
the class BoneCPConnectionProviderTest method testCreateBoneCPConfig.
@Test
public void testCreateBoneCPConfig() {
final Map<String, String> attributes = new HashMap<>();
attributes.put("qpid.jdbcstore.bonecp.idleMaxAgeInMinutes", "123");
attributes.put("qpid.jdbcstore.bonecp.connectionTimeoutInMs", "1234");
attributes.put("qpid.jdbcstore.bonecp.connectionTestStatement", "select 1");
attributes.put("qpid.jdbcstore.bonecp.logStatementsEnabled", "true");
attributes.put("qpid.jdbcstore.bonecp.partitionCount", "12");
String connectionUrl = "jdbc:mariadb://localhost:3306/test";
String username = "usr";
String password = "pwd";
BoneCPConfig config = BoneCPConnectionProvider.createBoneCPConfig(connectionUrl, username, password, attributes);
assertEquals(connectionUrl, config.getJdbcUrl());
assertEquals(username, config.getUsername());
assertEquals(password, config.getPassword());
assertEquals("Unexpected idleMaxAgeInMinutes", 123, config.getIdleMaxAgeInMinutes());
assertEquals("Unexpected connectionTimeout", 1234, config.getConnectionTimeoutInMs());
assertEquals("Unexpected connectionTestStatement", "select 1", config.getConnectionTestStatement());
assertEquals("Unexpected logStatementsEnabled", true, config.isLogStatementsEnabled());
assertEquals("Unexpected maxConnectionsPerPartition", DEFAULT_MAX_CONNECTIONS_PER_PARTITION, config.getMaxConnectionsPerPartition());
assertEquals("Unexpected minConnectionsPerPartition", DEFAULT_MIN_CONNECTIONS_PER_PARTITION, config.getMinConnectionsPerPartition());
assertEquals("Unexpected partitionCount", 12, config.getPartitionCount());
}
use of com.jolbox.bonecp.BoneCPConfig in project hive by apache.
the class BoneCPDataSourceProvider method create.
@Override
public DataSource create(Configuration hdpConfig) throws SQLException {
LOG.debug("Creating BoneCP connection pool for the MetaStore");
String driverUrl = DataSourceProvider.getMetastoreJdbcDriverUrl(hdpConfig);
String user = DataSourceProvider.getMetastoreJdbcUser(hdpConfig);
String passwd = DataSourceProvider.getMetastoreJdbcPasswd(hdpConfig);
int maxPoolSize = MetastoreConf.getIntVar(hdpConfig, MetastoreConf.ConfVars.CONNECTION_POOLING_MAX_CONNECTIONS);
Properties properties = DataSourceProvider.getPrefixedProperties(hdpConfig, BONECP);
long connectionTimeout = hdpConfig.getLong(CONNECTION_TIMEOUT_PROPERTY, 30000L);
String partitionCount = properties.getProperty(PARTITION_COUNT_PROPERTY, "1");
BoneCPConfig config = null;
try {
config = new BoneCPConfig(properties);
} catch (Exception e) {
throw new SQLException("Cannot create BoneCP configuration: ", e);
}
config.setJdbcUrl(driverUrl);
// if we are waiting for connection for a long time, something is really wrong
// better raise an error than hang forever
// see DefaultConnectionStrategy.getConnectionInternal()
config.setConnectionTimeoutInMs(connectionTimeout);
config.setMaxConnectionsPerPartition(maxPoolSize);
config.setPartitionCount(Integer.parseInt(partitionCount));
config.setUser(user);
config.setPassword(passwd);
return new BoneCPDataSource(config);
}
use of com.jolbox.bonecp.BoneCPConfig in project tomee by apache.
the class BoneCPDataSourceCreator method createPool.
private BoneCPDataSource createPool(final Properties properties) {
final BoneCPConfig config;
try {
config = new BoneCPConfig(prefixedProps(properties));
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
final BoneCPDataSource dataSourceProvidedPool = new BoneCPDataSource(config);
// no error
recipes.put(dataSourceProvidedPool, new ObjectRecipe(BoneCPDataSource.class.getName()));
return dataSourceProvidedPool;
}
use of com.jolbox.bonecp.BoneCPConfig in project qpid-broker-j by apache.
the class BoneCPConnectionProvider method createBoneCPConfig.
static BoneCPConfig createBoneCPConfig(final String connectionUrl, final String username, final String password, final Map<String, String> providerAttributes) {
BoneCPConfig config = new BoneCPConfig();
config.setJdbcUrl(connectionUrl);
if (username != null) {
config.setUsername(username);
config.setPassword(password);
}
Map<String, String> attributes = new HashMap<>(providerAttributes);
attributes.putIfAbsent(MIN_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MIN_CONNECTIONS_PER_PARTITION));
attributes.putIfAbsent(MAX_CONNECTIONS_PER_PARTITION, String.valueOf(DEFAULT_MAX_CONNECTIONS_PER_PARTITION));
attributes.putIfAbsent(PARTITION_COUNT, String.valueOf(DEFAULT_PARTITION_COUNT));
Map<String, String> propertiesMap = attributes.entrySet().stream().collect(Collectors.toMap(p -> p.getKey().substring(JDBCSTORE_PREFIX.length()), Map.Entry::getValue));
Properties properties = new Properties();
properties.putAll(propertiesMap);
try {
config.setProperties(properties);
} catch (Exception e) {
throw new IllegalConfigurationException("Unexpected exception on applying BoneCP configuration", e);
}
return config;
}
Aggregations