Search in sources :

Example 11 with PoolableConnection

use of org.apache.tomcat.dbcp.dbcp2.PoolableConnection 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)

Aggregations

PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)9 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)6 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)6 SQLException (java.sql.SQLException)4 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)4 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)4 Properties (java.util.Properties)3 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)3 Connection (java.sql.Connection)2 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)2 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Driver (java.sql.Driver)1 ObjectName (javax.management.ObjectName)1 TransactionManager (javax.transaction.TransactionManager)1 DriverConnectionFactory (org.apache.commons.dbcp2.DriverConnectionFactory)1 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)1 LocalXAConnectionFactory (org.apache.commons.dbcp2.managed.LocalXAConnectionFactory)1 ManagedConnection (org.apache.commons.dbcp2.managed.ManagedConnection)1