Class PGPooledConnection

  • All Implemented Interfaces:
    javax.sql.PooledConnection
    Direct Known Subclasses:
    PGXAConnection

    public class PGPooledConnection
    extends java.lang.Object
    implements javax.sql.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:
    PGConnectionPoolDataSource
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  PGPooledConnection.ConnectionHandler
      Instead of declaring a class implementing Connection, which would have to be updated for every JDK rev, use a dynamic proxy to handle all calls through the Connection interface.
      private class  PGPooledConnection.StatementHandler
      Instead of declaring classes implementing Statement, PreparedStatement, and CallableStatement, which would have to be updated for every JDK rev, use a dynamic proxy to handle all calls through the Statement interfaces.
    • Constructor Summary

      Constructors 
      Constructor Description
      PGPooledConnection​(java.sql.Connection con, boolean autoCommit)  
      PGPooledConnection​(java.sql.Connection con, boolean autoCommit, boolean isXA)
      Creates a new PooledConnection representing the specified physical connection.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConnectionEventListener​(javax.sql.ConnectionEventListener connectionEventListener)
      Adds a listener for close or fatal error events on the connection handed out to a client.
      void addStatementEventListener​(javax.sql.StatementEventListener listener)  
      void close()
      Closes the physical database connection represented by this PooledConnection.
      protected javax.sql.ConnectionEvent createConnectionEvent​(java.sql.SQLException e)  
      (package private) void fireConnectionClosed()
      Used to fire a connection closed event to all listeners.
      private void fireConnectionError​(java.sql.SQLException e)
      Fires a connection error event, but only if we think the exception is fatal.
      (package private) void fireConnectionFatalError​(java.sql.SQLException e)
      Used to fire a connection error event to all listeners.
      java.sql.Connection getConnection()
      Gets a handle for a client to use.
      private static boolean isFatalState​(java.lang.String state)  
      void removeConnectionEventListener​(javax.sql.ConnectionEventListener connectionEventListener)
      Removes a listener for close or fatal error events on the connection handed out to a client.
      void removeStatementEventListener​(javax.sql.StatementEventListener listener)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • listeners

        private final java.util.List<javax.sql.ConnectionEventListener> listeners
      • con

        private java.sql.Connection con
      • autoCommit

        private final boolean autoCommit
      • isXA

        private final boolean isXA
      • fatalClasses

        private static final java.lang.String[] fatalClasses
    • Constructor Detail

      • PGPooledConnection

        public PGPooledConnection​(java.sql.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​(java.sql.Connection con,
                                  boolean autoCommit)
    • Method Detail

      • addConnectionEventListener

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

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

        public void close()
                   throws java.sql.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 javax.sql.PooledConnection
        Throws:
        java.sql.SQLException
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.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 javax.sql.PooledConnection
        Throws:
        java.sql.SQLException
      • fireConnectionClosed

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

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

        protected javax.sql.ConnectionEvent createConnectionEvent​(java.sql.SQLException e)
      • isFatalState

        private static boolean isFatalState​(java.lang.String state)
      • fireConnectionError

        private void fireConnectionError​(java.sql.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​(javax.sql.StatementEventListener listener)
        Specified by:
        removeStatementEventListener in interface javax.sql.PooledConnection
      • addStatementEventListener

        public void addStatementEventListener​(javax.sql.StatementEventListener listener)
        Specified by:
        addStatementEventListener in interface javax.sql.PooledConnection