Class PoolConnectionProvider

  • All Implemented Interfaces:
    IConnectionProvider

    public class PoolConnectionProvider
    extends Object
    implements IConnectionProvider
    Provides a simple connection pool with some thread-local behavior so that requests for a connection within the same thread will get the same connection back. Cooperates with the TransactionFactory to provide a JEE-flavored experience, and makes it easy to write code which will work in both J2SE and JEE environments. Does not support distributed transactions.
    • Field Detail

      • allocated

        int allocated
    • Constructor Detail

      • PoolConnectionProvider

        public PoolConnectionProvider​(IConnectionProvider cp,
                                      int maxPoolSize)
        Public constructor
        Parameters:
        cp -
        maxPoolSize -
    • Method Detail

      • setCloseOnAnyError

        public void setCloseOnAnyError()
        Configure the pool to close connections after an error instead of returning them to the pool. Exceptions related to connection errors will always mark the connection as no longer usable.
      • returnConnection

        protected void returnConnection​(PooledConnection pc,
                                        boolean reuse)
        Called when the connection is closed, which in this case is pretty much a NOP, because this connection will stay active on this thread until the transaction commits
        Parameters:
        pc -
      • clearActiveConnection

        protected void clearActiveConnection()
                                      throws SQLException
        Remove the active connection on this thread. Called when the transaction completes
        Throws:
        SQLException
      • checkConnectionFailure

        protected boolean checkConnectionFailure​(SQLException x)
        Simple check to see if the exception is related to a connection error, in which case the connection shouldn't be returned to the pool when closed
        Parameters:
        x -
        Returns:
      • getTranslator

        public IDatabaseTranslator getTranslator()
        Description copied from interface: IConnectionProvider
        Get the translator associated with this connection provider. Supports interpretation of SQLExceptions and the ability to tweak SQL statements to handle differences between DB2 and Derby
        Specified by:
        getTranslator in interface IConnectionProvider
        Returns:
      • close

        public void close()
        The caller is telling us they no longer need to use the pool so we can free any internal resources. This also let's us check for anything currently in-use that shouldn't be
        Throws:
        IllegalStateException - if there are open connections or a transaction is active.