Package com.zaxxer.hikari
Class HikariDataSource
- java.lang.Object
-
- com.zaxxer.hikari.HikariConfig
-
- com.zaxxer.hikari.HikariDataSource
-
- All Implemented Interfaces:
HikariConfigMXBean,Closeable,AutoCloseable,Wrapper,CommonDataSource,DataSource
public class HikariDataSource extends HikariConfig implements DataSource, Closeable
The HikariCP pooled DataSource.- Author:
- Brett Wooldridge
-
-
Constructor Summary
Constructors Constructor Description HikariDataSource()Default constructor.HikariDataSource(HikariConfig configuration)Construct a HikariDataSource with the specified configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Shutdown the DataSource and its associated pool.voidevictConnection(Connection connection)Evict a connection from the pool.ConnectiongetConnection()ConnectiongetConnection(String username, String password)HikariConfigMXBeangetHikariConfigMXBean()Get theHikariConfigMXBeanfor this HikariDataSource instance.HikariPoolMXBeangetHikariPoolMXBean()Get theHikariPoolMXBeanfor this HikariDataSource instance.intgetLoginTimeout()PrintWritergetLogWriter()LoggergetParentLogger()booleanisClosed()Determine whether the HikariDataSource has been closed.booleanisRunning()Returnstrueif the pool as been started and is not suspended or shutdown.booleanisWrapperFor(Class<?> iface)voidsetHealthCheckRegistry(Object healthCheckRegistry)Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP.voidsetLoginTimeout(int seconds)voidsetLogWriter(PrintWriter out)voidsetMetricRegistry(Object metricRegistry)Set a MetricRegistry instance to use for registration of metrics used by HikariCP.voidsetMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)StringtoString()<T> Tunwrap(Class<T> iface)-
Methods inherited from class com.zaxxer.hikari.HikariConfig
addDataSourceProperty, addHealthCheckProperty, copyStateTo, getCatalog, getConnectionInitSql, getConnectionTestQuery, getConnectionTimeout, getCredentials, getDataSource, getDataSourceClassName, getDataSourceJNDI, getDataSourceProperties, getDriverClassName, getExceptionOverride, getExceptionOverrideClassName, getHealthCheckProperties, getHealthCheckRegistry, getIdleTimeout, getInitializationFailTimeout, getJdbcUrl, getKeepaliveTime, getLeakDetectionThreshold, getMaximumPoolSize, getMaxLifetime, getMetricRegistry, getMetricsTrackerFactory, getMinimumIdle, getPassword, getPoolName, getScheduledExecutor, getSchema, getThreadFactory, getTransactionIsolation, getUsername, getValidationTimeout, isAllowPoolSuspension, isAutoCommit, isIsolateInternalQueries, isReadOnly, isRegisterMbeans, setAllowPoolSuspension, setAutoCommit, setCatalog, setConnectionInitSql, setConnectionTestQuery, setConnectionTimeout, setCredentials, setDataSource, setDataSourceClassName, setDataSourceJNDI, setDataSourceProperties, setDriverClassName, setExceptionOverride, setExceptionOverrideClassName, setHealthCheckProperties, setIdleTimeout, setInitializationFailTimeout, setIsolateInternalQueries, setJdbcUrl, setKeepaliveTime, setLeakDetectionThreshold, setMaximumPoolSize, setMaxLifetime, setMinimumIdle, setPassword, setPoolName, setReadOnly, setRegisterMbeans, setScheduledExecutor, setSchema, setThreadFactory, setTransactionIsolation, setUsername, setValidationTimeout, validate
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
-
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
-
-
-
Constructor Detail
-
HikariDataSource
public HikariDataSource()
Default constructor. Setters are used to configure the pool. Using this constructor vs.HikariDataSource(HikariConfig)will result ingetConnection()performance that is slightly lower due to lazy initialization checks. The first call togetConnection()starts the pool. Once the pool is started, the configuration is "sealed" and no further configuration changes are possible -- except viaHikariConfigMXBeanmethods.
-
HikariDataSource
public HikariDataSource(HikariConfig configuration)
Construct a HikariDataSource with the specified configuration. TheHikariConfigis copied and the pool is started by invoking this constructor. TheHikariConfigcan be modified without affecting the HikariDataSource and used to initialize another HikariDataSource instance.- Parameters:
configuration- a HikariConfig instance
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
public Connection getConnection(String username, String password) throws SQLException
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getLogWriter
public PrintWriter getLogWriter() throws SQLException
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
public void setLogWriter(PrintWriter out) throws SQLException
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws SQLException- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
public int getLoginTimeout() throws SQLException- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
public Logger getParentLogger() throws SQLFeatureNotSupportedException
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
unwrap
public <T> T unwrap(Class<T> iface) throws SQLException
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
public boolean isWrapperFor(Class<?> iface) throws SQLException
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
setMetricRegistry
public void setMetricRegistry(Object metricRegistry)
Set a MetricRegistry instance to use for registration of metrics used by HikariCP.- Overrides:
setMetricRegistryin classHikariConfig- Parameters:
metricRegistry- the MetricRegistry instance to use
-
setMetricsTrackerFactory
public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
- Overrides:
setMetricsTrackerFactoryin classHikariConfig
-
setHealthCheckRegistry
public void setHealthCheckRegistry(Object healthCheckRegistry)
Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP. Currently only Codahale/DropWizard is supported for health checks. Default isnull.- Overrides:
setHealthCheckRegistryin classHikariConfig- Parameters:
healthCheckRegistry- the HealthCheckRegistry to be used
-
isRunning
public boolean isRunning()
Returnstrueif the pool as been started and is not suspended or shutdown.- Returns:
trueif the pool as been started and is not suspended or shutdown.
-
getHikariPoolMXBean
public HikariPoolMXBean getHikariPoolMXBean()
Get theHikariPoolMXBeanfor this HikariDataSource instance. If this method is called on aHikariDataSourcethat has been constructed without aHikariConfiginstance, and before an initial call to#getConnection(), the return value will benull.- Returns:
- the
HikariPoolMXBeaninstance, ornull.
-
getHikariConfigMXBean
public HikariConfigMXBean getHikariConfigMXBean()
Get theHikariConfigMXBeanfor this HikariDataSource instance.- Returns:
- the
HikariConfigMXBeaninstance.
-
evictConnection
public void evictConnection(Connection connection)
Evict a connection from the pool. If the connection has already been closed (returned to the pool) this may result in a "soft" eviction; the connection will be evicted sometime in the future if it is currently in use. If the connection has not been closed, the eviction is immediate.- Parameters:
connection- the connection to evict from the pool
-
close
public void close()
Shutdown the DataSource and its associated pool.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()
Determine whether the HikariDataSource has been closed.- Returns:
- true if the HikariDataSource has been closed, false otherwise
-
-