Class PGPooledConnection

java.lang.Object
org.postgresql.ds.PGPooledConnection
All Implemented Interfaces:
PooledConnection
Direct Known Subclasses:
PGXAConnection

public class PGPooledConnection extends Object implements PooledConnection
PostgreSQL implementation of the PooledConnection interface. This shouldn't be used directly, as the pooling client should just interact with the ConnectionPool instead.
See Also:
  • Field Details

  • Constructor Details

    • PGPooledConnection

      public PGPooledConnection(Connection con, boolean autoCommit, boolean isXA)
      Creates a new PooledConnection representing the specified physical connection.
      Parameters:
      con - connection
      autoCommit - whether to autocommit
      isXA - whether connection is a XA connection
    • PGPooledConnection

      public PGPooledConnection(Connection con, boolean autoCommit)
  • Method Details

    • addConnectionEventListener

      public void addConnectionEventListener(ConnectionEventListener connectionEventListener)
      Adds a listener for close or fatal error events on the connection handed out to a client.
      Specified by:
      addConnectionEventListener in interface PooledConnection
    • removeConnectionEventListener

      public void removeConnectionEventListener(ConnectionEventListener connectionEventListener)
      Removes a listener for close or fatal error events on the connection handed out to a client.
      Specified by:
      removeConnectionEventListener in interface PooledConnection
    • close

      public void close() throws SQLException
      Closes the physical database connection represented by this PooledConnection. If any client has a connection based on this PooledConnection, it is forcibly closed as well.
      Specified by:
      close in interface PooledConnection
      Throws:
      SQLException
    • getConnection

      public Connection getConnection() throws SQLException
      Gets a handle for a client to use. This is a wrapper around the physical connection, so the client can call close and it will just return the connection to the pool without really closing the pgysical connection.

      According to the JDBC 2.0 Optional Package spec (6.2.3), only one client may have an active handle to the connection at a time, so if there is a previous handle active when this is called, the previous one is forcibly closed and its work rolled back.

      Specified by:
      getConnection in interface PooledConnection
      Throws:
      SQLException
    • fireConnectionClosed

      void fireConnectionClosed()
      Used to fire a connection closed event to all listeners.
    • fireConnectionFatalError

      void fireConnectionFatalError(SQLException e)
      Used to fire a connection error event to all listeners.
    • createConnectionEvent

      protected ConnectionEvent createConnectionEvent(SQLException e)
    • isFatalState

      private static boolean isFatalState(String state)
    • fireConnectionError

      private void fireConnectionError(SQLException e)
      Fires a connection error event, but only if we think the exception is fatal.
      Parameters:
      e - the SQLException to consider
    • removeStatementEventListener

      public void removeStatementEventListener(StatementEventListener listener)
      Specified by:
      removeStatementEventListener in interface PooledConnection
    • addStatementEventListener

      public void addStatementEventListener(StatementEventListener listener)
      Specified by:
      addStatementEventListener in interface PooledConnection