Make HikariDataSource inherit from HikariConfig for convenience. This is useful

for Spring configuration, for example, because properties can be set directly on
the datasource rather than constructing a separate object.
pull/41/head
Brett Wooldridge 11 years ago
parent f1bdffa3b8
commit 6865443ddf

@ -32,7 +32,7 @@ import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.proxy.JavassistProxyFactory;
import com.zaxxer.hikari.util.PropertyBeanSetter;
public final class HikariConfig implements HikariConfigMBean
public class HikariConfig implements HikariConfigMBean
{
private static final long ACQUIRE_RETRY_DELAY = 750L;
private static final long CONNECTION_TIMEOUT = 5000L;

@ -31,15 +31,25 @@ import org.slf4j.LoggerFactory;
*
* @author Brett Wooldridge
*/
public class HikariDataSource implements DataSource
public class HikariDataSource extends HikariConfig implements DataSource
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariDataSource.class);
private int loginTimeout;
private volatile boolean isShutdown;
private int loginTimeout;
HikariPool fastPathPool;
volatile HikariPool pool;
// Package scope for testing
HikariPool pool;
/**
* Default constructor. Setters be used to configure the pool. Using
* this constructor vs. {@link #HikariDataSource(HikariConfig)} will
* result in {@link #getConnection()} performance that is slightly lower
* due to lazy initialization checks.
*/
public HikariDataSource()
{
}
/**
* Construct a HikariDataSource with the specified configuration.
@ -48,24 +58,42 @@ public class HikariDataSource implements DataSource
*/
public HikariDataSource(HikariConfig configuration)
{
pool = new HikariPool(configuration);
pool = fastPathPool = new HikariPool(configuration);
}
/** {@inheritDoc} */
public Connection getConnection() throws SQLException
{
if (!isShutdown)
if (isShutdown)
{
return pool.getConnection();
throw new IllegalStateException("The datasource has been shutdown.");
}
throw new IllegalStateException("The datasource has been shutdown.");
if (fastPathPool != null)
{
return fastPathPool.getConnection();
}
HikariPool result = pool;
if (result == null)
{
synchronized (this)
{
result = pool;
if (result == null)
{
pool = result = new HikariPool(this);
}
}
}
return result.getConnection();
}
/** {@inheritDoc} */
public Connection getConnection(String username, String password) throws SQLException
{
LOGGER.warn("getConnection() with username and password is not supported");
LOGGER.warn("getConnection() with username and password is not supported, calling getConnection() instead");
return getConnection();
}

Loading…
Cancel
Save