com.vladmihalcea.flexypool.adaptor.C3P0PoolAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flexy-c3p0 Show documentation
Show all versions of flexy-c3p0 Show documentation
The flexible pool c3p0 adapter
package com.vladmihalcea.flexypool.adaptor;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.vladmihalcea.flexypool.common.ConfigurationProperties;
import com.vladmihalcea.flexypool.metric.Metrics;
/**
* C3P0PoolAdapter
extends {@link AbstractPoolAdapter} and it adapts the required API to
* communicate with the c3p0 {@link ComboPooledDataSource}
*
* @author Vlad Mihalcea
* @since 1.0
*/
public class C3P0PoolAdapter extends AbstractPoolAdapter {
public static final String ACQUIRE_TIMEOUT_MESSAGE = "An attempt by a client to checkout a Connection has timed out.";
/**
* Singleton factory object reference
*/
public static final PoolAdapterFactory FACTORY = new PoolAdapterFactory() {
@Override
public PoolAdapter newInstance(
ConfigurationProperties> configurationProperties) {
return new C3P0PoolAdapter(configurationProperties);
}
};
/**
* Init constructor
* @param configurationProperties configuration properties
*/
public C3P0PoolAdapter(ConfigurationProperties> configurationProperties) {
super(configurationProperties);
}
/**
* {@inheritDoc}
*/
@Override
public int getMaxPoolSize() {
return getTargetDataSource().getMaxPoolSize();
}
/**
* {@inheritDoc}
*/
@Override
public void setMaxPoolSize(int maxPoolSize) {
getTargetDataSource().setMaxPoolSize(maxPoolSize);
}
/**
* {@inheritDoc}
*/
@Override
protected boolean isAcquireTimeoutException(Exception e) {
return e.getMessage() != null && ACQUIRE_TIMEOUT_MESSAGE.equals(e.getMessage());
}
}