com.ibm.as400.access

Class AS400JDBCManagedConnectionPoolDataSource

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.sql.Wrapper, javax.naming.Referenceable, javax.sql.CommonDataSource, javax.sql.ConnectionPoolDataSource, javax.sql.DataSource


    public class AS400JDBCManagedConnectionPoolDataSource
    extends AS400JDBCManagedDataSource
    implements javax.sql.ConnectionPoolDataSource, javax.naming.Referenceable, java.io.Serializable
    This implementation of javax.sql.ConnectionPoolDataSource can be used in conjunction with AS400JDBCManagedDataSource to produce PooledConnection objects (AS400JDBCPooledConnection) that are managed by the Toolbox's built-in connection pooling manager.

    A ConnectionPoolDataSource is a factory for PooledConnection objects. An object that implements the ConnectionPoolDataSource interface will typically be registered with a naming service that is based on the Java Naming and Directory Interface (JNDI).

    The operations on a ConnectionPoolDataSource class are completely internal to a driver implementation; the ConnectionPoolDataSource interface is not part of the API typically used by Java application programmers. Driver vendors use it in their implementation of connection pooling. Application programmers specify a DataSource class in their code to get a connection. However, since users/database administrators must register the corresponding ConnectionPoolDataSource with JNDI, the class needs to be public. Users must be able to call the different getters/setters to set up their connection pooling environment when they register the ConnectionPoolDataSource. Drivers then provide DataSource classes that implement javax.sql.DataSource, and the user will use this data source in their code.

    Design note: This class extends AS400JDBCManagedDataSource, solely in order to exploit shared implementation. This class should not be used as a "kind of" AS400JDBCManagedDataSource.

    Caution: To avoid the pitfalls of "double-managed" pools, do not use this class in conjunction with a separate connection pool manager, such as that available in WebSphere. When a separate pool manager is provided, use AS400JDBCConnectionPoolDataSource instead.

    See Also:
    AS400JDBCDataSource, AS400JDBCConnectionPoolDataSource, AS400JDBCXADataSource, Serialized Form
    • Constructor Detail

      • AS400JDBCManagedConnectionPoolDataSource

        public AS400JDBCManagedConnectionPoolDataSource()
        Constructs a default AS400JDBCManagedConnectionPoolDataSource object.
      • AS400JDBCManagedConnectionPoolDataSource

        public AS400JDBCManagedConnectionPoolDataSource(java.lang.String serverName)
        Constructs an AS400JDBCManagedConnectionPoolDataSource with the specified serverName.
        Parameters:
        serverName - The IBM i system name.
      • AS400JDBCManagedConnectionPoolDataSource

        public AS400JDBCManagedConnectionPoolDataSource(java.lang.String serverName,
                                                java.lang.String user,
                                                java.lang.String password)
        Constructs an AS400JDBCManagedConnectionPoolDataSource with the specified signon information.
        Parameters:
        serverName - The IBM i system name.
        user - The user id.
        password - The password.
      • AS400JDBCManagedConnectionPoolDataSource

        public AS400JDBCManagedConnectionPoolDataSource(java.lang.String serverName,
                                                java.lang.String user,
                                                char[] password)
        Constructs an AS400JDBCManagedConnectionPoolDataSource with the specified signon information.
        Parameters:
        serverName - The IBM i system name.
        user - The user id.
        password - The password.
      • AS400JDBCManagedConnectionPoolDataSource

        public AS400JDBCManagedConnectionPoolDataSource(java.lang.String serverName,
                                                java.lang.String user,
                                                java.lang.String password,
                                                java.lang.String keyRingNameX,
                                                java.lang.String keyRingPasswordX)
        Deprecated. 
        Constructs an AS400JDBCManagedConnectionPoolDataSource with the specified signon information to use for SSL communications with the IBM i system.
        Parameters:
        serverName - The IBM i system name.
        user - The user id.
        password - The password.
        keyRingNameX - The key ring class name to be used for SSL communications with the system.
        keyRingPasswordX - The password for the key ring class to be used for SSL communications with the system.
    • Method Detail

      • checkPoolHealth

        public boolean checkPoolHealth(boolean logStatistics)
        Deprecated. Use checkPoolHealth() instead. Refer to the class overview for a discussion of the intended role of this class, and the relationship between this class and its superclass.
        Prints a warning and calls the superclass's method. Users are discouraged from calling this method.
        Overrides:
        checkPoolHealth in class AS400JDBCManagedDataSource
        Parameters:
        logStatistics - If true, additional information is logged.
        Returns:
        true if connection pool exists and appears healthy; false otherwise.
      • closePool

        public void closePool()
        Deprecated. Use closePool() instead. Refer to the class overview for a discussion of the intended role of this class, and the relationship between this class and its superclass.
        Prints a warning and calls the superclass's method. Users are discouraged from calling this method.
        Overrides:
        closePool in class AS400JDBCManagedDataSource
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Deprecated. Use getConnection() instead. Refer to the class overview for a discussion of the intended role of this class, and the relationship between this class and its superclass.
        Prints a warning and calls the superclass's method. Users are discouraged from calling this method.
        Specified by:
        getConnection in interface javax.sql.DataSource
        Overrides:
        getConnection in class AS400JDBCManagedDataSource
        Returns:
        The connection.
        Throws:
        java.sql.SQLException - If a database error occurs.
        See Also:
        AS400JDBCManagedDataSource.setDataSourceName(java.lang.String)
      • getConnection

        public java.sql.Connection getConnection(java.lang.String user,
                                        java.lang.String password)
                                          throws java.sql.SQLException
        Deprecated. Use getConnection() instead. Refer to the class overview for a discussion of the intended role of this class, and the relationship between this class and its superclass.
        Prints a warning and calls the superclass's method. Users are discouraged from calling this method.
        Specified by:
        getConnection in interface javax.sql.DataSource
        Overrides:
        getConnection in class AS400JDBCManagedDataSource
        Parameters:
        user - The database user.
        password - The database password.
        Returns:
        The connection
        Throws:
        java.sql.SQLException - If a database error occurs.
        See Also:
        AS400JDBCManagedDataSource.setDataSourceName(java.lang.String)
      • getInitialPoolSize

        public int getInitialPoolSize()
        Returns the number of physical connections the connection pool should contain when it is created.
        Returns:
        The initial number of pooled connections. The default value is 5.
      • getMaxIdleTime

        public int getMaxIdleTime()
        Returns the amount of time (in seconds) after which an available pooled physical connection is considered "stale" and should be closed. A value of 0 indicates pooled connections are never automatically closed.
        Returns:
        The maximum idle time for a pooled connection, in seconds. The default value is 1 hour.
      • getMaxLifetime

        public int getMaxLifetime()
        Returns the maximum amount of time (in seconds) after which a physical connection is considered to be expired and should be closed. A value of 0 indicates in-use connections are never automatically closed.
        Returns:
        The maximum lifetime for an in-use connection, in seconds. The default value is 24 hours.
      • getMaxPoolSize

        public int getMaxPoolSize()
        Returns the maximum number of physical connections that the connection pool contains. A value of 0 indicates there is no maximum.
        Returns:
        The maximum number of connections in the pool. The default value is 0 (no maximum).
      • getMinPoolSize

        public int getMinPoolSize()
        Returns the minimum number of physical connections that the connection pool contains. A value of 0 indicates there is no minimum and connections are created as they are needed.
        Returns:
        The minimum number of available connections in the pool. The default value is 0.
      • getPooledConnection

        public javax.sql.PooledConnection getPooledConnection()
                                                       throws java.sql.SQLException
        Returns a pooled connection that is connected to the IBM i system.
        Specified by:
        getPooledConnection in interface javax.sql.ConnectionPoolDataSource
        Returns:
        A pooled connection.
        Throws:
        java.sql.SQLException - If a database error occurs.
      • getPooledConnection

        public javax.sql.PooledConnection getPooledConnection(java.lang.String user,
                                                     java.lang.String password)
                                                       throws java.sql.SQLException
        Returns a pooled connection that is connected to the IBM i system.
        Specified by:
        getPooledConnection in interface javax.sql.ConnectionPoolDataSource
        Parameters:
        user - The userid for the connection.
        password - The password for the connection.
        Returns:
        A pooled connection.
        Throws:
        java.sql.SQLException - If a database error occurs.
      • getPooledConnection

        public javax.sql.PooledConnection getPooledConnection(java.lang.String user,
                                                     char[] password)
                                                       throws java.sql.SQLException
        Returns a pooled connection that is connected to the IBM i system.
        Parameters:
        user - The userid for the connection.
        password - The password for the connection.
        Returns:
        A pooled connection.
        Throws:
        java.sql.SQLException - If a database error occurs.
      • getPropertyCycle

        public int getPropertyCycle()
        Returns the interval (in seconds) between runs of the connection pool's maintenance thread. The maintenance thread enforces this pool's connections and statements so that they conform to the specified minimum and maximum pool sizes, idle time, and maximum number of open statements.
        Returns:
        The number of seconds that this pool should wait before enforcing its properties. The default value is 5 minutes.
      • getReference

        public javax.naming.Reference getReference()
                                            throws javax.naming.NamingException
        Returns a Reference object for the data source object. This is used by JNDI when bound in a JNDI naming service. Contains the information necessary to reconstruct the data source object when it is later retrieved from JNDI via an object factory.
        Specified by:
        getReference in interface javax.naming.Referenceable
        Overrides:
        getReference in class AS400JDBCManagedDataSource
        Returns:
        A Reference object for the data source object.
        Throws:
        javax.naming.NamingException - If a naming error occurs resolving the object.
      • isEnforceMaxPoolSize

        public boolean isEnforceMaxPoolSize()
        Indicates whether pool size restriction should be strictly enforced. If set to true, and a connection is requested from the pool when the pool is at its maximum size limit and no connections are available, then an exception will be thrown. If set to false, then a warning will be traced, and a new (unpooled) physical connection will be returned.
        Returns:
        true if the pool size restriction should be strictly enforced; false otherwise. The default value is false.
        See Also:
        setMaxPoolSize(int)
      • isPretestConnections

        public boolean isPretestConnections()
        Indicates whether connections are pretested before being allocated to a requester.
        Returns:
        true if connections are pretested; false otherwise. The default value is false.
      • isReuseConnections

        public boolean isReuseConnections()
        Indicates whether connections are re-used after being returned to the connection pool.
        Returns:
        true if connections may be reused; false if connections are closed after they are returned to the pool. The default value is true.
      • setEnforceMaxPoolSize

        public void setEnforceMaxPoolSize(boolean enforce)
        Sets whether pool size restriction should be strictly enforced. If set to true, and a connection is requested from a full pool with no available connections, then an exception will be thrown. If set to false, then a warning will be traced, and a new (unpooled) physical connection will be returned.
        Parameters:
        enforce - If true, then the pool size restriction should be strictly enforced. The default value is false.
        See Also:
        setMaxPoolSize(int)
      • setInitialPoolSize

        public void setInitialPoolSize(int initialPoolSize)
        Sets the number of connections that the connection pool contains when it is created. If the pool has already been created, this method has no effect.
        Parameters:
        initialPoolSize - The number of pooled connections. Valid values are 0 or greater. The default value is 5.
      • setMaxIdleTime

        public void setMaxIdleTime(int maxIdleTime)
        Sets the maximum amount of time (in seconds) that a pooled connection in this pool is allowed to remain idle before it is automatically closed. A value of 0 indicates pooled connections are never automatically closed.
        Parameters:
        maxIdleTime - The maximum idle time for a pooled connection, in seconds. Valid values are 0 or greater. The default value is 1 hour.
      • setMaxLifetime

        public void setMaxLifetime(int maxLifetime)
        Sets the maximum amount of time (in seconds) after which an in-use physical connection is considered to be expired and should be closed. A value of 0 indicates in-use connections are never automatically closed.
        Parameters:
        maxLifetime - The maximum lifetime for an in-use connection, in seconds. Valid values are 0 or greater. The default value is 24 hours.
      • setMaxPoolSize

        public void setMaxPoolSize(int maxPoolSize)
        Sets the maximum number of connections that the connection pool contains. A value of 0 indicates there is no maximum.
        Parameters:
        maxPoolSize - The maximum number of connections in this pool. Valid values are 0 or greater. The default value is 0 (no maximum).
        See Also:
        setEnforceMaxPoolSize(boolean)
      • setMinPoolSize

        public void setMinPoolSize(int minPoolSize)
        Sets the minimum number of connections that the connection pool contains. A value of 0 indicates there is no minimum and connections are created as they are needed.
        Parameters:
        minPoolSize - The minimum number of available connections in the pool. Valid values are 0 or greater. The default value is 0.
      • setPretestConnections

        public void setPretestConnections(boolean pretest)
        Sets whether connections are pretested before being allocated to requesters.
        Parameters:
        pretest - If true, then connections are pretested; if false, then connections are not pretested. The default value is false.
      • setPropertyCycle

        public void setPropertyCycle(int propertyCycle)
        Sets the interval (in seconds) between runs of the connection pool's maintenance thread. The maintenance thread enforces this pool's connections and statements so that they conform to the specified minimum and maximum pool sizes, idle time, and maximum number of open statements. A value of 0 indicates that a maintenance thread should not be created.
        Parameters:
        propertyCycle - The number of seconds that this pool should wait before enforcing its properties. Valid values are 0 or greater. The default value is 5 minutes.
      • setReuseConnections

        public void setReuseConnections(boolean reuse)
        Sets whether connections may be re-used after being returned to the connection pool.
        Parameters:
        reuse - If true, then connections may be reused; if false, then connections are closed after they are returned to the pool. The default value is true.