Package com.zaxxer.hikari
Class HikariDataSource
- java.lang.Object
-
- com.zaxxer.hikari.HikariConfig
-
- com.zaxxer.hikari.HikariDataSource
-
- All Implemented Interfaces:
HikariConfigMXBean,java.io.Closeable,java.lang.AutoCloseable,java.sql.Wrapper,javax.sql.CommonDataSource,javax.sql.DataSource
public class HikariDataSource extends HikariConfig implements javax.sql.DataSource, java.io.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(java.sql.Connection connection)Evict a connection from the pool.java.sql.ConnectiongetConnection()java.sql.ConnectiongetConnection(java.lang.String username, java.lang.String password)HikariConfigMXBeangetHikariConfigMXBean()Get theHikariConfigMXBeanfor this HikariDataSource instance.HikariPoolMXBeangetHikariPoolMXBean()Get theHikariPoolMXBeanfor this HikariDataSource instance.intgetLoginTimeout()java.io.PrintWritergetLogWriter()java.util.logging.LoggergetParentLogger()booleanisClosed()Determine whether the HikariDataSource has been closed.booleanisRunning()Returnstrueif the pool as been started and is not suspended or shutdown.booleanisWrapperFor(java.lang.Class<?> iface)voidsetHealthCheckRegistry(java.lang.Object healthCheckRegistry)Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP.voidsetLoginTimeout(int seconds)voidsetLogWriter(java.io.PrintWriter out)voidsetMetricRegistry(java.lang.Object metricRegistry)Set a MetricRegistry instance to use for registration of metrics used by HikariCP.voidsetMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)java.lang.StringtoString()<T> Tunwrap(java.lang.Class<T> iface)-
Methods 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, validate
-
-
-
-
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 java.sql.Connection getConnection() throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException- Specified by:
getConnectionin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException- Specified by:
getLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
getLogWriterin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException- Specified by:
setLogWriterin interfacejavax.sql.CommonDataSource- Specified by:
setLogWriterin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException- Specified by:
setLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
setLoginTimeoutin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException- Specified by:
getLoginTimeoutin interfacejavax.sql.CommonDataSource- Specified by:
getLoginTimeoutin interfacejavax.sql.DataSource- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
getParentLoggerin interfacejavax.sql.CommonDataSource- Throws:
java.sql.SQLFeatureNotSupportedException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException- Specified by:
unwrapin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Throws:
java.sql.SQLException
-
setMetricRegistry
public void setMetricRegistry(java.lang.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(java.lang.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(java.sql.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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
isClosed
public boolean isClosed()
Determine whether the HikariDataSource has been closed.- Returns:
- true if the HikariDataSource has been closed, false otherwise
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-