|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.postgresql.ds.common.BaseDataSource
org.postgresql.ds.PGPoolingDataSource
public class PGPoolingDataSource
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.
| Field Summary | |
|---|---|
protected String |
dataSourceName
|
protected static ConcurrentMap<String,PGPoolingDataSource> |
dataSources
|
| Constructor Summary | |
|---|---|
PGPoolingDataSource()
|
|
| Method Summary | ||
|---|---|---|
protected void |
addDataSource(String dataSourceName)
|
|
void |
close()
Closes this DataSource, and all the pooled connections, whether in use or not. |
|
protected PGConnectionPoolDataSource |
createConnectionPool()
Creates the appropriate ConnectionPool to use for this DataSource. |
|
Connection |
getConnection()
Gets a connection from the connection pool. |
|
Connection |
getConnection(String user,
String password)
Gets a non-pooled connection, unless the user and password are the same as the default values for this connection pool. |
|
static PGPoolingDataSource |
getDataSource(String name)
|
|
String |
getDataSourceName()
Gets the name of this DataSource. |
|
String |
getDescription()
Gets a description of this DataSource. |
|
int |
getInitialConnections()
Gets the number of connections that will be created when this DataSource is initialized. |
|
int |
getMaxConnections()
Gets the maximum number of connections that the pool will allow. |
|
Logger |
getParentLogger()
|
|
Reference |
getReference()
Adds custom properties for this DataSource to the properties defined in the superclass. |
|
void |
initialize()
Initializes this DataSource. |
|
protected boolean |
isInitialized()
|
|
boolean |
isWrapperFor(Class<?> iface)
|
|
protected void |
removeStoredDataSource()
|
|
void |
setDatabaseName(String databaseName)
Ensures the DataSource properties are not changed after the DataSource has been used. |
|
void |
setDataSourceName(String dataSourceName)
Sets the name of this DataSource. |
|
void |
setInitialConnections(int initialConnections)
Sets the number of connections that will be created when this DataSource is initialized. |
|
void |
setMaxConnections(int maxConnections)
Sets the maximum number of connections that the pool will allow. |
|
void |
setPassword(String password)
Ensures the DataSource properties are not changed after the DataSource has been used. |
|
void |
setPortNumber(int portNumber)
Ensures the DataSource properties are not changed after the DataSource has been used. |
|
void |
setServerName(String serverName)
Ensures the DataSource properties are not changed after the DataSource has been used. |
|
void |
setUser(String user)
Ensures the DataSource properties are not changed after the DataSource has been used. |
|
|
unwrap(Class<T> iface)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface javax.sql.CommonDataSource |
|---|
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter |
| Field Detail |
|---|
protected static ConcurrentMap<String,PGPoolingDataSource> dataSources
protected String dataSourceName
| Constructor Detail |
|---|
public PGPoolingDataSource()
| Method Detail |
|---|
public static PGPoolingDataSource getDataSource(String name)
public String getDescription()
getDescription in class BaseDataSourcepublic void setServerName(String serverName)
setServerName in class BaseDataSourceserverName - name of the host the PostgreSQL database is running on
IllegalStateException - The Server Name cannot be changed after the DataSource has been
used.public void setDatabaseName(String databaseName)
setDatabaseName in class BaseDataSourcedatabaseName - name of the PostgreSQL database
IllegalStateException - The Database Name cannot be changed after the DataSource has been
used.public void setUser(String user)
setUser in class BaseDataSourceuser - user to connect as by default
IllegalStateException - The User cannot be changed after the DataSource has been used.public void setPassword(String password)
setPassword in class BaseDataSourcepassword - password to connect with by default
IllegalStateException - The Password cannot be changed after the DataSource has been
used.public void setPortNumber(int portNumber)
setPortNumber in class BaseDataSourceportNumber - port which the PostgreSQL server is listening on for TCP/IP
IllegalStateException - The Port Number cannot be changed after the DataSource has been
used.public int getInitialConnections()
public void setInitialConnections(int initialConnections)
initialConnections - number of initial connections
IllegalStateException - The Initial Connections cannot be changed after the DataSource
has been used.public int getMaxConnections()
public void setMaxConnections(int maxConnections)
maxConnections - The maximum number of pooled connection to allow, or 0 for no maximum.
IllegalStateException - The Maximum Connections cannot be changed after the DataSource
has been used.public String getDataSourceName()
public void setDataSourceName(String dataSourceName)
dataSourceName - datasource name
IllegalStateException - The Data Source Name cannot be changed after the DataSource has
been used.
IllegalArgumentException - Another PoolingDataSource with the same dataSourceName already
exists.
public void initialize()
throws SQLException
SQLException - Occurs when the initialConnections is greater than zero, but the
DataSource is not able to create enough physical connections.protected boolean isInitialized()
protected PGConnectionPoolDataSource createConnectionPool()
public Connection getConnection(String user,
String password)
throws SQLException
getConnection in interface DataSourcegetConnection in class BaseDataSourceuser - userpassword - password
SQLException - Occurs when no pooled connection is available, and a new physical
connection cannot be created.
public Connection getConnection()
throws SQLException
getConnection in interface DataSourcegetConnection in class BaseDataSourceSQLException - Occurs when no pooled connection is available, and a new physical
connection cannot be created.public void close()
protected void removeStoredDataSource()
protected void addDataSource(String dataSourceName)
public Reference getReference()
throws NamingException
getReference in interface ReferenceablegetReference in class BaseDataSourceNamingException
public boolean isWrapperFor(Class<?> iface)
throws SQLException
isWrapperFor in interface WrapperSQLException
public <T> T unwrap(Class<T> iface)
throws SQLException
unwrap in interface WrapperSQLException
public Logger getParentLogger()
throws SQLFeatureNotSupportedException
SQLFeatureNotSupportedException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||