Class PoolingDriver

  • All Implemented Interfaces:
    java.sql.Driver

    public class PoolingDriver
    extends java.lang.Object
    implements java.sql.Driver
    A Driver implementation that obtains Connections from a registered ObjectPool.
    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int MAJOR_VERSION  
      protected static int MINOR_VERSION  
      protected static java.util.HashMap<java.lang.String,​ObjectPool<? extends java.sql.Connection>> pools
      The map of registered pools.
      static java.lang.String URL_PREFIX
      My URL prefix
      protected static int URL_PREFIX_LEN  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        PoolingDriver()
      Constructs a new driver with accessToUnderlyingConnectionAllowed enabled.
      protected PoolingDriver​(boolean accessToUnderlyingConnectionAllowed)
      For unit testing purposes.
    • Field Detail

      • pools

        protected static final java.util.HashMap<java.lang.String,​ObjectPool<? extends java.sql.Connection>> pools
        The map of registered pools.
      • URL_PREFIX

        public static final java.lang.String URL_PREFIX
        My URL prefix
        See Also:
        Constant Field Values
      • URL_PREFIX_LEN

        protected static final int URL_PREFIX_LEN
    • Constructor Detail

      • PoolingDriver

        public PoolingDriver()
        Constructs a new driver with accessToUnderlyingConnectionAllowed enabled.
      • PoolingDriver

        protected PoolingDriver​(boolean accessToUnderlyingConnectionAllowed)
        For unit testing purposes.
        Parameters:
        accessToUnderlyingConnectionAllowed - Do DelegatingConnections created by this driver permit access to the delegate?
    • Method Detail

      • acceptsURL

        public boolean acceptsURL​(java.lang.String url)
                           throws java.sql.SQLException
        Specified by:
        acceptsURL in interface java.sql.Driver
        Throws:
        java.sql.SQLException
      • closePool

        public void closePool​(java.lang.String name)
                       throws java.sql.SQLException
        Closes a named pool.
        Parameters:
        name - The pool name.
        Throws:
        java.sql.SQLException - Thrown when a problem is caught closing the pool.
      • connect

        public java.sql.Connection connect​(java.lang.String url,
                                           java.util.Properties info)
                                    throws java.sql.SQLException
        Specified by:
        connect in interface java.sql.Driver
        Throws:
        java.sql.SQLException
      • getConnectionPool

        public ObjectPool<? extends java.sql.Connection> getConnectionPool​(java.lang.String name)
                                                                    throws java.sql.SQLException
        Gets the connection pool for the given name.
        Parameters:
        name - The pool name
        Returns:
        The pool
        Throws:
        java.sql.SQLException - Thrown when the named pool is not registered.
      • getMajorVersion

        public int getMajorVersion()
        Specified by:
        getMajorVersion in interface java.sql.Driver
      • getMinorVersion

        public int getMinorVersion()
        Specified by:
        getMinorVersion in interface java.sql.Driver
      • getParentLogger

        public java.util.logging.Logger getParentLogger()
                                                 throws java.sql.SQLFeatureNotSupportedException
        Specified by:
        getParentLogger in interface java.sql.Driver
        Throws:
        java.sql.SQLFeatureNotSupportedException
      • getPoolNames

        public java.lang.String[] getPoolNames()
        Gets the pool names.
        Returns:
        the pool names.
      • getPropertyInfo

        public java.sql.DriverPropertyInfo[] getPropertyInfo​(java.lang.String url,
                                                             java.util.Properties info)
        Specified by:
        getPropertyInfo in interface java.sql.Driver
      • invalidateConnection

        public void invalidateConnection​(java.sql.Connection conn)
                                  throws java.sql.SQLException
        Invalidates the given connection.
        Parameters:
        conn - connection to invalidate
        Throws:
        java.sql.SQLException - if the connection is not a PoolGuardConnectionWrapper or an error occurs invalidating the connection
      • isAccessToUnderlyingConnectionAllowed

        protected boolean isAccessToUnderlyingConnectionAllowed()
        Returns the value of the accessToUnderlyingConnectionAllowed property.
        Returns:
        true if access to the underlying is allowed, false otherwise.
      • jdbcCompliant

        public boolean jdbcCompliant()
        Specified by:
        jdbcCompliant in interface java.sql.Driver
      • registerPool

        public void registerPool​(java.lang.String name,
                                 ObjectPool<? extends java.sql.Connection> pool)
        Registers a named pool.
        Parameters:
        name - The pool name.
        pool - The pool.