Search in sources :

Example 1 with GenericObjectPool

use of com.frameworkset.commons.pool.impl.GenericObjectPool in project bboss by bbossgroups.

the class BasicDataSource method createConnectionPool.

/**
 * Creates a connection pool for this datasource.  This method only exists
 * so subclasses can replace the implementation class.
 */
protected void createConnectionPool() {
    // Create an object pool to contain our active connections
    GenericObjectPool gop;
    if ((abandonedConfig != null) && (abandonedConfig.getRemoveAbandoned())) {
        gop = new AbandonedObjectPool(null, abandonedConfig);
    } else {
        gop = new GenericObjectPool();
    }
    gop.setMaxActive(maxActive);
    gop.setMaxIdle(maxIdle);
    gop.setMinIdle(minIdle);
    gop.setMaxWait(maxWait);
    gop.setTestOnBorrow(testOnBorrow);
    gop.setTestOnReturn(testOnReturn);
    gop.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    gop.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    gop.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    gop.setTestWhileIdle(testWhileIdle);
    connectionPool = gop;
}
Also used : GenericObjectPool(com.frameworkset.commons.pool.impl.GenericObjectPool)

Example 2 with GenericObjectPool

use of com.frameworkset.commons.pool.impl.GenericObjectPool in project bboss by bbossgroups.

the class PerUserPoolDataSource method registerPool.

private synchronized void registerPool(String username, String password) throws javax.naming.NamingException, SQLException {
    ConnectionPoolDataSource cpds = testCPDS(username, password);
    Integer userMax = getPerUserMaxActive(username);
    int maxActive = (userMax == null) ? getDefaultMaxActive() : userMax.intValue();
    userMax = getPerUserMaxIdle(username);
    int maxIdle = (userMax == null) ? getDefaultMaxIdle() : userMax.intValue();
    userMax = getPerUserMaxWait(username);
    int maxWait = (userMax == null) ? getDefaultMaxWait() : userMax.intValue();
    // Create an object pool to contain our PooledConnections
    GenericObjectPool pool = new GenericObjectPool(null);
    pool.setMaxActive(maxActive);
    pool.setMaxIdle(maxIdle);
    pool.setMaxWait(maxWait);
    pool.setWhenExhaustedAction(whenExhaustedAction(maxActive, maxWait));
    pool.setTestOnBorrow(getTestOnBorrow());
    pool.setTestOnReturn(getTestOnReturn());
    pool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
    pool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
    pool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
    pool.setTestWhileIdle(getTestWhileIdle());
    // Set up the factory we will use (passing the pool associates
    // the factory with the pool, so we do not have to do so
    // explicitly)
    CPDSConnectionFactory factory = new CPDSConnectionFactory(cpds, pool, getValidationQuery(), isRollbackAfterValidation(), username, password);
    Object old = managers.put(getPoolKey(username, password), factory);
    if (old != null) {
        throw new IllegalStateException("Pool already contains an entry for this user/password: " + username);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) GenericObjectPool(com.frameworkset.commons.pool.impl.GenericObjectPool)

Example 3 with GenericObjectPool

use of com.frameworkset.commons.pool.impl.GenericObjectPool in project bboss by bbossgroups.

the class BasicDataSource method close.

/**
 * <p>Closes and releases all idle connections that are currently stored in the connection pool
 * associated with this data source.</p>
 *
 * <p>Connections that are checked out to clients when this method is invoked are not affected.
 * When client applications subsequently invoke {@link Connection#close()} to return
 * these connections to the pool, the underlying JDBC connections are closed.</p>
 *
 * <p>Attempts to acquire connections using {@link #getConnection()} after this method has been
 * invoked result in SQLExceptions.<p>
 *
 * <p>This method is idempotent - i.e., closing an already closed BasicDataSource has no effect
 * and does not generate exceptions.</p>
 *
 * @throws SQLException if an error occurs closing idle connections
 */
public synchronized void close() throws SQLException {
    closed = true;
    GenericObjectPool oldpool = connectionPool;
    connectionPool = null;
    dataSource = null;
    try {
        if (oldpool != null) {
            oldpool.close();
        }
    } catch (SQLException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLNestedException("Cannot close connection pool", e);
    }
}
Also used : SQLException(java.sql.SQLException) GenericObjectPool(com.frameworkset.commons.pool.impl.GenericObjectPool) SQLException(java.sql.SQLException)

Aggregations

GenericObjectPool (com.frameworkset.commons.pool.impl.GenericObjectPool)3 SQLException (java.sql.SQLException)1 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1