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

    Constructors
    Constructor
    Description
    Default constructor.
    HikariDataSource(com.zaxxer.hikari.HikariConfig configuration)
    Construct a HikariDataSource with the specified configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shutdown the DataSource and its associated pool.
    void
    Evict a connection from the pool.
    getConnection(String username, String password)
    com.zaxxer.hikari.HikariConfigMXBean
    Get the HikariConfigMXBean for this HikariDataSource instance.
    com.zaxxer.hikari.HikariPoolMXBean
    Get the HikariPoolMXBean for this HikariDataSource instance.
    int
    boolean
    Determine whether the HikariDataSource has been closed.
    boolean
    Returns true if the pool as been started and is not suspended or shutdown.
    boolean
    isWrapperFor(Class<?> iface)
    void
    setHealthCheckRegistry(Object healthCheckRegistry)
    void
    setLoginTimeout(int seconds)
    void
    void
    setMetricRegistry(Object metricRegistry)
    void
    setMetricsTrackerFactory(com.zaxxer.hikari.metrics.MetricsTrackerFactory metricsTrackerFactory)
    <T> T
    unwrap(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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javax.sql.CommonDataSource

    createShardingKeyBuilder

    Methods 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 in getConnection() performance that is slightly lower due to lazy initialization checks. The first call to getConnection() starts the pool. Once the pool is started, the configuration is "sealed" and no further configuration changes are possible -- except via HikariConfigMXBean methods.
    • HikariDataSource

      public HikariDataSource(com.zaxxer.hikari.HikariConfig configuration)
      Construct a HikariDataSource with the specified configuration. The HikariConfig is copied and the pool is started by invoking this constructor. The HikariConfig can be modified without affecting the HikariDataSource and used to initialize another HikariDataSource instance.
      Parameters:
      configuration - a HikariConfig instance
  • Method Details

    • getConnection

      public Connection getConnection() throws SQLException
      Specified by:
      getConnection in interface DataSource
      Throws:
      SQLException
    • getConnection

      public Connection getConnection(String username, String password) throws SQLException
      Specified by:
      getConnection in interface DataSource
      Throws:
      SQLException
    • getLogWriter

      public PrintWriter getLogWriter() throws SQLException
      Specified by:
      getLogWriter in interface CommonDataSource
      Specified by:
      getLogWriter in interface DataSource
      Throws:
      SQLException
    • setLogWriter

      public void setLogWriter(PrintWriter out) throws SQLException
      Specified by:
      setLogWriter in interface CommonDataSource
      Specified by:
      setLogWriter in interface DataSource
      Throws:
      SQLException
    • setLoginTimeout

      public void setLoginTimeout(int seconds) throws SQLException
      Specified by:
      setLoginTimeout in interface CommonDataSource
      Specified by:
      setLoginTimeout in interface DataSource
      Throws:
      SQLException
    • getLoginTimeout

      public int getLoginTimeout() throws SQLException
      Specified by:
      getLoginTimeout in interface CommonDataSource
      Specified by:
      getLoginTimeout in interface DataSource
      Throws:
      SQLException
    • getParentLogger

      public Logger getParentLogger() throws SQLFeatureNotSupportedException
      Specified by:
      getParentLogger in interface CommonDataSource
      Throws:
      SQLFeatureNotSupportedException
    • unwrap

      public <T> T unwrap(Class<T> iface) throws SQLException
      Specified by:
      unwrap in interface Wrapper
      Throws:
      SQLException
    • isWrapperFor

      public boolean isWrapperFor(Class<?> iface) throws SQLException
      Specified by:
      isWrapperFor in interface Wrapper
      Throws:
      SQLException
    • setMetricRegistry

      public void setMetricRegistry(Object metricRegistry)
      Overrides:
      setMetricRegistry in class com.zaxxer.hikari.HikariConfig
    • setMetricsTrackerFactory

      public void setMetricsTrackerFactory(com.zaxxer.hikari.metrics.MetricsTrackerFactory metricsTrackerFactory)
      Overrides:
      setMetricsTrackerFactory in class com.zaxxer.hikari.HikariConfig
    • setHealthCheckRegistry

      public void setHealthCheckRegistry(Object healthCheckRegistry)
      Overrides:
      setHealthCheckRegistry in class com.zaxxer.hikari.HikariConfig
    • isRunning

      public boolean isRunning()
      Returns true 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 com.zaxxer.hikari.HikariPoolMXBean getHikariPoolMXBean()
      Get the HikariPoolMXBean for this HikariDataSource instance. If this method is called on a HikariDataSource that has been constructed without a HikariConfig instance, and before an initial call to #getConnection(), the return value will be null.
      Returns:
      the HikariPoolMXBean instance, or null.
    • getHikariConfigMXBean

      public com.zaxxer.hikari.HikariConfigMXBean getHikariConfigMXBean()
      Get the HikariConfigMXBean for this HikariDataSource instance.
      Returns:
      the HikariConfigMXBean instance.
    • 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:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isClosed

      public boolean isClosed()
      Determine whether the HikariDataSource has been closed.
      Returns:
      true if the HikariDataSource has been closed, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object