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);
}
}
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);
}
}
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);
}
}
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);
}
}
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.
//
}
Aggregations