Search in sources :

Example 26 with GenericObjectPool

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method setAbandonedUsageTracking.

/**
 * If the connection pool implements {@link org.datanucleus.store.rdbms.datasource.dbcp2.pool2.UsageTracking UsageTracking}, configure whether
 * the connection pool should record a stack trace every time a method is called on a pooled connection and retain
 * the most recent stack trace to aid debugging of abandoned connections.
 *
 * @param usageTracking A value of <code>true</code> will enable the recording of a stack trace on every use of a
 *                      pooled connection
 */
public void setAbandonedUsageTracking(final boolean usageTracking) {
    if (abandonedConfig == null) {
        abandonedConfig = new AbandonedConfig();
    }
    abandonedConfig.setUseUsageTracking(usageTracking);
    final GenericObjectPool<?> gop = this.connectionPool;
    if (gop != null) {
        gop.setAbandonedConfig(abandonedConfig);
    }
}
Also used : AbandonedConfig(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.AbandonedConfig)

Example 27 with GenericObjectPool

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method setRemoveAbandonedOnBorrow.

/**
 * @param removeAbandonedOnBorrow true means abandoned connections may be removed when connections are borrowed from
 *                                the pool.
 * @see #getRemoveAbandonedOnBorrow()
 */
public void setRemoveAbandonedOnBorrow(final boolean removeAbandonedOnBorrow) {
    if (abandonedConfig == null) {
        abandonedConfig = new AbandonedConfig();
    }
    abandonedConfig.setRemoveAbandonedOnBorrow(removeAbandonedOnBorrow);
    final GenericObjectPool<?> gop = this.connectionPool;
    if (gop != null) {
        gop.setAbandonedConfig(abandonedConfig);
    }
}
Also used : AbandonedConfig(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.AbandonedConfig)

Example 28 with GenericObjectPool

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method setAbandonedLogWriter.

/**
 * Sets the print writer to be used by this configuration to log information on abandoned objects.
 *
 * @param logWriter The new log writer
 */
public void setAbandonedLogWriter(final PrintWriter logWriter) {
    if (abandonedConfig == null) {
        abandonedConfig = new AbandonedConfig();
    }
    abandonedConfig.setLogWriter(logWriter);
    final GenericObjectPool<?> gop = this.connectionPool;
    if (gop != null) {
        gop.setAbandonedConfig(abandonedConfig);
    }
}
Also used : AbandonedConfig(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.AbandonedConfig)

Example 29 with GenericObjectPool

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method setRemoveAbandonedTimeout.

/**
 * <p>
 * Sets the timeout in seconds before an abandoned connection can be removed.
 * </p>
 *
 * <p>
 * Setting this property has no effect if {@link #getRemoveAbandonedOnBorrow()} and
 * {@link #getRemoveAbandonedOnMaintenance()} are false.
 * </p>
 *
 * @param removeAbandonedTimeout new abandoned timeout in seconds
 * @see #getRemoveAbandonedTimeout()
 * @see #getRemoveAbandonedOnBorrow()
 * @see #getRemoveAbandonedOnMaintenance()
 */
public void setRemoveAbandonedTimeout(final int removeAbandonedTimeout) {
    if (abandonedConfig == null) {
        abandonedConfig = new AbandonedConfig();
    }
    abandonedConfig.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    final GenericObjectPool<?> gop = this.connectionPool;
    if (gop != null) {
        gop.setAbandonedConfig(abandonedConfig);
    }
}
Also used : AbandonedConfig(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.AbandonedConfig)

Example 30 with GenericObjectPool

use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool in project logging-log4j2 by apache.

the class PoolingDriverConnectionSource method setupDriver.

private void setupDriver(final String connectionString, final PoolableConnectionFactoryConfig poolableConnectionFactoryConfig) throws SQLException {
    // 
    // First, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    // 
    final Property[] properties = getProperties();
    final char[] userName = getUserName();
    final char[] password = getPassword();
    final ConnectionFactory connectionFactory;
    if (properties != null && properties.length > 0) {
        if (userName != null || password != null) {
            throw new SQLException("Either set the userName and password, or set the Properties, but not both.");
        }
        connectionFactory = new DriverManagerConnectionFactory(connectionString, toProperties(properties));
    } else {
        connectionFactory = new DriverManagerConnectionFactory(connectionString, toString(userName), toString(password));
    }
    // 
    // Next, we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    // 
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null);
    if (poolableConnectionFactoryConfig != null) {
        poolableConnectionFactoryConfig.init(poolableConnectionFactory);
    }
    // 
    // Now we'll need a ObjectPool that serves as the
    // actual pool of connections.
    // 
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    // 
    @SuppressWarnings("resource") final ObjectPool<PoolableConnection> // This GenericObjectPool will be closed on shutdown
    connectionPool = new GenericObjectPool<>(poolableConnectionFactory);
    // Set the factory's pool property to the owning pool
    poolableConnectionFactory.setPool(connectionPool);
    loadDriver(poolingDriverClassName);
    final PoolingDriver driver = getPoolingDriver();
    if (driver != null) {
        getLogger().debug("Registering DBCP pool '{}' with pooling driver {}: {}", poolName, driver, connectionPool);
        driver.registerPool(poolName, connectionPool);
    }
// 
// Now we can just use the connect string "jdbc:apache:commons:dbcp:example"
// to access our pool of Connections.
// 
}
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) SQLException(java.sql.SQLException) PoolableConnection(org.apache.commons.dbcp2.PoolableConnection) PoolingDriver(org.apache.commons.dbcp2.PoolingDriver) GenericObjectPool(org.apache.commons.pool2.impl.GenericObjectPool) Property(org.apache.logging.log4j.core.config.Property) PoolableConnectionFactory(org.apache.commons.dbcp2.PoolableConnectionFactory)

Aggregations

GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)24 PoolableConnectionFactory (org.apache.commons.dbcp2.PoolableConnectionFactory)9 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)9 ConnectionFactory (org.apache.commons.dbcp2.ConnectionFactory)7 PoolableConnection (org.apache.commons.dbcp2.PoolableConnection)6 AbandonedConfig (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.AbandonedConfig)6 DriverManagerConnectionFactory (org.apache.commons.dbcp2.DriverManagerConnectionFactory)5 PoolingDataSource (org.apache.commons.dbcp2.PoolingDataSource)4 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 File (java.io.File)2 IOException (java.io.IOException)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 lombok.val (lombok.val)2 PoolingDriver (org.apache.commons.dbcp2.PoolingDriver)2 MemcachedPooledClientConnectionFactory (org.apereo.cas.memcached.MemcachedPooledClientConnectionFactory)2 GenericObjectPool (org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPool)2 Bean (org.springframework.context.annotation.Bean)2 NettyClient (com.ctrip.xpipe.netty.commands.NettyClient)1 NettyClientFactory (com.ctrip.xpipe.netty.commands.NettyClientFactory)1