public class HikariConfig extends java.lang.Object implements HikariConfigMXBean
Constructor and Description |
---|
HikariConfig()
Default constructor
|
HikariConfig(java.util.Properties properties)
Construct a HikariConfig from the specified properties object.
|
HikariConfig(java.lang.String propertyFileName)
Construct a HikariConfig from the specified property file name.
|
Modifier and Type | Method and Description |
---|---|
void |
addDataSourceProperty(java.lang.String propertyName,
java.lang.Object value)
Add a property (name/value pair) that will be used to configure the
DataSource /Driver . |
void |
addHealthCheckProperty(java.lang.String key,
java.lang.String value) |
void |
copyStateTo(HikariConfig other)
Copies the state of
this into other . |
java.lang.String |
getCatalog()
Get the default catalog name to be set on connections.
|
java.lang.String |
getConnectionInitSql()
Get the SQL string that will be executed on all new connections when they are
created, before they are added to the pool.
|
java.lang.String |
getConnectionTestQuery()
Get the SQL query to be executed to test the validity of connections.
|
long |
getConnectionTimeout()
Get the maximum number of milliseconds that a client will wait for a connection from the pool.
|
javax.sql.DataSource |
getDataSource()
Get the
DataSource that has been explicitly specified to be wrapped by the
pool. |
java.lang.String |
getDataSourceClassName()
Get the name of the JDBC
DataSource class used to create Connections. |
java.lang.String |
getDataSourceJNDI() |
java.util.Properties |
getDataSourceProperties() |
java.lang.String |
getDriverClassName() |
java.util.Properties |
getHealthCheckProperties() |
java.lang.Object |
getHealthCheckRegistry()
Get the HealthCheckRegistry that will be used for registration of health checks by HikariCP.
|
long |
getIdleTimeout()
This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
idle in the pool.
|
long |
getInitializationFailTimeout()
Get the pool initialization failure timeout.
|
java.lang.String |
getJdbcUrl() |
long |
getLeakDetectionThreshold()
This property controls the amount of time that a connection can be out of the pool before a message is
logged indicating a possible connection leak.
|
int |
getMaximumPoolSize()
The property controls the maximum number of connections that HikariCP will keep in the pool,
including both idle and in-use connections.
|
long |
getMaxLifetime()
This property controls the maximum lifetime of a connection in the pool.
|
java.lang.Object |
getMetricRegistry()
Get the MetricRegistry instance to used for registration of metrics used by HikariCP.
|
MetricsTrackerFactory |
getMetricsTrackerFactory() |
int |
getMinimumIdle()
The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
including both idle and in-use connections.
|
java.lang.String |
getPassword()
Get the default password to use for DataSource.getConnection(username, password) calls.
|
java.lang.String |
getPoolName()
The name of the connection pool.
|
java.util.concurrent.ScheduledExecutorService |
getScheduledExecutor()
Get the ScheduledExecutorService used for housekeeping.
|
java.lang.String |
getSchema()
Get the default schema name to be set on connections.
|
java.util.concurrent.ThreadFactory |
getThreadFactory()
Get the thread factory used to create threads.
|
java.lang.String |
getTransactionIsolation() |
java.lang.String |
getUsername()
Get the default username used for DataSource.getConnection(username, password) calls.
|
long |
getValidationTimeout()
Get the maximum number of milliseconds that the pool will wait for a connection to be validated as
alive.
|
boolean |
isAllowPoolSuspension()
Get the pool suspension behavior (allowed or disallowed).
|
boolean |
isAutoCommit()
Get the default auto-commit behavior of connections in the pool.
|
boolean |
isIsolateInternalQueries()
Determine whether internal pool queries, principally aliveness checks, will be isolated in their own transaction
via
Connection.rollback() . |
boolean |
isReadOnly()
Determine whether the Connections in the pool are in read-only mode.
|
boolean |
isRegisterMbeans()
Determine whether HikariCP will self-register
HikariConfigMXBean and HikariPoolMXBean instances
in JMX. |
void |
setAllowPoolSuspension(boolean isAllowPoolSuspension)
Set whether or not pool suspension is allowed.
|
void |
setAutoCommit(boolean isAutoCommit)
Set the default auto-commit behavior of connections in the pool.
|
void |
setCatalog(java.lang.String catalog)
Set the default catalog name to be set on connections.
|
void |
setConnectionInitSql(java.lang.String connectionInitSql)
Set the SQL string that will be executed on all new connections when they are
created, before they are added to the pool.
|
void |
setConnectionTestQuery(java.lang.String connectionTestQuery)
Set the SQL query to be executed to test the validity of connections.
|
void |
setConnectionTimeout(long connectionTimeoutMs)
Set the maximum number of milliseconds that a client will wait for a connection from the pool.
|
void |
setDataSource(javax.sql.DataSource dataSource)
Set a
DataSource for the pool to explicitly wrap. |
void |
setDataSourceClassName(java.lang.String className)
Set the fully qualified class name of the JDBC
DataSource that will be used create Connections. |
void |
setDataSourceJNDI(java.lang.String jndiDataSource) |
void |
setDataSourceProperties(java.util.Properties dsProperties) |
void |
setDriverClassName(java.lang.String driverClassName) |
void |
setHealthCheckProperties(java.util.Properties healthCheckProperties) |
void |
setHealthCheckRegistry(java.lang.Object healthCheckRegistry)
Set the HealthCheckRegistry that will be used for registration of health checks by HikariCP.
|
void |
setIdleTimeout(long idleTimeoutMs)
This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit
idle in the pool.
|
void |
setInitializationFailTimeout(long initializationFailTimeout)
Set the pool initialization failure timeout.
|
void |
setIsolateInternalQueries(boolean isolate)
Configure whether internal pool queries, principally aliveness checks, will be isolated in their own transaction
via
Connection.rollback() . |
void |
setJdbcUrl(java.lang.String jdbcUrl) |
void |
setLeakDetectionThreshold(long leakDetectionThresholdMs)
This property controls the amount of time that a connection can be out of the pool before a message is
logged indicating a possible connection leak.
|
void |
setMaximumPoolSize(int maxPoolSize)
The property controls the maximum size that the pool is allowed to reach, including both idle and in-use
connections.
|
void |
setMaxLifetime(long maxLifetimeMs)
This property controls the maximum lifetime of a connection in the pool.
|
void |
setMetricRegistry(java.lang.Object metricRegistry)
Set a MetricRegistry instance to use for registration of metrics used by HikariCP.
|
void |
setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory) |
void |
setMinimumIdle(int minIdle)
The property controls the minimum number of idle connections that HikariCP tries to maintain in the pool,
including both idle and in-use connections.
|
void |
setPassword(java.lang.String password)
Set the default password to use for DataSource.getConnection(username, password) calls.
|
void |
setPoolName(java.lang.String poolName)
Set the name of the connection pool.
|
void |
setReadOnly(boolean readOnly)
Configures the Connections to be added to the pool as read-only Connections.
|
void |
setRegisterMbeans(boolean register)
Configures whether HikariCP self-registers the
HikariConfigMXBean and HikariPoolMXBean in JMX. |
void |
setScheduledExecutor(java.util.concurrent.ScheduledExecutorService executor)
Set the ScheduledExecutorService used for housekeeping.
|
void |
setSchema(java.lang.String schema)
Set the default schema name to be set on connections.
|
void |
setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
Set the thread factory to be used to create threads.
|
void |
setTransactionIsolation(java.lang.String isolationLevel)
Set the default transaction isolation level.
|
void |
setUsername(java.lang.String username)
Set the default username used for DataSource.getConnection(username, password) calls.
|
void |
setValidationTimeout(long validationTimeoutMs)
Sets the maximum number of milliseconds that the pool will wait for a connection to be validated as
alive.
|
void |
validate() |
public HikariConfig()
public HikariConfig(java.util.Properties properties)
properties
- the name of the property filepublic HikariConfig(java.lang.String propertyFileName)
propertyFileName
will first be treated as a path in the file-system, and if that fails the
Class.getResourceAsStream(propertyFileName) will be tried.propertyFileName
- the name of the property filepublic java.lang.String getCatalog()
getCatalog
in interface HikariConfigMXBean
public void setCatalog(java.lang.String catalog)
WARNING: THIS VALUE SHOULD ONLY BE CHANGED WHILE THE POOL IS SUSPENDED, AFTER CONNECTIONS HAVE BEEN EVICTED.
setCatalog
in interface HikariConfigMXBean
catalog
- the catalog name, or nullpublic long getConnectionTimeout()
DataSource.getConnection()
.getConnectionTimeout
in interface HikariConfigMXBean
public void setConnectionTimeout(long connectionTimeoutMs)
DataSource.getConnection()
.setConnectionTimeout
in interface HikariConfigMXBean
connectionTimeoutMs
- the connection timeout in millisecondspublic long getIdleTimeout()
getIdleTimeout
in interface HikariConfigMXBean
public void setIdleTimeout(long idleTimeoutMs)
setIdleTimeout
in interface HikariConfigMXBean
idleTimeoutMs
- the idle timeout in millisecondspublic long getLeakDetectionThreshold()
getLeakDetectionThreshold
in interface HikariConfigMXBean
public void setLeakDetectionThreshold(long leakDetectionThresholdMs)
setLeakDetectionThreshold
in interface HikariConfigMXBean
leakDetectionThresholdMs
- the connection leak detection threshold in millisecondspublic long getMaxLifetime()
getMaxLifetime
in interface HikariConfigMXBean
public void setMaxLifetime(long maxLifetimeMs)
setMaxLifetime
in interface HikariConfigMXBean
maxLifetimeMs
- the maximum connection lifetime in millisecondspublic int getMaximumPoolSize()
getMaximumPoolSize
in interface HikariConfigMXBean
public void setMaximumPoolSize(int maxPoolSize)
When the pool reaches this size, and no idle connections are available, calls to getConnection() will block for up to connectionTimeout milliseconds before timing out.
setMaximumPoolSize
in interface HikariConfigMXBean
maxPoolSize
- the maximum number of connections in the poolpublic int getMinimumIdle()
getMinimumIdle
in interface HikariConfigMXBean
public void setMinimumIdle(int minIdle)
setMinimumIdle
in interface HikariConfigMXBean
minIdle
- the minimum number of idle connections in the pool to maintainpublic java.lang.String getPassword()
public void setPassword(java.lang.String password)
setPassword
in interface HikariConfigMXBean
password
- the passwordpublic java.lang.String getUsername()
public void setUsername(java.lang.String username)
setUsername
in interface HikariConfigMXBean
username
- the usernamepublic long getValidationTimeout()
getValidationTimeout
in interface HikariConfigMXBean
public void setValidationTimeout(long validationTimeoutMs)
setValidationTimeout
in interface HikariConfigMXBean
validationTimeoutMs
- the validation timeout in millisecondspublic java.lang.String getConnectionTestQuery()
public void setConnectionTestQuery(java.lang.String connectionTestQuery)
Connection.isValid()
method to test connection validity can
be more efficient on some databases and is recommended.connectionTestQuery
- a SQL query stringpublic java.lang.String getConnectionInitSql()
public void setConnectionInitSql(java.lang.String connectionInitSql)
connectionInitSql
- the SQL to execute on new connectionspublic javax.sql.DataSource getDataSource()
DataSource
that has been explicitly specified to be wrapped by the
pool.DataSource
instance, or nullpublic void setDataSource(javax.sql.DataSource dataSource)
DataSource
for the pool to explicitly wrap. This setter is not
available through property file based initialization.dataSource
- a specific DataSource
to be wrapped by the poolpublic java.lang.String getDataSourceClassName()
DataSource
class used to create Connections.DataSource
classpublic void setDataSourceClassName(java.lang.String className)
DataSource
that will be used create Connections.className
- the fully qualified name of the JDBC DataSource
classpublic void addDataSourceProperty(java.lang.String propertyName, java.lang.Object value)
DataSource
/Driver
.
In the case of a DataSource
, the property names will be translated to Java setters following the Java Bean
naming convention. For example, the property cachePrepStmts
will translate into setCachePrepStmts()
with the value
passed as a parameter.
In the case of a Driver
, the property will be added to a Properties
instance that will
be passed to the driver during Driver.connect(String, Properties)
calls.propertyName
- the name of the propertyvalue
- the value to be used by the DataSource/Driverpublic java.lang.String getDataSourceJNDI()
public void setDataSourceJNDI(java.lang.String jndiDataSource)
public java.util.Properties getDataSourceProperties()
public void setDataSourceProperties(java.util.Properties dsProperties)
public java.lang.String getDriverClassName()
public void setDriverClassName(java.lang.String driverClassName)
public java.lang.String getJdbcUrl()
public void setJdbcUrl(java.lang.String jdbcUrl)
public boolean isAutoCommit()
public void setAutoCommit(boolean isAutoCommit)
isAutoCommit
- the desired auto-commit default for connectionspublic boolean isAllowPoolSuspension()
public void setAllowPoolSuspension(boolean isAllowPoolSuspension)
isAllowPoolSuspension
- the desired pool suspension allowancepublic long getInitializationFailTimeout()
#setInitializationFailTimeout(long)
for details.setInitializationFailTimeout(long)
public void setInitializationFailTimeout(long initializationFailTimeout)
HikariDataSource
is constructed with a HikariConfig
,
or when HikariDataSource
is constructed using the no-arg constructor
and HikariDataSource.getConnection()
is called.
PoolInitializationException
will be thrown. connectionTestQuery
and connectionInitSql
are valid. If those validations fail, an exception
will be thrown. If a connection cannot be obtained, the validation is skipped
and the the pool will start and continue to try to obtain connections in the
background. This can mean that callers to DataSource#getConnection()
may
encounter exceptions. DataSource#getConnection()
may encounter exceptions. connectionTimeout
or validationTimeout
; they will be honored before this
timeout is applied. The default value is one millisecond.initializationFailTimeout
- the number of milliseconds before the
pool initialization fails, or 0 to validate connection setup but continue with
pool start, or less than zero to skip all initialization checks and start the
pool without delay.public boolean isIsolateInternalQueries()
Connection.rollback()
. Defaults to false
.true
if internal pool queries are isolated, false
if notpublic void setIsolateInternalQueries(boolean isolate)
Connection.rollback()
. Defaults to false
.isolate
- true
if internal pool queries should be isolated, false
if notpublic MetricsTrackerFactory getMetricsTrackerFactory()
public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory)
public java.lang.Object getMetricRegistry()
null
.public void setMetricRegistry(java.lang.Object metricRegistry)
metricRegistry
- the MetricRegistry instance to usepublic java.lang.Object getHealthCheckRegistry()
public void setHealthCheckRegistry(java.lang.Object healthCheckRegistry)
null
.healthCheckRegistry
- the HealthCheckRegistry to be usedpublic java.util.Properties getHealthCheckProperties()
public void setHealthCheckProperties(java.util.Properties healthCheckProperties)
public void addHealthCheckProperty(java.lang.String key, java.lang.String value)
public boolean isReadOnly()
true
if the Connections in the pool are read-only, false
if notpublic void setReadOnly(boolean readOnly)
readOnly
- true
if the Connections in the pool are read-only, false
if notpublic boolean isRegisterMbeans()
HikariConfigMXBean
and HikariPoolMXBean
instances
in JMX.true
if HikariCP will register MXBeans, false
if it will notpublic void setRegisterMbeans(boolean register)
HikariConfigMXBean
and HikariPoolMXBean
in JMX.register
- true
if HikariCP should register MXBeans, false
if it should notpublic java.lang.String getPoolName()
getPoolName
in interface HikariConfigMXBean
public void setPoolName(java.lang.String poolName)
poolName
- the name of the connection pool to usepublic java.util.concurrent.ScheduledExecutorService getScheduledExecutor()
public void setScheduledExecutor(java.util.concurrent.ScheduledExecutorService executor)
executor
- the ScheduledExecutorServicepublic java.lang.String getTransactionIsolation()
public java.lang.String getSchema()
public void setSchema(java.lang.String schema)
schema
- the name of the default schemapublic void setTransactionIsolation(java.lang.String isolationLevel)
Connection
class, eg.
TRANSACTION_REPEATABLE_READ
.isolationLevel
- the name of the isolation levelpublic java.util.concurrent.ThreadFactory getThreadFactory()
public void setThreadFactory(java.util.concurrent.ThreadFactory threadFactory)
threadFactory
- the thread factory (setting to null causes the default thread factory to be used)public void copyStateTo(HikariConfig other)
this
into other
.other
- Other HikariConfig
to copy the state to.public void validate()
Copyright © 2019 Zaxxer.com. All Rights Reserved.