Class StandardConnectionPool


public class StandardConnectionPool extends ConnectionPool<StandardPooledConnection>
Class that implements the standard ConnectionPool
  • Field Details

  • Constructor Details

    • StandardConnectionPool

      public StandardConnectionPool(String name, String driver, String url, String user, String password, String testStatement, String script, StringGetter parameters, int number) throws ClassNotFoundException
      Creates a StandardConnectionPool with the desired number of connections
      Parameters:
      name - The name of the ConnectionPool. If the name starts with "Service" the pool will be used for the service communication, for example for the StaticView loading.
      driver - The name of the JDBC driver
      url - The address of the database
      user - The username for the database access
      password - The password for the database access
      testStatement - A test command for the database access
      script - Script that will be executed in the connection phase
      parameters - The StringGetter that contains the database parameters
      number - The number of connections of the pool
      Throws:
      ClassNotFoundException - The search for the correct JDBC driver can raise a ClassNotFoundException
  • Method Details

    • getConnectionInfo

      public List<PooledConnectionInfo> getConnectionInfo()
      Returns the informations (see PooledConnectionInfo) about all the connection of the pool
      Specified by:
      getConnectionInfo in class ConnectionPool<StandardPooledConnection>
      Returns:
      The List of PooledConnectionInfo of all the connections
    • isFree

      public boolean isFree(int i)
      Checks if the desired connection is free
      Parameters:
      i - The index that identifies the connection
      Returns:
      true if the connections is free, false otherwise
    • releaseConnection

      public void releaseConnection(StandardPooledConnection spc) throws SQLException
      Releases a connection previously extracted with getConnection()
      Specified by:
      releaseConnection in class ConnectionPool<StandardPooledConnection>
      Parameters:
      spc - The Connection to release
      Throws:
      SQLException - If there is an error during the release, an SQLException will be raised
    • size

      public int size()
      Returns the size of the ConnectionPool, i.e. the number of its connections
      Specified by:
      size in class ConnectionPool<StandardPooledConnection>
      Returns:
      The number of connections of this instance of StandardConnectionPool
    • getMax

      public int getMax()
      Returns the max number of utilized connections
      Returns:
      The max number of utilized connections
    • getDate

      public Date getDate()
      Returns the Date of the max number of utilized connections
      Returns:
      The Date of the max number of utilized connections
    • resetMax

      public void resetMax()
      Resets the max number of utilized connections
    • getConnection

      public StandardPooledConnection getConnection(int i, String activity) throws SQLException
      Extract a free connection from the pool
      Parameters:
      i - The index of the connection to be extracted
      activity - Motivation / operation from which the extract request originates
      Returns:
      A free connection, ready to use
      Throws:
      SQLException - If there is an error during the extraction, an SQLException will be raised
    • getConnection

      public StandardPooledConnection getConnection(String activity) throws SQLException
      Extract a free connection from the pool
      Specified by:
      getConnection in class ConnectionPool<StandardPooledConnection>
      Parameters:
      activity - Motivation / operation from which the extract request originates
      Returns:
      A free connection, ready to use
      Throws:
      SQLException - If there is an error during the extraction, an SQLException will be raised
    • disconnect

      public void disconnect(int i)
      Close a connection
      Parameters:
      i - The index of the connection to be closed
    • dispose

      public void dispose()
      Disposes the StandardConnectionPool. Use this method when the object is no longer needed, for example when the application is closed
      Overrides:
      dispose in class ConnectionPool<StandardPooledConnection>
    • locked

      public int locked()
      Return the number of locked (not free) connections of the pool
      Specified by:
      locked in class ConnectionPool<StandardPooledConnection>
      Returns:
      The number of locked connections