Class PoolableConnectionFactory

    • Constructor Detail

      • PoolableConnectionFactory

        public PoolableConnectionFactory​(ConnectionFactory connFactory,
                                         javax.management.ObjectName dataSourceJmxObjectName)
        Creates a new PoolableConnectionFactory.
        Parameters:
        connFactory - the ConnectionFactory from which to obtain base Connections
        dataSourceJmxObjectName - The JMX object name, may be null.
    • Method Detail

      • getCacheState

        public boolean getCacheState()
        Gets the cache state.
        Returns:
        The cache state.
        Since:
        Made public in 2.6.0.
      • getConnectionFactory

        public ConnectionFactory getConnectionFactory()
        Gets the connection factory.
        Returns:
        The connection factory.
        Since:
        Made public in 2.6.0.
      • getConnectionIndex

        protected java.util.concurrent.atomic.AtomicLong getConnectionIndex()
      • getConnectionInitSqls

        public java.util.Collection<java.lang.String> getConnectionInitSqls()
        Returns:
        The collection of initialization SQL statements.
        Since:
        2.6.0
      • getDataSourceJmxName

        public javax.management.ObjectName getDataSourceJmxName()
        Returns:
        The data source JMX ObjectName
        Since:
        Made public in 2.6.0.
      • getDataSourceJmxObjectName

        public javax.management.ObjectName getDataSourceJmxObjectName()
        Returns:
        The data source JMS ObjectName.
        Since:
        2.6.0
      • getDefaultAutoCommit

        public java.lang.Boolean getDefaultAutoCommit()
        Returns:
        Default auto-commit value.
        Since:
        2.6.0
      • getDefaultCatalog

        public java.lang.String getDefaultCatalog()
        Returns:
        Default catalog.
        Since:
        2.6.0
      • getDefaultQueryTimeout

        @Deprecated
        public java.lang.Integer getDefaultQueryTimeout()
        Returns:
        Default query timeout in seconds.
      • getDefaultQueryTimeoutDuration

        public java.time.Duration getDefaultQueryTimeoutDuration()
        Gets the default query timeout Duration.
        Returns:
        Default query timeout Duration.
        Since:
        2.10.0
      • getDefaultQueryTimeoutSeconds

        @Deprecated
        public java.lang.Integer getDefaultQueryTimeoutSeconds()
        Returns:
        Default query timeout in seconds.
        Since:
        2.6.0
      • getDefaultReadOnly

        public java.lang.Boolean getDefaultReadOnly()
        Returns:
        Default read-only-value.
        Since:
        2.6.0
      • getDefaultSchema

        public java.lang.String getDefaultSchema()
        Returns:
        Default schema.
        Since:
        2.6.0
      • getDefaultTransactionIsolation

        public int getDefaultTransactionIsolation()
        Returns:
        Default transaction isolation.
        Since:
        2.6.0
      • getDisconnectionSqlCodes

        public java.util.Collection<java.lang.String> getDisconnectionSqlCodes()
        SQL_STATE codes considered to signal fatal conditions.

        Overrides the defaults in Utils.DISCONNECTION_SQL_CODES (plus anything starting with Utils.DISCONNECTION_SQL_CODE_PREFIX). If this property is non-null and isFastFailValidation() is true, whenever connections created by this factory generate exceptions with SQL_STATE codes in this list, they will be marked as "fatally disconnected" and subsequent validations will fail fast (no attempt at isValid or validation query).

        If isFastFailValidation() is false setting this property has no effect.

        Returns:
        SQL_STATE codes overriding defaults
        Since:
        2.1
      • getMaxConnDuration

        public java.time.Duration getMaxConnDuration()
        Gets the Maximum connection duration.
        Returns:
        Maximum connection duration.
        Since:
        2.10.0
      • getMaxConnLifetimeMillis

        public long getMaxConnLifetimeMillis()
        Gets the Maximum connection lifetime in milliseconds.
        Returns:
        Maximum connection lifetime in milliseconds.
        Since:
        2.6.0
      • getMaxOpenPreparedStatements

        protected int getMaxOpenPreparedStatements()
      • getPoolStatements

        public boolean getPoolStatements()
        Returns:
        Whether to pool statements.
        Since:
        Made public in 2.6.0.
      • getValidationQuery

        public java.lang.String getValidationQuery()
        Returns:
        Validation query.
        Since:
        2.6.0
      • getValidationQueryTimeoutDuration

        public java.time.Duration getValidationQueryTimeoutDuration()
        Gets the query timeout in seconds.
        Returns:
        Validation query timeout in seconds.
        Since:
        2.10.0
      • getValidationQueryTimeoutSeconds

        @Deprecated
        public int getValidationQueryTimeoutSeconds()
        Gets the query timeout in seconds.
        Returns:
        Validation query timeout in seconds.
        Since:
        2.6.0
      • initializeConnection

        protected void initializeConnection​(java.sql.Connection conn)
                                     throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • isAutoCommitOnReturn

        public boolean isAutoCommitOnReturn()
        Returns:
        Whether to auto-commit on return.
        Since:
        2.6.0
      • isEnableAutoCommitOnReturn

        @Deprecated
        public boolean isEnableAutoCommitOnReturn()
        Deprecated.
        Returns:
        Whether to auto-commit on return.
      • isFastFailValidation

        public boolean isFastFailValidation()
        True means that validation will fail immediately for connections that have previously thrown SQLExceptions with SQL_STATE indicating fatal disconnection errors.
        Returns:
        true if connections created by this factory will fast fail validation.
        Since:
        2.1, 2.5.0 Defaults to true, previous versions defaulted to false.
        See Also:
        setDisconnectionSqlCodes(Collection)
      • isRollbackOnReturn

        public boolean isRollbackOnReturn()
        Returns:
        Whether to rollback on return.
      • makeObject

        public PooledObject<PoolableConnection> makeObject()
                                                    throws java.lang.Exception
        Description copied from interface: PooledObjectFactory
        Creates an instance that can be served by the pool and wrap it in a PooledObject to be managed by the pool.
        Specified by:
        makeObject in interface PooledObjectFactory<PoolableConnection>
        Returns:
        a PooledObject wrapping an instance that can be served by the pool
        Throws:
        java.lang.Exception - if there is a problem creating a new instance, this will be propagated to the code requesting an object.
      • setAutoCommitOnReturn

        public void setAutoCommitOnReturn​(boolean autoCommitOnReturn)
      • setCacheState

        public void setCacheState​(boolean cacheState)
      • setClearStatementPoolOnReturn

        public void setClearStatementPoolOnReturn​(boolean clearStatementPoolOnReturn)
        Sets whether the pool of statements (which was enabled with setPoolStatements(boolean)) should be cleared when the connection is returned to its pool. Default is false.
        Parameters:
        clearStatementPoolOnReturn - clear or not
        Since:
        2.8.0
      • setConnectionInitSql

        public void setConnectionInitSql​(java.util.Collection<java.lang.String> connectionInitSqls)
        Sets the SQL statements I use to initialize newly created Connections. Using null turns off connection initialization.
        Parameters:
        connectionInitSqls - SQL statement to initialize Connections.
      • setDefaultAutoCommit

        public void setDefaultAutoCommit​(java.lang.Boolean defaultAutoCommit)
        Sets the default "auto commit" setting for borrowed Connections
        Parameters:
        defaultAutoCommit - the default "auto commit" setting for borrowed Connections
      • setDefaultCatalog

        public void setDefaultCatalog​(java.lang.String defaultCatalog)
        Sets the default "catalog" setting for borrowed Connections
        Parameters:
        defaultCatalog - the default "catalog" setting for borrowed Connections
      • setDefaultQueryTimeout

        public void setDefaultQueryTimeout​(java.time.Duration defaultQueryTimeoutDuration)
        Sets the query timeout Duration.
        Parameters:
        defaultQueryTimeoutDuration - the query timeout Duration.
        Since:
        2.10.0
      • setDefaultQueryTimeout

        @Deprecated
        public void setDefaultQueryTimeout​(java.lang.Integer defaultQueryTimeoutSeconds)
        Sets the query timeout in seconds.
        Parameters:
        defaultQueryTimeoutSeconds - the query timeout in seconds.
      • setDefaultReadOnly

        public void setDefaultReadOnly​(java.lang.Boolean defaultReadOnly)
        Sets the default "read only" setting for borrowed Connections
        Parameters:
        defaultReadOnly - the default "read only" setting for borrowed Connections
      • setDefaultSchema

        public void setDefaultSchema​(java.lang.String defaultSchema)
        Sets the default "schema" setting for borrowed Connections
        Parameters:
        defaultSchema - the default "schema" setting for borrowed Connections
        Since:
        2.5.0
      • setDefaultTransactionIsolation

        public void setDefaultTransactionIsolation​(int defaultTransactionIsolation)
        Sets the default "Transaction Isolation" setting for borrowed Connections
        Parameters:
        defaultTransactionIsolation - the default "Transaction Isolation" setting for returned Connections
      • setDisconnectionSqlCodes

        public void setDisconnectionSqlCodes​(java.util.Collection<java.lang.String> disconnectionSqlCodes)
        Parameters:
        disconnectionSqlCodes - The disconnection SQL codes.
        Since:
        2.1
        See Also:
        getDisconnectionSqlCodes()
      • setEnableAutoCommitOnReturn

        @Deprecated
        public void setEnableAutoCommitOnReturn​(boolean autoCommitOnReturn)
        Parameters:
        autoCommitOnReturn - Whether to auto-commit on return.
      • setFastFailValidation

        public void setFastFailValidation​(boolean fastFailValidation)
        Parameters:
        fastFailValidation - true means connections created by this factory will fast fail validation
        Since:
        2.1
        See Also:
        isFastFailValidation()
      • setMaxConn

        public void setMaxConn​(java.time.Duration maxConnDuration)
        Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation. A value of zero or less indicates an infinite lifetime. The default value is -1.
        Parameters:
        maxConnDuration - The maximum lifetime in milliseconds.
        Since:
        2.10.0
      • setMaxConnLifetimeMillis

        @Deprecated
        public void setMaxConnLifetimeMillis​(long maxConnLifetimeMillis)
        Deprecated.
        Sets the maximum lifetime in milliseconds of a connection after which the connection will always fail activation, passivation and validation. A value of zero or less indicates an infinite lifetime. The default value is -1.
        Parameters:
        maxConnLifetimeMillis - The maximum lifetime in milliseconds.
      • setMaxOpenPreparedStatements

        public void setMaxOpenPreparedStatements​(int maxOpenPreparedStatements)
        Sets the maximum number of open prepared statements.
        Parameters:
        maxOpenPreparedStatements - The maximum number of open prepared statements.
      • setMaxOpenPrepatedStatements

        @Deprecated
        public void setMaxOpenPrepatedStatements​(int maxOpenPreparedStatements)
        Deprecated due to typo in method name.
        Parameters:
        maxOpenPreparedStatements - The maximum number of open prepared statements.
      • setPoolStatements

        public void setPoolStatements​(boolean poolStatements)
      • setRollbackOnReturn

        public void setRollbackOnReturn​(boolean rollbackOnReturn)
      • setValidationQuery

        public void setValidationQuery​(java.lang.String validationQuery)
        Sets the query I use to validate Connections. Should return at least one row. If not specified, Connection.isValid(int) will be used to validate connections.
        Parameters:
        validationQuery - a query to use to validate Connections.
      • setValidationQueryTimeout

        public void setValidationQueryTimeout​(java.time.Duration validationQueryTimeoutDuration)
        Sets the validation query timeout, the amount of time, that connection validation will wait for a response from the database when executing a validation query. Use a value less than or equal to 0 for no timeout.
        Parameters:
        validationQueryTimeoutDuration - new validation query timeout duration.
        Since:
        2.10.0
      • setValidationQueryTimeout

        @Deprecated
        public void setValidationQueryTimeout​(int validationQueryTimeoutSeconds)
        Sets the validation query timeout, the amount of time, in seconds, that connection validation will wait for a response from the database when executing a validation query. Use a value less than or equal to 0 for no timeout.
        Parameters:
        validationQueryTimeoutSeconds - new validation query timeout value in seconds
      • validateConnection

        public void validateConnection​(PoolableConnection conn)
                                throws java.sql.SQLException
        Validates the given connection if it is open.
        Parameters:
        conn - the connection to validate.
        Throws:
        java.sql.SQLException - if the connection is closed or validate fails.