public class PoolManager extends Object implements ScopeEventListener, DataSource, ConnectionEventListener
| Modifier and Type | Field and Description |
|---|---|
protected String |
dataSourceUrl |
protected String |
jdbcDriver |
static int |
MAX_QUEUE_WAIT
Defines a maximum time in milliseconds that a connection request could wait in the
connection queue.
|
protected int |
maxConnections |
protected int |
minConnections |
protected String |
password |
protected ConnectionPoolDataSource |
poolDataSource |
protected List<PooledConnection> |
unusedPool |
protected List<PooledConnection> |
usedPool |
protected String |
userName |
| Constructor and Description |
|---|
PoolManager(ConnectionPoolDataSource poolDataSource,
int minCons,
int maxCons,
String userName,
String password)
Creates new PoolManager with the specified policy for connection pooling and a
ConnectionPoolDataSource object.
|
PoolManager(String jdbcDriver,
String dataSourceUrl,
int minCons,
int maxCons,
String userName,
String password)
Creates new PoolManager using org.apache.cayenne.conn.PoolDataSource for an
underlying ConnectionPoolDataSource.
|
PoolManager(String jdbcDriver,
String dataSourceUrl,
int minCons,
int maxCons,
String userName,
String password,
JdbcEventLogger logger) |
| Modifier and Type | Method and Description |
|---|---|
void |
beforeScopeEnd()
An implementation of
ScopeEventListener that simply calls
shutdown(). |
protected boolean |
canGrowPool() |
void |
connectionClosed(ConnectionEvent event)
Returns closed connection to the pool.
|
void |
connectionErrorOccurred(ConnectionEvent event)
Removes connection with an error from the pool.
|
void |
dispose()
Deprecated.
since 3.1 replaced with
shutdown() method for naming
consistency. |
protected void |
disposeOfMaintenanceThread() |
Connection |
getConnection()
Returns connection from the pool using internal values of user name and password.
|
Connection |
getConnection(String userName,
String password)
Returns connection from the pool.
|
int |
getCurrentlyInUse()
Returns the number of connections obtained via this DataSource that are currently
in use by the DataSource clients.
|
int |
getCurrentlyUnused()
Returns the number of connections maintained in the pool that are currently not
used by any clients and are available immediately via
getConnection
method. |
String |
getDataSourceUrl()
Returns a database URL used to initialize this pool.
|
String |
getJdbcDriver()
Returns a name of a JDBC driver used to initialize this pool.
|
int |
getLoginTimeout() |
PrintWriter |
getLogWriter() |
int |
getMaxConnections()
Returns maximum number of connections this pool can keep.
|
int |
getMinConnections()
Returns the absolute minimum number of connections allowed in this pool at any
moment in time.
|
Logger |
getParentLogger() |
String |
getPassword()
Returns a data source password used to initialize this pool.
|
int |
getPoolSize()
Returns current number of connections.
|
String |
getUserName()
Returns a data source user name used to initialize this pool.
|
protected int |
growPool(int addConnections,
String userName,
String password)
Increases connection pool by the specified number of connections.
|
protected void |
init(ConnectionPoolDataSource poolDataSource,
int minCons,
int maxCons,
String userName,
String password)
Initializes pool.
|
boolean |
isWrapperFor(Class<?> iface) |
protected PooledConnection |
newPooledConnection(String userName,
String password)
Creates and returns new PooledConnection object, adding itself as a listener for
connection events.
|
void |
setLoginTimeout(int seconds) |
void |
setLogWriter(PrintWriter out) |
void |
setMaxConnections(int maxConnections) |
void |
setMinConnections(int minConnections) |
protected void |
shrinkPool(int closeConnections) |
void |
shutdown()
Closes all existing connections, drains the pool and stops the maintenance thread.
|
protected void |
startMaintenanceThread() |
<T> T |
unwrap(Class<T> iface) |
public static final int MAX_QUEUE_WAIT
protected ConnectionPoolDataSource poolDataSource
protected int minConnections
protected int maxConnections
protected String dataSourceUrl
protected String jdbcDriver
protected String password
protected String userName
protected List<PooledConnection> unusedPool
protected List<PooledConnection> usedPool
public PoolManager(String jdbcDriver, String dataSourceUrl, int minCons, int maxCons, String userName, String password) throws SQLException
SQLExceptionpublic PoolManager(String jdbcDriver, String dataSourceUrl, int minCons, int maxCons, String userName, String password, JdbcEventLogger logger) throws SQLException
SQLExceptionpublic PoolManager(ConnectionPoolDataSource poolDataSource, int minCons, int maxCons, String userName, String password) throws SQLException
poolDataSource - data source for pooled connectionsminCons - Non-negative integer that specifies a minimum number of open
connections to keep in the pool at all timesmaxCons - Non-negative integer that specifies maximum number of simultaneuosly
open connectionsSQLException - if pool manager can not be created.protected void init(ConnectionPoolDataSource poolDataSource, int minCons, int maxCons, String userName, String password) throws SQLException
SQLExceptionprotected void startMaintenanceThread()
protected PooledConnection newPooledConnection(String userName, String password) throws SQLException
SQLException@Deprecated public void dispose() throws SQLException
shutdown() method for naming
consistency.SQLExceptionpublic void shutdown()
throws SQLException
SQLExceptionpublic void beforeScopeEnd()
ScopeEventListener that simply calls
shutdown().beforeScopeEnd in interface ScopeEventListenerprotected void disposeOfMaintenanceThread()
protected boolean canGrowPool()
protected int growPool(int addConnections,
String userName,
String password)
throws SQLException
SQLException - if an error happens when creating a new connection.protected void shrinkPool(int closeConnections)
public int getMaxConnections()
public void setMaxConnections(int maxConnections)
public int getMinConnections()
public void setMinConnections(int minConnections)
public String getDataSourceUrl()
public String getJdbcDriver()
public String getPassword()
public String getUserName()
public int getPoolSize()
public int getCurrentlyInUse()
public int getCurrentlyUnused()
getConnection
method.public Connection getConnection() throws SQLException
ds.getConnection(ds.getUserName(), ds.getPassword())
getConnection in interface DataSourceSQLExceptionpublic Connection getConnection(String userName, String password) throws SQLException
getConnection in interface DataSourceSQLExceptionpublic int getLoginTimeout()
throws SQLException
getLoginTimeout in interface CommonDataSourceSQLExceptionpublic void setLoginTimeout(int seconds)
throws SQLException
setLoginTimeout in interface CommonDataSourceSQLExceptionpublic PrintWriter getLogWriter() throws SQLException
getLogWriter in interface CommonDataSourceSQLExceptionpublic void setLogWriter(PrintWriter out) throws SQLException
setLogWriter in interface CommonDataSourceSQLExceptionpublic void connectionClosed(ConnectionEvent event)
connectionClosed in interface ConnectionEventListenerpublic void connectionErrorOccurred(ConnectionEvent event)
connectionErrorOccurred in interface ConnectionEventListenerpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor in interface WrapperSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap in interface WrapperSQLExceptionpublic Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger in interface CommonDataSourceSQLFeatureNotSupportedExceptionCopyright © 2001–2018 Apache Cayenne. All rights reserved.