Class DatabaseConnectionPool

java.lang.Object
com.kheops.util.KObjectPool
com.kheops.jmap.db.DatabaseConnectionPool
All Implemented Interfaces:
KSchedulerClient
Direct Known Subclasses:
DatabaseNamedConnectionPool

public class DatabaseConnectionPool extends KObjectPool
This class manages a pool of JDBC connections. A pool has an initial size but can automatically grow if necessary. Users of a connection pool use the method borrowConnection to get exclusive use of a database connection and returnConnection to return the connection in the pool and thus make it available for others. Optionally, the connections can be recycled if they are inactive for a certain period of time. This is used with databases that automatically close connections when they are inactive.
  • Field Details

  • Constructor Details

  • Method Details

    • init

      public boolean init(DatabaseConnectionPoolInfo poolInfo, DatabaseConfig databaseConfig)
      Initializes the connection pool with the specified pool info.
      Parameters:
      poolInfo - the DatabaseConnectionPoolInfo instance associated with this DatabaseconnectionPool
      databaseConfig - the database configuration to use with borrowed connections.
      Returns:
      true if no error occurred during the initialization.
      Since:
      6.5
    • create

      public Object create() throws SQLException
      Should not be called.
      Specified by:
      create in class KObjectPool
      Returns:
      a new object (Connection)
      Throws:
      SQLException
    • reset

      public void reset() throws Exception
      Description copied from class: KObjectPool
      This will close and reinitialize the pool.
      Overrides:
      reset in class KObjectPool
      Throws:
      Exception
    • validate

      public boolean validate(Object o)
      Should not be called. Important note : The createStatement test works only with Oracle and mySQL.
      Specified by:
      validate in class KObjectPool
      Parameters:
      o - object (Connection) to validate
      Returns:
      true if valid
    • expire

      public void expire(Object o)
      Should not be called.
      Specified by:
      expire in class KObjectPool
      Parameters:
      o - object (Connection) to close
    • borrowConnection

      public Connection borrowConnection(int sessionId) throws SQLException
      Throws:
      SQLException
    • borrowConnection

      public Connection borrowConnection() throws SQLException
      Borrows a connection from the pool for exclusive use until it is returned by calling the method returnConnection.
      Returns:
      a database connection
      Throws:
      SQLException
    • borrowConnection

      public Connection borrowConnection(long timeout, TimeUnit unit) throws SQLException
      Borrows a connection from the pool for exclusive use until it is returned by calling the method returnConnection.
      Parameters:
      timeout - the maximum time to wait
      unit - the time unit of the timeout argument
      Returns:
      a database connection
      Throws:
      SQLException
    • returnConnection

      public void returnConnection(Connection c)
      Returns a connection to the poll that was obtained using the method borrowConnection. This method MUST ABSOLUTELY be called when the connection not needed anymore otherwise it will stay unavailable for ever for other users.
      Parameters:
      c - the corresponding connection
    • returnConnection

      public void returnConnection(int id, Connection c)
    • getStatus

      public int getStatus()
      Returns:
      the status of this database connection pool
    • setStatus

      protected void setStatus(int status)
      Sets the status of this database connection pool.
    • getId

      protected int getId()
      Overrides:
      getId in class KObjectPool
    • internalErrorOccurred

      protected void internalErrorOccurred(Exception e)
      Overrides:
      internalErrorOccurred in class KObjectPool
    • getLastException

      public Exception getLastException()
      This method returns the last exception thrown.
      Returns:
      the last exception thrown
    • addListener

      public void addListener(DatabaseConnectionPoolListener listener)
    • removeListener

      public void removeListener(DatabaseConnectionPoolListener listener)
    • getDatabaseConnectionPoolInfo

      public DatabaseConnectionPoolInfo getDatabaseConnectionPoolInfo()
    • getCurrentSchema

      public String getCurrentSchema() throws SQLException
      Throws:
      SQLException
    • setDatabaseConfig

      public void setDatabaseConfig(DatabaseConfig databaseConfig)
      Sets the database configuration to be associated with this connection pool.
      Parameters:
      databaseConfig - the database configuration to set.
    • getDatabaseConfig

      public DatabaseConfig getDatabaseConfig()
      Returns the database configuration associated with this connection pool. Note that the returned instance may be null.
      Returns:
      the database configuration associated with this connection pool.
    • getSystemDefaultTimeout

      public long getSystemDefaultTimeout()
      Overrides:
      getSystemDefaultTimeout in class KObjectPool
    • isInactive

      public boolean isInactive()
    • activate

      public void activate()
    • deactivate

      public void deactivate()