Search in sources :

Example 6 with BoneCPConfig

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);
    }
}
Also used : BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) BoneCP(com.jolbox.bonecp.BoneCP)

Example 7 with BoneCPConfig

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());
}
Also used : HashMap(java.util.HashMap) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) Test(org.junit.Test)

Example 8 with BoneCPConfig

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);
}
Also used : SQLException(java.sql.SQLException) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) Properties(java.util.Properties) SQLException(java.sql.SQLException)

Example 9 with BoneCPConfig

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;
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) BoneCPDataSource(com.jolbox.bonecp.BoneCPDataSource) SQLException(java.sql.SQLException)

Example 10 with BoneCPConfig

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;
}
Also used : JDBCSTORE_PREFIX(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.JDBCSTORE_PREFIX) Connection(java.sql.Connection) Properties(java.util.Properties) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) MAX_CONNECTIONS_PER_PARTITION(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.MAX_CONNECTIONS_PER_PARTITION) PARTITION_COUNT(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.PARTITION_COUNT) SQLException(java.sql.SQLException) BoneCP(com.jolbox.bonecp.BoneCP) Map(java.util.Map) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException) MIN_CONNECTIONS_PER_PARTITION(org.apache.qpid.server.store.jdbc.bonecp.BoneCPConnectionProviderFactory.MIN_CONNECTIONS_PER_PARTITION) ConnectionProvider(org.apache.qpid.server.store.jdbc.ConnectionProvider) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) BoneCPConfig(com.jolbox.bonecp.BoneCPConfig) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) SQLException(java.sql.SQLException) ServerScopedRuntimeException(org.apache.qpid.server.util.ServerScopedRuntimeException)

Aggregations

BoneCPConfig (com.jolbox.bonecp.BoneCPConfig)10 SQLException (java.sql.SQLException)6 BoneCP (com.jolbox.bonecp.BoneCP)5 BoneCPDataSource (com.jolbox.bonecp.BoneCPDataSource)4 HashMap (java.util.HashMap)4 Connection (java.sql.Connection)3 Properties (java.util.Properties)3 HikariConfig (com.zaxxer.hikari.HikariConfig)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1