Package de.chojo.sqlutil.datasource
Class DataSourceCreator<T extends JdbcConfig<?>>
java.lang.Object
de.chojo.sqlutil.datasource.DataSourceCreator<T>
- Type Parameters:
T- database type defined by theSqlType
- All Implemented Interfaces:
ConfigurationStage,JdbcStage<T>
public class DataSourceCreator<T extends JdbcConfig<?>>
extends Object
implements JdbcStage<T>, ConfigurationStage
Class to create a
HikariDataSource with a builder pattern.-
Method Summary
Modifier and TypeMethodDescriptioncom.zaxxer.hikari.HikariDataSourcebuild()Create a new hikari data sourceconfigure the jdbc buildercreate()Create a configuration with these properties.static <T extends JdbcConfig<?>>
JdbcStage<T>Create a new DataSource creator.Set the default schema name to be set on connections.usingPassword(String password) Set the default password to use for DataSource.getConnection(username, password) calls.usingUsername(String username) Set the default username used for DataSource.getConnection(username, password) calls.withAutoCommit(boolean isAutoCommit) Set the default auto-commit behavior of connections in the pool.withConnectionTimeout(long connectionTimeoutMs) Set the maximum number of milliseconds that a client will wait for a connection from the pool.withDataSourceClassName(Class<? extends DataSource> className) Set the fully qualified class name of the JDBCDataSourcethat will be used create Connections.withIdleTimeout(long idleTimeoutMs) This property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit idle in the pool.withKeepaliveTime(long keepaliveTimeMs) This property controls the keepalive interval for a connection in the pool.withMaximumPoolSize(int maxPoolSize) The property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections.withMaxLifetime(long maxLifetimeMs) This property controls the maximum lifetime of a connection in the pool.withMinimumIdle(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.withPoolName(String poolName) Set the name of the connection pool.Set the ScheduledExecutorService used for housekeeping.withThreadFactory(ThreadFactory threadFactory) Set the thread factory to be used to create threads.
-
Method Details
-
create
Create a new DataSource creator.- Type Parameters:
T- database type defined by theSqlType- Parameters:
type- The type of database which is targeted by this data source- Returns:
- a
DataSourceCreatorinJdbcStage.
-
configure
Description copied from interface:JdbcStageconfigure the jdbc builder- Specified by:
configurein interfaceJdbcStage<T extends JdbcConfig<?>>- Parameters:
builder- builder- Returns:
- builder isntance
-
create
Description copied from interface:JdbcStageCreate a configuration with these properties.- Specified by:
createin interfaceJdbcStage<T extends JdbcConfig<?>>- Returns:
- a configuration stage with a configuration with applied properties.
-
withConnectionTimeout
Description copied from interface:ConfigurationStageSet the maximum number of milliseconds that a client will wait for a connection from the pool. If this time is exceeded without a connection becoming available, a SQLException will be thrown fromDataSource.getConnection().- Specified by:
withConnectionTimeoutin interfaceConfigurationStage- Parameters:
connectionTimeoutMs- the connection timeout in milliseconds- Returns:
- Configuration Stage with value set.
-
withIdleTimeout
Description copied from interface:ConfigurationStageThis property controls the maximum amount of time (in milliseconds) that a connection is allowed to sit idle in the pool. Whether a connection is retired as idle or not is subject to a maximum variation of +30 seconds, and average variation of +15 seconds. A connection will never be retired as idle before this timeout. A value of 0 means that idle connections are never removed from the pool.- Specified by:
withIdleTimeoutin interfaceConfigurationStage- Parameters:
idleTimeoutMs- the idle timeout in milliseconds- Returns:
- Configuration Stage with value set.
-
withMaxLifetime
Description copied from interface:ConfigurationStageThis property controls the maximum lifetime of a connection in the pool. When a connection reaches this timeout, even if recently used, it will be retired from the pool. An in-use connection will never be retired, only when it is idle will it be removed.- Specified by:
withMaxLifetimein interfaceConfigurationStage- Parameters:
maxLifetimeMs- the maximum connection lifetime in milliseconds- Returns:
- Configuration Stage with value set.
-
withMaximumPoolSize
Description copied from interface:ConfigurationStageThe property controls the maximum size that the pool is allowed to reach, including both idle and in-use connections. Basically this value will determine the maximum number of actual connections to the database backend.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.
- Specified by:
withMaximumPoolSizein interfaceConfigurationStage- Parameters:
maxPoolSize- the maximum number of connections in the pool- Returns:
- Configuration Stage with value set.
-
withMinimumIdle
Description copied from interface:ConfigurationStageThe property controls the minimum number of idle connections that HikariCP tries to maintain in the pool, including both idle and in-use connections. If the idle connections dip below this value, HikariCP will make a best effort to restore them quickly and efficiently.- Specified by:
withMinimumIdlein interfaceConfigurationStage- Parameters:
minIdle- the minimum number of idle connections in the pool to maintain- Returns:
- Configuration Stage with value set.
-
usingPassword
Description copied from interface:ConfigurationStageSet the default password to use for DataSource.getConnection(username, password) calls.- Specified by:
usingPasswordin interfaceConfigurationStage- Parameters:
password- the password- Returns:
- Configuration Stage with value set.
-
usingUsername
Description copied from interface:ConfigurationStageSet the default username used for DataSource.getConnection(username, password) calls.- Specified by:
usingUsernamein interfaceConfigurationStage- Parameters:
username- the username- Returns:
- Configuration Stage with value set.
-
withDataSourceClassName
Description copied from interface:ConfigurationStageSet the fully qualified class name of the JDBCDataSourcethat will be used create Connections.- Specified by:
withDataSourceClassNamein interfaceConfigurationStage- Parameters:
className- the fully qualified name of the JDBCDataSourceclass- Returns:
- Configuration Stage with value set.
-
withAutoCommit
Description copied from interface:ConfigurationStageSet the default auto-commit behavior of connections in the pool.- Specified by:
withAutoCommitin interfaceConfigurationStage- Parameters:
isAutoCommit- the desired auto-commit default for connections- Returns:
- Configuration Stage with value set.
-
withKeepaliveTime
Description copied from interface:ConfigurationStageThis property controls the keepalive interval for a connection in the pool. An in-use connection will never be tested by the keepalive thread, only when it is idle will it be tested.- Specified by:
withKeepaliveTimein interfaceConfigurationStage- Parameters:
keepaliveTimeMs- the interval in which connections will be tested for aliveness, thus keeping them alive by the act of checking. Value is in milliseconds, default is 0 (disabled).- Returns:
- Configuration Stage with value set.
-
withPoolName
Description copied from interface:ConfigurationStageSet the name of the connection pool. This is primarily used for the MBean to uniquely identify the pool configuration.- Specified by:
withPoolNamein interfaceConfigurationStage- Parameters:
poolName- the name of the connection pool to use- Returns:
- Configuration Stage with value set.
-
withScheduledExecutor
Description copied from interface:ConfigurationStageSet the ScheduledExecutorService used for housekeeping.- Specified by:
withScheduledExecutorin interfaceConfigurationStage- Parameters:
executor- the ScheduledExecutorService- Returns:
- Configuration Stage with value set.
-
forSchema
Description copied from interface:ConfigurationStageSet the default schema name to be set on connections.- Specified by:
forSchemain interfaceConfigurationStage- Parameters:
schema- the name of the default schema- Returns:
- Configuration Stage with value set.
-
withThreadFactory
Description copied from interface:ConfigurationStageSet the thread factory to be used to create threads.- Specified by:
withThreadFactoryin interfaceConfigurationStage- Parameters:
threadFactory- the thread factory (setting to null causes the default thread factory to be used)- Returns:
- Configuration Stage with value set.
-
build
public com.zaxxer.hikari.HikariDataSource build()Description copied from interface:ConfigurationStageCreate a new hikari data source- Specified by:
buildin interfaceConfigurationStage- Returns:
- hikari data source instance
-