Class DataSourceCreator<T extends JdbcConfig<?>>

java.lang.Object
de.chojo.sqlutil.datasource.DataSourceCreator<T>
Type Parameters:
T - database type defined by the SqlType
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 Details

    • create

      public static <T extends JdbcConfig<?>> JdbcStage<T> create(SqlType<T> type)
      Create a new DataSource creator.
      Type Parameters:
      T - database type defined by the SqlType
      Parameters:
      type - The type of database which is targeted by this data source
      Returns:
      a DataSourceCreator in JdbcStage.
    • configure

      public JdbcStage<T> configure(Consumer<T> builder)
      Description copied from interface: JdbcStage
      configure the jdbc builder
      Specified by:
      configure in interface JdbcStage<T extends JdbcConfig<?>>
      Parameters:
      builder - builder
      Returns:
      builder isntance
    • create

      public ConfigurationStage create()
      Description copied from interface: JdbcStage
      Create a configuration with these properties.
      Specified by:
      create in interface JdbcStage<T extends JdbcConfig<?>>
      Returns:
      a configuration stage with a configuration with applied properties.
    • withConnectionTimeout

      public ConfigurationStage withConnectionTimeout(long connectionTimeoutMs)
      Description copied from interface: ConfigurationStage
      Set 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 from DataSource.getConnection().
      Specified by:
      withConnectionTimeout in interface ConfigurationStage
      Parameters:
      connectionTimeoutMs - the connection timeout in milliseconds
      Returns:
      Configuration Stage with value set.
    • withIdleTimeout

      public ConfigurationStage withIdleTimeout(long idleTimeoutMs)
      Description copied from interface: ConfigurationStage
      This 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:
      withIdleTimeout in interface ConfigurationStage
      Parameters:
      idleTimeoutMs - the idle timeout in milliseconds
      Returns:
      Configuration Stage with value set.
    • withMaxLifetime

      public ConfigurationStage withMaxLifetime(long maxLifetimeMs)
      Description copied from interface: ConfigurationStage
      This 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:
      withMaxLifetime in interface ConfigurationStage
      Parameters:
      maxLifetimeMs - the maximum connection lifetime in milliseconds
      Returns:
      Configuration Stage with value set.
    • withMaximumPoolSize

      public ConfigurationStage withMaximumPoolSize(int maxPoolSize)
      Description copied from interface: ConfigurationStage
      The 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:
      withMaximumPoolSize in interface ConfigurationStage
      Parameters:
      maxPoolSize - the maximum number of connections in the pool
      Returns:
      Configuration Stage with value set.
    • withMinimumIdle

      public ConfigurationStage withMinimumIdle(int minIdle)
      Description copied from interface: ConfigurationStage
      The 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:
      withMinimumIdle in interface ConfigurationStage
      Parameters:
      minIdle - the minimum number of idle connections in the pool to maintain
      Returns:
      Configuration Stage with value set.
    • usingPassword

      public ConfigurationStage usingPassword(String password)
      Description copied from interface: ConfigurationStage
      Set the default password to use for DataSource.getConnection(username, password) calls.
      Specified by:
      usingPassword in interface ConfigurationStage
      Parameters:
      password - the password
      Returns:
      Configuration Stage with value set.
    • usingUsername

      public ConfigurationStage usingUsername(String username)
      Description copied from interface: ConfigurationStage
      Set the default username used for DataSource.getConnection(username, password) calls.
      Specified by:
      usingUsername in interface ConfigurationStage
      Parameters:
      username - the username
      Returns:
      Configuration Stage with value set.
    • withDataSourceClassName

      public DataSourceCreator<T> withDataSourceClassName(Class<? extends DataSource> className)
      Description copied from interface: ConfigurationStage
      Set the fully qualified class name of the JDBC DataSource that will be used create Connections.
      Specified by:
      withDataSourceClassName in interface ConfigurationStage
      Parameters:
      className - the fully qualified name of the JDBC DataSource class
      Returns:
      Configuration Stage with value set.
    • withAutoCommit

      public ConfigurationStage withAutoCommit(boolean isAutoCommit)
      Description copied from interface: ConfigurationStage
      Set the default auto-commit behavior of connections in the pool.
      Specified by:
      withAutoCommit in interface ConfigurationStage
      Parameters:
      isAutoCommit - the desired auto-commit default for connections
      Returns:
      Configuration Stage with value set.
    • withKeepaliveTime

      public ConfigurationStage withKeepaliveTime(long keepaliveTimeMs)
      Description copied from interface: ConfigurationStage
      This 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:
      withKeepaliveTime in interface ConfigurationStage
      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

      public ConfigurationStage withPoolName(String poolName)
      Description copied from interface: ConfigurationStage
      Set the name of the connection pool. This is primarily used for the MBean to uniquely identify the pool configuration.
      Specified by:
      withPoolName in interface ConfigurationStage
      Parameters:
      poolName - the name of the connection pool to use
      Returns:
      Configuration Stage with value set.
    • withScheduledExecutor

      public ConfigurationStage withScheduledExecutor(ScheduledExecutorService executor)
      Description copied from interface: ConfigurationStage
      Set the ScheduledExecutorService used for housekeeping.
      Specified by:
      withScheduledExecutor in interface ConfigurationStage
      Parameters:
      executor - the ScheduledExecutorService
      Returns:
      Configuration Stage with value set.
    • forSchema

      public ConfigurationStage forSchema(String schema)
      Description copied from interface: ConfigurationStage
      Set the default schema name to be set on connections.
      Specified by:
      forSchema in interface ConfigurationStage
      Parameters:
      schema - the name of the default schema
      Returns:
      Configuration Stage with value set.
    • withThreadFactory

      public ConfigurationStage withThreadFactory(ThreadFactory threadFactory)
      Description copied from interface: ConfigurationStage
      Set the thread factory to be used to create threads.
      Specified by:
      withThreadFactory in interface ConfigurationStage
      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: ConfigurationStage
      Create a new hikari data source
      Specified by:
      build in interface ConfigurationStage
      Returns:
      hikari data source instance