Class PoolableConnection

    • Field Detail

      • MBEAN_SERVER

        private static javax.management.MBeanServer MBEAN_SERVER
      • validationPreparedStatement

        private java.sql.PreparedStatement validationPreparedStatement
      • lastValidationSql

        private java.lang.String lastValidationSql
      • fatalSqlExceptionThrown

        private boolean fatalSqlExceptionThrown
        Indicate that unrecoverable SQLException was thrown when using this connection. Such a connection should be considered broken and not pass validation in the future.
      • fastFailValidation

        private final boolean fastFailValidation
        Whether or not to fast fail validation after fatal connection errors
    • Constructor Detail

      • PoolableConnection

        public PoolableConnection​(java.sql.Connection conn,
                                  ObjectPool<PoolableConnection> pool,
                                  javax.management.ObjectName jmxObjectName,
                                  java.util.Collection<java.lang.String> disconnectSqlCodes,
                                  boolean fastFailValidation)
        Parameters:
        conn - my underlying connection
        pool - the pool to which I should return when closed
        jmxObjectName - JMX name
        disconnectSqlCodes - SQL_STATE codes considered fatal disconnection errors
        fastFailValidation - true means fatal disconnection errors cause subsequent validations to fail immediately (no attempt to run query or isValid)
      • PoolableConnection

        public PoolableConnection​(java.sql.Connection conn,
                                  ObjectPool<PoolableConnection> pool,
                                  javax.management.ObjectName jmxName)
        Parameters:
        conn - my underlying connection
        pool - the pool to which I should return when closed
        jmxName - JMX name
    • Method Detail

      • passivate

        protected void passivate()
                          throws java.sql.SQLException
        Overrides:
        passivate in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException
      • isClosed

        public boolean isClosed()
                         throws java.sql.SQLException

        This method should not be used by a client to determine whether or not a connection should be return to the connection pool (by calling close()). Clients should always attempt to return a connection to the pool once it is no longer required.

        Specified by:
        isClosed in interface java.sql.Connection
        Specified by:
        isClosed in interface PoolableConnectionMXBean
        Overrides:
        isClosed in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException
      • close

        public void close()
                   throws java.sql.SQLException
        Returns me to my pool.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.sql.Connection
        Specified by:
        close in interface PoolableConnectionMXBean
        Overrides:
        close in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException
      • reallyClose

        public void reallyClose()
                         throws java.sql.SQLException
        Actually close my underlying Connection.
        Specified by:
        reallyClose in interface PoolableConnectionMXBean
        Throws:
        java.sql.SQLException
      • validate

        public void validate​(java.lang.String sql,
                             int timeoutSeconds)
                      throws java.sql.SQLException
        Validates the connection, using the following algorithm:
        1. If fastFailValidation (constructor argument) is true and this connection has previously thrown a fatal disconnection exception, a SQLException is thrown.
        2. If sql is null, the driver's #isValid(timeout) is called. If it returns false, SQLException is thrown; otherwise, this method returns successfully.
        3. If sql is not null, it is executed as a query and if the resulting ResultSet contains at least one row, this method returns successfully. If not, SQLException is thrown.
        Parameters:
        sql - The validation SQL query.
        timeoutSeconds - The validation timeout in seconds.
        Throws:
        java.sql.SQLException - Thrown when validation fails or an SQLException occurs during validation
      • isDisconnectionSqlException

        private boolean isDisconnectionSqlException​(java.sql.SQLException e)
        Checks the SQLState of the input exception and any nested SQLExceptions it wraps.

        If disconnectionSqlCodes has been set, sql states are compared to those in the configured list of fatal exception codes. If this property is not set, codes are compared against the default codes in Utils.DISCONNECTION_SQL_CODES and in this case anything starting with #{link Utils.DISCONNECTION_SQL_CODE_PREFIX} is considered a disconnection.

        Parameters:
        e - SQLException to be examined
        Returns:
        true if the exception signals a disconnection
      • handleException

        protected void handleException​(java.sql.SQLException e)
                                throws java.sql.SQLException
        Overrides:
        handleException in class DelegatingConnection<java.sql.Connection>
        Throws:
        java.sql.SQLException
      • getDisconnectionSqlCodes

        public java.util.Collection<java.lang.String> getDisconnectionSqlCodes()
        Returns:
        The disconnection SQL codes.
        Since:
        2.6.0
      • isFastFailValidation

        public boolean isFastFailValidation()
        Returns:
        Whether to fail-fast.
        Since:
        2.6.0