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 void
close()
Shutdown the DataSource and its associated pool.void
evictConnection(java.sql.Connection connection)
Evict a connection from the pool.java.sql.Connection
getConnection()
java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
HikariConfigMXBean
getHikariConfigMXBean()
Get theHikariConfigMXBean
for this HikariDataSource instance.HikariPoolMXBean
getHikariPoolMXBean()
Get theHikariPoolMXBean
for this HikariDataSource instance.int
getLoginTimeout()
java.io.PrintWriter
getLogWriter()
java.util.logging.Logger
getParentLogger()
boolean
isClosed()
Determine whether the HikariDataSource has been closed.boolean
isRunning()
Returnstrue
if the pool as been started and is not suspended or shutdown.boolean
isWrapperFor(java.lang.Class<?> iface)
void
setHealthCheckRegistry(java.lang.Object healthCheckRegistry)
Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP.void
setLoginTimeout(int seconds)
void
setLogWriter(java.io.PrintWriter out)
void
setMetricRegistry(java.lang.Object metricRegistry)
Set a MetricRegistry instance to use for registration of metrics used by HikariCP.void
setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
java.lang.String
toString()
<T> T
unwrap(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 viaHikariConfigMXBean
methods.
-
HikariDataSource
public HikariDataSource(HikariConfig configuration)
Construct a HikariDataSource with the specified configuration. TheHikariConfig
is copied and the pool is started by invoking this constructor. TheHikariConfig
can 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:
getConnection
in 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:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
setLoginTimeout
public void setLoginTimeout(int seconds) throws java.sql.SQLException
- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getLoginTimeout
public int getLoginTimeout() throws java.sql.SQLException
- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfacejavax.sql.CommonDataSource
- Throws:
java.sql.SQLFeatureNotSupportedException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
- Specified by:
isWrapperFor
in 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:
setMetricRegistry
in classHikariConfig
- Parameters:
metricRegistry
- the MetricRegistry instance to use
-
setMetricsTrackerFactory
public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
- Overrides:
setMetricsTrackerFactory
in 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:
setHealthCheckRegistry
in classHikariConfig
- Parameters:
healthCheckRegistry
- the HealthCheckRegistry to be used
-
isRunning
public boolean isRunning()
Returnstrue
if the pool as been started and is not suspended or shutdown.- Returns:
true
if the pool as been started and is not suspended or shutdown.
-
getHikariPoolMXBean
public HikariPoolMXBean getHikariPoolMXBean()
Get theHikariPoolMXBean
for this HikariDataSource instance. If this method is called on aHikariDataSource
that has been constructed without aHikariConfig
instance, and before an initial call to#getConnection()
, the return value will benull
.- Returns:
- the
HikariPoolMXBean
instance, ornull
.
-
getHikariConfigMXBean
public HikariConfigMXBean getHikariConfigMXBean()
Get theHikariConfigMXBean
for this HikariDataSource instance.- Returns:
- the
HikariConfigMXBean
instance.
-
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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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:
toString
in classjava.lang.Object
-
-