Class CPDSConnectionFactory

    • Field Detail

      • cpds

        private final javax.sql.ConnectionPoolDataSource cpds
      • validationQuery

        private final java.lang.String validationQuery
      • validationQueryTimeoutSeconds

        private final int validationQueryTimeoutSeconds
      • rollbackAfterValidation

        private final boolean rollbackAfterValidation
      • userName

        private final java.lang.String userName
      • userPassword

        private char[] userPassword
      • maxConnLifetimeMillis

        private long maxConnLifetimeMillis
      • validatingSet

        private final java.util.Set<javax.sql.PooledConnection> validatingSet
        Map of PooledConnections for which close events are ignored. Connections are muted when they are being validated.
      • pcMap

        private final java.util.Map<javax.sql.PooledConnection,​PooledConnectionAndInfo> pcMap
        Map of PooledConnectionAndInfo instances
    • Constructor Detail

      • CPDSConnectionFactory

        public CPDSConnectionFactory​(javax.sql.ConnectionPoolDataSource cpds,
                                     java.lang.String validationQuery,
                                     int validationQueryTimeoutSeconds,
                                     boolean rollbackAfterValidation,
                                     java.lang.String userName,
                                     char[] userPassword)
        Creates a new PoolableConnectionFactory.
        Parameters:
        cpds - the ConnectionPoolDataSource from which to obtain PooledConnection's
        validationQuery - a query to use to validate Connections. Should return at least one row. May be null in which case Connection.isValid(int) will be used to validate connections.
        validationQueryTimeoutSeconds - Timeout in seconds before validation fails
        rollbackAfterValidation - whether a rollback should be issued after validating Connections.
        userName - The user name to use to create connections
        userPassword - The password to use to create connections
        Since:
        2.4.0
      • CPDSConnectionFactory

        public CPDSConnectionFactory​(javax.sql.ConnectionPoolDataSource cpds,
                                     java.lang.String validationQuery,
                                     int validationQueryTimeoutSeconds,
                                     boolean rollbackAfterValidation,
                                     java.lang.String userName,
                                     java.lang.String userPassword)
        Creates a new PoolableConnectionFactory.
        Parameters:
        cpds - the ConnectionPoolDataSource from which to obtain PooledConnection's
        validationQuery - a query to use to validate Connections. Should return at least one row. May be null in which case Connection.isValid(int) will be used to validate connections.
        validationQueryTimeoutSeconds - Timeout in seconds before validation fails
        rollbackAfterValidation - whether a rollback should be issued after validating Connections.
        userName - The user name to use to create connections
        userPassword - The password to use to create connections
    • Method Detail

      • getPasswordCharArray

        char[] getPasswordCharArray()
        (Testing API) Gets the value of password for the default user.
        Returns:
        value of password.
      • getPool

        public ObjectPool<PooledConnectionAndInfo> getPool()
        Returns the object pool used to pool connections created by this factory.
        Returns:
        ObjectPool managing pooled connections
      • doDestroyObject

        private void doDestroyObject​(PooledConnectionAndInfo pci)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • connectionClosed

        public void connectionClosed​(javax.sql.ConnectionEvent event)
        This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the user calls the close() method of this connection object. What we need to do here is to release this PooledConnection from our pool...
        Specified by:
        connectionClosed in interface javax.sql.ConnectionEventListener
      • connectionErrorOccurred

        public void connectionErrorOccurred​(javax.sql.ConnectionEvent event)
        If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
        Specified by:
        connectionErrorOccurred in interface javax.sql.ConnectionEventListener
      • invalidate

        public void invalidate​(javax.sql.PooledConnection pc)
                        throws java.sql.SQLException
        Invalidates the PooledConnection in the pool. The CPDSConnectionFactory closes the connection and pool counters are updated appropriately. Also closes the pool. This ensures that all idle connections are closed and connections that are checked out are closed on return.
        Specified by:
        invalidate in interface PooledConnectionManager
        Parameters:
        pc - PooledConnection to be invalidated
        Throws:
        java.sql.SQLException - if an SQL error occurs closing the connection
      • setPassword

        public void setPassword​(char[] userPassword)
        Sets the database password used when creating new connections.
        Parameters:
        userPassword - new password
      • setPassword

        public void setPassword​(java.lang.String userPassword)
        Sets the database password used when creating new connections.
        Specified by:
        setPassword in interface PooledConnectionManager
        Parameters:
        userPassword - new password
      • setMaxConnLifetimeMillis

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

        public void closePool​(java.lang.String userName)
                       throws java.sql.SQLException
        Verifies that the user name matches the user whose connections are being managed by this factory and closes the pool if this is the case; otherwise does nothing.
        Specified by:
        closePool in interface PooledConnectionManager
        Parameters:
        userName - user name
        Throws:
        java.sql.SQLException - if an error occurs closing idle connections in the pool
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Since:
        2.6.0