Search in sources :

Example 6 with DriverManagerConnectionFactory

use of org.datanucleus.store.rdbms.datasource.dbcp2.DriverManagerConnectionFactory in project Openfire by igniterealtime.

the class DefaultConnectionProvider method start.

@Override
public void start() {
    try {
        Class.forName(driver);
    } catch (final ClassNotFoundException e) {
        throw new RuntimeException("Unable to find JDBC driver " + driver, e);
    }
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, username, password);
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setValidationQuery(testSQL);
    poolableConnectionFactory.setValidationQueryTimeout(testTimeout);
    poolableConnectionFactory.setMaxConnLifetimeMillis((long) (connectionTimeout * JiveConstants.DAY));
    final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setTestOnBorrow(testBeforeUse);
    poolConfig.setTestOnReturn(testAfterUse);
    poolConfig.setMinIdle(minConnections);
    if (minConnections > GenericObjectPoolConfig.DEFAULT_MAX_IDLE) {
        poolConfig.setMaxIdle(minConnections);
    }
    poolConfig.setMaxTotal(maxConnections);
    poolConfig.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns);
    poolConfig.setSoftMinEvictableIdleTimeMillis(minIdleTime);
    poolConfig.setMaxWaitMillis(maxWaitTime);
    connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
    poolableConnectionFactory.setPool(connectionPool);
    dataSource = new PoolingDataSource<>(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 7 with DriverManagerConnectionFactory

use of org.datanucleus.store.rdbms.datasource.dbcp2.DriverManagerConnectionFactory in project Openfire by igniterealtime.

the class EmbeddedConnectionProvider method start.

@Override
public void start() {
    File databaseDir = new File(JiveGlobals.getHomeDirectory(), File.separator + "embedded-db");
    // If the database doesn't exist, create it.
    if (!databaseDir.exists()) {
        databaseDir.mkdirs();
    }
    try {
        serverURL = "jdbc:hsqldb:" + databaseDir.getCanonicalPath() + File.separator + "openfire";
    } catch (IOException ioe) {
        Log.error("EmbeddedConnectionProvider: Error starting connection pool: ", ioe);
    }
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(serverURL, "sa", "");
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    poolableConnectionFactory.setMaxConnLifetimeMillis((long) (0.5 * JiveConstants.DAY));
    final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMinIdle(3);
    poolConfig.setMaxTotal(25);
    final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, poolConfig);
    poolableConnectionFactory.setPool(connectionPool);
    dataSource = new PoolingDataSource<>(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) IOException(java.io.IOException) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) File(java.io.File) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Example 8 with DriverManagerConnectionFactory

use of org.datanucleus.store.rdbms.datasource.dbcp2.DriverManagerConnectionFactory in project cloudstack by apache.

the class TransactionLegacy method getDefaultDataSource.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static DataSource getDefaultDataSource(final String database) {
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    return new PoolingDataSource(connectionPool);
}
Also used : ConnectionFactory(org.apache.commons.dbcp2.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory) PoolingDataSource(org.apache.commons.dbcp2.PoolingDataSource) DriverManagerConnectionFactory(org.apache.commons.dbcp2.DriverManagerConnectionFactory) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Aggregations

ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)7 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)7 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)7 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)5 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)3 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)3 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)2 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)2 File (java.io.File)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 ObjectPool (org.apache.commons.pool2.ObjectPool)1 Property (org.apache.logging.log4j.core.config.Property)1 ConnectionFactory (org.datanucleus.store.rdbms.datasource.dbcp2.ConnectionFactory)1 DriverManagerConnectionFactory (org.datanucleus.store.rdbms.datasource.dbcp2.DriverManagerConnectionFactory)1 PoolableConnection (org.datanucleus.store.rdbms.datasource.dbcp2.PoolableConnection)1 PoolableConnectionFactory (org.datanucleus.store.rdbms.datasource.dbcp2.PoolableConnectionFactory)1 PoolingDataSource (org.datanucleus.store.rdbms.datasource.dbcp2.PoolingDataSource)1 GenericObjectPool (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool)1