Package com.zaxxer.hikari
Class HikariDataSource
java.lang.Object
com.zaxxer.hikari.HikariConfig
com.zaxxer.hikari.HikariDataSource
- All Implemented Interfaces:
com.zaxxer.hikari.HikariConfigMXBean,Closeable,AutoCloseable,Wrapper,CommonDataSource,DataSource
public class HikariDataSource
extends com.zaxxer.hikari.HikariConfig
implements DataSource, Closeable
The HikariCP pooled DataSource.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HikariDataSource(com.zaxxer.hikari.HikariConfig configuration) Construct a HikariDataSource with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Shutdown the DataSource and its associated pool.voidevictConnection(Connection connection) Evict a connection from the pool.getConnection(String username, String password) com.zaxxer.hikari.HikariConfigMXBeanGet theHikariConfigMXBeanfor this HikariDataSource instance.com.zaxxer.hikari.HikariPoolMXBeanGet theHikariPoolMXBeanfor this HikariDataSource instance.intbooleanisClosed()Determine whether the HikariDataSource has been closed.booleanReturnstrueif the pool as been started and is not suspended or shutdown.booleanisWrapperFor(Class<?> iface) voidsetHealthCheckRegistry(Object healthCheckRegistry) voidsetLoginTimeout(int seconds) voidsetLogWriter(PrintWriter out) voidsetMetricRegistry(Object metricRegistry) voidsetMetricsTrackerFactory(com.zaxxer.hikari.metrics.MetricsTrackerFactory metricsTrackerFactory) toString()<T> TMethods inherited from class com.zaxxer.hikari.HikariConfig
addDataSourceProperty, addHealthCheckProperty, copyStateTo, getCatalog, getConnectionInitSql, getConnectionTestQuery, getConnectionTimeout, getDataSource, getDataSourceClassName, getDataSourceJNDI, getDataSourceProperties, getDriverClassName, 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, setDataSource, setDataSourceClassName, setDataSourceJNDI, setDataSourceProperties, setDriverClassName, setExceptionOverrideClassName, setHealthCheckProperties, setIdleTimeout, setInitializationFailTimeout, setIsolateInternalQueries, setJdbcUrl, setKeepaliveTime, setLeakDetectionThreshold, setMaximumPoolSize, setMaxLifetime, setMinimumIdle, setPassword, setPoolName, setReadOnly, setRegisterMbeans, setScheduledExecutor, setSchema, setThreadFactory, setTransactionIsolation, setUsername, setValidationTimeout, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilderMethods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
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(com.zaxxer.hikari.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 Details
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getConnection
- Specified by:
getConnectionin interfaceDataSource- Throws:
SQLException
-
getLogWriter
- Specified by:
getLogWriterin interfaceCommonDataSource- Specified by:
getLogWriterin interfaceDataSource- Throws:
SQLException
-
setLogWriter
- Specified by:
setLogWriterin interfaceCommonDataSource- Specified by:
setLogWriterin interfaceDataSource- Throws:
SQLException
-
setLoginTimeout
- Specified by:
setLoginTimeoutin interfaceCommonDataSource- Specified by:
setLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getLoginTimeout
- Specified by:
getLoginTimeoutin interfaceCommonDataSource- Specified by:
getLoginTimeoutin interfaceDataSource- Throws:
SQLException
-
getParentLogger
- Specified by:
getParentLoggerin interfaceCommonDataSource- Throws:
SQLFeatureNotSupportedException
-
unwrap
- Specified by:
unwrapin interfaceWrapper- Throws:
SQLException
-
isWrapperFor
- Specified by:
isWrapperForin interfaceWrapper- Throws:
SQLException
-
setMetricRegistry
- Overrides:
setMetricRegistryin classcom.zaxxer.hikari.HikariConfig
-
setMetricsTrackerFactory
public void setMetricsTrackerFactory(com.zaxxer.hikari.metrics.MetricsTrackerFactory metricsTrackerFactory) - Overrides:
setMetricsTrackerFactoryin classcom.zaxxer.hikari.HikariConfig
-
setHealthCheckRegistry
- Overrides:
setHealthCheckRegistryin classcom.zaxxer.hikari.HikariConfig
-
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 com.zaxxer.hikari.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 com.zaxxer.hikari.HikariConfigMXBean getHikariConfigMXBean()Get theHikariConfigMXBeanfor this HikariDataSource instance.- Returns:
- the
HikariConfigMXBeaninstance.
-
evictConnection
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
-
toString
-