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.
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.
| Modifier and Type | Field and Description |
|---|---|
| private final Stack | |
| private final ConnectionEventListener | connectionEventListener
Notified when a pooled connection is closed, or a fatal error occurs on a pooled connection. |
| protected @Nullable String | |
| protected static ConcurrentMap | |
| private int | |
| private boolean | |
| private boolean | |
| private final ResourceLock | |
| private final Condition | |
| private int | |
| private @Nullable PGConnectionPoolDataSource | |
| private final Stack |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected void | |
| public void | |
| protected PGConnectionPoolDataSource | Returns: appropriate ConnectionPool to use for this DataSourceCreates the appropriate ConnectionPool to use for this DataSource. |
| public Connection | Returns: A pooled connection.the database user on whose behalf the connection is
being made user, @Nullable String the user's password password)Implements javax. Gets a non-pooled connection, unless the user and password are the same as the default values for this connection pool. |
| public Connection | Returns: A pooled connection.Overrides org. Implements javax. Gets a connection from the connection pool. |
| public static @Nullable PGPoolingDataSource | getDataSource(String name)
References Deprecated
PGPoolingDataSource is deprecated or references (maybe indirectly) at least one deprecated element.
|
| public @Nullable String | |
| public String | getDescription()
Implements abstract org. Gets a description of this DataSource. |
| public int | Returns: number of connections that will be created when this DataSource is initializedGets the number of connections that will be created when this DataSource is initialized. |
| public int | Returns: The maximum number of pooled connection allowed, or 0 for no maximum.Gets the maximum number of connections that the pool will allow. |
| private Connection | |
| public Reference | getReference()
Overrides org. Implements javax. Adds custom properties for this DataSource to the properties defined in the superclass. |
| public void | |
| protected boolean | |
| public boolean | isWrapperFor(Class<?>
a Class defining an interface. iface)Implements java. Returns true if this either implements the interface argument or is directly or indirectly a wrapper for an object that does. |
| protected void | |
| public void | setDatabaseName(@Nullable String databaseName)
Ensures the DataSource properties are not changed after the DataSource has been used. |
| public void | |
| public void | setInitialConnections(int
number of initial connections initialConnections)Sets the number of connections that will be created when this DataSource is initialized. |
| public void | setMaxConnections(int
The maximum number of pooled connection to allow, or 0 for no maximum. maxConnections)Sets the maximum number of connections that the pool will allow. |
| public void | setPassword(@Nullable String password)
Ensures the DataSource properties are not changed after the DataSource has been used. |
| public void | setPortNumber(int
port which the PostgreSQL server is listening on for TCP/IP portNumber)Overrides org. Ensures the DataSource properties are not changed after the DataSource has been used. |
| public void | setServerName(String
name of the host the PostgreSQL database is running on serverName)Overrides org. Ensures the DataSource properties are not changed after the DataSource has been used. |
| public void | |
| public <T> T | unwrap(Class<T>
A Class defining an interface that the result must implement. iface)Implements java. Returns an object that implements the given interface to allow access to non-standard methods, or standard methods not exposed by the proxy. |
| available | back to summary |
|---|---|
| private final Stack<PooledConnection> available | |
| connectionEventListener | back to summary |
|---|---|
| private final ConnectionEventListener connectionEventListener Notified when a pooled connection is closed, or a fatal error occurs on a pooled connection. This is the only way connections are marked as unused. | |
| dataSourceName | back to summary |
|---|---|
| protected @Nullable String dataSourceName | |
| dataSources | back to summary |
|---|---|
| protected static ConcurrentMap<String, PGPoolingDataSource> dataSources | |
| initialConnections | back to summary |
|---|---|
| private int initialConnections | |
| initialized | back to summary |
|---|---|
| private boolean initialized | |
| isClosed | back to summary |
|---|---|
| private boolean isClosed | |
| lock | back to summary |
|---|---|
| private final ResourceLock lock | |
| lockCondition | back to summary |
|---|---|
| private final Condition lockCondition | |
| maxConnections | back to summary |
|---|---|
| private int maxConnections | |
| source | back to summary |
|---|---|
| private @Nullable PGConnectionPoolDataSource source | |
| used | back to summary |
|---|---|
| private final Stack<PooledConnection> used | |
| PGPoolingDataSource | back to summary |
|---|---|
| public PGPoolingDataSource() | |
| addDataSource | back to summary |
|---|---|
| protected void addDataSource(String dataSourceName) | |
| close | back to summary |
|---|---|
| public void close() Closes this DataSource, and all the pooled connections, whether in use or not. | |
| createConnectionPool | back to summary |
|---|---|
| protected PGConnectionPoolDataSource createConnectionPool() Creates the appropriate ConnectionPool to use for this DataSource.
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection(@Nullable String user, @Nullable String password) throws SQLException Implements javax. Gets a non-pooled connection, unless the user and password are the same as the default values for this connection pool.
| |
| getConnection | back to summary |
|---|---|
| public Connection getConnection() throws SQLException Overrides org. Implements javax. Gets a connection from the connection pool.
| |
| getDataSource | back to summary |
|---|---|
| public static @Nullable PGPoolingDataSource getDataSource(String name)
References Deprecated
See corresponding docs for further information. | |
| getDataSourceName | back to summary |
|---|---|
| public @Nullable String getDataSourceName() 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. | |
| getDescription | back to summary |
|---|---|
| public String getDescription() Implements abstract org. Gets a description of this DataSource.
| |
| getInitialConnections | back to summary |
|---|---|
| public int getInitialConnections() 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.
| |
| getMaxConnections | back to summary |
|---|---|
| public int getMaxConnections() 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.
| |
| getPooledConnection | back to summary |
|---|---|
| private Connection getPooledConnection() throws SQLException Gets a connection from the pool. Will get an available one if present, or create a new one if under the max limit. Will block if all used and a new one would exceed the max. | |
| getReference | back to summary |
|---|---|
| public Reference getReference() throws NamingException Overrides org. Implements javax. Adds custom properties for this DataSource to the properties defined in the superclass.
| |
| initialize | back to summary |
|---|---|
| public void initialize() throws SQLException 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.
| |
| isInitialized | back to summary |
|---|---|
| protected boolean isInitialized() | |
| isWrapperFor | back to summary |
|---|---|
| public boolean isWrapperFor(Class<?> iface) throws SQLException Implements java. Doc from java. Returns true if this either implements the interface argument or is directly or indirectly a wrapper
for an object that does. Returns false otherwise. If this implements the interface then return true,
else if this is a wrapper then return the result of recursively calling
| |
| removeStoredDataSource | back to summary |
|---|---|
| protected void removeStoredDataSource() | |
| setDatabaseName | back to summary |
|---|---|
| public void setDatabaseName(@Nullable String databaseName) Ensures the DataSource properties are not changed after the DataSource has been used.
| |
| setDataSourceName | back to summary |
|---|---|
| public void setDataSourceName(String dataSourceName) 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.
| |
| setInitialConnections | back to summary |
|---|---|
| public void setInitialConnections(int initialConnections) 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.
| |
| setMaxConnections | back to summary |
|---|---|
| public void setMaxConnections(int maxConnections) 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.
| |
| setPassword | back to summary |
|---|---|
| public void setPassword(@Nullable String password) Ensures the DataSource properties are not changed after the DataSource has been used.
| |
| setPortNumber | back to summary |
|---|---|
| public void setPortNumber(int portNumber) Overrides org. Ensures the DataSource properties are not changed after the DataSource has been used.
| |
| setServerName | back to summary |
|---|---|
| public void setServerName(String serverName) Overrides org. Ensures the DataSource properties are not changed after the DataSource has been used.
| |
| setUser | back to summary |
|---|---|
| public void setUser(@Nullable String user) Ensures the DataSource properties are not changed after the DataSource has been used.
| |
| unwrap | back to summary |
|---|---|
| public <T> T unwrap(Class<T> iface) throws SQLException Implements java. Doc from java. Returns an object that implements the given interface to allow access to
non-standard methods, or standard methods not exposed by the proxy.
If the receiver implements the interface then the result is the receiver
or a proxy for the receiver. If the receiver is a wrapper
and the wrapped object implements the interface then the result is the
wrapped object or a proxy for the wrapped object. Otherwise return the
the result of calling
| |