Class PGPoolingDataSource

  • All Implemented Interfaces:
    java.sql.Wrapper, javax.naming.Referenceable, javax.sql.CommonDataSource, javax.sql.DataSource
    Direct Known Subclasses:
    Jdbc3PoolingDataSource, PoolingDataSource

    @Deprecated
    public class PGPoolingDataSource
    extends BaseDataSource
    implements javax.sql.DataSource
    Deprecated.
    Since 42.0.0, instead of this class you should use a fully featured connection pool like HikariCP, vibur-dbcp, commons-dbcp, c3p0, etc.
    DataSource which uses connection pooling. Don't use this if your server/middleware vendor provides a connection pooling implementation which interfaces with the PostgreSQL ConnectionPoolDataSource implementation! This class is provided as a convenience, but the JDBC Driver is really not supposed to handle the connection pooling algorithm. Instead, the server or middleware product is supposed to handle the mechanics of connection pooling, and use the PostgreSQL implementation of ConnectionPoolDataSource to provide the connections to pool.

    If you're sure you want to use this, then you must set the properties dataSourceName, databaseName, user, and password (if required for the user). The settings for serverName, portNumber, initialConnections, and maxConnections are optional. Note that only connections for the default user will be pooled! Connections for other users will be normal non-pooled connections, and will not count against the maximum pool size limit.

    If you put this DataSource in JNDI, and access it from different JVMs (or otherwise load this class from different ClassLoaders), you'll end up with one pool per ClassLoader or VM. This is another area where a server-specific implementation may provide advanced features, such as using a single pool across all VMs in a cluster.

    This implementation supports JDK 1.5 and higher.

    Author:
    Aaron Mulder (ammulder@chariotsolutions.com)
    • Field Detail

      • dataSources

        protected static java.util.concurrent.ConcurrentMap<java.lang.String,​PGPoolingDataSource> dataSources
        Deprecated.
      • dataSourceName

        protected java.lang.String dataSourceName
        Deprecated.
    • Constructor Detail

      • PGPoolingDataSource

        public PGPoolingDataSource()
        Deprecated.
    • Method Detail

      • getDataSource

        public static PGPoolingDataSource getDataSource​(java.lang.String name)
        Deprecated.
      • getDescription

        public java.lang.String getDescription()
        Deprecated.
        Gets a description of this DataSource.
        Specified by:
        getDescription in class BaseDataSource
        Returns:
        description of this DataSource-ish thing
      • setServerName

        public void setServerName​(java.lang.String serverName)
        Deprecated.
        Ensures the DataSource properties are not changed after the DataSource has been used.
        Overrides:
        setServerName in class BaseDataSource
        Parameters:
        serverName - name of the host the PostgreSQL database is running on
        Throws:
        java.lang.IllegalStateException - The Server Name cannot be changed after the DataSource has been used.
      • setDatabaseName

        public void setDatabaseName​(java.lang.String databaseName)
        Deprecated.
        Ensures the DataSource properties are not changed after the DataSource has been used.
        Overrides:
        setDatabaseName in class BaseDataSource
        Parameters:
        databaseName - name of the PostgreSQL database
        Throws:
        java.lang.IllegalStateException - The Database Name cannot be changed after the DataSource has been used.
      • setUser

        public void setUser​(java.lang.String user)
        Deprecated.
        Ensures the DataSource properties are not changed after the DataSource has been used.
        Overrides:
        setUser in class BaseDataSource
        Parameters:
        user - user to connect as by default
        Throws:
        java.lang.IllegalStateException - The User cannot be changed after the DataSource has been used.
      • setPassword

        public void setPassword​(java.lang.String password)
        Deprecated.
        Ensures the DataSource properties are not changed after the DataSource has been used.
        Overrides:
        setPassword in class BaseDataSource
        Parameters:
        password - password to connect with by default
        Throws:
        java.lang.IllegalStateException - The Password cannot be changed after the DataSource has been used.
      • setPortNumber

        public void setPortNumber​(int portNumber)
        Deprecated.
        Ensures the DataSource properties are not changed after the DataSource has been used.
        Overrides:
        setPortNumber in class BaseDataSource
        Parameters:
        portNumber - port which the PostgreSQL server is listening on for TCP/IP
        Throws:
        java.lang.IllegalStateException - The Port Number cannot be changed after the DataSource has been used.
      • getInitialConnections

        public int getInitialConnections()
        Deprecated.
        Gets the number of connections that will be created when this DataSource is initialized. If you do not call initialize explicitly, it will be initialized the first time a connection is drawn from it.
        Returns:
        number of connections that will be created when this DataSource is initialized
      • setInitialConnections

        public void setInitialConnections​(int initialConnections)
        Deprecated.
        Sets the number of connections that will be created when this DataSource is initialized. If you do not call initialize explicitly, it will be initialized the first time a connection is drawn from it.
        Parameters:
        initialConnections - number of initial connections
        Throws:
        java.lang.IllegalStateException - The Initial Connections cannot be changed after the DataSource has been used.
      • getMaxConnections

        public int getMaxConnections()
        Deprecated.
        Gets the maximum number of connections that the pool will allow. If a request comes in and this many connections are in use, the request will block until a connection is available. Note that connections for a user other than the default user will not be pooled and don't count against this limit.
        Returns:
        The maximum number of pooled connection allowed, or 0 for no maximum.
      • setMaxConnections

        public void setMaxConnections​(int maxConnections)
        Deprecated.
        Sets the maximum number of connections that the pool will allow. If a request comes in and this many connections are in use, the request will block until a connection is available. Note that connections for a user other than the default user will not be pooled and don't count against this limit.
        Parameters:
        maxConnections - The maximum number of pooled connection to allow, or 0 for no maximum.
        Throws:
        java.lang.IllegalStateException - The Maximum Connections cannot be changed after the DataSource has been used.
      • getDataSourceName

        public java.lang.String getDataSourceName()
        Deprecated.
        Gets the name of this DataSource. This uniquely identifies the DataSource. You cannot use more than one DataSource in the same VM with the same name.
        Returns:
        name of this DataSource
      • setDataSourceName

        public void setDataSourceName​(java.lang.String dataSourceName)
        Deprecated.
        Sets the name of this DataSource. This is required, and uniquely identifies the DataSource. You cannot create or use more than one DataSource in the same VM with the same name.
        Parameters:
        dataSourceName - datasource name
        Throws:
        java.lang.IllegalStateException - The Data Source Name cannot be changed after the DataSource has been used.
        java.lang.IllegalArgumentException - Another PoolingDataSource with the same dataSourceName already exists.
      • initialize

        public void initialize()
                        throws java.sql.SQLException
        Deprecated.
        Initializes this DataSource. If the initialConnections is greater than zero, that number of connections will be created. After this method is called, the DataSource properties cannot be changed. If you do not call this explicitly, it will be called the first time you get a connection from the DataSource.
        Throws:
        java.sql.SQLException - Occurs when the initialConnections is greater than zero, but the DataSource is not able to create enough physical connections.
      • isInitialized

        protected boolean isInitialized()
        Deprecated.
      • createConnectionPool

        protected PGConnectionPoolDataSource createConnectionPool()
        Deprecated.
        Creates the appropriate ConnectionPool to use for this DataSource.
        Returns:
        appropriate ConnectionPool to use for this DataSource
      • getConnection

        public java.sql.Connection getConnection​(java.lang.String user,
                                                 java.lang.String password)
                                          throws java.sql.SQLException
        Deprecated.
        Gets a non-pooled connection, unless the user and password are the same as the default values for this connection pool.
        Specified by:
        getConnection in interface javax.sql.DataSource
        Overrides:
        getConnection in class BaseDataSource
        Parameters:
        user - user
        password - password
        Returns:
        A pooled connection.
        Throws:
        java.sql.SQLException - Occurs when no pooled connection is available, and a new physical connection cannot be created.
      • getConnection

        public java.sql.Connection getConnection()
                                          throws java.sql.SQLException
        Deprecated.
        Gets a connection from the connection pool.
        Specified by:
        getConnection in interface javax.sql.DataSource
        Overrides:
        getConnection in class BaseDataSource
        Returns:
        A pooled connection.
        Throws:
        java.sql.SQLException - Occurs when no pooled connection is available, and a new physical connection cannot be created.
      • close

        public void close()
        Deprecated.
        Closes this DataSource, and all the pooled connections, whether in use or not.
      • removeStoredDataSource

        protected void removeStoredDataSource()
        Deprecated.
      • addDataSource

        protected void addDataSource​(java.lang.String dataSourceName)
        Deprecated.
      • getReference

        public javax.naming.Reference getReference()
                                            throws javax.naming.NamingException
        Deprecated.
        Adds custom properties for this DataSource to the properties defined in the superclass.
        Specified by:
        getReference in interface javax.naming.Referenceable
        Overrides:
        getReference in class BaseDataSource
        Throws:
        javax.naming.NamingException
      • isWrapperFor

        public boolean isWrapperFor​(java.lang.Class<?> iface)
                             throws java.sql.SQLException
        Deprecated.
        Specified by:
        isWrapperFor in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> iface)
                     throws java.sql.SQLException
        Deprecated.
        Specified by:
        unwrap in interface java.sql.Wrapper
        Throws:
        java.sql.SQLException