Class ConnectionPoolManager

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ConnectionPoolManager
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Connection pool used to connect to database using a pre-created set of reusable connections. When a new connection is required, an arbitrary available connection is retrieved from the pool. When connection closed, it is returned to connection pool for future use.
    • Constructor Detail

      • ConnectionPoolManager

        public ConnectionPoolManager​(java.lang.String jdbcUrl,
                                     java.lang.String jdbcUser,
                                     java.lang.String jdbcPassword,
                                     java.util.Properties jdbcProperties,
                                     int initialPoolSize,
                                     int maxPoolSize)
        Constructs ConnectionPoolManager
        Parameters:
        jdbcUrl -
        jdbcUser -
        jdbcPassword -
        initialPoolSize -
        maxPoolSize -
    • Method Detail

      • init

        public void init()
                  throws java.security.NoSuchAlgorithmException,
                         java.security.NoSuchProviderException,
                         java.sql.SQLException,
                         java.io.FileNotFoundException,
                         java.io.IOException
        Initialize ConnectionPoolManager
        Throws:
        java.security.NoSuchAlgorithmException
        java.security.NoSuchProviderException
        java.sql.SQLException
        java.io.FileNotFoundException
        java.io.IOException
      • close

        public void close()
                   throws java.sql.SQLException
        Close ConnectionPoolManager
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.sql.SQLException
      • getConnection

        public DbConnection getConnection()
                                   throws java.sql.SQLException
        Get available connection from pool
        Returns:
        Throws:
        java.sql.SQLException
      • releaseConnection

        public boolean releaseConnection​(DbConnection dbConnection)
                                  throws java.sql.SQLException
        Release connection
        Parameters:
        dbConnection -
        Returns:
        true if connection successfully released
        Throws:
        java.sql.SQLException
      • addNewConnection

        private void addNewConnection()
                               throws java.sql.SQLException
        Add new connection to pool
        Throws:
        java.sql.SQLException