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
`HikariDataSource()` Default constructor.
`HikariDataSource​(HikariConfig configuration)` Construct a HikariDataSource with the specified configuration.

### Method Summary

All Methods Instance Methods Concrete Methods
`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 the `HikariConfigMXBean` for this HikariDataSource instance.
`HikariPoolMXBean` `getHikariPoolMXBean()` Get the `HikariPoolMXBean` 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()` Returns `true` 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`

### 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 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​(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 Detail

#### getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

Specified by:
  `getConnection` in interface `javax.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 interface `javax.sql.DataSource`
Throws:
  `java.sql.SQLException`

#### getLogWriter

    public java.io.PrintWriter getLogWriter()
                                     throws java.sql.SQLException

Specified by:
  `getLogWriter` in interface `javax.sql.CommonDataSource`
Specified by:
  `getLogWriter` in interface `javax.sql.DataSource`
Throws:
  `java.sql.SQLException`

#### setLogWriter

    public void setLogWriter​(java.io.PrintWriter out)
                      throws java.sql.SQLException

Specified by:
  `setLogWriter` in interface `javax.sql.CommonDataSource`
Specified by:
  `setLogWriter` in interface `javax.sql.DataSource`
Throws:
  `java.sql.SQLException`

#### setLoginTimeout

    public void setLoginTimeout​(int seconds)
                         throws java.sql.SQLException

Specified by:
  `setLoginTimeout` in interface `javax.sql.CommonDataSource`
Specified by:
  `setLoginTimeout` in interface `javax.sql.DataSource`
Throws:
  `java.sql.SQLException`

#### getLoginTimeout

    public int getLoginTimeout()
                        throws java.sql.SQLException

Specified by:
  `getLoginTimeout` in interface `javax.sql.CommonDataSource`
Specified by:
  `getLoginTimeout` in interface `javax.sql.DataSource`
Throws:
  `java.sql.SQLException`

#### getParentLogger

    public java.util.logging.Logger getParentLogger()
                                             throws java.sql.SQLFeatureNotSupportedException

Specified by:
  `getParentLogger` in interface `javax.sql.CommonDataSource`
Throws:
  `java.sql.SQLFeatureNotSupportedException`

#### unwrap

    public <T> T unwrap​(java.lang.Class<T> iface)
                 throws java.sql.SQLException

Specified by:
  `unwrap` in interface `java.sql.Wrapper`
Throws:
  `java.sql.SQLException`

#### isWrapperFor

    public boolean isWrapperFor​(java.lang.Class<?> iface)
                         throws java.sql.SQLException

Specified by:
  `isWrapperFor` in interface `java.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 class `HikariConfig`
Parameters:
  `metricRegistry` - the MetricRegistry instance to use

#### setMetricsTrackerFactory

    public void setMetricsTrackerFactory​(MetricsTrackerFactory metricsTrackerFactory)

Overrides:
  `setMetricsTrackerFactory` in class `HikariConfig`

#### 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 is `null`.

Overrides:
  `setHealthCheckRegistry` in class `HikariConfig`
Parameters:
  `healthCheckRegistry` - the HealthCheckRegistry to be used

#### 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 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 HikariConfigMXBean getHikariConfigMXBean()

Get the `HikariConfigMXBean` 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 interface `java.lang.AutoCloseable`
Specified by:
  `close` in interface `java.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 class `java.lang.Object`