Search in sources :

Example 1 with GenericKeyedObjectPool

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

the class SharedPoolDataSource method registerPool.

private void registerPool(String username, String password) throws javax.naming.NamingException, SQLException {
    ConnectionPoolDataSource cpds = testCPDS(username, password);
    // Create an object pool to contain our PooledConnections
    GenericKeyedObjectPool tmpPool = new GenericKeyedObjectPool(null);
    tmpPool.setMaxActive(getMaxActive());
    tmpPool.setMaxIdle(getMaxIdle());
    tmpPool.setMaxWait(getMaxWait());
    tmpPool.setWhenExhaustedAction(whenExhaustedAction(maxActive, maxWait));
    tmpPool.setTestOnBorrow(getTestOnBorrow());
    tmpPool.setTestOnReturn(getTestOnReturn());
    tmpPool.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
    tmpPool.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
    tmpPool.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
    tmpPool.setTestWhileIdle(getTestWhileIdle());
    pool = tmpPool;
    // 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)
    factory = new KeyedCPDSConnectionFactory(cpds, pool, getValidationQuery(), isRollbackAfterValidation());
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) GenericKeyedObjectPool(com.frameworkset.commons.pool.impl.GenericKeyedObjectPool)

Example 2 with GenericKeyedObjectPool

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

the class DriverAdapterCPDS method getPooledConnection.

/**
 * Attempt to establish a database connection.
 * @param username name to be used for the connection
 * @param pass password to be used fur the connection
 */
public PooledConnection getPooledConnection(String username, String pass) throws SQLException {
    getConnectionCalled = true;
    /*
        public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory, 
        int maxActive, byte whenExhaustedAction, long maxWait, 
        int maxIdle, boolean testOnBorrow, boolean testOnReturn, 
        long timeBetweenEvictionRunsMillis, 
        int numTestsPerEvictionRun, long minEvictableIdleTimeMillis, 
        boolean testWhileIdle) {
        */
    KeyedObjectPool stmtPool = null;
    if (isPoolPreparedStatements()) {
        if (getMaxPreparedStatements() <= 0) {
            // since there is no limit, create a prepared statement pool with an eviction thread
            // evictor settings are the same as the connection pool settings.
            stmtPool = new GenericKeyedObjectPool(null, getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0, getMaxIdle(), false, false, getTimeBetweenEvictionRunsMillis(), getNumTestsPerEvictionRun(), getMinEvictableIdleTimeMillis(), false);
        } else {
            // since there is limit, create a prepared statement pool without an eviction thread
            // pool has LRU functionality so when the limit is reached, 15% of the pool is cleared.
            // see com.frameworkset.commons.pool.impl.GenericKeyedObjectPool.clearOldest method
            stmtPool = new GenericKeyedObjectPool(null, getMaxActive(), GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW, 0, getMaxIdle(), getMaxPreparedStatements(), false, false, // -1 tells the pool that there should be no eviction thread.
            -1, // -1 tells the pool that there should be no eviction thread.
            0, // -1 tells the pool that there should be no eviction thread.
            0, false);
        }
    }
    // exception upon first invocation.
    try {
        PooledConnectionImpl pci = null;
        if (connectionProperties != null) {
            connectionProperties.put("user", username);
            connectionProperties.put("password", pass);
            pci = new PooledConnectionImpl(DriverManager.getConnection(getUrl(), connectionProperties), stmtPool);
        } else {
            pci = new PooledConnectionImpl(DriverManager.getConnection(getUrl(), username, pass), stmtPool);
        }
        pci.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
        return pci;
    } catch (ClassCircularityError e) {
        PooledConnectionImpl pci = null;
        if (connectionProperties != null) {
            pci = new PooledConnectionImpl(DriverManager.getConnection(getUrl(), connectionProperties), stmtPool);
        } else {
            pci = new PooledConnectionImpl(DriverManager.getConnection(getUrl(), username, pass), stmtPool);
        }
        pci.setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
        return pci;
    }
}
Also used : KeyedObjectPool(com.frameworkset.commons.pool.KeyedObjectPool) GenericKeyedObjectPool(com.frameworkset.commons.pool.impl.GenericKeyedObjectPool) GenericKeyedObjectPool(com.frameworkset.commons.pool.impl.GenericKeyedObjectPool)

Aggregations

GenericKeyedObjectPool (com.frameworkset.commons.pool.impl.GenericKeyedObjectPool)2 KeyedObjectPool (com.frameworkset.commons.pool.KeyedObjectPool)1 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)1