Class HikariCPConnectionFactory

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.sql.Wrapper, javax.sql.CommonDataSource, javax.sql.DataSource, ClosableDataSource

    public class HikariCPConnectionFactory
    extends BaseConnectionFactory
    A factory for creating HikariCPConnection objects.
    Author:
    Alejandro Galue
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.slf4j.Logger LOG
      The Constant LOG.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      close
      java.sql.Connection getConnection()  
      java.sql.Connection getConnection​(java.lang.String username, java.lang.String password)  
      javax.sql.DataSource getDataSource()
      getDataSource
      int getLoginTimeout()
      getLoginTimeout
      java.io.PrintWriter getLogWriter()  
      java.util.logging.Logger getParentLogger()  
      java.lang.String getUrl()
      getUrl
      java.lang.String getUser()
      getUser
      protected void initializePool​(JdbcDataSource dataSource)  
      void setIdleTimeout​(int idleTimeout)
      How long, in seconds, an idle connection is kept in the pool before it is removed.
      void setLoginTimeout​(int seconds)
      How long, in seconds, to attempt to make a connection to the database.
      void setLogWriter​(java.io.PrintWriter out)  
      void setMaxLifetime​(int maxLifetimeMs)
      Set the maximum lifetime of the connections in the pool (in milliseconds) which forces occasional connection recycling.
      void setMaxPool​(int maxPool)
      The maximum number of pooled connections to retain.
      void setMaxSize​(int maxSize)
      The maximum number of connections that can be created.
      void setMinPool​(int minPool)
      The minimum number of pooled connections to retain.
      void setUrl​(java.lang.String url)
      setUrl
      void setUser​(java.lang.String user)
      setUser
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface javax.sql.CommonDataSource

        createShardingKeyBuilder
      • Methods inherited from interface javax.sql.DataSource

        createConnectionBuilder
    • Field Detail

      • LOG

        public static final org.slf4j.Logger LOG
        The Constant LOG.
    • Constructor Detail

      • HikariCPConnectionFactory

        public HikariCPConnectionFactory​(JdbcDataSource dataSource)
                                  throws java.beans.PropertyVetoException,
                                         java.sql.SQLException
        Instantiates a new HikariCP connection factory.
        Parameters:
        dataSource - the data source
        Throws:
        java.beans.PropertyVetoException - the property veto exception
        java.sql.SQLException - the SQL exception
    • Method Detail

      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getConnection

        public java.sql.Connection getConnection​(java.lang.String username,
                                                 java.lang.String password)
                                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • getLogWriter

        public java.io.PrintWriter getLogWriter()
                                         throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setLogWriter

        public void setLogWriter​(java.io.PrintWriter out)
                          throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • setLoginTimeout

        public void setLoginTimeout​(int seconds)
                             throws java.sql.SQLException
        Description copied from interface: ClosableDataSource
        How long, in seconds, to attempt to make a connection to the database.
        Throws:
        java.sql.SQLException
      • getLoginTimeout

        public int getLoginTimeout()
                            throws java.sql.SQLException
        Description copied from class: BaseConnectionFactory

        getLoginTimeout

        Specified by:
        getLoginTimeout in interface javax.sql.CommonDataSource
        Specified by:
        getLoginTimeout in interface javax.sql.DataSource
        Specified by:
        getLoginTimeout in class BaseConnectionFactory
        Returns:
        a int.
        Throws:
        java.sql.SQLException - if any.
      • getParentLogger

        public java.util.logging.Logger getParentLogger()
                                                 throws java.sql.SQLFeatureNotSupportedException
        Throws:
        java.sql.SQLFeatureNotSupportedException
      • setIdleTimeout

        public void setIdleTimeout​(int idleTimeout)
        Description copied from interface: ClosableDataSource
        How long, in seconds, an idle connection is kept in the pool before it is removed.
      • setMaxLifetime

        public void setMaxLifetime​(int maxLifetimeMs)
        Set the maximum lifetime of the connections in the pool (in milliseconds) which forces occasional connection recycling. This will probably only be used inside tests although it might be a good idea to do it in production as well to reset server-side query caches and metrics.
        Parameters:
        maxLifetimeMs -
      • setMinPool

        public void setMinPool​(int minPool)
        Description copied from interface: ClosableDataSource
        The minimum number of pooled connections to retain.
      • setMaxPool

        public void setMaxPool​(int maxPool)
        Description copied from interface: ClosableDataSource
        The maximum number of pooled connections to retain.
      • setMaxSize

        public void setMaxSize​(int maxSize)
        Description copied from interface: ClosableDataSource
        The maximum number of connections that can be created.